ctypes-commit Mailing List for ctypes (Page 72)
Brought to you by:
theller
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
(8) |
May
(90) |
Jun
(143) |
Jul
(106) |
Aug
(94) |
Sep
(84) |
Oct
(163) |
Nov
(60) |
Dec
(58) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(128) |
Feb
(79) |
Mar
(227) |
Apr
(192) |
May
(179) |
Jun
(41) |
Jul
(53) |
Aug
(103) |
Sep
(28) |
Oct
(38) |
Nov
(81) |
Dec
(17) |
2006 |
Jan
(184) |
Feb
(111) |
Mar
(188) |
Apr
(67) |
May
(58) |
Jun
(123) |
Jul
(73) |
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: Thomas H. <th...@us...> - 2005-02-24 16:23:53
|
Update of /cvsroot/ctypes/ctypes/comtypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3126 Added Files: test_typeinfo.py Log Message: ITypeInfo and ITypeLib interfaces, support structures and functions. --- NEW FILE: test_typeinfo.py --- import unittest from ctypes import POINTER, byref from comtypes import GUID from comtypes.automation import DISPATCH_METHOD from comtypes.automation.typeinfo import LoadTypeLibEx, LoadRegTypeLib, \ QueryPathOfRegTypeLib, TKIND_INTERFACE, TKIND_DISPATCH, TKIND_ENUM class Test(unittest.TestCase): def test_LoadTypeLibEx(self): self.assertRaises(WindowsError, lambda: LoadTypeLibEx("<xxx.xx>")) tlib = LoadTypeLibEx("shdocvw.dll") self.failUnless(tlib.GetTypeInfoCount()) tlib.GetDocumentation(-1) self.failUnlessEqual(tlib.IsName("IWebBrowser"), True) self.failUnlessEqual(tlib.IsName("Spam"), False) self.failUnless(tlib.FindName("IWebBrowser")) self.failUnlessEqual(tlib.FindName("Spam"), None) tlib.GetTypeComp() attr = tlib.GetLibAttr() info = attr.guid, attr.wMajorVerNum, attr.wMinorVerNum other_tlib = LoadRegTypeLib(*info) self.failUnlessEqual(tlib, other_tlib) ## for n in dir(attr): ## if not n.startswith("_"): ## print "\t", n, getattr(attr, n) for i in range(tlib.GetTypeInfoCount()): ti = tlib.GetTypeInfo(i) ti.GetTypeAttr() tlib.GetDocumentation(i) tlib.GetTypeInfoType(i) index, c_tlib = ti.GetContainingTypeLib() self.failUnlessEqual(c_tlib, tlib) self.failUnlessEqual(index, i) self.assertRaises(WindowsError, lambda: tlib.GetTypeInfoOfGuid(GUID())) self.failUnless(tlib.GetTypeInfoOfGuid(GUID("{EAB22AC1-30C1-11CF-A7EB-0000C05BAE0B}"))) path = QueryPathOfRegTypeLib(*info) path = path.split("\0")[0] self.failUnless(path.lower().endswith("shdocvw.dll")) def test_TypeInfo(self): tlib = LoadTypeLibEx("shdocvw.dll") for index in range(tlib.GetTypeInfoCount()): ti = tlib.GetTypeInfo(index) ta = ti.GetTypeAttr() ti.GetDocumentation(-1) if ta.typekind in (TKIND_INTERFACE, TKIND_DISPATCH): if ta.cImplTypes: href = ti.GetRefTypeOfImplType(0) base = ti.GetRefTypeInfo(href) base.GetDocumentation(-1) ti.GetImplTypeFlags(0) for f in range(ta.cFuncs): fd = ti.GetFuncDesc(f) names = ti.GetNames(fd.memid, 32) ti.GetIDsOfNames(names) ti.GetMops(fd.memid) for v in range(ta.cVars): ti.GetVarDesc(v) if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2005-02-24 16:22:31
|
Update of /cvsroot/ctypes/ctypes/comtypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2713 Modified Files: .cvsignore Log Message: Standard ignores. Index: .cvsignore =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/unittests/.cvsignore,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** .cvsignore 12 Jan 2005 20:54:05 -0000 1.1 --- .cvsignore 24 Feb 2005 16:22:16 -0000 1.2 *************** *** 1 **** ! test_basic.pyc --- 1,2 ---- ! *.pyc ! *.pyo |
From: Thomas H. <th...@us...> - 2005-02-24 16:22:24
|
Update of /cvsroot/ctypes/ctypes/comtypes/automation In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2625 Added Files: .cvsignore Log Message: Standard ignores. --- NEW FILE: .cvsignore --- *.pyc *.pyo |
From: Thomas H. <th...@us...> - 2005-02-24 16:17:53
|
Update of /cvsroot/ctypes/ctypes/comtypes/automation In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1367 Modified Files: __init__.py Log Message: Fix GetTypeInfo(), and add some constants. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/automation/__init__.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** __init__.py 16 Feb 2005 20:46:35 -0000 1.2 --- __init__.py 24 Feb 2005 16:17:23 -0000 1.3 *************** *** 30,33 **** --- 30,38 ---- VARTYPE = c_ushort + DISPATCH_METHOD = 1 + DISPATCH_PROPERTYGET = 2 + DISPATCH_PROPERTYPUT = 4 + DISPATCH_PROPERTYPUTREF = 8 + ################################ # helper constants *************** *** 306,310 **** def GetTypeInfo(self, index, lcid=0): ! p = POINTER(IUnknown)() self.__com_GetTypeInfo(index, lcid, byref(p)) return p --- 311,316 ---- def GetTypeInfo(self, index, lcid=0): ! from typeinfo import ITypeInfo ! p = POINTER(ITypeInfo)() self.__com_GetTypeInfo(index, lcid, byref(p)) return p *************** *** 376,380 **** ################################################################ ! if __name__ == "__main__": oledll.ole32.CoInitialize(None) p = POINTER(IDispatch)() --- 382,386 ---- ################################################################ ! if 0 and __name__ == "__main__": oledll.ole32.CoInitialize(None) p = POINTER(IDispatch)() *************** *** 388,392 **** byref(p)) for i in range(p.GetTypeInfoCount()): ! result = p.GetTypeInfo(i) id_quit = p.GetIDsOfNames("Quit")[0] --- 394,398 ---- byref(p)) for i in range(p.GetTypeInfoCount()): ! print p.GetTypeInfo(i) id_quit = p.GetIDsOfNames("Quit")[0] *************** *** 396,404 **** try: ! p.Invoke(id_visible, True, wFlags = 4) ! p.Invoke(id_navigate, "http://www.python.org/", 1) import time ! time.sleep(3) ! p.Invoke(id_quit, wFlags = 1) ## p.Invoke(id_quit, True, wFlags = 1) finally: --- 402,410 ---- try: ! ## p.Invoke(id_visible, True, wFlags = 4) ! ## p.Invoke(id_navigate, "http://www.python.org/", 1) import time ! ## time.sleep(3) ! print p.Invoke(id_quit) ## p.Invoke(id_quit, True, wFlags = 1) finally: |
From: Thomas H. <th...@us...> - 2005-02-17 19:23:07
|
Update of /cvsroot/ctypes/ctypes/ctypes/wrap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1719 Modified Files: codegenerator.py Log Message: Refactoring for easier dynamic code generation. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/wrap/codegenerator.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** codegenerator.py 4 Feb 2005 18:04:24 -0000 1.2 --- codegenerator.py 17 Feb 2005 19:22:54 -0000 1.3 *************** *** 3,6 **** --- 3,9 ---- # $Log$ + # Revision 1.3 2005/02/17 19:22:54 theller + # Refactoring for easier dynamic code generation. + # # Revision 1.2 2005/02/04 18:04:24 theller # The code generator now assumes decorators are present in the ctypes module. *************** *** 141,150 **** ) class Generator(object): ! def __init__(self, output, use_decorators=False): self.output = output ! self.stream = StringIO.StringIO() ! self.imports = StringIO.StringIO() self.use_decorators = use_decorators self.done = set() # type descriptions that have been generated self.names = set() # names that have been generated --- 144,162 ---- ) + ################################################################ + class Generator(object): ! def __init__(self, output, ! use_decorators=False, ! known_symbols=None, ! searched_dlls=None): self.output = output ! ## self.stream = StringIO.StringIO() ! ## self.imports = StringIO.StringIO() ! self.stream = self.imports = self.output self.use_decorators = use_decorators + self.known_symbols = known_symbols or {} + self.searched_dlls = searched_dlls or [] + self.done = set() # type descriptions that have been generated self.names = set() # names that have been generated *************** *** 560,571 **** self.generate(item) ! def generate_code(self, items, known_symbols, searched_dlls): print >> self.imports, "from ctypes import *" items = set(items) - if known_symbols: - self.known_symbols = known_symbols - else: - self.known_symbols = {} - self.searched_dlls = searched_dlls loops = 0 while items: --- 572,578 ---- self.generate(item) ! def generate_code(self, items): print >> self.imports, "from ctypes import *" items = set(items) loops = 0 while items: *************** *** 577,583 **** items -= self.done ! self.output.write(self.imports.getvalue()) ! self.output.write("\n\n") ! self.output.write(self.stream.getvalue()) return loops --- 584,590 ---- items -= self.done ! ## self.output.write(self.imports.getvalue()) ! ## self.output.write("\n\n") ! ## self.output.write(self.stream.getvalue()) return loops *************** *** 618,621 **** --- 625,629 ---- items = parse(xmlfile) + # filter symbols to generate todo = [] *************** *** 646,653 **** items = todo ! gen = Generator(outfile, use_decorators=use_decorators) ! loops = gen.generate_code(items, ! known_symbols, ! searched_dlls) if verbose: gen.print_stats(sys.stderr) --- 654,664 ---- items = todo ! ################ ! gen = Generator(outfile, ! use_decorators=use_decorators, ! known_symbols=known_symbols, ! searched_dlls=searched_dlls) ! ! loops = gen.generate_code(items) if verbose: gen.print_stats(sys.stderr) |
From: Thomas H. <th...@us...> - 2005-02-17 19:04:56
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29714 Modified Files: tlbparser.py Log Message: Record some wisdom about SAFEARRAY. Index: tlbparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/tlbparser.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tlbparser.py 7 Feb 2005 12:06:26 -0000 1.2 --- tlbparser.py 17 Feb 2005 19:04:46 -0000 1.3 *************** *** 1,3 **** ! from comtypes import automation import typedesc --- 1,3 ---- ! from comtypes import _automation as automation import typedesc *************** *** 62,78 **** automation.VT_VOID: typedesc.FundamentalType("void", 0, 0), # 24 automation.VT_HRESULT: HRESULT_type, # 25 ! #automation.VT_PTR = 26 # enum VARENUM automation.VT_SAFEARRAY: SAFEARRAY_type, # 27 - #automation.VT_CARRAY = 28 # enum VARENUM automation.VT_LPSTR: PTR(char_type), # 30 automation.VT_LPWSTR: PTR(wchar_t_type), # 31 } ! #automation.VT_USERDEFINED = 29 # enum VARENUM ! #automation.VT_RECORD = 36 # enum VARENUM ! #automation.VT_ARRAY = 8192 # enum VARENUM ! #automation.VT_BYREF = 16384 # enum VARENUM ################################################################ --- 62,79 ---- automation.VT_VOID: typedesc.FundamentalType("void", 0, 0), # 24 automation.VT_HRESULT: HRESULT_type, # 25 ! # This is wrong. We must create separate SAFEARRAY(type) things. automation.VT_SAFEARRAY: SAFEARRAY_type, # 27 automation.VT_LPSTR: PTR(char_type), # 30 automation.VT_LPWSTR: PTR(wchar_t_type), # 31 } ! #automation.VT_PTR = 26 # below ! #automation.VT_CARRAY = 28 # below ! #automation.VT_USERDEFINED = 29 # below ! #automation.VT_RECORD = 36 ! #automation.VT_ARRAY = 8192 ! #automation.VT_BYREF = 16384 ################################################################ *************** *** 83,86 **** --- 84,88 ---- self.tlib = automation.LoadTypeLibEx(path, regkind=automation.REGKIND_REGISTER) self.items = {} + self.tlib.GetLibAttr() def make_type(self, tdesc, tinfo): *************** *** 108,111 **** --- 110,118 ---- return result + elif tdesc.vt == automation.VT_SAFEARRAY: + # SAFEARRAY(long), see Don Box pp.331f + print "SAFEARRAY", tdesc._.lptdesc[0].vt + return SAFEARRAY_type + # VT_SAFEARRAY ??? raise "NYI", tdesc.vt *************** *** 482,486 **** return self.ParseUnion(tinfo, ta) else: ! raise "NYI", tkind ################################################################ --- 489,494 ---- return self.ParseUnion(tinfo, ta) else: ! print "NYI", tkind ! ## raise "NYI", tkind ################################################################ *************** *** 502,506 **** ## path = r"simpdata.tlb" ## path = r"nscompat.tlb" ! ## path = r"mshtml.tlb" ## path = r"stdole32.tlb" ## path = "msscript.ocx" --- 510,514 ---- ## path = r"simpdata.tlb" ## path = r"nscompat.tlb" ! ## path = r"mshtml.tlb" # has propputref ## path = r"stdole32.tlb" ## path = "msscript.ocx" *************** *** 508,512 **** ## path = r"c:\Programme\Microsoft Office\Office\MSO97.DLL" ! ## path = r"c:\Programme\Microsoft Office\Office\MSWORD8.OLB" ## path = r"msi.dll" # DispProperty --- 516,520 ---- ## path = r"c:\Programme\Microsoft Office\Office\MSO97.DLL" ! ## path = r"c:\Programme\Microsoft Office\Office\MSWORD8.OLB" # has propputref ## path = r"msi.dll" # DispProperty *************** *** 514,532 **** ## path = r"C:\Dokumente und Einstellungen\thomas\Desktop\tlb\win.tlb" ## path = r"C:\Dokumente und Einstellungen\thomas\Desktop\tlb\win32.tlb" ! ## path = r"MSHFLXGD.OCX" ! ## path = r"scrrun.dll" ## path = r"c:\Programme\Gemeinsame Dateien\Microsoft Shared\Speech\sapi.dll" ## path = r"C:\Dokumente und Einstellungen\thomas\Desktop\tlb\threadapi.tlb" ## path = r"C:\Dokumente und Einstellungen\thomas\Desktop\tlb\win32.tlb" ! ## path = "mytlb.tlb" ## # this has a IUnknown* default parameter ## path = r"c:\Programme\Gemeinsame Dateien\Microsoft Shared\Speech\sapi.dll" ! ## path = r"c:\tss5\include\fpanel.tlb" ! path = "auto.tlb" known_symbols = {} ! for name in ("comtypes.automation", "comtypes", "ctypes"): mod = __import__(name) for submodule in name.split(".")[1:]: --- 522,546 ---- ## path = r"C:\Dokumente und Einstellungen\thomas\Desktop\tlb\win.tlb" ## path = r"C:\Dokumente und Einstellungen\thomas\Desktop\tlb\win32.tlb" ! ## path = r"MSHFLXGD.OCX" # DispProperty, propputref ! ## path = r"scrrun.dll" # propput AND propputref on IDictionary::Item ## path = r"c:\Programme\Gemeinsame Dateien\Microsoft Shared\Speech\sapi.dll" ## path = r"C:\Dokumente und Einstellungen\thomas\Desktop\tlb\threadapi.tlb" ## path = r"C:\Dokumente und Einstellungen\thomas\Desktop\tlb\win32.tlb" ! path = "mytlb.tlb" ## # this has a IUnknown* default parameter ## path = r"c:\Programme\Gemeinsame Dateien\Microsoft Shared\Speech\sapi.dll" ! ## path = r"c:\tss5\include\fpanel.tlb" ! ! ## path = "auto.tlb" known_symbols = {} ! from ctypes.wrap import template ! templates = {} ! ## templates = template.get_templates("mytlb.py") ! ! ## for name in ("comtypes._automation", "comtypes", "ctypes"): ! for name in ("auto", "comtypes", "ctypes"): mod = __import__(name) for submodule in name.split(".")[1:]: *************** *** 540,546 **** from codegenerator import Generator gen = Generator(sys.stdout) print >> gen.imports, "from helpers import *" ! loops = gen.generate_code(items.values(), known_symbols, []) if __name__ == "__main__": --- 554,561 ---- from codegenerator import Generator + ## gen = Generator(open("mytlb.py", "w")) gen = Generator(sys.stdout) print >> gen.imports, "from helpers import *" ! loops = gen.generate_code(items.values(), known_symbols, [], templates) if __name__ == "__main__": |
From: Thomas H. <th...@us...> - 2005-02-17 15:22:52
|
Update of /cvsroot/ctypes/ctypes/unittests/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5740 Modified Files: test_variant.py Log Message: Preliminary support for one-dimensional safearray support in VARIANT. Index: test_variant.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/com/test_variant.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** test_variant.py 14 Feb 2005 14:33:39 -0000 1.4 --- test_variant.py 17 Feb 2005 15:22:43 -0000 1.5 *************** *** 55,59 **** # XXX The following line fails, which is a real bug in ctypes: # SystemError: ...\Objects\listobject.c:105: bad argument to internal function ! ## d.rgvarg[0].value = 1 def test_pythonobjects(self): --- 55,61 ---- # XXX The following line fails, which is a real bug in ctypes: # SystemError: ...\Objects\listobject.c:105: bad argument to internal function ! # ! # Update: this bug is fixed, now I have to rememeber what I wanted to test here. ! d.rgvarg[0].value = 1 def test_pythonobjects(self): *************** *** 103,106 **** --- 105,127 ---- self.failUnlessEqual(v.value, "") + class ArrayTest(unittest.TestCase): + def test_double(self): + import array + for typecode in "df": + # because of FLOAT rounding errors, whi will only work for + # certain values! + a = array.array(typecode, [1.0, 2.0, 3.0, 4.5]) + v = VARIANT() + v.value = a + self.failUnlessEqual(v.value, [1.0, 2.0, 3.0, 4.5]) + + def test_int(self): + import array + for typecode in "bhiBHIlL": + a = array.array(typecode, [1, 1, 1, 1]) + v = VARIANT() + v.value = a + self.failUnlessEqual(v.value, [1, 1, 1, 1]) + ################################################################ |
From: Thomas H. <th...@us...> - 2005-02-17 15:05:42
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv615 Modified Files: automation.py Log Message: Preliminary support for one-dimensional safearray support in VARIANT. Index: automation.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/automation.py,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** automation.py 14 Feb 2005 14:30:18 -0000 1.20 --- automation.py 17 Feb 2005 15:05:25 -0000 1.21 *************** *** 1,3 **** ! import datetime from ctypes import * --- 1,3 ---- ! import datetime, array from ctypes import * *************** *** 282,285 **** --- 282,289 ---- PVARIANT = POINTER("VARIANT") + class SAFEARRAYBOUND(Structure): + _fields_ = [("cElements", c_ulong), + ("lLbound", c_long)] + class VARIANT(Structure): class U(Union): *************** *** 354,357 **** --- 358,385 ---- elif value is None: return + elif typ is array.array: + TYPECODE = { + "d": (VT_R8, c_double), + "f": (VT_R4, c_float), + "l": (VT_I4, c_long), + "i": (VT_INT, c_int), + "h": (VT_I2, c_short), + "b": (VT_I1, c_byte), + "I": (VT_UINT, c_uint), + "L": (VT_UI4, c_ulong), + "H": (VT_UI2, c_ushort), + "B": (VT_UI1, c_ubyte), + } + vt, itemklass = TYPECODE[value.typecode] + sab = SAFEARRAYBOUND(len(value), 0) + psa = oleaut32.SafeArrayCreate(vt, 1, byref(sab)) + ix = c_long() + item = itemklass() + for index, v in enumerate(value): + ix.value = index + item.value = v + oleaut32.SafeArrayPutElement(psa, byref(ix), byref(item)) + self._.VT_I4 = psa + self.vt = VT_ARRAY | vt elif typ is bool: self.vt = VT_BOOL *************** *** 441,444 **** --- 469,503 ---- return datetime.timedelta(days=days) + self._com_null_date raise "NYI" + elif self.vt & VT_ARRAY: + TYPECODE = { + VT_R8: c_double, + VT_R4: c_float, + VT_I4: c_long, + VT_INT: c_int, + VT_I2: c_short, + VT_I1: c_byte, + VT_UI4: c_ulong, + VT_UINT: c_uint, + VT_UI2: c_ushort, + VT_UI1: c_ubyte, + } + + # idea: use a LONG array (array.array('l') + # to specify indices? + # requires buffer support for function calls + psa = self._.VT_I4 + dim = oleaut32.SafeArrayGetDim(psa) + assert dim == 1 + lb, ub = c_long(), c_long() + oleaut32.SafeArrayGetLBound(psa, 1, byref(lb)) + oleaut32.SafeArrayGetUBound(psa, 1, byref(ub)) + ix = c_long() + data = TYPECODE[self.vt & ~VT_ARRAY]() + result = [] + for i in range(lb.value, ub.value+1): + ix.value = i + oleaut32.SafeArrayGetElement(psa, byref(ix), byref(data)) + result.append(data.value) + return result else: raise TypeError, "don't know how to convert typecode %d" % self.vt *************** *** 494,498 **** ("pvReserved", c_void_p), ("pfnDeferredFillIn", c_int), # XXX ! ("scode", SCODE)] def as_tuple(self): return (self.wCode, self.bstrSource, self.bstrDescription, --- 553,558 ---- ("pvReserved", c_void_p), ("pfnDeferredFillIn", c_int), # XXX ! ## ("scode", SCODE)] ! ("scode", c_long)] def as_tuple(self): return (self.wCode, self.bstrSource, self.bstrDescription, |
From: Thomas H. <th...@us...> - 2005-02-16 20:58:45
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10627 Modified Files: README.txt Log Message: Add comment. Index: README.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/README.txt,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** README.txt 29 Jan 2005 22:06:52 -0000 1.2 --- README.txt 16 Feb 2005 20:58:23 -0000 1.3 *************** *** 3,7 **** =============================== ! .. _REST quickref: http://docutils.sourceforge.net/docs/user/rst/quickstart.html This document describes the ctypes code generator. The generator --- 3,7 ---- =============================== ! .. _REST quickref (only for the editor): http://docutils.sourceforge.net/docs/user/rst/quickstart.html This document describes the ctypes code generator. The generator |
From: Thomas H. <th...@us...> - 2005-02-16 20:57:45
|
Update of /cvsroot/ctypes/ctypes/unittests/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10346 Modified Files: test_perf.py Log Message: Performance improvement by simple optimization. Index: test_perf.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/com/test_perf.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_perf.py 16 Feb 2005 20:40:20 -0000 1.2 --- test_perf.py 16 Feb 2005 20:57:24 -0000 1.3 *************** *** 108,128 **** ##ctypes version: 0.9.3 ##python version: 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] ! ## 0.41: Class() ! ## 1.34: POINT() ! ## 1.39: RECT() ! ## 0.23: point.y ! ## 2.36: rect.lr ! ## 7.22: fd.lprgelemdescParam ! ## 10.80: fd.lprgelemdescParam[0] ! ## 10.90: fd.lprgelemdescParam[1] ! ## 13.50: fd.lprgelemdescParam[1].tdesc ! ## 14.40: fd.lprgelemdescParam[1].tdesc.vt ! ## 21.70: fd.lprgelemdescParam[1].tdesc.u.lptdesc[0].vt ! ## 1.13: c_int() ! ## 1.32: c_int(42) ! ## 2.34: VARIANT() # ctypes.com ! ## 5.49: variant.value # ctypes.com ! ## 11.60: variant.value = 3.14 # ctypes.com ! ## 1.40: VARIANT() # comtypes ! ## 5.54: variant.value # comtypes ! ## 12.10: variant.value = 3.14 # comtypes --- 108,128 ---- ##ctypes version: 0.9.3 ##python version: 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] ! ## 0.37: Class() ! ## 0.96: POINT() ! ## 0.94: RECT() ! ## 0.25: point.y ! ## 1.94: rect.lr ! ## 7.16: fd.lprgelemdescParam ! ## 10.10: fd.lprgelemdescParam[0] ! ## 10.00: fd.lprgelemdescParam[1] ! ## 12.30: fd.lprgelemdescParam[1].tdesc ! ## 13.70: fd.lprgelemdescParam[1].tdesc.vt ! ## 19.30: fd.lprgelemdescParam[1].tdesc.u.lptdesc[0].vt ! ## 1.16: c_int() ! ## 1.34: c_int(42) ! ## 2.40: VARIANT() # ctypes.com ! ## 5.25: variant.value # ctypes.com ! ## 11.20: variant.value = 3.14 # ctypes.com ! ## 1.00: VARIANT() # comtypes ! ## 4.99: variant.value # comtypes ! ## 11.40: variant.value = 3.14 # comtypes |
From: Thomas H. <th...@us...> - 2005-02-16 20:53:17
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9105 Modified Files: _ctypes.c Log Message: Performance improvement. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.207 retrieving revision 1.208 diff -C2 -d -r1.207 -r1.208 *** _ctypes.c 16 Feb 2005 20:41:53 -0000 1.207 --- _ctypes.c 16 Feb 2005 20:53:05 -0000 1.208 *************** *** 2710,2713 **** --- 2710,2715 ---- return -1; } + if (PyTuple_GET_SIZE(args) == 0) + return 0; /* no initializers: nothing to do */ fields = PyObject_GetAttrString(self, "_fields_"); if (!fields) { |
From: Thomas H. <th...@us...> - 2005-02-16 20:47:04
|
Update of /cvsroot/ctypes/ctypes/comtypes/automation In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7302 Modified Files: __init__.py Log Message: Add new simple data type: VARIANT_BOOL, typecode 'v'. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/automation/__init__.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** __init__.py 11 Feb 2005 20:51:35 -0000 1.1 --- __init__.py 16 Feb 2005 20:46:35 -0000 1.2 *************** *** 12,16 **** from ctypes import _SimpleCData class VARIANT_BOOL(_SimpleCData): ! _type_ = "y" def __repr__(self): return "%s(%r)" % (self.__class__.__name__, self.value) --- 12,16 ---- from ctypes import _SimpleCData class VARIANT_BOOL(_SimpleCData): ! _type_ = "v" def __repr__(self): return "%s(%r)" % (self.__class__.__name__, self.value) *************** *** 119,122 **** --- 119,124 ---- ("c_wchar_p", c_wchar_p), ("c_void_p", c_void_p), + + ("bstrVal", BSTR), ] _fields_ = [("vt", VARTYPE), *************** *** 147,154 **** elif isinstance(value, unicode): self.vt = VT_BSTR ! self._.c_void_p = _oleaut32.SysAllocString(value) elif isinstance(value, str): self.vt = VT_BSTR ! self._.c_void_p = _oleaut32.SysAllocString(unicode(value)) elif isinstance(value, bool): self.vt = VT_BOOL --- 149,157 ---- elif isinstance(value, unicode): self.vt = VT_BSTR ! self._.c_void_p = _oleaut32.SysAllocStringLen(value, len(value)) elif isinstance(value, str): self.vt = VT_BSTR ! value = unicode(value) ! self._.c_void_p = _oleaut32.SysAllocStringLen(value, len(value)) elif isinstance(value, bool): self.vt = VT_BOOL *************** *** 200,204 **** return self._.VT_BOOL elif vt == VT_BSTR: ! return self._.c_wchar_p elif vt == VT_DATE: days = self._.VT_R8 --- 203,207 ---- return self._.VT_BOOL elif vt == VT_BSTR: ! return self._.bstrVal or u'' elif vt == VT_DATE: days = self._.VT_R8 *************** *** 242,245 **** --- 245,252 ---- VARIANTARG = VARIANT + ##from _ctypes import VARIANT_set + ##import new + ##VARIANT.value = property(VARIANT._get_value, new.instancemethod(VARIANT_set, None, VARIANT)) + class tagEXCEPINFO(Structure): |
From: Thomas H. <th...@us...> - 2005-02-16 20:42:22
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5888 Modified Files: cfield.c _ctypes.c Log Message: Add new simple data type: VARIANT_BOOL, typecode 'v'. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.72 retrieving revision 1.73 diff -C2 -d -r1.72 -r1.73 *** cfield.c 28 Jan 2005 15:11:54 -0000 1.72 --- cfield.c 16 Feb 2005 20:41:53 -0000 1.73 *************** *** 540,543 **** --- 540,567 ---- } + #ifdef MS_WIN32 + /* short BOOL - VARIANT_BOOL */ + static PyObject * + vBOOL_set(void *ptr, PyObject *value, unsigned size) + { + switch (PyObject_IsTrue(value)) { + case -1: + return NULL; + case 0: + *(short int *)ptr = VARIANT_FALSE; + _RET(value); + default: + *(short int *)ptr = VARIANT_TRUE; + _RET(value); + } + } + + static PyObject * + vBOOL_get(void *ptr, unsigned size) + { + return PyBool_FromLong((long)*(short int *)ptr); + } + #endif + static PyObject * I_set(void *ptr, PyObject *value, unsigned size) *************** *** 1134,1137 **** --- 1158,1162 ---- #ifdef MS_WIN32 { 'X', BSTR_set, BSTR_get, &ffi_type_pointer}, + { 'v', vBOOL_set, vBOOL_get, &ffi_type_sshort}, #endif { 'O', O_set, O_get, &ffi_type_pointer}, Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.206 retrieving revision 1.207 diff -C2 -d -r1.206 -r1.207 *** _ctypes.c 16 Feb 2005 13:17:33 -0000 1.206 --- _ctypes.c 16 Feb 2005 20:41:53 -0000 1.207 *************** *** 1001,1005 **** */ ! static char *SIMPLE_TYPE_CHARS = "cbBhHiIlLdfuzZqQPXO"; static PyObject * --- 1001,1005 ---- */ ! static char *SIMPLE_TYPE_CHARS = "cbBhHiIlLdfuzZqQPXOv"; static PyObject * |
From: Thomas H. <th...@us...> - 2005-02-16 20:40:32
|
Update of /cvsroot/ctypes/ctypes/unittests/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5422 Modified Files: test_perf.py Log Message: It's in better shape now. And includes some figures. Index: test_perf.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/com/test_perf.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_perf.py 16 Feb 2005 18:31:32 -0000 1.1 --- test_perf.py 16 Feb 2005 20:40:20 -0000 1.2 *************** *** 1,14 **** ! # Some preformance measurements ! def test(*args): from timeit import main ! print args[-1] main(args) - print ! from ctypes.com.client import Dispatch ! d = Dispatch("InternetExplorer.Application") ! fd = d.Navigate.fd from ctypes import * class POINT(Structure): --- 1,22 ---- ! import sys, re ! # Some preformance measurements ! def timeit(*args): from timeit import main ! from cStringIO import StringIO ! ! prev_stdout = sys.stdout ! sys.stdout = StringIO() ! main(args) ! out = sys.stdout.getvalue() ! sys.stdout = prev_stdout ! match = re.search(r"(\d+\.\d*|\d+) usec", out) ! time = float(match.group(1)) ! print "%8.2f: %s" % (time, args[-1]) + ################################################################ + import ctypes from ctypes import * class POINT(Structure): *************** *** 21,88 **** pass if __name__ == "__main__": ! # 0.382 us ! test("-s", "from test_perf import Class", "Class()") ! # 1.38 us ! test("-s", "from test_perf import POINT", "POINT()") ! # 1.43 us ! test("-s", "from test_perf import RECT", "RECT()") ! ! import sys ! sys.exit() ! ! # 0.238 us ! test("-s", "from test_perf import POINT; pt = POINT()", ! "pt.y") ! ! # 2.37 us ! test("-s", "from test_perf import RECT; rc = RECT()", ! "rc.lr") ! ! # 6.72 us ! test("-s", "from test_perf import fd", "fd.lprgelemdescParam") ! ! # 10.4 us = 6.72 us + 3.68 us ! test("-s", "from test_perf import fd", "fd.lprgelemdescParam[0]") ! ! # 10.4 us = 6.72 us + 3.68 us ! test("-s", "from test_perf import fd", "fd.lprgelemdescParam[1]") ! ! # 13.2 us = 10.u us + 2.80 us ! test("-s", "from test_perf import fd", "fd.lprgelemdescParam[1].tdesc") ! ! # 14 us = 13.2 + 0.8 us ! test("-s", "from test_perf import fd", "fd.lprgelemdescParam[1].tdesc.vt") ! ! # 20.7 us = 14 us + 6.7 us ! test("-s", "from test_perf import fd", "fd.lprgelemdescParam[1].tdesc.u.lptdesc[0].vt") ! # 1.12 us ! test('-s', "from ctypes import c_int", "c_int()") ! # 1.33 us ! test('-s', "from ctypes import c_int", "c_int(42)") ! # 2.46 us ! test('-s', "from ctypes.com.automation import VARIANT", "VARIANT()") ! ! # 5.41 us ! test('-s', "from ctypes.com.automation import VARIANT; v = VARIANT(3)", "v.value") ! ! # 5.27 us ! test('-s', "from comtypes.automation import VARIANT; v = VARIANT(3)", "v.value") ! # 11.7 us ! test('-s', "from ctypes.com.automation import VARIANT; v = VARIANT()", "v.value = 3.14") - # 13.3 us - test('-s', "from comtypes.automation import VARIANT; v = VARIANT()", "v.value = 3.14") --- 29,128 ---- pass + # get a FUNCDESC instance + from ctypes.com.client import Dispatch + d = Dispatch("InternetExplorer.Application") + fd = d.Navigate.fd + + ################################################################ + if __name__ == "__main__": ! print "ctypes version:", ctypes.__version__ ! print "python version:", sys.version ! ! timeit("-s", "from test_perf import Class", "Class()") ! timeit("-s", "from test_perf import POINT", "POINT()") ! timeit("-s", "from test_perf import RECT", "RECT()") ! timeit("-s", "from test_perf import POINT; point = POINT()", ! "point.y") ! timeit("-s", "from test_perf import RECT; rect = RECT()", ! "rect.lr") ! timeit("-s", "from test_perf import fd", "fd.lprgelemdescParam") ! timeit("-s", "from test_perf import fd", "fd.lprgelemdescParam[0]") ! timeit("-s", "from test_perf import fd", "fd.lprgelemdescParam[1]") ! timeit("-s", "from test_perf import fd", "fd.lprgelemdescParam[1].tdesc") ! timeit("-s", "from test_perf import fd", "fd.lprgelemdescParam[1].tdesc.vt") ! timeit("-s", "from test_perf import fd", "fd.lprgelemdescParam[1].tdesc.u.lptdesc[0].vt") + timeit('-s', "from ctypes import c_int", + "c_int()") + timeit('-s', "from ctypes import c_int", + "c_int(42)") + timeit('-s', "from ctypes.com.automation import VARIANT", + "VARIANT() # ctypes.com") + timeit('-s', "from ctypes.com.automation import VARIANT; variant = VARIANT(3)", + "variant.value # ctypes.com") + timeit('-s', "from ctypes.com.automation import VARIANT; variant = VARIANT()", + "variant.value = 3.14 # ctypes.com") + try: + import comtypes + except ImportError: + sys.exit() + timeit('-s', "from comtypes.automation import VARIANT", + "VARIANT() # comtypes") + timeit('-s', "from comtypes.automation import VARIANT; variant = VARIANT(3)", + "variant.value # comtypes") + timeit('-s', "from comtypes.automation import VARIANT; variant = VARIANT()", + "variant.value = 3.14 # comtypes") ! # on my machine: ! ##ctypes version: 0.9.2 ! ##python version: 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] ! ## 0.38: Class() ! ## 1.97: POINT() ! ## 1.98: RECT() ! ## 0.24: point.y ! ## 2.43: rect.lr ! ## 7.21: fd.lprgelemdescParam ! ## 10.90: fd.lprgelemdescParam[0] ! ## 12.00: fd.lprgelemdescParam[1] ! ## 15.30: fd.lprgelemdescParam[1].tdesc ! ## 16.00: fd.lprgelemdescParam[1].tdesc.vt ! ## 26.20: fd.lprgelemdescParam[1].tdesc.u.lptdesc[0].vt ! ## 1.80: c_int() ! ## 1.97: c_int(42) ! ## 2.93: VARIANT() # ctypes.com ! ## 5.30: variant.value # ctypes.com ! ## 11.60: variant.value = 3.14 # ctypes.com + ##ctypes version: 0.9.3 + ##python version: 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] + ## 0.41: Class() + ## 1.34: POINT() + ## 1.39: RECT() + ## 0.23: point.y + ## 2.36: rect.lr + ## 7.22: fd.lprgelemdescParam + ## 10.80: fd.lprgelemdescParam[0] + ## 10.90: fd.lprgelemdescParam[1] + ## 13.50: fd.lprgelemdescParam[1].tdesc + ## 14.40: fd.lprgelemdescParam[1].tdesc.vt + ## 21.70: fd.lprgelemdescParam[1].tdesc.u.lptdesc[0].vt + ## 1.13: c_int() + ## 1.32: c_int(42) + ## 2.34: VARIANT() # ctypes.com + ## 5.49: variant.value # ctypes.com + ## 11.60: variant.value = 3.14 # ctypes.com + ## 1.40: VARIANT() # comtypes + ## 5.54: variant.value # comtypes + ## 12.10: variant.value = 3.14 # comtypes |
From: Thomas H. <th...@us...> - 2005-02-16 18:31:42
|
Update of /cvsroot/ctypes/ctypes/unittests/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3651 Added Files: test_perf.py Log Message: Some performance tests. --- NEW FILE: test_perf.py --- # Some preformance measurements def test(*args): from timeit import main print args[-1] main(args) print from ctypes.com.client import Dispatch d = Dispatch("InternetExplorer.Application") fd = d.Navigate.fd from ctypes import * class POINT(Structure): _fields_ = [("x", c_int), ("y", c_int)] class RECT(Structure): _fields_ = [("ul", POINT), ("lr", POINT)] class Class(object): pass if __name__ == "__main__": # 0.382 us test("-s", "from test_perf import Class", "Class()") # 1.38 us test("-s", "from test_perf import POINT", "POINT()") # 1.43 us test("-s", "from test_perf import RECT", "RECT()") import sys sys.exit() # 0.238 us test("-s", "from test_perf import POINT; pt = POINT()", "pt.y") # 2.37 us test("-s", "from test_perf import RECT; rc = RECT()", "rc.lr") # 6.72 us test("-s", "from test_perf import fd", "fd.lprgelemdescParam") # 10.4 us = 6.72 us + 3.68 us test("-s", "from test_perf import fd", "fd.lprgelemdescParam[0]") # 10.4 us = 6.72 us + 3.68 us test("-s", "from test_perf import fd", "fd.lprgelemdescParam[1]") # 13.2 us = 10.u us + 2.80 us test("-s", "from test_perf import fd", "fd.lprgelemdescParam[1].tdesc") # 14 us = 13.2 + 0.8 us test("-s", "from test_perf import fd", "fd.lprgelemdescParam[1].tdesc.vt") # 20.7 us = 14 us + 6.7 us test("-s", "from test_perf import fd", "fd.lprgelemdescParam[1].tdesc.u.lptdesc[0].vt") # 1.12 us test('-s', "from ctypes import c_int", "c_int()") # 1.33 us test('-s', "from ctypes import c_int", "c_int(42)") # 2.46 us test('-s', "from ctypes.com.automation import VARIANT", "VARIANT()") # 5.41 us test('-s', "from ctypes.com.automation import VARIANT; v = VARIANT(3)", "v.value") # 5.27 us test('-s', "from comtypes.automation import VARIANT; v = VARIANT(3)", "v.value") # 11.7 us test('-s', "from ctypes.com.automation import VARIANT; v = VARIANT()", "v.value = 3.14") # 13.3 us test('-s', "from comtypes.automation import VARIANT; v = VARIANT()", "v.value = 3.14") |
From: Thomas H. <th...@us...> - 2005-02-16 16:39:13
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6854 Modified Files: client.py Log Message: Refactoring: move some common code into the _do_invoke helper method. Index: client.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/client.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** client.py 16 Feb 2005 16:32:22 -0000 1.8 --- client.py 16 Feb 2005 16:39:04 -0000 1.9 *************** *** 190,194 **** # http://aromakiki.ismyweb.net/doc/S1227.htm ! class _Dispatch(object): # these are to silence pychecker _comobj = None --- 190,213 ---- # http://aromakiki.ismyweb.net/doc/S1227.htm ! class _InvokeMixin(object): ! def _do_invoke(self, memid, invkind, parms): ! result = VARIANT() ! excepinfo = EXCEPINFO() ! uArgError = c_uint() ! try: ! self._comobj.Invoke(memid, ! byref(guid_null), ! 0, # LCID ! invkind, ! byref(parms), ! byref(result), # pVarResult ! byref(excepinfo), # pExcepInfo ! byref(uArgError)) # puArgError ! except WindowsError, what: ! assert excepinfo.pfnDeferredFillIn == 0 ! raise COMError(what.errno, what.strerror, excepinfo.as_tuple(), uArgError.value) ! return result ! ! class _Dispatch(_InvokeMixin): # these are to silence pychecker _comobj = None *************** *** 227,255 **** def __prop_get(self, memid): ! result = VARIANT() ! self._comobj.Invoke(memid, ! byref(guid_null), ! 0, # LCID ! DISPATCH_PROPERTYGET, ! byref(DISPPARAMS()), ! byref(result), ! None, # pExcepInfo ! None) # puArgError return _wrap(result) def __prop_put(self, memid, value): parms = DISPPARAMS() - parms.cArgs = 1 parms.rgvarg = pointer(VARIANT(value)) - parms.cNamedArgs = 1 parms.rgdispidNamedArgs = pointer(DISPID(DISPID_PROPERTYPUT)) ! self._comobj.Invoke(memid, ! byref(guid_null), ! 0, # LCID ! DISPATCH_PROPERTYPUT, ! byref(parms), ! None, # pVarResult ! None, # pExcepInfo ! None) # puArgError def __setattr__(self, name, value): --- 246,259 ---- def __prop_get(self, memid): ! result = self._do_invoke(memid, DISPATCH_PROPERTYGET, DISPPARAMS()) return _wrap(result) def __prop_put(self, memid, value): parms = DISPPARAMS() parms.rgvarg = pointer(VARIANT(value)) parms.rgdispidNamedArgs = pointer(DISPID(DISPID_PROPERTYPUT)) ! parms.cArgs = 1 ! parms.cNamedArgs = 1 ! self._do_invoke(memid, DISPATCH_PROPERTYPUT, parms) def __setattr__(self, name, value): *************** *** 323,327 **** return _wrap(result) ! class _DispMethod(object): def __init__(self, name, comobj, fd): self.name = name --- 327,331 ---- return _wrap(result) ! class _DispMethod(_InvokeMixin): def __init__(self, name, comobj, fd): self.name = name *************** *** 378,398 **** def __call__(self, *args, **kw): parms = self._build_parms(*args, **kw) ! result = VARIANT() ! excepinfo = EXCEPINFO() ! uArgError = c_uint() ! try: ! self._comobj.Invoke(self.fd.memid, ! byref(guid_null), ! 0, # LCID ! self.fd.invkind, ! byref(parms), ! byref(result), # pVarResult ! byref(excepinfo), # pExcepInfo ! byref(uArgError)) # puArgError ! except WindowsError, (errno, strerror): ! assert excepinfo.pfnDeferredFillIn == 0 ! # No need for GetErrorInfo, DispInvoke already returns ! # info in excepinfo. ! raise COMError(errno, strerror, excepinfo.as_tuple(), uArgError.value) return _wrap(result) --- 382,386 ---- def __call__(self, *args, **kw): parms = self._build_parms(*args, **kw) ! result = self._do_invoke(self.fd.memid, self.fd.invkind, parms) return _wrap(result) |
From: Thomas H. <th...@us...> - 2005-02-16 16:32:33
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5063 Modified Files: client.py Log Message: Remove test code. Index: client.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/client.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** client.py 16 Feb 2005 16:17:01 -0000 1.7 --- client.py 16 Feb 2005 16:32:22 -0000 1.8 *************** *** 572,651 **** - if __name__ == "__main__": - - # win32com code: - # moniker, i, bindCtx = pythoncom.MkParseDisplayName(Pathname) - # dispatch = moniker.BindToObject(bindCtx, None, pythoncom.IID_IDispatch) - - d = GetObject("winmgmts:") - result = d.ExecQuery("SELECT * FROM Win32_LogicalDisk")# WHERE CAPTION = 'System Idle Process'") - ## print len(result) - ## print result.Count - for i in result: - print i.GetObjectText_() - ## print len(i.Properties_) - - ## print i.Properties_.Item("Handle").Value - - ## for p in i.Properties_: - ## print p.Name, p.Value - - - raise SystemExit - - ################################################################ - - if __name__ == "__main__": - - def test1(): - ## from ctypes.com.client import Dispatch - - ag = Dispatch("Agent.Control") - ag.Connected = 1 - ag.ShowDefaultCharacterProperties() - ag.Characters.Load("Merlin") - c1 = ag.Characters.Item("Merlin") - #ch = ag.Characters("Merlin") - c1.Show() - c1.Speak("Python is cool!") - c1.GestureAt(500, 20) - c1.Think("Although you need ctypes as well ;-)") - import time - time.sleep(10) - c1.Hide() - ag.Connected = 0 - ##ag.Unload() - ## test1() - - def test3(): - ## from win32com.client import DispatchWithEvents - - class Receiver: - - def OnQuit(self, *args): - print "OnQuit", args - windll.user32.PostQuitMessage(0) - - def BeforeNavigate2(self, disp, URL, Flags, TargetFrameName, PostData, Headers, Cancel): - print "BeforeNavigate2", (disp, URL, Flags, TargetFrameName, PostData, Headers, Cancel) - ## return disp, URL, Flags, TargetFrameName, PostData, Headers, Cancel - ## return 1 - - def NewWindow2(self, *args): - print "NewWindow2", args - - def NavigateComplete2(self, *args): - print "NavigateComplete2", args - - def StatusTextChange(self, *args): - print "StatusTextChange", args - - m = DispatchWithEvents("InternetExplorer.Application", Receiver) - m.Visible = True - m.Navigate("http://www.python.org") - - from ctypes.com.server import pump_messages - pump_messages() - - test3() --- 572,574 ---- |
From: Thomas H. <th...@us...> - 2005-02-16 16:17:10
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv972 Modified Files: client.py Log Message: Add WithEvents function. Index: client.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/client.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** client.py 16 Feb 2005 16:06:27 -0000 1.6 --- client.py 16 Feb 2005 16:17:01 -0000 1.7 *************** *** 552,564 **** return result ! ##def GetObject(displayName): ! ## # see also: c:/python23/lib/site-packages/win32com/client/__init__.py 47 ! ## # win32com is more flexible ! ## from ctypes.com.moniker import MkParseDisplayName ! ## moniker, i, bindCtx = MkParseDisplayName(displayName) ! ## pdisp = POINTER(IDispatch)() ! ## moniker.BindToObject(bindCtx, None, byref(IDispatch._iid_), byref(pdisp)) ! ## return _Dispatch(pdisp) def GetObject(displayName): --- 552,567 ---- return result ! def WithEvents(d, user_class): ! class EventReceiver(_EventReceiver): ! _com_interfaces_ = [_CreateOutgoingInterface(d._comobj, None)] ! rcv = EventReceiver(user_class) ! _objects.append(rcv) ! info = rcv.connect(d._comobj) ! ! ## def disconnect(): ! ## rcv.disconnect(info) ! ! return rcv def GetObject(displayName): |
From: Thomas H. <th...@us...> - 2005-02-16 16:06:36
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30607 Modified Files: client.py Log Message: Improve COM property get, by some guesswork. Index: client.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/client.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** client.py 27 May 2004 18:22:14 -0000 1.5 --- client.py 16 Feb 2005 16:06:27 -0000 1.6 *************** *** 267,270 **** --- 267,278 ---- if fd.cParams == 0: return self.__prop_get(fd.memid) + if fd.cParams == 1 and fd.cParamsOpt == 0: + # Guesswork. InternetExplorer, and other typelibs, + # have propget properties with cParams == 1, and cParamsOpt == 0. + # The parameter type is VT_PTR | VT_..., and wPARAMFlags == PARAMFLAG_FOPT. + # + # And calling those without any parameter via Invoke works great... + if fd.lprgelemdescParam[0].paramdesc.wPARAMFlags == 10: + return self.__prop_get(fd.memid) return _DispMethod(name, self._comobj, fd) elif fd.invkind == DISPATCH_METHOD: *************** *** 384,387 **** --- 392,397 ---- except WindowsError, (errno, strerror): assert excepinfo.pfnDeferredFillIn == 0 + # No need for GetErrorInfo, DispInvoke already returns + # info in excepinfo. raise COMError(errno, strerror, excepinfo.as_tuple(), uArgError.value) return _wrap(result) |
From: Thomas H. <th...@us...> - 2005-02-16 13:17:53
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20511 Modified Files: test_slicing.py Log Message: Fixes for cygwin. Index: test_slicing.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_slicing.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** test_slicing.py 14 Oct 2004 13:16:13 -0000 1.4 --- test_slicing.py 16 Feb 2005 13:17:42 -0000 1.5 *************** *** 70,73 **** --- 70,74 ---- dll = CDLL(find_test_dll()) dll.my_wcsdup.restype = POINTER(c_wchar) + dll.my_wcsdup.argtypes = POINTER(c_wchar), res = dll.my_wcsdup(s) self.failUnlessEqual(res[:len(s)], s) |
From: Thomas H. <th...@us...> - 2005-02-16 13:17:43
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20464 Modified Files: _ctypes_test.c _ctypes.c Log Message: Fixes for cygwin. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.205 retrieving revision 1.206 diff -C2 -d -r1.205 -r1.206 *** _ctypes.c 10 Feb 2005 09:11:00 -0000 1.205 --- _ctypes.c 16 Feb 2005 13:17:33 -0000 1.206 *************** *** 244,247 **** --- 244,252 ---- if (!address) { PyErr_Format(PyExc_ValueError, + #ifdef __CYGWIN__ + /* dlerror() isn't very helpful on cygwin */ + "symbol '%s' not found (%s) ", + name, + #endif dlerror()); return NULL; *************** *** 2302,2305 **** --- 2307,2315 ---- if (!address) { PyErr_Format(PyExc_AttributeError, + #ifdef __CYGWIN__ + /* dlerror() isn't very helpful on cygwin */ + "function '%s' not found (%s) ", + name, + #endif dlerror()); return NULL; Index: _ctypes_test.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes_test.c,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** _ctypes_test.c 3 Dec 2004 09:09:40 -0000 1.41 --- _ctypes_test.c 16 Feb 2005 13:17:32 -0000 1.42 *************** *** 13,17 **** #endif ! #ifdef MS_WIN32 #define EXPORT(x) __declspec(dllexport) x #else --- 13,17 ---- #endif ! #if defined(MS_WIN32) || defined(__CYGWIN__) #define EXPORT(x) __declspec(dllexport) x #else |
From: Thomas H. <th...@us...> - 2005-02-16 13:17:25
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20414 Modified Files: __init__.py Log Message: Fixes for cygwin. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** __init__.py 4 Feb 2005 18:07:44 -0000 1.53 --- __init__.py 16 Feb 2005 13:17:15 -0000 1.54 *************** *** 416,419 **** --- 416,421 ---- if _os.name == "nt": pythonapi = PyDLL("python dll", sys.dllhandle) + elif sys.platform == "cygwin": + pythonapi = PyDLL("libpython%d.%d.dll" % sys.version_info[:2]) else: pythonapi = PyDLL(None) |
From: Thomas H. <th...@us...> - 2005-02-16 08:49:49
|
Update of /cvsroot/ctypes/ctypes/comtypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24306 Added Files: test_GUID.py Log Message: Tests for GUID. --- NEW FILE: test_GUID.py --- import unittest from comtypes import GUID class Test(unittest.TestCase): def test(self): self.failUnlessEqual(GUID(), GUID()) self.failUnlessEqual(GUID("{00000000-0000-0000-C000-000000000046}"), GUID("{00000000-0000-0000-C000-000000000046}")) self.failUnlessEqual(str(GUID("{0002DF01-0000-0000-C000-000000000046}")), "{0002DF01-0000-0000-C000-000000000046}") self.failUnlessEqual(repr(GUID("{0002DF01-0000-0000-C000-000000000046}")), 'GUID("{0002DF01-0000-0000-C000-000000000046}")') self.assertRaises(WindowsError, GUID, "abc") self.assertRaises(WindowsError, GUID.from_progid, "abc") self.assertRaises(WindowsError, lambda guid: guid.progid(), GUID("{00000000-0000-0000-C000-000000000046}")) self.failUnlessEqual(GUID.from_progid("InternetExplorer.Application"), GUID("{0002DF01-0000-0000-C000-000000000046}")) self.failUnlessEqual(GUID("{0002DF01-0000-0000-C000-000000000046}").progid(), u'InternetExplorer.Application.1') if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2005-02-16 08:49:15
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24197 Modified Files: GUID.py Log Message: Add a progid method. Index: GUID.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/GUID.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GUID.py 11 Feb 2005 20:44:27 -0000 1.3 --- GUID.py 16 Feb 2005 08:49:05 -0000 1.4 *************** *** 49,52 **** --- 49,57 ---- from_progid = classmethod(from_progid) + def progid(self): + progid = c_wchar_p() + _ole32.ProgIDFromCLSID(byref(self), byref(progid)) + return progid.value + assert(sizeof(GUID) == 16), sizeof(GUID) |
From: Thomas H. <th...@us...> - 2005-02-14 14:33:48
|
Update of /cvsroot/ctypes/ctypes/unittests/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16874 Modified Files: test_variant.py Log Message: BSTR instances can contain NUL bytes: transfer these in and out of VARIANTs. Index: test_variant.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/com/test_variant.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_variant.py 19 Aug 2004 10:21:22 -0000 1.3 --- test_variant.py 14 Feb 2005 14:33:39 -0000 1.4 *************** *** 89,92 **** --- 89,106 ---- self.failUnlessEqual(v.value, now) + def test_BSTR(self): + from ctypes.com.automation import BSTR, VT_BSTR + v = VARIANT() + v.value = u"abc\x00123\x00" + self.failUnlessEqual(v.value, "abc\x00123\x00") + + v.value = None + # manually clear the variant + v._.VT_I4 = 0 + + # NULL pointer BSTR should be handled as empty string + v.vt = VT_BSTR + self.failUnlessEqual(v.value, "") + ################################################################ |