pywin32-checkins Mailing List for Python for Windows Extensions (Page 151)
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
(2) |
May
(1) |
Jun
(6) |
Jul
(50) |
Aug
(11) |
Sep
(24) |
Oct
(184) |
Nov
(118) |
Dec
(22) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(31) |
Feb
(25) |
Mar
(34) |
Apr
(105) |
May
(49) |
Jun
(38) |
Jul
(39) |
Aug
(7) |
Sep
(98) |
Oct
(79) |
Nov
(20) |
Dec
(17) |
2005 |
Jan
(66) |
Feb
(32) |
Mar
(43) |
Apr
(30) |
May
(58) |
Jun
(30) |
Jul
(16) |
Aug
(4) |
Sep
(21) |
Oct
(42) |
Nov
(11) |
Dec
(14) |
2006 |
Jan
(42) |
Feb
(30) |
Mar
(22) |
Apr
(1) |
May
(9) |
Jun
(15) |
Jul
(20) |
Aug
(9) |
Sep
(8) |
Oct
(1) |
Nov
(9) |
Dec
(43) |
2007 |
Jan
(52) |
Feb
(45) |
Mar
(20) |
Apr
(12) |
May
(59) |
Jun
(39) |
Jul
(35) |
Aug
(31) |
Sep
(17) |
Oct
(20) |
Nov
(4) |
Dec
(4) |
2008 |
Jan
(28) |
Feb
(111) |
Mar
(4) |
Apr
(27) |
May
(40) |
Jun
(27) |
Jul
(32) |
Aug
(94) |
Sep
(87) |
Oct
(153) |
Nov
(336) |
Dec
(331) |
2009 |
Jan
(298) |
Feb
(127) |
Mar
(20) |
Apr
(8) |
May
|
Jun
(10) |
Jul
(6) |
Aug
|
Sep
(2) |
Oct
(2) |
Nov
|
Dec
(1) |
2010 |
Jan
(7) |
Feb
(1) |
Mar
|
Apr
|
May
(15) |
Jun
(4) |
Jul
(3) |
Aug
(28) |
Sep
(1) |
Oct
(19) |
Nov
(16) |
Dec
(6) |
2011 |
Jan
(2) |
Feb
(18) |
Mar
(17) |
Apr
(12) |
May
(5) |
Jun
(11) |
Jul
(7) |
Aug
(2) |
Sep
(2) |
Oct
(4) |
Nov
(4) |
Dec
|
2012 |
Jan
(6) |
Feb
(2) |
Mar
|
Apr
(8) |
May
(4) |
Jun
(3) |
Jul
(13) |
Aug
(27) |
Sep
(8) |
Oct
(9) |
Nov
(3) |
Dec
(2) |
2013 |
Jan
|
Feb
(1) |
Mar
(5) |
Apr
(10) |
May
|
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(9) |
2014 |
Jan
(2) |
Feb
(4) |
Mar
(4) |
Apr
(1) |
May
(4) |
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
(1) |
2015 |
Jan
(1) |
Feb
|
Mar
|
Apr
(6) |
May
(2) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
2016 |
Jan
(3) |
Feb
(2) |
Mar
|
Apr
(3) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2017 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
From: <mha...@us...> - 2003-10-23 14:14:26
|
Update of /cvsroot/pywin32/pywin32/com/win32com/test In directory sc8-pr-cvs1:/tmp/cvs-serv26852 Modified Files: testExchange.py Log Message: Handle an error when in offline mode. Index: testExchange.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testExchange.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** testExchange.py 18 Nov 2002 11:20:06 -0000 1.4 --- testExchange.py 23 Oct 2003 06:56:17 -0000 1.5 *************** *** 1,3 **** --- 1,6 ---- # TestExchange = Exchange Server Dump + # Note that this code uses "CDO", which is unlikely to get the best choice. + # You should use the Outlook object model, or + # the win32com.mapi examples for a low-level interface. from win32com.client import gencache, constants *************** *** 36,40 **** infostore = infostores[i+1] print "Infostore = ", infostore.Name ! folder = infostore.RootFolder DumpFolder(folder) --- 39,50 ---- infostore = infostores[i+1] print "Infostore = ", infostore.Name ! try: ! folder = infostore.RootFolder ! except pythoncom.com_error, details: ! hr, msg, exc, arg = details ! # -2147221219 == MAPI_E_FAILONEPROVIDER - a single provider temporarily not available. ! if exc and exc[-1]==-2147221219: ! print "This info store is currently not available" ! continue DumpFolder(folder) |
From: <mha...@us...> - 2003-10-23 13:43:50
|
Update of /cvsroot/pywin32/pywin32/com/win32com/src In directory sc8-pr-cvs1:/tmp/cvs-serv20823 Modified Files: ErrorUtils.cpp Log Message: If we fail to write to sys.stderr, fprintf to stderr and restore the Python exception state. Index: ErrorUtils.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/ErrorUtils.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** ErrorUtils.cpp 10 Jan 2003 02:42:46 -0000 1.18 --- ErrorUtils.cpp 23 Oct 2003 06:17:49 -0000 1.19 *************** *** 439,445 **** // PySys_WriteStderr has an internal 1024 limit due to varargs. // weve already resolved them, so we gotta do it the hard way PyObject *pyfile = PySys_GetObject("stderr"); if (pyfile) ! PyFile_WriteString((char *)pszMessageText, pyfile); } --- 439,451 ---- // PySys_WriteStderr has an internal 1024 limit due to varargs. // weve already resolved them, so we gotta do it the hard way + // We can't afford to screw with the Python exception state + PyObject *typ, *val, *tb; + PyErr_Fetch(&typ, &val, &tb); PyObject *pyfile = PySys_GetObject("stderr"); if (pyfile) ! if (PyFile_WriteString((char *)pszMessageText, pyfile)!=0) ! // eeek - Python error writing this error - write it to stdout. ! fprintf(stdout, "%s", pszMessageText); ! PyErr_Restore(typ, val, tb); } |
From: <mha...@us...> - 2003-10-23 12:50:27
|
Update of /cvsroot/pywin32/pywin32/com/win32com/test In directory sc8-pr-cvs1:/tmp/cvs-serv28834 Modified Files: testPyComTest.py Log Message: Ensure our server is registered before testing. Index: testPyComTest.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testPyComTest.py,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** testPyComTest.py 26 Jul 2003 14:13:33 -0000 1.15 --- testPyComTest.py 23 Oct 2003 07:09:05 -0000 1.16 *************** *** 4,8 **** import sys; sys.coinit_flags=0 # Must be free-threaded! import win32api, types, pythoncom, time ! import sys, win32com, win32com.client.connect from win32com.test.util import CheckClean from win32com.client import constants --- 4,8 ---- import sys; sys.coinit_flags=0 # Must be free-threaded! import win32api, types, pythoncom, time ! import sys, os, win32com, win32com.client.connect from win32com.test.util import CheckClean from win32com.client import constants *************** *** 11,14 **** --- 11,19 ---- error = "testPyCOMTest error" + + # This test uses a Python implemented COM server - ensure correctly registered. + from util import RegisterPythonServer + import win32com + RegisterPythonServer(os.path.join(win32com.__path__[0], "servers", "test_pycomtest.py")) from win32com.client import gencache |
From: <mha...@us...> - 2003-10-23 11:49:45
|
Update of /cvsroot/pywin32/pywin32/com/win32com/src/include In directory sc8-pr-cvs1:/tmp/cvs-serv32579/include Modified Files: PythonCOM.h Log Message: Move to the tp_getattro() slot, so we can use PyObject_GenericGetAttr(), so we can get some of the new type benefits, such as the automatic 'next' method on iterators. Start moving towards Python's new tp_base slot in favour of the hand-rolled one we built before Python saw the light :) Index: PythonCOM.h =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/include/PythonCOM.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** PythonCOM.h 6 Oct 2003 13:09:44 -0000 1.10 --- PythonCOM.h 23 Oct 2003 07:34:37 -0000 1.11 *************** *** 178,185 **** static void dealloc(PyObject *ob); static PyObject *repr(PyObject *ob); ! static PyObject *getattr(PyObject *self, char *name); static int setattr(PyObject *op, char *name, PyObject *v); static int cmp(PyObject *ob1, PyObject *ob2); ! static PyObject *iter(PyObject *self); static PyObject *iternext(PyObject *self); }; --- 178,185 ---- static void dealloc(PyObject *ob); static PyObject *repr(PyObject *ob); ! static PyObject *getattro(PyObject *self, PyObject *name); static int setattr(PyObject *op, char *name, PyObject *v); static int cmp(PyObject *ob1, PyObject *ob2); ! static PyObject *iter(PyObject *self) {return PyObject_SelfIter(self);} static PyObject *iternext(PyObject *self); }; |
From: <mha...@us...> - 2003-10-23 11:11:12
|
Update of /cvsroot/pywin32/pywin32/com/win32com/client In directory sc8-pr-cvs1:/tmp/cvs-serv29800 Modified Files: build.py Log Message: Don't let a gen_py created file overwrite a builtin (such as None!) Index: build.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/client/build.py,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** build.py 18 Mar 2003 07:12:10 -0000 1.23 --- build.py 23 Oct 2003 07:15:30 -0000 1.24 *************** *** 495,506 **** # make sure it is a legal (and reasonable!) Python name. def MakePublicAttributeName(className): ! # Given a class attribute that needs to be public, but Python munges ! # convert it. Also need to be careful that the munging doesnt # create duplicates - eg, just removing a leading "_" is likely to cause # a clash. if className[:2]=='__' and className[-2:]!='__': return className[1:] + '_' # First '_' moved at the end. ! elif iskeyword(className): return string.capitalize(className) # Strip non printable chars return filter( lambda char: char in valid_identifier_chars, className) --- 495,514 ---- # make sure it is a legal (and reasonable!) Python name. def MakePublicAttributeName(className): ! # Given a class attribute that needs to be public, convert it to a ! # reasonable name. ! # Also need to be careful that the munging doesnt # create duplicates - eg, just removing a leading "_" is likely to cause # a clash. if className[:2]=='__' and className[-2:]!='__': return className[1:] + '_' # First '_' moved at the end. ! elif iskeyword(className): # all keywords are lower case return string.capitalize(className) + elif __builtins__.has_key(className): + # builtins may be mixed case. If capitalizing it doesn't change it, + # force to all uppercase (eg, "None", "True" become "NONE", "TRUE" + ret = className.capitalize() + if ret==className: # didn't change - force all uppercase. + ret = ret.upper() + return ret # Strip non printable chars return filter( lambda char: char in valid_identifier_chars, className) |
From: <mha...@us...> - 2003-10-23 10:32:52
|
Update of /cvsroot/pywin32/pywin32/com/win32com/test In directory sc8-pr-cvs1:/tmp/cvs-serv28423 Modified Files: util.py Log Message: Utility function for registering a Python server. Index: util.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/util.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** util.py 18 Nov 2002 11:20:07 -0000 1.2 --- util.py 23 Oct 2003 07:05:46 -0000 1.3 *************** *** 1,4 **** ! import sys ! import string from pythoncom import _GetInterfaceCount, _GetGatewayCount --- 1,4 ---- ! import sys, os ! import win32api from pythoncom import _GetInterfaceCount, _GetGatewayCount *************** *** 14,17 **** --- 14,26 ---- print "Warning - %d com gateway objects still alive" % c + def RegisterPythonServer(filename, verbose=0): + cmd = '%s "%s" > nul' % (win32api.GetModuleFileName(0), filename) + if verbose: + print "Registering engine", filename + # print cmd + rc = os.system(cmd) + if rc: + raise RuntimeError, "Registration of engine '%s' failed" % filename + class CaptureWriter: def __init__(self): *************** *** 31,35 **** self.captured.append(msg) def get_captured(self): ! return string.join(self.captured,"") def get_num_lines_captured(self): ! return len(string.split(string.join(self.captured, ""),"\n")) --- 40,44 ---- self.captured.append(msg) def get_captured(self): ! return "".join(self.captured) def get_num_lines_captured(self): ! return len("".join(self.captured).split("\n")) |
From: <mha...@us...> - 2003-10-23 10:21:41
|
Update of /cvsroot/pywin32/pywin32/win32/test In directory sc8-pr-cvs1:/tmp/cvs-serv13409 Added Files: testall.py Log Message: Driver to execute all tests. --- NEW FILE: testall.py --- import sys, os import unittest def suite(): # Loop over all .py files here, except me :) try: me = __file__ except NameError: me = sys.argv[0] files = os.listdir(os.path.dirname(me)) suite = unittest.TestSuite() for file in files: base, ext = os.path.splitext(file) if ext=='.py' and os.path.basename(me) != file: mod = __import__(base) if hasattr(mod, "suite"): test = mod.suite() else: test = unittest.defaultTestLoader.loadTestsFromModule(mod) suite.addTest(test) return suite if __name__=='__main__': unittest.main(argv=sys.argv + ['suite']) |
From: <mha...@us...> - 2003-10-23 10:21:16
|
Update of /cvsroot/pywin32/pywin32/win32/test In directory sc8-pr-cvs1:/tmp/cvs-serv13176 Modified Files: test_win32trace.py Log Message: Allow this to work even when run by an external file, and make some basic cehcks that no other reader is running, as this can cause our tests to hang. Index: test_win32trace.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/test/test_win32trace.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_win32trace.py 31 Aug 2003 04:47:57 -0000 1.2 --- test_win32trace.py 23 Oct 2003 05:16:02 -0000 1.3 *************** *** 6,9 **** --- 6,24 ---- import sys + if __name__=='__main__': + this_file = sys.argv[0] + else: + this_file = __file__ + + def CheckNoOtherWriters(): + win32trace.write("Hi") + time.sleep(0.05) + if win32trace.read() != "Hi": + # Reset everything so following tests still fail with this error!S + win32trace.TermRead() + win32trace.TermWrite() + raise RuntimeError, "An existing win32trace reader appears to be " \ + "running - please stop this process and try again" + class TestInitOps(unittest.TestCase): def tearDown(self): *************** *** 127,130 **** --- 142,146 ---- win32trace.InitRead() win32trace.InitWrite() + CheckNoOtherWriters() self.threads = [WriterThread() for each in range(self.FullBucket)] self.buckets = range(self.BucketCount) *************** *** 196,200 **** procHandle, threadHandle, procId, threadId = win32process.CreateProcess( None, # appName ! 'python.exe %s /run_test_process %s %s' % (sys.argv[0], self.BucketCount, self.threadCount), --- 212,216 ---- procHandle, threadHandle, procId, threadId = win32process.CreateProcess( None, # appName ! 'python.exe %s /run_test_process %s %s' % (this_file, self.BucketCount, self.threadCount), |
From: <mha...@us...> - 2003-10-23 09:24:14
|
Update of /cvsroot/pywin32/pywin32/com/win32com/src In directory sc8-pr-cvs1:/tmp/cvs-serv31815 Modified Files: PyIUnknown.cpp Log Message: Fix the message when we capture a win32 exception, to make it a) clearer who is printing it, and b) so it fits on one line and doesn't imply a refcount bug when there is no evidence that is what it is (that is but one reason - another common one is pythoncom.CoUninitialize() called while before the otherwise valid reference is released. Index: PyIUnknown.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/PyIUnknown.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PyIUnknown.cpp 10 Jan 2003 02:37:34 -0000 1.6 --- PyIUnknown.cpp 23 Oct 2003 07:29:40 -0000 1.7 *************** *** 152,157 **** { PyEval_RestoreThread(_save); ! LogF(_T("Exception occured:\n\tTry to release object at address 0x%08x\n\twhich was already destroyed"), ob->m_obj); ob->m_obj = NULL; return; } --- 152,160 ---- { PyEval_RestoreThread(_save); ! LogF(_T("Win32 exception occurred releasing IUnknown at 0x%08x"), ob->m_obj); ob->m_obj = NULL; + #ifdef _DEBUG + DebugBreak(); + #endif return; } |
From: <mha...@us...> - 2003-10-23 07:38:11
|
Update of /cvsroot/pywin32/pywin32/com/win32com/test In directory sc8-pr-cvs1:/tmp/cvs-serv28498 Modified Files: testvb.py Log Message: Add some enumerator tests. Index: testvb.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testvb.py,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** testvb.py 20 Oct 2003 10:01:45 -0000 1.14 --- testvb.py 23 Oct 2003 07:06:27 -0000 1.15 *************** *** 233,236 **** --- 233,256 ---- if check != list(expected): raise error, "Collection %s didn't have %r (had %r)" % (col_name, expected, check) + # Just looping over the collection again works (ie, is restartable) + check = [] + for item in c: + check.append(item) + if check != list(expected): + raise error, "Collection 2nd time around %s didn't have %r (had %r)" % (col_name, expected, check) + # Check we can get it via iter() + i = iter(getattr(vbtest, col_name)) + check = [] + for item in i: + check.append(item) + if check != list(expected): + raise error, "Collection iterator %s didn't have %r 2nd time around (had %r)" % (col_name, expected, check) + # but an iterator is not restartable + check = [] + for item in i: + check.append(item) + if check != []: + raise error, "2nd time around Collection iterator %s wasn't empty (had %r)" % (col_name, check) + # Check len()==Count() c = getattr(vbtest, col_name) |
From: <mha...@us...> - 2003-10-23 07:37:39
|
Update of /cvsroot/pywin32/pywin32/com/win32com/test In directory sc8-pr-cvs1:/tmp/cvs-serv28696 Modified Files: testmakepy.py Log Message: Quieten down some errors, and report how many we generated. Index: testmakepy.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testmakepy.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** testmakepy.py 18 Nov 2002 11:20:07 -0000 1.2 --- testmakepy.py 23 Oct 2003 07:08:18 -0000 1.3 *************** *** 12,17 **** --- 12,19 ---- from win32com.client import makepy, selecttlb import pythoncom + import winerror def TestBuildAll(verbose = 1): + num = 0 tlbInfos = selecttlb.EnumTlbs() for info in tlbInfos: *************** *** 20,27 **** try: makepy.GenerateFromTypeLibSpec(info) except pythoncom.com_error, details: ! ! print "COM error on", info.desc ! print details except KeyboardInterrupt: print "Interrupted!" --- 22,33 ---- try: makepy.GenerateFromTypeLibSpec(info) + num += 1 except pythoncom.com_error, details: ! # Ignore these 2 errors, as the are very common and can obscure ! # useful warnings. ! if details[0] not in [winerror.TYPE_E_CANTLOADLIBRARY, ! winerror.TYPE_E_LIBNOTREGISTERED]: ! print "** COM error on", info.desc ! print details except KeyboardInterrupt: print "Interrupted!" *************** *** 30,37 **** print "Failed:", info.desc traceback.print_exc() ! def TestAll(verbose = 0): ! TestBuildAll(verbose) win32com.test.util.CheckClean() --- 36,44 ---- print "Failed:", info.desc traceback.print_exc() ! return num def TestAll(verbose = 0): ! num = TestBuildAll(verbose) ! print "Generated and imported", num, "modules" win32com.test.util.CheckClean() |
From: <mha...@us...> - 2003-10-23 07:34:07
|
Update of /cvsroot/pywin32/pywin32/com/win32com/client In directory sc8-pr-cvs1:/tmp/cvs-serv29566 Modified Files: util.py Log Message: Add an Iterator class, which is used whenever Python wants an Iterator (the Enumerator is still used when Python tried indexed access) Index: util.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/client/util.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** util.py 1 Sep 1999 22:58:56 -0000 1.1 --- util.py 23 Oct 2003 07:14:19 -0000 1.2 *************** *** 5,9 **** """ import pythoncom ! from win32com.client import Dispatch PyIDispatchType = pythoncom.TypeIIDs[pythoncom.IID_IDispatch] --- 5,9 ---- """ import pythoncom ! from win32com.client import Dispatch, _get_good_object_ PyIDispatchType = pythoncom.TypeIIDs[pythoncom.IID_IDispatch] *************** *** 57,61 **** def Next(self, count=1): ret = self._oleobj_.Next(count) - if ret is None: return None realRets = [] for r in ret: --- 57,60 ---- *************** *** 74,79 **** Enumerator.__init__(self, enum) def _make_retval_(self, result): ! if type(result)==PyIDispatchType: ! result = Dispatch(result, resultCLSID = self.resultCLSID) ! return result --- 73,83 ---- Enumerator.__init__(self, enum) def _make_retval_(self, result): ! return _get_good_object_(result, resultCLSID = self.resultCLSID) + class Iterator: + def __init__(self, enum): + self._iter_ = iter(enum.QueryInterface(pythoncom.IID_IEnumVARIANT)) + def __iter__(self): + return self + def next(self): + return _get_good_object_(self._iter_.next()) |
From: <mha...@us...> - 2003-10-23 07:26:51
|
Update of /cvsroot/pywin32/pywin32/com/win32com/client In directory sc8-pr-cvs1:/tmp/cvs-serv30563 Modified Files: dynamic.py Log Message: Previously, dynamic objects only supported enumeration if there was a method named _NewEnum() - now we always try and invoke with DISPID_NEWENUM. Also add __iter__ support for these objects Index: dynamic.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/client/dynamic.py,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** dynamic.py 2 Jul 2003 03:43:13 -0000 1.18 --- dynamic.py 23 Oct 2003 07:21:53 -0000 1.19 *************** *** 188,196 **** def _NewEnum(self): ! invkind, dispid = self._find_dispatch_type_("_NewEnum") ! if invkind is None: ! return None ! ! enum = self._oleobj_.InvokeTypes(pythoncom.DISPID_NEWENUM,LCID,invkind,(13, 10),()) import util return util.WrapEnum(enum, None) --- 188,196 ---- def _NewEnum(self): ! try: ! invkind = pythoncom.DISPATCH_METHOD | pythoncom.DISPATCH_PROPERTYGET ! enum = self._oleobj_.InvokeTypes(pythoncom.DISPID_NEWENUM,LCID,invkind,(13, 10),()) ! except pythoncom.com_error: ! return None # no enumerator for this object. import util return util.WrapEnum(enum, None) *************** *** 396,399 **** --- 396,416 ---- def __getattr__(self, attr): + if attr=='__iter__': + # We can't handle this as a normal method, as if the attribute + # exists, then it must return an iterable object. + try: + invkind = pythoncom.DISPATCH_METHOD | pythoncom.DISPATCH_PROPERTYGET + enum = self._oleobj_.InvokeTypes(pythoncom.DISPID_NEWENUM,LCID,invkind,(13, 10),()) + except pythoncom.com_error: + raise AttributeError, "This object can not function as an iterator" + # We must return a callable object. + class Factory: + def __init__(self, ob): + self.ob = ob + def __call__(self): + import win32com.client.util + return win32com.client.util.Iterator(self.ob) + return Factory(enum) + if attr[0]=='_' and attr[-1]=='_': # Fast-track. raise AttributeError, attr |
From: <mha...@us...> - 2003-10-23 07:22:44
|
Update of /cvsroot/pywin32/pywin32/com/win32com/client In directory sc8-pr-cvs1:/tmp/cvs-serv30458 Modified Files: genpy.py Log Message: Add __iter__ support for objects with enumerators Index: genpy.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/client/genpy.py,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** genpy.py 26 Jul 2003 00:52:14 -0000 1.33 --- genpy.py 23 Oct 2003 07:19:15 -0000 1.34 *************** *** 24,28 **** error = "makepy.error" ! makepy_version = "0.4.6" # Written to generated file. GEN_FULL="full" --- 24,28 ---- error = "makepy.error" ! makepy_version = "0.4.7" # Written to generated file. GEN_FULL="full" *************** *** 484,487 **** --- 484,494 ---- if resultCLSID == "None" and self.mapFuncs.has_key("Item"): resultCLSID = self.mapFuncs["Item"].GetResultCLSIDStr() + # "Native" Python iterator support + print '\tdef __iter__(self):' + print '\t\t"Return a Python iterator for this object"' + print '\t\tob = self._oleobj_.InvokeTypes(%d,LCID,%d,(13, 10),())' % (pythoncom.DISPID_NEWENUM, enumEntry.desc[4]) + print '\t\treturn win32com.client.util.Iterator(ob)' + # And 'old style' iterator support - magically used to simulate iterators + # before Python grew them print '\tdef _NewEnum(self):' print '\t\t"Create an enumerator from this object"' |
From: <mha...@us...> - 2003-10-23 06:34:41
|
Update of /cvsroot/pywin32/pywin32/com/win32com/test In directory sc8-pr-cvs1:/tmp/cvs-serv22188 Added Files: testIterators.py Log Message: test iterator semantics. --- NEW FILE: testIterators.py --- from __future__ import generators # Some raw iter tests. Some "high-level" iterator tests can be found in # testvb.py and testOutlook.py import sys import unittest from win32com.client.gencache import EnsureDispatch import pythoncom def yield_iter(iter): while 1: yield iter.next() class _BaseTestCase(unittest.TestCase): def test_enumvariant_vb(self): ob, iter = self.iter_factory() num=0 for v in iter: num += 1 self.failUnless(num==self.expected_length, "didnt get the %d items (got %d)" % (self.expected_length, num)) def test_yield(self): ob, i = self.iter_factory() num=0 for v in yield_iter(iter(i)): num += 1 self.failUnless(num==self.expected_length, "didnt get the %d items (got %d)" % (self.expected_length, num)) def test_nonenum(self): try: for i in self.object: pass self.fail("Could iterate over a non-iterable object") except TypeError: pass # this is expected. self.assertRaises(TypeError, iter, self.object) self.assertRaises(AttributeError, getattr, self.object, "next") class VBTestCase(_BaseTestCase): def setUp(self): def factory(): # Our VB test harness exposes a property with IEnumVariant. ob = self.object.EnumerableCollectionProperty ob.Add(1) ob.Add("Two") ob.Add("3") # Get the raw IEnumVARIANT. invkind = pythoncom.DISPATCH_METHOD | pythoncom.DISPATCH_PROPERTYGET iter = ob._oleobj_.InvokeTypes(pythoncom.DISPID_NEWENUM,0,invkind,(13, 10),()) return ob, iter.QueryInterface(pythoncom.IID_IEnumVARIANT) # We *need* generated dispatch semantics, so dynamic __getitem__ etc # don't get in the way of our tests. self.object = EnsureDispatch("PyCOMVBTest.Tester") self.iter_factory = factory self.expected_length = 3 def tearDown(self): self.object = None def suite(): # We dont want our base class run suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(VBTestCase)) return suite if __name__=='__main__': unittest.main(argv=sys.argv + ['suite']) |
From: <mha...@us...> - 2003-10-23 04:15:11
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1:/tmp/cvs-serv5403 Modified Files: PyHANDLE.cpp Log Message: Fix up handle error semantics when destructing. This makes the handles.py test case work again. Index: PyHANDLE.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/PyHANDLE.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PyHANDLE.cpp 2 May 2003 00:07:38 -0000 1.6 --- PyHANDLE.cpp 23 Oct 2003 04:11:39 -0000 1.7 *************** *** 53,57 **** PyWin_SetAPIError("CloseHandle"); } else { ! PyErr_SetString(PyExc_TypeError, "A handle must be a HANDLE object or an integer"); return FALSE; } --- 53,57 ---- PyWin_SetAPIError("CloseHandle"); } else { ! PyErr_Format(PyExc_TypeError, "A handle must be a HANDLE object or an integer (got %s)", obHandle->ob_type->tp_name); return FALSE; } *************** *** 350,359 **** /*static*/ void PyHANDLE::deallocFunc(PyObject *ob) { ! // Python will print a strange message if we leave pending exceptions in destructors, ! // but we don't want to supress exceptions as generally that is evil (supressing ! // ours is bad enough, but supressing existing ones is nasty). ! // For now, we call it a Python bug that the message is printed. ((PyHANDLE *)ob)->Close(); delete (PyHANDLE *)ob; } --- 350,365 ---- /*static*/ void PyHANDLE::deallocFunc(PyObject *ob) { ! // This can be delicate. Setting an exception in a destructor is evil ! // (as it will cause gc to die with a fatal error, and if that doesn't ! // happen, make unrelated code appear to fail with the exception.) ! // Clearing any existing exceptions that may be set is also evil, as ! // we may be destructing as part of unwinding the stack handling an ! // existing exception. Therefore, we "push" any existing exception ! // contexts, and restoring it clobbers any we raise. ! PyObject *typ, *val, *tb; ! PyErr_Fetch(&typ, &val, &tb); ((PyHANDLE *)ob)->Close(); delete (PyHANDLE *)ob; + PyErr_Restore(typ, val, tb); } |
From: <mha...@us...> - 2003-10-23 03:51:23
|
Update of /cvsroot/pywin32/pywin32/com/win32com/src/include In directory sc8-pr-cvs1:/tmp/cvs-serv25500/include Modified Files: PyIEnumFORMATETC.h Log Message: Don't ask subclasses to provide iter() - we manage that. Index: PyIEnumFORMATETC.h =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/include/PyIEnumFORMATETC.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PyIEnumFORMATETC.h 8 Oct 2003 04:28:42 -0000 1.1 --- PyIEnumFORMATETC.h 23 Oct 2003 02:44:12 -0000 1.2 *************** *** 12,16 **** static PyComTypeObject type; - virtual PyObject *iter(); virtual PyObject *iternext(); --- 12,15 ---- |
From: <mha...@us...> - 2003-10-23 03:45:45
|
Update of /cvsroot/pywin32/pywin32/com/win32com/test In directory sc8-pr-cvs1:/tmp/cvs-serv26577 Removed Files: testuniv.py Log Message: Delete old test file that never ran --- testuniv.py DELETED --- |
From: <mha...@us...> - 2003-10-23 02:50:29
|
Update of /cvsroot/pywin32/pywin32/com/win32com/src/extensions In directory sc8-pr-cvs1:/tmp/cvs-serv25500/extensions Modified Files: PyIEnumFORMATETC.cpp Log Message: Don't ask subclasses to provide iter() - we manage that. Index: PyIEnumFORMATETC.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/extensions/PyIEnumFORMATETC.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PyIEnumFORMATETC.cpp 8 Oct 2003 04:28:42 -0000 1.1 --- PyIEnumFORMATETC.cpp 23 Oct 2003 02:44:12 -0000 1.2 *************** *** 30,39 **** } - PyObject * - PyIEnumFORMATETC::iter() - { - Py_INCREF(this); - return this; - } PyObject * --- 30,33 ---- |
From: <mha...@us...> - 2003-10-23 02:33:38
|
Update of /cvsroot/pywin32/pywin32/win32/test In directory sc8-pr-cvs1:/tmp/cvs-serv14178 Modified Files: test_win32api.py Log Message: Add simple tests for GetShortPathName, GetLongPathName and GetLongPathNameW Index: test_win32api.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/test/test_win32api.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** test_win32api.py 18 Oct 2003 05:56:27 -0000 1.4 --- test_win32api.py 23 Oct 2003 01:21:09 -0000 1.5 *************** *** 4,7 **** --- 4,8 ---- import win32api, win32con, win32event + import sys, os class CurrentUserTestCase(unittest.TestCase): *************** *** 62,65 **** --- 63,82 ---- ret_code=win32event.WaitForSingleObject(evt,0) self.failUnless(ret_code==win32con.WAIT_OBJECT_0) + + class FileNames(unittest.TestCase): + def testShortLongPathNames(self): + try: + me = __file__ + except NameError: + me = sys.argv[0] + fname = os.path.abspath(me) + short_name = win32api.GetShortPathName(fname) + long_name = win32api.GetLongPathName(short_name) + self.failUnless(long_name==fname, \ + "Expected long name ('%s') to be original name ('%s')" % (long_name, fname)) + long_name = win32api.GetLongPathNameW(short_name) + self.failUnless(type(long_name)==unicode, "GetLongPathNameW returned type '%s'" % (type(long_name),)) + self.failUnless(long_name==fname, \ + "Expected long name ('%s') to be original name ('%s')" % (long_name, fname)) if __name__ == '__main__': |
From: <mha...@us...> - 2003-10-23 02:07:47
|
Update of /cvsroot/pywin32/pywin32/win32 In directory sc8-pr-cvs1:/tmp/cvs-serv14301 Modified Files: win32api.dsp Log Message: Add version.lib to the project. Index: win32api.dsp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/win32api.dsp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** win32api.dsp 2 Mar 2000 10:23:15 -0000 1.2 --- win32api.dsp 23 Oct 2003 01:21:59 -0000 1.3 *************** *** 55,59 **** LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 ! # ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x1e200000" /subsystem:windows /dll /debug /machine:I386 /out:"Build\win32api.pyd" /libpath:"Build" # SUBTRACT LINK32 /pdb:none --- 55,59 ---- LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 ! # ADD LINK32 version.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x1e200000" /subsystem:windows /dll /debug /machine:I386 /out:"Build\win32api.pyd" /libpath:"Build" # SUBTRACT LINK32 /pdb:none *************** *** 83,87 **** LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept ! # ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x1e200000" /subsystem:windows /dll /debug /machine:I386 /out:"Build\win32api_d.pyd" /pdbtype:sept /libpath:"Build" !ENDIF --- 83,87 ---- LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept ! # ADD LINK32 version.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x1e200000" /subsystem:windows /dll /debug /machine:I386 /out:"Build\win32api_d.pyd" /pdbtype:sept /libpath:"Build" !ENDIF |
From: <mha...@us...> - 2003-10-23 01:53:20
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1:/tmp/cvs-serv13992 Modified Files: win32apimodule.cpp Log Message: Added GetLongPathName and GetLongPAthNameW Index: win32apimodule.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32apimodule.cpp,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** win32apimodule.cpp 21 Oct 2003 02:06:45 -0000 1.27 --- win32apimodule.cpp 23 Oct 2003 01:20:20 -0000 1.28 *************** *** 38,41 **** --- 38,43 ---- static BOOL (WINAPI *myGetUserNameEx)(EXTENDED_NAME_FORMAT, LPWSTR, PULONG)=NULL; + static BOOL (WINAPI *myGetLongPathNameA)(LPCSTR, LPSTR, DWORD)=NULL; + static BOOL (WINAPI *myGetLongPathNameW)(LPCWSTR, LPWSTR, DWORD)=NULL; /* error helper */ *************** *** 1572,1575 **** --- 1574,1624 ---- } + // @pymethod string|win32api|GetLongPathName|Converts the specified path to its long form. + static PyObject * + PyGetLongPathNameA (PyObject *self, PyObject *args) + { + char pathBuf[MAX_PATH]; + char *fileName; + if (!myGetLongPathNameA) + PyErr_SetString(PyExc_NotImplementedError, "GetLongPathNameA does not exist in this version of Windows"); + // @pyparm string|fileName||The file name. + if (!PyArg_ParseTuple (args, "s:GetLongPathName", &fileName)) + return NULL; + PyW32_BEGIN_ALLOW_THREADS + BOOL ok = (*myGetLongPathNameA)(fileName, pathBuf, sizeof(pathBuf)); + PyW32_END_ALLOW_THREADS + if (!ok) + return ReturnAPIError("GetLongPathName"); + return Py_BuildValue("s", pathBuf); + // @comm This function may raise a NotImplementedError exception if the version + // of Windows does not support this function. + } + + // @pymethod unicode|win32api|GetLongPathNameW|Converts the specified path to its long form. + static PyObject * + PyGetLongPathNameW (PyObject *self, PyObject *args) + { + WCHAR pathBuf[MAX_PATH]; + WCHAR *fileName; + if (!myGetLongPathNameW) + PyErr_SetString(PyExc_NotImplementedError, "GetLongPathNameW does not exist in this version of Windows"); + // @pyparm string|fileName||The file name. + PyObject *obFileName; + if (!PyArg_ParseTuple (args, "O:GetLongPathNameW", &obFileName)) + return NULL; + if (!PyWinObject_AsWCHAR(obFileName, &fileName)) + return NULL; + PyW32_BEGIN_ALLOW_THREADS + BOOL ok = (*myGetLongPathNameW)(fileName, pathBuf, sizeof(pathBuf)/sizeof(pathBuf[0])); + PyW32_END_ALLOW_THREADS + PyWinObject_FreeWCHAR(fileName); + if (!ok) + return ReturnAPIError("GetLongPathName"); + return PyWinObject_FromWCHAR(pathBuf); + // @comm This function may raise a NotImplementedError exception if the version + // of Windows does not support this function. + } + + // @pymethod string|win32api|GetTickCount|Returns the number of milliseconds since windows started. static PyObject * *************** *** 4213,4216 **** --- 4262,4267 ---- {"GetLastError", PyGetLastError, 1}, // @pymeth GetLastError|Retrieves the last error code known by the system. {"GetLocalTime", PyGetLocalTime, 1}, // @pymeth GetLocalTime|Returns the current local time. + {"GetLongPathName", PyGetLongPathNameA, 1}, // @pymeth GetLongPathName|Converts the specified path to its long form. + {"GetLongPathNameW", PyGetLongPathNameW, 1}, // @pymeth GetLongPathNameW|Converts the specified path to its long form. {"GetLogicalDrives", PyGetLogicalDrives, 1}, // @pymeth GetLogicalDrives|Returns a bitmask representing the currently available disk drives. {"GetLogicalDriveStrings", PyGetLogicalDriveStrings, 1}, // @pymeth GetLogicalDriveStrings|Returns a list of strings for all the drives. *************** *** 4387,4392 **** FARPROC fp = GetProcAddress(hmodule,"GetUserNameExW"); if (fp!=NULL) ! myGetUserNameEx=(BOOL (WINAPI *)(EXTENDED_NAME_FORMAT, LPWSTR, PULONG))(fp); ! } } --- 4438,4452 ---- FARPROC fp = GetProcAddress(hmodule,"GetUserNameExW"); if (fp!=NULL) ! myGetUserNameEx=(BOOL (WINAPI *)(EXTENDED_NAME_FORMAT, LPWSTR, PULONG))(fp); ! } ! hmodule = LoadLibrary("kernel32.dll"); ! if (hmodule!=NULL){ ! FARPROC fp = GetProcAddress(hmodule,"GetLongPathNameA"); ! if (fp!=NULL) ! myGetLongPathNameA=(BOOL (WINAPI *)(LPCSTR, LPSTR, DWORD))(fp); ! fp = GetProcAddress(hmodule,"GetLongPathNameW"); ! if (fp!=NULL) ! myGetLongPathNameW=(BOOL (WINAPI *)(LPCWSTR, LPWSTR, DWORD))(fp); ! } } |
From: <mha...@us...> - 2003-10-23 01:49:45
|
Update of /cvsroot/pywin32/pywin32/win32/Demos/security In directory sc8-pr-cvs1:/tmp/cvs-serv10198 Added Files: lsaregevent.py lsastore.py Log Message: New LSA demos/tests from Roger. --- NEW FILE: lsaregevent.py --- import win32security, win32event evt = win32event.CreateEvent(None,0,0,None) win32security.LsaRegisterPolicyChangeNotification(win32security.PolicyNotifyAuditEventsInformation, evt) print "Waiting for you change Audit policy in Management console ..." ret_code=win32event.WaitForSingleObject(evt,1000000000) ## should come back when you change Audit policy in Management console ... print ret_code win32security.LsaUnregisterPolicyChangeNotification(win32security.PolicyNotifyAuditEventsInformation, evt) --- NEW FILE: lsastore.py --- import win32security policy_handle = win32security.GetPolicyHandle('',win32security.POLICY_ALL_ACCESS) privatedata='some sensitive data' keyname='tmp' win32security.LsaStorePrivateData(policy_handle,keyname,privatedata) retrieveddata=win32security.LsaRetrievePrivateData(policy_handle,keyname) assert retrieveddata==privatedata ## passing None deletes key win32security.LsaStorePrivateData(policy_handle,keyname,None) win32security.LsaClose(policy_handle) |
From: <mha...@us...> - 2003-10-23 01:43:17
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1:/tmp/cvs-serv10473 Modified Files: win32security.i Log Message: New LSA functions from Roger, and support for a LSA_HANDLE object Index: win32security.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32security.i,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** win32security.i 1 Sep 2003 12:09:50 -0000 1.11 --- win32security.i 23 Oct 2003 00:56:35 -0000 1.12 *************** *** 49,52 **** --- 49,102 ---- } + %{ + #undef PyHANDLE + #include "PyWinObjects.h" + // Support for LSAHandle objects. Like a PyHANDLE, but calls LsaClose + class PyLSA_HANDLE: public PyHANDLE + { + public: + PyLSA_HANDLE(HANDLE hInit) : PyHANDLE(hInit) {} + virtual BOOL Close(void) { + NTSTATUS err = m_handle ? LsaClose((LSA_HANDLE)m_handle) : STATUS_SUCCESS; + m_handle = 0; + if (err!= STATUS_SUCCESS) + PyWin_SetAPIError("LsaClose", LsaNtStatusToWinError(err)); + return err== STATUS_SUCCESS; + } + virtual const char *GetTypeName() { + return "PyLSA_HANDLE"; + } + }; + + BOOL PyWinObject_AsLSA_HANDLE(PyObject *ob, LSA_HANDLE *pRes, BOOL bNoneOK = FALSE); + PyObject *PyWinObject_FromLSA_HANDLE(LSA_HANDLE h) + { + return new PyLSA_HANDLE(h); + } + + BOOL PyWinObject_CloseLSA_HANDLE(PyObject *obHandle) + { + BOOL ok; + if (PyHANDLE_Check(obHandle)) + // Python error already set. + ok = ((PyLSA_HANDLE *)obHandle)->Close(); + else if PyInt_Check(obHandle) { + NTSTATUS err; + err=LsaClose((HKEY)PyInt_AsLong(obHandle)); + ok = err == STATUS_SUCCESS; + if (!ok) + PyWin_SetAPIError("LsaClose",LsaNtStatusToWinError(err)); + } else { + PyErr_SetString(PyExc_TypeError, "A handle must be a LSA_HANDLE object or an integer"); + ok = FALSE; + } + return ok; + } + + // And re-define, so PyHANDLE in function sigs gets the PyHANDLE treatment. + #define PyHANDLE HANDLE + + %} + // @object PyTOKEN_PRIVILEGES|An object representing Win32 token privileges. // @comm This is a sequence (eg, list) of (id, attributes) *************** *** 87,93 **** TCHAR *ret_string = NULL; USHORT strlen = 0; ! if (!PyWinObject_AsTCHAR(obstr, &ret_string, bNoneOk)) return FALSE; ! strlen = wcslen(ret_string); plsaus->Buffer = ret_string; plsaus->Length = strlen * sizeof(WCHAR); --- 137,148 ---- TCHAR *ret_string = NULL; USHORT strlen = 0; ! if (!PyWinObject_AsTCHAR(obstr, &ret_string, bNoneOk)) { ! plsaus->Buffer = ret_string; return FALSE; ! } ! if (ret_string == NULL) ! strlen=0; ! else ! strlen = wcslen(ret_string); plsaus->Buffer = ret_string; plsaus->Length = strlen * sizeof(WCHAR); *************** *** 199,202 **** --- 254,259 ---- static BOOL (WINAPI *csdtssd)(PSECURITY_DESCRIPTOR,DWORD,SECURITY_INFORMATION, LPTSTR*,PULONG) = NULL; static BOOL (WINAPI *cssdtsd)(LPCTSTR,DWORD,PSECURITY_DESCRIPTOR*,PULONG) = NULL; + static long (WINAPI *lsarpcn)(POLICY_NOTIFICATION_INFORMATION_CLASS,HANDLE) = NULL; + static long (WINAPI *lsaupcn)(POLICY_NOTIFICATION_INFORMATION_CLASS,HANDLE) = NULL; BOOL CheckIfSupported(char *funcname, WCHAR *dllname, FARPROC *fp) *************** *** 286,289 **** --- 343,349 ---- FARPROC fp=NULL; + // Load the Secur32.dll library to CheckIfSupported's GetModuleHandle will work. + // If we fail here, GetModuleHandle will too, so no need to check result here. + HMODULE hMod = LoadLibrary(_T("Secur32.dll")); if (CheckIfSupported("ConvertSidToStringSidW",_T("Advapi32.dll"),&fp)) cstss= (BOOL (WINAPI *)(PSID, WCHAR **))(fp); *************** *** 294,297 **** --- 354,362 ---- if (CheckIfSupported("ConvertStringSecurityDescriptorToSecurityDescriptorW",_T("Advapi32.dll"),&fp)) cssdtsd=(BOOL (WINAPI *)(LPCTSTR,DWORD,PSECURITY_DESCRIPTOR*,PULONG))(fp); + if (CheckIfSupported("LsaRegisterPolicyChangeNotification",_T("Secur32.dll"),&fp)) + lsarpcn=(NTSTATUS (NTAPI *)(POLICY_NOTIFICATION_INFORMATION_CLASS,HANDLE))(fp); + if (CheckIfSupported("LsaUnregisterPolicyChangeNotification",_T("Secur32.dll"),&fp)) + lsaupcn=(NTSTATUS (NTAPI *)(POLICY_NOTIFICATION_INFORMATION_CLASS,HANDLE))(fp); + %} *************** *** 1332,1339 **** %} ! // @pyswig <o PyHandle>|GetPolicyHandle|Opens a policy handle for the specified system ! %native(GetPolicyHandle) PyGetPolicyHandle; %{ ! static PyObject *PyGetPolicyHandle(PyObject *self, PyObject *args) { PyObject *obsystem_name = NULL; --- 1397,1409 ---- %} ! // we used to expose this as "GetPolicyHandle". It has been renamed ! // to "LsaOpenPolicy" to be consistent with win32, but GetPolicyHandle still ! // exists as an alias. ! %native(GetPolicyHandle) PyLsaOpenPolicy; ! ! // @pyswig <o PyHandle>|LsaOpenPolicy|Opens a policy handle for the specified system ! %native(LsaOpenPolicy) PyLsaOpenPolicy; %{ ! static PyObject *PyLsaOpenPolicy(PyObject *self, PyObject *args) { PyObject *obsystem_name = NULL; *************** *** 1346,1350 **** ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes)); ! if (!PyArg_ParseTuple(args, "Oi:GetPolicyHandle", &obsystem_name, // @pyparm string/<o PyUnicode>|obsystem_name||System name, local system assumed if not specified &access_mask)) // @pyparm int|access_mask||Bitmask of requested access types --- 1416,1420 ---- ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes)); ! if (!PyArg_ParseTuple(args, "Oi:LsaOpenPolicy", &obsystem_name, // @pyparm string/<o PyUnicode>|obsystem_name||System name, local system assumed if not specified &access_mask)) // @pyparm int|access_mask||Bitmask of requested access types *************** *** 1355,1362 **** ntsResult = LsaOpenPolicy(&system_name, &ObjectAttributes, access_mask, &lsahPolicyHandle); if (ntsResult != STATUS_SUCCESS){ ! PyWin_SetAPIError("GetPolicyHandle",LsaNtStatusToWinError(ntsResult)); goto done; } ! ret = PyWinObject_FromHANDLE(lsahPolicyHandle); done: PyWinObject_FreeTCHAR(system_name.Buffer); --- 1425,1432 ---- ntsResult = LsaOpenPolicy(&system_name, &ObjectAttributes, access_mask, &lsahPolicyHandle); if (ntsResult != STATUS_SUCCESS){ ! PyWin_SetAPIError("LsaOpenPolicy",LsaNtStatusToWinError(ntsResult)); goto done; } ! ret = PyWinObject_FromLSA_HANDLE(lsahPolicyHandle); done: PyWinObject_FreeTCHAR(system_name.Buffer); *************** *** 1370,1385 **** static PyObject *PyLsaClose(PyObject *self, PyObject *args) { ! PyObject *obhandle; ! LSA_HANDLE lsah; ! NTSTATUS err; ! if (!PyArg_ParseTuple(args, "O:LsaClose", &obhandle)) return NULL; ! if (!PyWinObject_AsHANDLE(obhandle, &lsah)) ! return NULL; ! err=LsaClose(lsah); ! if (err != STATUS_SUCCESS){ ! PyWin_SetAPIError("LsaClose",LsaNtStatusToWinError(err)); return NULL; - } Py_INCREF(Py_None); return Py_None; --- 1440,1449 ---- static PyObject *PyLsaClose(PyObject *self, PyObject *args) { ! PyObject *obHandle; ! if (!PyArg_ParseTuple(args, "O:LsaClose", &obHandle)) return NULL; ! ! if (!PyWinObject_CloseLSA_HANDLE(obHandle)) return NULL; Py_INCREF(Py_None); return Py_None; *************** *** 1883,1886 **** --- 1947,2135 ---- %} + // @pyswig |LsaStorePrivateData|Stores encrypted unicode data under specified Lsa registry key. Returns None on success + %native(LsaStorePrivateData) PyLsaStorePrivateData; + %{ + static PyObject *PyLsaStorePrivateData(PyObject *self, PyObject *args) + { + // @pyparm <o PyHANDLE>||Policy handle + // @pyparm string|KeyName||Registry key in which to store data + // @pyparm int|PrivateData||Unicode string to be encrypted and stored + PyObject *obpolicyhandle=NULL, *obkeyname=NULL, *obprivatedata=NULL; + PyObject * ret=NULL; + LSA_HANDLE policyhandle; + LSA_UNICODE_STRING keyname, privatedata; + keyname.Buffer=NULL; + privatedata.Buffer=NULL; + NTSTATUS err = NULL; + if (!PyArg_ParseTuple(args, "OOO:LsaStorePrivateData", &obpolicyhandle, &obkeyname, &obprivatedata)) + return NULL; + if (!PyWinObject_AsHANDLE(obpolicyhandle, &policyhandle)) + return NULL; + if (!PyWinObject_AsLSA_UNICODE_STRING(obkeyname, &keyname, FALSE)) + goto done; + // passing NULL deletes the data stored under specified key + // use Py_None since empty string is considered valid data + if (obprivatedata==Py_None) + err = LsaStorePrivateData(policyhandle, &keyname, NULL); + else{ + if (!PyWinObject_AsLSA_UNICODE_STRING(obprivatedata, &privatedata, FALSE)) + goto done; + err = LsaStorePrivateData(policyhandle, &keyname, &privatedata); + } + if (err == STATUS_SUCCESS) + ret=Py_None; + else + PyWin_SetAPIError("LsaStorePrivateData",LsaNtStatusToWinError(err)); + + done: + if (keyname.Buffer != NULL) + PyWinObject_FreeWCHAR(keyname.Buffer); + if (privatedata.Buffer != NULL) + PyWinObject_FreeWCHAR(privatedata.Buffer); + Py_XINCREF(ret); + return ret; + } + %} + + // @pyswig <o PyUnicode>|LsaRetrievePrivateData|Retreives encrypted unicode data from Lsa registry key. + %native(LsaRetrievePrivateData) PyLsaRetrievePrivateData; + %{ + static PyObject *PyLsaRetrievePrivateData(PyObject *self, PyObject *args) + { + // @pyparm <o PyHANDLE>||Policy handle + // @pyparm string|KeyName||Registry key to read + PyObject *obpolicyhandle=NULL, *obkeyname=NULL, *obprivatedata=NULL; + PyObject * ret=NULL; + LSA_HANDLE policyhandle; + LSA_UNICODE_STRING keyname; + keyname.Buffer=NULL; + PLSA_UNICODE_STRING privatedata = NULL; + NTSTATUS err = NULL; + if (!PyArg_ParseTuple(args, "OO:LsaRetrievePrivateData", &obpolicyhandle, &obkeyname)) + return NULL; + if (!PyWinObject_AsHANDLE(obpolicyhandle, &policyhandle)) + return NULL; + if (!PyWinObject_AsLSA_UNICODE_STRING(obkeyname, &keyname, FALSE)) + goto done; + + err = LsaRetrievePrivateData(policyhandle, &keyname, &privatedata); + if (err == STATUS_SUCCESS) + ret=PyWinObject_FromLSA_UNICODE_STRING(*privatedata); + else + PyWin_SetAPIError("LsaRetrievePrivateData",LsaNtStatusToWinError(err)); + done: + if (keyname.Buffer != NULL) + PyWinObject_FreeWCHAR(keyname.Buffer); + if (privatedata != NULL) + LsaFreeMemory(privatedata); + return ret; + } + %} + + // @pyswig object|LsaRegisterPolicyChangeNotification|Register an event handle to receive policy change events + %native(LsaRegisterPolicyChangeNotification) PyLsaRegisterPolicyChangeNotification; + %{ + static PyObject *PyLsaRegisterPolicyChangeNotification(PyObject *self, PyObject *args) + { + if (lsarpcn==NULL) + return PyErr_Format(PyExc_NotImplementedError,"LsaRegisterPolicyChangeNotification not supported by this version of Windows"); + PyObject *obHandle=NULL; + PyObject *ret=NULL; + HANDLE hevent; + POLICY_NOTIFICATION_INFORMATION_CLASS info_class; + NTSTATUS err; + if (!PyArg_ParseTuple(args, "lO:LsaRegisterPolicyChangeNotification", + (long *)&info_class, // @pyparm int|InformationClass||One of POLICY_NOTIFICATION_INFORMATION_CLASS contants + &obHandle)) // @pyparm <o PyHANDLE>|NotificationEventHandle||Event handle to receives notification + return NULL; + if (!PyWinObject_AsHANDLE(obHandle, &hevent, FALSE)) + return NULL; + err=(*lsarpcn)(info_class,hevent); + if (err==STATUS_SUCCESS) + ret=Py_None; + else + PyWin_SetAPIError("LsaRegisterPolicyChangeNotification",LsaNtStatusToWinError(err)); + Py_XINCREF(ret); + return ret; + } + %} + + // @pyswig object|LsaUnregisterPolicyChangeNotification|Stop receiving policy change notification + %native(LsaUnregisterPolicyChangeNotification) PyLsaUnregisterPolicyChangeNotification; + %{ + static PyObject *PyLsaUnregisterPolicyChangeNotification(PyObject *self, PyObject *args) + { + if (lsaupcn==NULL) + return PyErr_Format(PyExc_NotImplementedError,"LsaUnregisterPolicyChangeNotification not supported by this version of Windows"); + PyObject *obHandle; + PyObject *ret=NULL; + HANDLE hevent; + POLICY_NOTIFICATION_INFORMATION_CLASS info_class; + NTSTATUS err; + if (!PyArg_ParseTuple(args, "lO:LsaUnregisterPolicyChangeNotification", + (long *)&info_class, // @pyparm int|InformationClass||POLICY_NOTIFICATION_INFORMATION_CLASS constant + &obHandle)) // @pyparm <o PyHANDLE>|NotificationEventHandle||Event handle previously registered to receive policy change events + return NULL; + if (!PyWinObject_AsHANDLE(obHandle, &hevent, FALSE)) + return NULL; + err=(*lsaupcn)(info_class,hevent); + if (err==STATUS_SUCCESS) + ret=Py_None; + else + PyWin_SetAPIError("LsaUnregisterPolicyChangeNotification",LsaNtStatusToWinError(err)); + Py_XINCREF(ret); + return ret; + } + %} + + // @pyswig object|CryptEnumProviders|List cryptography providers + %native(CryptEnumProviders) PyCryptEnumProviders; + %{ + static PyObject *PyCryptEnumProviders(PyObject *self, PyObject *args) + { + if (!PyArg_ParseTuple(args, ":CryptEnumProviders")) + return NULL; + DWORD dwFlags=0, dwIndex=0, dwReserved=NULL, dwProvType=0, cbProvName=0; + WCHAR *pszProvName=NULL; + PyObject *ret=PyList_New(0); + PyObject *ret_item=NULL; + BOOL succeeded = TRUE; + DWORD err = 0; + do{ + cbProvName=0; + pszProvName=NULL; + succeeded = CryptEnumProviders(dwIndex, NULL, dwFlags, &dwProvType, NULL, &cbProvName); + if (!succeeded) + break; + // test breaking out of loop if out of memory + // if (dwIndex==3) + // cbProvName=0x77777777; + pszProvName = (WCHAR *)malloc(cbProvName); + if (pszProvName==NULL){ + Py_DECREF(ret); + PyErr_SetString(PyExc_MemoryError, "CryptEnumProviders: SOM"); + return NULL; + } + succeeded = CryptEnumProviders(dwIndex, NULL, dwFlags, &dwProvType, pszProvName, &cbProvName); + if (!succeeded){ + free(pszProvName); + break; + } + ret_item = Py_BuildValue("ul",pszProvName, dwProvType); + PyList_Append(ret, ret_item); + Py_DECREF(ret_item); + free(pszProvName); + dwIndex++; + } + while (succeeded); + err=GetLastError(); + if (err != ERROR_NO_MORE_ITEMS){ + Py_DECREF(ret); + ret=NULL; + PyWin_SetAPIError("CryptEnumProviders",err); + } + return ret; + } + %} #define TOKEN_ADJUST_DEFAULT TOKEN_ADJUST_DEFAULT // Required to change the default ACL, primary group, or owner of an access token. *************** *** 2074,2081 **** --- 2323,2334 ---- #ifdef PolicyServerEnabled #define PolicyServerEnabled PolicyServerEnabled + #else + #define PolicyServerEnabled 2 #endif #ifdef PolicyServerDisabled #define PolicyServerDisabled PolicyServerDisabled + #else + #define PolicyServerDisabled 3 #endif |
From: <mha...@us...> - 2003-10-23 01:36:10
|
Update of /cvsroot/pywin32/pywin32/win32/Demos/security In directory sc8-pr-cvs1:/tmp/cvs-serv10106 Modified Files: explicit_entries.py Log Message: Don't use a hardcoded filename in the tests. Index: explicit_entries.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/Demos/security/explicit_entries.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** explicit_entries.py 10 Mar 2003 01:18:15 -0000 1.1 --- explicit_entries.py 23 Oct 2003 00:53:37 -0000 1.2 *************** *** 1,5 **** ! fname=r'h:\tmp.txt' import win32security,win32file,win32api,ntsecuritycon,win32con from security_enums import TRUSTEE_TYPE,TRUSTEE_FORM,ACE_FLAGS,ACCESS_MODE new_privs = ((win32security.LookupPrivilegeValue('',ntsecuritycon.SE_SECURITY_NAME),win32con.SE_PRIVILEGE_ENABLED), --- 1,11 ---- ! import os import win32security,win32file,win32api,ntsecuritycon,win32con from security_enums import TRUSTEE_TYPE,TRUSTEE_FORM,ACE_FLAGS,ACCESS_MODE + + fname = os.path.join(win32api.GetTempPath(), "win32security_test.txt") + f=open(fname, "w") + f.write("Hello from Python\n"); + f.close() + print "Testing on file", fname new_privs = ((win32security.LookupPrivilegeValue('',ntsecuritycon.SE_SECURITY_NAME),win32con.SE_PRIVILEGE_ENABLED), |