ctypes-commit Mailing List for ctypes (Page 73)
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-14 14:30:28
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15311 Modified Files: automation.py Log Message: BSTR instances can contain NUL bytes: transfer these in and out of VARIANTs. Index: automation.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/automation.py,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** automation.py 19 Aug 2004 10:21:32 -0000 1.19 --- automation.py 14 Feb 2005 14:30:18 -0000 1.20 *************** *** 311,314 **** --- 311,315 ---- # faked fields, only for our convenience: ("wstrVal", c_wchar_p), + ("bstrVal", BSTR), ("voidp", c_void_p), ] *************** *** 346,353 **** elif typ is str: self.vt = VT_BSTR ! self._.voidp = oleaut32.SysAllocString(unicode(value)) elif typ is unicode: self.vt = VT_BSTR ! self._.voidp = oleaut32.SysAllocString(value) elif value is None: return --- 347,355 ---- elif typ is str: self.vt = VT_BSTR ! value = unicode(value) ! self._.voidp = oleaut32.SysAllocStringLen(value, len(value)) elif typ is unicode: self.vt = VT_BSTR ! self._.voidp = oleaut32.SysAllocStringLen(value, len(value)) elif value is None: return *************** *** 399,403 **** elif self.vt == VT_BSTR: # NULL BSTR count as empty strings, not None! ! return self._.wstrVal or u'' # The following code can be enabled again when all the POINTER(ISomeInterface) # classes have a constructor that calls AddRef() if not-null. --- 401,406 ---- elif self.vt == VT_BSTR: # NULL BSTR count as empty strings, not None! ! ## return self._.wstrVal or u'' ! return self._.bstrVal or u'' # The following code can be enabled again when all the POINTER(ISomeInterface) # classes have a constructor that calls AddRef() if not-null. |
From: Thomas H. <th...@us...> - 2005-02-11 20:54:55
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24658 Modified Files: codegenerator.py Log Message: Small fixes, plus COMMethod wrapper generation, plus commented out template support. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/codegenerator.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** codegenerator.py 4 Feb 2005 21:19:41 -0000 1.1 --- codegenerator.py 11 Feb 2005 20:54:32 -0000 1.2 *************** *** 11,16 **** # def CoClass(self, coclass): - for itf, idlflags in coclass.interfaces: - self.generate(itf) print >> self.stream, "class %s(CoClass):" % coclass.name doc = getattr(coclass, "doc", None) --- 11,14 ---- *************** *** 19,22 **** --- 17,22 ---- print >> self.stream, " _clsid_ = GUID(%r)" % coclass.clsid print >> self.stream, " _idlflags_ = %s" % coclass.idlflags + for itf, idlflags in coclass.interfaces: + self.generate(itf) implemented = [i[0].name for i in coclass.interfaces if i[1] & 2 == 0] *************** *** 24,30 **** if i[1] & 2] if implemented: ! print >> self.stream, " _com_interfaces_ = [%s]" % ", ".join(implemented) if sources: ! print >> self.stream, " _outgoing_interfaces_ = [%s]" % ", ".join(sources) print >> self.stream --- 24,30 ---- if i[1] & 2] if implemented: ! print >> self.stream, "%s._com_interfaces_ = [%s]" % (coclass.name, ", ".join(implemented)) if sources: ! print >> self.stream, "%s._outgoing_interfaces_ = [%s]" % (coclass.name, ", ".join(sources)) print >> self.stream *************** *** 36,43 **** --- 36,52 ---- self.generate(head.itf.base) basename = self.type_name(head.itf.base) + + ## tpl = self.templates.get(head.itf.name, None) + ## if tpl is not None: + ## print >> self.stream, tpl + ## return + print >> self.stream, "class %s(%s):" % (head.itf.name, basename) print >> self.stream, " _iid_ = GUID(%r)" % head.itf.iid print >> self.stream, " _idlflags_ = %s" % head.itf.idlflags + for m in head.itf.members: + is_property = self.make_ComMethodWrapper(m) + def ComInterfaceBody(self, body): # make sure we can generate the body *************** *** 62,65 **** --- 71,79 ---- self.generate(head.itf.base) basename = self.type_name(head.itf.base) + ## tpl = self.templates.get(head.itf.name, None) + ## if tpl is not None: + ## print >> self.stream, tpl + ## return + print >> self.stream, "class %s(%s):" % (head.itf.name, basename) doc = getattr(head.itf, "doc", None) *************** *** 204,207 **** --- 218,263 ---- return None + def make_ComMethodWrapper(self, m): + funcname = m.name + args = m.arguments + inargs = [] + for typ, name, idlflags, default in args: + if "in" in idlflags: + if default is not None: + inargs.append("%s=%r" % (name, default)) + elif "optional" in idlflags: + inargs.append("%s=%s" % (name, "MISSING")) + else: + inargs.append(name) + + allargs = [] + flocals = [] + for typ, name, idlflags, default in args: + # XXX What about [in, out] parameters? + if "out" in idlflags: + assert isinstance(typ, typedesc.PointerType) + flocals.append((name, self.type_name(typ.typ))) + allargs.append("byref(%s)" % name) + else: + allargs.append(name) + + # Now that POINTER(<com_interface>) instances have a .value property + # which returns the com pointer itself, we can do this FOR ALL types: + outargs = ["%s.value" % name for (typ, name, idlflags, default) in args + if "out" in idlflags] + + print >> self.stream, " def %s(%s):" % (funcname, ", ".join(["self"] + inargs)) + doc = getattr(m, "doc", None) + if doc: + print >> self.stream, " %r" % doc + for n, t in flocals: + print >> self.stream, " %s = %s()" % (n, t) + if outargs: + print >> self.stream, " self.__com_%s(%s)" % (funcname, ", ".join(allargs)) + print >> self.stream, " return %s" % ", ".join(outargs) + else: + print >> self.stream, " return self.__com_%s(%s)" % (funcname, ", ".join(allargs)) + + def make_DispMethodWrapper(self, m): if isinstance(m, typedesc.DispProperty): |
From: Thomas H. <th...@us...> - 2005-02-11 20:51:47
|
Update of /cvsroot/ctypes/ctypes/comtypes/automation In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23377 Added Files: __init__.py Log Message: comtypes.automation is a package now. TypeInfo support will go into a submodule. --- NEW FILE: __init__.py --- # comtypes.automation package from ctypes import * from _ctypes import CopyComPointer from comtypes import IUnknown, GUID, IID, STDMETHOD, BSTR import datetime # for VT_DATE, standard in Python 2.3 and up try: import decimal # standard in Python 2.4 and up except ImportError: decimal = None from ctypes import _SimpleCData class VARIANT_BOOL(_SimpleCData): _type_ = "y" def __repr__(self): return "%s(%r)" % (self.__class__.__name__, self.value) assert(sizeof(VARIANT_BOOL) == 2) # these may be moved elsewhere... WORD = c_ushort UINT = c_uint DWORD = c_ulong LONG = c_long WCHAR = c_wchar LCID = DWORD DISPID = LONG SCODE = LONG VARTYPE = c_ushort ################################ # helper constants IID_NULL = GUID() riid_null = byref(IID_NULL) _oleaut32 = oledll.oleaut32 # 30. December 1899, midnight. For VT_DATE. _com_null_date = datetime.datetime(1899, 12, 30, 0, 0, 0) ################################################################ # VARIANT, in all it's glory. VARENUM = c_int # enum VT_EMPTY = 0 VT_NULL = 1 VT_I2 = 2 VT_I4 = 3 VT_R4 = 4 VT_R8 = 5 VT_CY = 6 VT_DATE = 7 VT_BSTR = 8 VT_DISPATCH = 9 VT_ERROR = 10 VT_BOOL = 11 VT_VARIANT = 12 VT_UNKNOWN = 13 VT_DECIMAL = 14 VT_I1 = 16 VT_UI1 = 17 VT_UI2 = 18 VT_UI4 = 19 VT_I8 = 20 VT_UI8 = 21 VT_INT = 22 VT_UINT = 23 VT_VOID = 24 VT_HRESULT = 25 VT_PTR = 26 VT_SAFEARRAY = 27 VT_CARRAY = 28 VT_USERDEFINED = 29 VT_LPSTR = 30 VT_LPWSTR = 31 VT_RECORD = 36 VT_INT_PTR = 37 VT_UINT_PTR = 38 VT_FILETIME = 64 VT_BLOB = 65 VT_STREAM = 66 VT_STORAGE = 67 VT_STREAMED_OBJECT = 68 VT_STORED_OBJECT = 69 VT_BLOB_OBJECT = 70 VT_CF = 71 VT_CLSID = 72 VT_VERSIONED_STREAM = 73 VT_BSTR_BLOB = 4095 VT_VECTOR = 4096 VT_ARRAY = 8192 VT_BYREF = 16384 VT_RESERVED = 32768 VT_ILLEGAL = 65535 VT_ILLEGALMASKED = 4095 VT_TYPEMASK = 4095 class tagCY(Structure): _fields_ = [("int64", c_longlong)] CY = tagCY CURRENCY = CY class tagVARIANT(Structure): # The C Header file defn of VARIANT is much more complicated, but # this is the ctypes version - functional as well. class U_VARIANT(Union): _fields_ = [ ("VT_BOOL", VARIANT_BOOL), ("VT_I1", c_byte), ("VT_I2", c_short), ("VT_I4", c_long), ("VT_INT", c_int), ("VT_UI1", c_ubyte), ("VT_UI2", c_ushort), ("VT_UI4", c_ulong), ("VT_UINT", c_uint), ("VT_R4", c_float), ("VT_R8", c_double), ("VT_CY", c_longlong), ("c_wchar_p", c_wchar_p), ("c_void_p", c_void_p), ] _fields_ = [("vt", VARTYPE), ("wReserved1", c_ushort), ("wReserved2", c_ushort), ("wReserved3", c_ushort), ("_", U_VARIANT) ] # see also c:/sf/pywin32/com/win32com/src/oleargs.cpp 54 def _set_value(self, value): _oleaut32.VariantClear(byref(self)) if value is None: self.vt = VT_NULL elif isinstance(value, int): self.vt = VT_I4 self._.VT_I4 = value elif isinstance(value, long): self.vt = VT_I4 u = self._ u.VT_I4 = value if u.VT_I4 != value: self.vt = VT_R8 u.VT_R8 = float(value) elif isinstance(value, float): self.vt = VT_R8 self._.VT_R8 = value 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 self._.VT_BOOL = value elif isinstance(value, datetime.datetime): delta = value - _com_null_date # a day has 24 * 60 * 60 = 86400 seconds com_days = delta.days + (delta.seconds + delta.microseconds * 1e-6) / 86400. self.vt = VT_DATE self._.VT_R8 = com_days elif decimal is not None and isinstance(value, decimal.Decimal): self._.VT_CY = int(round(value * 10000)) elif isinstance(value, POINTER(IDispatch)): CopyComPointer(value, byref(self._)) self.vt = VT_DISPATCH elif isinstance(value, POINTER(IUnknown)): CopyComPointer(value, byref(self._)) self.vt = VT_UNKNOWN else: raise "NYI", value # buffer -> SAFEARRAY of VT_UI1 ? # c:/sf/pywin32/com/win32com/src/oleargs.cpp 197 def _get_value(self): vt = self.vt if vt in (VT_EMPTY, VT_NULL): return None elif vt == VT_I1: return self._.VT_I1 elif vt == VT_I2: return self._.VT_I2 elif vt == VT_I4: return self._.VT_I4 elif vt == VT_INT: return self._.VT_INT elif vt == VT_UI1: return self._.VT_UI1 elif vt == VT_UI2: return self._.VT_UI2 elif vt == VT_UI4: return self._.VT_UI4 elif vt == VT_UINT: return self._.VT_UINT elif vt == VT_R4: return self._.VT_R4 elif vt == VT_R8: return self._.VT_R8 elif vt == VT_BOOL: return self._.VT_BOOL elif vt == VT_BSTR: return self._.c_wchar_p elif vt == VT_DATE: days = self._.VT_R8 return datetime.timedelta(days=days) + _com_null_date elif vt == VT_CY: if decimal is not None: return self._.VT_CY / decimal.Decimal("10000") else: return self._.VT_CY / 10000. else: raise "NYI", vt # these are missing: ## getter[VT_ERROR] ## getter[VT_ARRAY] ## getter[VT_BYREF|VT_UI1] ## getter[VT_BYREF|VT_I2] ## getter[VT_BYREF|VT_I4] ## getter[VT_BYREF|VT_R4] ## getter[VT_BYREF|VT_R8] ## getter[VT_BYREF|VT_BOOL] ## getter[VT_BYREF|VT_ERROR] ## getter[VT_BYREF|VT_CY] ## getter[VT_BYREF|VT_DATE] ## getter[VT_BYREF|VT_BSTR] ## getter[VT_BYREF|VT_UNKNOWN] ## getter[VT_BYREF|VT_DISPATCH] ## getter[VT_BYREF|VT_ARRAY] ## getter[VT_BYREF|VT_VARIANT] ## getter[VT_BYREF] ## getter[VT_BYREF|VT_DECIMAL] ## getter[VT_BYREF|VT_I1] ## getter[VT_BYREF|VT_UI2] ## getter[VT_BYREF|VT_UI4] ## getter[VT_BYREF|VT_INT] ## getter[VT_BYREF|VT_UINT] value = property(_get_value, _set_value) VARIANT = tagVARIANT VARIANTARG = VARIANT class tagEXCEPINFO(Structure): pass tagEXCEPINFO._fields_ = [ ('wCode', WORD), ('wReserved', WORD), ('bstrSource', BSTR), ('bstrDescription', BSTR), ('bstrHelpFile', BSTR), ('dwHelpContext', DWORD), ('pvReserved', c_void_p), ('pfnDeferredFillIn', WINFUNCTYPE(HRESULT, POINTER(tagEXCEPINFO))), ('scode', SCODE), ] assert sizeof(tagEXCEPINFO) == 32, sizeof(tagEXCEPINFO) assert alignment(tagEXCEPINFO) == 4, alignment(tagEXCEPINFO) EXCEPINFO = tagEXCEPINFO class tagDISPPARAMS(Structure): _fields_ = [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 696 ('rgvarg', POINTER(VARIANTARG)), ('rgdispidNamedArgs', POINTER(DISPID)), ('cArgs', UINT), ('cNamedArgs', UINT), ] assert sizeof(tagDISPPARAMS) == 16, sizeof(tagDISPPARAMS) assert alignment(tagDISPPARAMS) == 4, alignment(tagDISPPARAMS) DISPPARAMS = tagDISPPARAMS DISPID_VALUE = 0 DISPID_UNKNOWN = -1 DISPID_PROPERTYPUT = -3 DISPID_NEWENUM = -4 DISPID_EVALUATE = -5 DISPID_CONSTRUCTOR = -6 DISPID_DESTRUCTOR = -7 DISPID_COLLECT = -8 class IDispatch(IUnknown): _iid_ = GUID("{00020400-0000-0000-C000-000000000046}") _methods_ = [ STDMETHOD(HRESULT, 'GetTypeInfoCount', [POINTER(UINT)]), STDMETHOD(HRESULT, 'GetTypeInfo', [UINT, LCID, POINTER(c_void_p)]), STDMETHOD(HRESULT, 'GetIDsOfNames', [POINTER(IID), POINTER(c_wchar_p), UINT, LCID, POINTER(DISPID)]), STDMETHOD(HRESULT, 'Invoke', [DISPID, POINTER(IID), LCID, WORD, POINTER(DISPPARAMS), POINTER(VARIANT), POINTER(EXCEPINFO), POINTER(UINT)]), ] def GetTypeInfoCount(self): r = c_uint() self.__com_GetTypeInfoCount(byref(r)) return r.value def GetTypeInfo(self, index, lcid=0): p = POINTER(IUnknown)() self.__com_GetTypeInfo(index, lcid, byref(p)) return p def GetIDsOfNames(self, *names, **kw): lcid = kw.pop("lcid", 0) assert not kw arr = (c_wchar_p * len(names))(*names) ids = (DISPID * len(names))() self.__com_GetIDsOfNames(riid_null, arr, len(names), lcid, ids) return [i for i in ids] def Invoke(self, dispid, *args, **kw): _invkind = kw.pop("_invkind", 1) # DISPATCH_METHOD _lcid = kw.pop("_lcid", 0) result = VARIANT() excepinfo = EXCEPINFO() argerr = c_uint() if _invkind == 1: # method dp = DISPPARAMS() dp.cArgs = len(args) dp.cNamedArgs = 0 dp.rgvarg = (VARIANT * len(args))() for i, a in enumerate(args): dp.rgvarg[len(args) - i - 1].value = a elif _invkind == 4: # propput assert len(args) == 1 dp = DISPPARAMS() dp.cArgs = 1 dp.cNamedArgs = 1 dp.rgvarg = pointer(VARIANT()) dp.rgvarg[0].value = args[0] dp.rgdispidNamedArgs = pointer(DISPID(DISPID_PROPERTYPUT)) try: self.__com_Invoke(dispid, riid_null, _lcid, _invkind, byref(dp), byref(result), byref(excepinfo), byref(argerr)) except WindowsError: # , details: # we should parse exception information now, depending on # the errno we got. XXX Problem (?): error numbers are # signed integers, although in C the HRESULT values are # normally written in hex notation. raise # all the DISP_E_ values from windows.h DISP_E_BUFFERTOOSMALL = -2147352557 DISP_E_DIVBYZERO = -2147352558 DISP_E_NOTACOLLECTION = -2147352559 DISP_E_BADCALLEE = -2147352560 DISP_E_PARAMNOTOPTIONAL = -2147352561 DISP_E_BADPARAMCOUNT = -2147352562 DISP_E_ARRAYISLOCKED = -2147352563 DISP_E_UNKNOWNLCID = -2147352564 DISP_E_BADINDEX = -2147352565 DISP_E_OVERFLOW = -2147352566 DISP_E_EXCEPTION = -2147352567 DISP_E_BADVARTYPE = -2147352568 DISP_E_NONAMEDARGS = -2147352569 DISP_E_UNKNOWNNAME = -2147352570 DISP_E_TYPEMISMATCH = -2147352571 DISP_E_PARAMNOTFOUND = -2147352572 DISP_E_MEMBERNOTFOUND = -2147352573 DISP_E_UNKNOWNINTERFACE = -2147352575 ################################################################ if __name__ == "__main__": oledll.ole32.CoInitialize(None) p = POINTER(IDispatch)() clsid = GUID.from_progid("InternetExplorer.Application") # Internet.Explorer oledll.ole32.CoCreateInstance(byref(clsid), None, 7, # CLSCTX byref(p._iid_), byref(p)) for i in range(p.GetTypeInfoCount()): result = p.GetTypeInfo(i) id_quit = p.GetIDsOfNames("Quit")[0] id_visible = p.GetIDsOfNames("Visible")[0] id_navigate = p.GetIDsOfNames("Navigate2")[0] print p.GetIDsOfNames("Navigate2", "URL", "Flags", "TargetFrameName", "PostData", "Headers") 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: oledll.ole32.CoUninitialize() |
From: Thomas H. <th...@us...> - 2005-02-11 20:51:37
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23282 Removed Files: automation.py Log Message: comtypes.automation is a package now. TypeInfo support will go into a submodule. --- automation.py DELETED --- |
From: Thomas H. <th...@us...> - 2005-02-11 20:46:52
|
Update of /cvsroot/ctypes/ctypes/comtypes/automation In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21167/automation Log Message: Directory /cvsroot/ctypes/ctypes/comtypes/automation added to the repository |
From: Thomas H. <th...@us...> - 2005-02-11 20:46:20
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21041 Modified Files: __init__.py Log Message: Minor changes. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/__init__.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** __init__.py 4 Feb 2005 21:17:10 -0000 1.8 --- __init__.py 11 Feb 2005 20:46:07 -0000 1.9 *************** *** 3,6 **** --- 3,9 ---- from ctypes import * from comtypes.GUID import GUID + _GUID = GUID + IID = GUID + DWORD = c_ulong ################################################################ *************** *** 118,122 **** STDMETHOD(c_ulong, "AddRef"), STDMETHOD(c_ulong, "Release") ! ] def QueryInterface(self, interface): --- 121,125 ---- STDMETHOD(c_ulong, "AddRef"), STDMETHOD(c_ulong, "Release") ! ] def QueryInterface(self, interface): *************** *** 134,137 **** --- 137,141 ---- return self.__com_Release() + ################ class CoClass(object): # creation, and so on *************** *** 147,150 **** --- 151,174 ---- return p + ################ + ##class IErrorInfo(IUnknown): + ## _iid_ = GUID("{1CF2B120-547D-101B-8E65-08002B2BD119}") + ## _methods_ = [ + ## # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 5186 + ## STDMETHOD(HRESULT, 'GetGUID', [POINTER(GUID)]), + ## STDMETHOD(HRESULT, 'GetSource', [POINTER(BSTR)]), + ## STDMETHOD(HRESULT, 'GetDescription', [POINTER(BSTR)]), + ## STDMETHOD(HRESULT, 'GetHelpFile', [POINTER(BSTR)]), + ## STDMETHOD(HRESULT, 'GetHelpContext', [POINTER(DWORD)]), + ## ] + + ################ + ##class ISupportErrorInfo(IUnknown): + ## _iid_ = GUID("{DF0B3D60-548F-101B-8E65-08002B2BD119}") + ## _methods_ = [ + ## # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 5546 + ## STDMETHOD(HRESULT, 'InterfaceSupportsErrorInfo', [POINTER(IID)]), + ## ] + __all__ = ["CoClass", "IUnknown", "GUID", "HRESULT", "BSTR", "STDMETHOD"] |
From: Thomas H. <th...@us...> - 2005-02-11 20:44:37
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20316 Modified Files: GUID.py Log Message: Remove test code. Index: GUID.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/GUID.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GUID.py 3 Feb 2005 14:09:12 -0000 1.2 --- GUID.py 11 Feb 2005 20:44:27 -0000 1.3 *************** *** 52,59 **** __all__ = ["GUID"] - - if __name__ == "__main__": - print GUID() - print repr(GUID()) - print GUID().copy() - print GUID(GUID()) --- 52,53 ---- |
From: Thomas H. <th...@us...> - 2005-02-10 19:37:21
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12328 Modified Files: automation.py Log Message: Restructuring. Index: automation.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/automation.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** automation.py 8 Feb 2005 20:44:27 -0000 1.7 --- automation.py 10 Feb 2005 19:37:12 -0000 1.8 *************** *** 230,233 **** --- 230,296 ---- ################################################################ + class tagTLIBATTR(Structure): + _fields_ = [ + ('guid', GUID), + ('lcid', LCID), + ('syskind', SYSKIND), + ('wMajorVerNum', WORD), + ('wMinorVerNum', WORD), + ('wLibFlags', WORD), + ] + assert sizeof(tagTLIBATTR) == 32, sizeof(tagTLIBATTR) + assert alignment(tagTLIBATTR) == 4, alignment(tagTLIBATTR) + TLIBATTR = tagTLIBATTR # typedef + + class tagIDLDESC(Structure): + _fields_ = [ + ('dwReserved', ULONG_PTR), + ('wIDLFlags', USHORT), + ] + assert sizeof(tagIDLDESC) == 8, sizeof(tagIDLDESC) + assert alignment(tagIDLDESC) == 4, alignment(tagIDLDESC) + IDLDESC = tagIDLDESC # typedef + + class tagSAFEARRAYBOUND(Structure): + _fields_ = [ + ('cElements', DWORD), + ('lLbound', LONG), + ] + assert sizeof(tagSAFEARRAYBOUND) == 8, sizeof(tagSAFEARRAYBOUND) + assert alignment(tagSAFEARRAYBOUND) == 4, alignment(tagSAFEARRAYBOUND) + SAFEARRAYBOUND = tagSAFEARRAYBOUND # typedef + + class tagSAFEARRAY(Structure): + _fields_ = [ + ('cDims', USHORT), + ('fFeatures', USHORT), + ('cbElements', DWORD), + ('cLocks', DWORD), + ('pvData', PVOID), + ('rgsabound', SAFEARRAYBOUND * 1), + ] + assert sizeof(tagSAFEARRAY) == 24, sizeof(tagSAFEARRAY) + assert alignment(tagSAFEARRAY) == 4, alignment(tagSAFEARRAY) + SAFEARRAY = tagSAFEARRAY # typedef + + class tagEXCEPINFO(Structure): + pass + tagEXCEPINFO._fields_ = [ + ('wCode', WORD), + ('wReserved', WORD), + ('bstrSource', BSTR), + ('bstrDescription', BSTR), + ('bstrHelpFile', BSTR), + ('dwHelpContext', DWORD), + ('pvReserved', PVOID), + ('pfnDeferredFillIn', WINFUNCTYPE(HRESULT, POINTER(tagEXCEPINFO))), + ('scode', SCODE), + ] + assert sizeof(tagEXCEPINFO) == 32, sizeof(tagEXCEPINFO) + assert alignment(tagEXCEPINFO) == 4, alignment(tagEXCEPINFO) + EXCEPINFO = tagEXCEPINFO # typedef + + ################################################################ + class ITypeLib(IUnknown): # c:/vc98/include/OAIDL.H 4460 *************** *** 260,266 **** def GetLibAttr(self): p = POINTER(TLIBATTR)() ! self.GetLibAttr._api_(byref(p)) # XXX register for release ! return p.value ## STDMETHOD(HRESULT, 'GetTypeComp', [POINTER(POINTER(ITypeComp))]), --- 323,329 ---- def GetLibAttr(self): p = POINTER(TLIBATTR)() ! self.__com_GetLibAttr(byref(p)) # XXX register for release ! return p ## STDMETHOD(HRESULT, 'GetTypeComp', [POINTER(POINTER(ITypeComp))]), *************** *** 383,389 **** - class tagTLIBATTR(Structure): - pass - TLIBATTR = tagTLIBATTR # typedef class ITypeComp(IUnknown): def Bind(self, p0, p1, p2, p3, p4, p5): --- 446,449 ---- *************** *** 415,429 **** ] - # tagTLIBATTR - tagTLIBATTR._fields_ = [ - ('guid', GUID), - ('lcid', LCID), - ('syskind', SYSKIND), - ('wMajorVerNum', WORD), - ('wMinorVerNum', WORD), - ('wLibFlags', WORD), - ] - assert sizeof(tagTLIBATTR) == 32, sizeof(tagTLIBATTR) - assert alignment(tagTLIBATTR) == 4, alignment(tagTLIBATTR) class tagTYPEATTR(Structure): _owner = None --- 475,478 ---- *************** *** 472,479 **** - class tagEXCEPINFO(Structure): - pass - EXCEPINFO = tagEXCEPINFO # typedef - ITypeInfo._methods_ = [ STDMETHOD(HRESULT, 'GetTypeAttr', [POINTER(POINTER(TYPEATTR))]), --- 521,524 ---- *************** *** 497,514 **** STDMETHOD(None, 'ReleaseVarDesc', [POINTER(VARDESC)]), ] ! # tagEXCEPINFO ! tagEXCEPINFO._fields_ = [ ! ('wCode', WORD), ! ('wReserved', WORD), ! ('bstrSource', BSTR), ! ('bstrDescription', BSTR), ! ('bstrHelpFile', BSTR), ! ('dwHelpContext', DWORD), ! ('pvReserved', PVOID), ! ('pfnDeferredFillIn', WINFUNCTYPE(HRESULT, POINTER(tagEXCEPINFO))), ! ('scode', SCODE), ! ] ! assert sizeof(tagEXCEPINFO) == 32, sizeof(tagEXCEPINFO) ! assert alignment(tagEXCEPINFO) == 4, alignment(tagEXCEPINFO) VARIANTARG = VARIANT # typedef # tagDISPPARAMS --- 542,546 ---- STDMETHOD(None, 'ReleaseVarDesc', [POINTER(VARDESC)]), ] ! VARIANTARG = VARIANT # typedef # tagDISPPARAMS *************** *** 551,565 **** assert alignment(tagTYPEDESC) == 4, alignment(tagTYPEDESC) TYPEDESC = tagTYPEDESC # typedef ! class tagIDLDESC(Structure): ! pass ! # tagIDLDESC ! tagIDLDESC._fields_ = [ ! ('dwReserved', ULONG_PTR), ! ('wIDLFlags', USHORT), ! ] ! assert sizeof(tagIDLDESC) == 8, sizeof(tagIDLDESC) ! assert alignment(tagIDLDESC) == 4, alignment(tagIDLDESC) ! IDLDESC = tagIDLDESC # typedef ! # tagTYPEATTR tagTYPEATTR._fields_ = [ ('guid', GUID), --- 583,587 ---- assert alignment(tagTYPEDESC) == 4, alignment(tagTYPEDESC) TYPEDESC = tagTYPEDESC # typedef ! tagTYPEATTR._fields_ = [ ('guid', GUID), *************** *** 623,629 **** pass - class tagSAFEARRAY(Structure): - pass - SAFEARRAY = tagSAFEARRAY # typedef class tagDEC(Structure): pass --- 645,648 ---- *************** *** 882,906 **** assert sizeof(tagFUNCDESC) == 52, sizeof(tagFUNCDESC) assert alignment(tagFUNCDESC) == 4, alignment(tagFUNCDESC) ! class tagSAFEARRAYBOUND(Structure): ! pass ! # tagSAFEARRAYBOUND ! tagSAFEARRAYBOUND._fields_ = [ ! ('cElements', DWORD), ! ('lLbound', LONG), ! ] ! assert sizeof(tagSAFEARRAYBOUND) == 8, sizeof(tagSAFEARRAYBOUND) ! assert alignment(tagSAFEARRAYBOUND) == 4, alignment(tagSAFEARRAYBOUND) ! SAFEARRAYBOUND = tagSAFEARRAYBOUND # typedef ! # tagSAFEARRAY ! tagSAFEARRAY._fields_ = [ ! ('cDims', USHORT), ! ('fFeatures', USHORT), ! ('cbElements', DWORD), ! ('cLocks', DWORD), ! ('pvData', PVOID), ! ('rgsabound', SAFEARRAYBOUND * 1), ! ] ! assert sizeof(tagSAFEARRAY) == 24, sizeof(tagSAFEARRAY) ! assert alignment(tagSAFEARRAY) == 4, alignment(tagSAFEARRAY) # tagPARAMDESCEX tagPARAMDESCEX._fields_ = [ --- 901,905 ---- assert sizeof(tagFUNCDESC) == 52, sizeof(tagFUNCDESC) assert alignment(tagFUNCDESC) == 4, alignment(tagFUNCDESC) ! # tagPARAMDESCEX tagPARAMDESCEX._fields_ = [ |
From: Thomas H. <th...@us...> - 2005-02-10 09:20:36
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18608 Modified Files: ChangeLog Log Message: Record changes. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.77 retrieving revision 1.78 diff -C2 -d -r1.77 -r1.78 *** ChangeLog 28 Jan 2005 18:06:56 -0000 1.77 --- ChangeLog 10 Feb 2005 09:20:26 -0000 1.78 *************** *** 1,2 **** --- 1,12 ---- + 2005-02-10 Thomas Heller <th...@py...> + + * Clean up the_ semantics on Structure/Union types. The _fields_ + attribute can no longer be set after one of the following happens: + + - The _fields_ attribute is set. + - An instance of the type is created. + - The type is used as field in another Structure/Union. + - The type is subclassed. + 2005-01-26 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2005-02-10 09:18:45
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17760 Modified Files: stgdict.c Log Message: Fix a GCC compiler warning. Index: stgdict.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/stgdict.c,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** stgdict.c 10 Feb 2005 09:10:59 -0000 1.30 --- stgdict.c 10 Feb 2005 09:18:37 -0000 1.31 *************** *** 225,229 **** PyMem_Free(stgdict->ffi_type.elements); ! basedict = PyType_stgdict(((PyTypeObject *)type)->tp_base); if (basedict && !use_broken_old_ctypes_semantics) { size = offset = basedict->size; --- 225,229 ---- PyMem_Free(stgdict->ffi_type.elements); ! basedict = PyType_stgdict((PyObject *)((PyTypeObject *)type)->tp_base); if (basedict && !use_broken_old_ctypes_semantics) { size = offset = basedict->size; |
From: Thomas H. <th...@us...> - 2005-02-10 09:12:45
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15074 Added Files: test_struct_fields.py Log Message: New flag value DICTFLAG_FINAL. The flag is set when one of the following occurrs: - The _fields_ attribute is set. - An instance of the type is created. - The type is used as field in another Structure/Union. - The type is subclassed. When this flag is set, assigning the _fields_ attribute is no longer allowed. --- NEW FILE: test_struct_fields.py --- import unittest from ctypes import * class StructFieldsTestCase(unittest.TestCase): # Structure/Union classes must get 'finalized' sooner or # later, when one of these things happen: # # 1. _fields_ is set. # 2. An instance is created. # 3. The type is used as field of another Structure/Union. # 4. The type is subclassed # # When they are finalized, assigning _fields_ is no longer allowed. def test_1_A(self): class X(Structure): pass self.failUnlessEqual(sizeof(X), 0) # not finalized X._fields_ = [] # finalized self.assertRaises(AttributeError, setattr, X, "_fields_", []) def test_1_B(self): class X(Structure): _fields_ = [] # finalized self.assertRaises(AttributeError, setattr, X, "_fields_", []) def test_2(self): class X(Structure): pass X() self.assertRaises(AttributeError, setattr, X, "_fields_", []) def test_3(self): class X(Structure): pass class Y(Structure): _fields_ = [("x", X)] # finalizes X self.assertRaises(AttributeError, setattr, X, "_fields_", []) def test_4(self): class X(Structure): pass class Y(X): pass self.assertRaises(AttributeError, setattr, X, "_fields_", []) Y._fields_ = [] self.assertRaises(AttributeError, setattr, X, "_fields_", []) if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2005-02-10 09:11:09
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14412 Modified Files: stgdict.c ctypes.h _ctypes.c Log Message: New flag value DICTFLAG_FINAL. The flag is set when one of the following occurrs: - The _fields_ attribute is set. - An instance of the type is created. - The type is used as field in another Structure/Union. - The type is subclassed. When this flag is set, assigning the _fields_ attribute is no longer allowed. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.68 retrieving revision 1.69 diff -C2 -d -r1.68 -r1.69 *** ctypes.h 28 Jan 2005 16:47:29 -0000 1.68 --- ctypes.h 10 Feb 2005 09:10:59 -0000 1.69 *************** *** 32,36 **** int b_index; /* index of this object into base's b_object list */ - PyObject *b_objects; /* list of references we need to keep */ }; --- 32,35 ---- *************** *** 46,50 **** int b_index; /* index of this object into base's b_object list */ - PyObject *b_objects; /* list of references we need to keep */ /* end of tagCDataObject, additional fields follow */ --- 45,48 ---- *************** *** 191,194 **** --- 189,194 ---- #define FUNCFLAG_PYTHONAPI 0x4 + #define DICTFLAG_FINAL 0x1000 + typedef struct { PyObject_HEAD Index: stgdict.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/stgdict.c,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** stgdict.c 28 Jan 2005 16:47:45 -0000 1.29 --- stgdict.c 10 Feb 2005 09:10:59 -0000 1.30 *************** *** 215,218 **** --- 215,224 ---- if (!stgdict) return -1; + if (stgdict->flags & DICTFLAG_FINAL) {/* is final ? */ + PyErr_SetString(PyExc_AttributeError, + "_fields_ is final"); + return -1; + } + stgdict->flags |= DICTFLAG_FINAL; /* set final */ if (stgdict->ffi_type.elements) *************** *** 258,263 **** } dict = PyType_stgdict(desc); ! if (dict) ! stgdict->ffi_type.elements[ffi_ofs + i] = &dict->ffi_type; if (PyTuple_Size(pair) == 3) { /* bits specified */ switch(dict->ffi_type.type) { --- 264,269 ---- } dict = PyType_stgdict(desc); ! stgdict->ffi_type.elements[ffi_ofs + i] = &dict->ffi_type; ! dict->flags |= DICTFLAG_FINAL; /* mark field type final */ if (PyTuple_Size(pair) == 3) { /* bits specified */ switch(dict->ffi_type.type) { Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.204 retrieving revision 1.205 diff -C2 -d -r1.204 -r1.205 *** _ctypes.c 10 Feb 2005 08:55:28 -0000 1.204 --- _ctypes.c 10 Feb 2005 09:11:00 -0000 1.205 *************** *** 166,169 **** --- 166,171 ---- return NULL; } + dict->flags &= ~DICTFLAG_FINAL; /* clear the 'final' flag in the subclass dict */ + basedict->flags |= DICTFLAG_FINAL; /* set the 'final' flag in the baseclass dict */ return (PyObject *)result; } *************** *** 2030,2033 **** --- 2032,2036 ---- return NULL; } + dict->flags |= DICTFLAG_FINAL; size = dict->size; align = dict->align; *************** *** 2698,2703 **** } fields = PyObject_GetAttrString(self, "_fields_"); ! if (!fields) ! return IBUG("no _fields_"); if (PyTuple_GET_SIZE(args) > PySequence_Length(fields)) { --- 2701,2708 ---- } fields = PyObject_GetAttrString(self, "_fields_"); ! if (!fields) { ! PyErr_Clear(); ! fields = PyTuple_New(0); ! } if (PyTuple_GET_SIZE(args) > PySequence_Length(fields)) { |
From: Thomas H. <th...@us...> - 2005-02-10 08:55:48
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7947 Modified Files: _ctypes.c Log Message: Emit a better error message when a wrong type is passed as byref() parameter in a function call. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.203 retrieving revision 1.204 diff -C2 -d -r1.203 -r1.204 *** _ctypes.c 28 Jan 2005 16:47:45 -0000 1.203 --- _ctypes.c 10 Feb 2005 08:55:28 -0000 1.204 *************** *** 273,276 **** --- 273,281 ---- return value; } + PyErr_Format(PyExc_TypeError, + "expected %s instance instead of pointer to %s", + ((PyTypeObject *)type)->tp_name, + ob->ob_type->tp_name); + return NULL; } #if 1 |
From: Thomas H. <th...@us...> - 2005-02-08 20:45:18
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21675 Modified Files: automation.py Log Message: Reordering code, and some cleanup. Index: automation.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/automation.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** automation.py 4 Feb 2005 21:18:49 -0000 1.6 --- automation.py 8 Feb 2005 20:44:27 -0000 1.7 *************** *** 5,8 **** --- 5,38 ---- from comtypes import IUnknown, GUID, BSTR, STDMETHOD + UINT = c_uint # typedef + LONG = c_long # typedef + INT = c_int # typedef + WCHAR = c_wchar # typedef + OLECHAR = WCHAR # typedef + DWORD = c_ulong # typedef + LPOLESTR = POINTER(OLECHAR) # typedef + BOOL = c_int # typedef + DISPID = LONG # typedef + MEMBERID = DISPID # typedef + USHORT = c_ushort # typedef + WORD = c_ushort # typedef + LCID = DWORD # typedef + HREFTYPE = DWORD # typedef + PVOID = c_void_p # typedef + SCODE = LONG # typedef + VARTYPE = c_ushort # typedef + ULONG_PTR = c_ulong # typedef + LONGLONG = c_longlong # typedef + BYTE = c_ubyte # typedef + SHORT = c_short # typedef + FLOAT = c_float # typedef + DOUBLE = c_double # typedef + VARIANT_BOOL = c_short # typedef + DATE = c_double # typedef + CHAR = c_char # typedef + ULONGLONG = c_ulonglong # typedef + + ################################################################ + PARAMFLAG_NONE = 0 PARAMFLAG_FIN = 1 *************** *** 56,160 **** VARFLAGS = tagVARFLAGS ! UINT = c_uint # typedef ! LONG = c_long # typedef ! INT = c_int # typedef ! WCHAR = c_wchar # typedef ! OLECHAR = WCHAR # typedef ! DWORD = c_ulong # typedef ! LPOLESTR = POINTER(OLECHAR) # typedef ! BOOL = c_int # typedef ! DISPID = LONG # typedef ! MEMBERID = DISPID # typedef ! USHORT = c_ushort # typedef ! WORD = c_ushort # typedef ! LCID = DWORD # typedef ! HREFTYPE = DWORD # typedef ! PVOID = c_void_p # typedef ! SCODE = LONG # typedef ! VARTYPE = c_ushort # typedef ! ULONG_PTR = c_ulong # typedef ! LONGLONG = c_longlong # typedef ! BYTE = c_ubyte # typedef ! SHORT = c_short # typedef ! FLOAT = c_float # typedef ! DOUBLE = c_double # typedef ! VARIANT_BOOL = c_short # typedef ! DATE = c_double # typedef ! CHAR = c_char # typedef ! ULONGLONG = c_ulonglong # typedef VARENUM = c_int # enum ! VT_EMPTY = 0 # enum VARENUM ! VT_NULL = 1 # enum VARENUM ! VT_I2 = 2 # enum VARENUM ! VT_I4 = 3 # enum VARENUM ! VT_R4 = 4 # enum VARENUM ! VT_R8 = 5 # enum VARENUM ! VT_CY = 6 # enum VARENUM ! VT_DATE = 7 # enum VARENUM ! VT_BSTR = 8 # enum VARENUM ! VT_DISPATCH = 9 # enum VARENUM ! VT_ERROR = 10 # enum VARENUM ! VT_BOOL = 11 # enum VARENUM ! VT_VARIANT = 12 # enum VARENUM ! VT_UNKNOWN = 13 # enum VARENUM ! VT_DECIMAL = 14 # enum VARENUM ! VT_I1 = 16 # enum VARENUM ! VT_UI1 = 17 # enum VARENUM ! VT_UI2 = 18 # enum VARENUM ! VT_UI4 = 19 # enum VARENUM ! VT_I8 = 20 # enum VARENUM ! VT_UI8 = 21 # enum VARENUM ! VT_INT = 22 # enum VARENUM ! VT_UINT = 23 # enum VARENUM ! VT_VOID = 24 # enum VARENUM ! VT_HRESULT = 25 # enum VARENUM ! VT_PTR = 26 # enum VARENUM ! VT_SAFEARRAY = 27 # enum VARENUM ! VT_CARRAY = 28 # enum VARENUM ! VT_USERDEFINED = 29 # enum VARENUM ! VT_LPSTR = 30 # enum VARENUM ! VT_LPWSTR = 31 # enum VARENUM ! VT_RECORD = 36 # enum VARENUM ! VT_INT_PTR = 37 # enum VARENUM ! VT_UINT_PTR = 38 # enum VARENUM ! VT_FILETIME = 64 # enum VARENUM ! VT_BLOB = 65 # enum VARENUM ! VT_STREAM = 66 # enum VARENUM ! VT_STORAGE = 67 # enum VARENUM ! VT_STREAMED_OBJECT = 68 # enum VARENUM ! VT_STORED_OBJECT = 69 # enum VARENUM ! VT_BLOB_OBJECT = 70 # enum VARENUM ! VT_CF = 71 # enum VARENUM ! VT_CLSID = 72 # enum VARENUM ! VT_VERSIONED_STREAM = 73 # enum VARENUM ! VT_BSTR_BLOB = 4095 # enum VARENUM ! VT_VECTOR = 4096 # enum VARENUM ! VT_ARRAY = 8192 # enum VARENUM ! VT_BYREF = 16384 # enum VARENUM ! VT_RESERVED = 32768 # enum VARENUM ! VT_ILLEGAL = 65535 # enum VARENUM ! VT_ILLEGALMASKED = 4095 # enum VARENUM ! VT_TYPEMASK = 4095 # enum VARENUM tagTYPEFLAGS = c_int # enum ! TYPEFLAG_FAPPOBJECT = 1 # enum tagTYPEFLAGS ! TYPEFLAG_FCANCREATE = 2 # enum tagTYPEFLAGS ! TYPEFLAG_FLICENSED = 4 # enum tagTYPEFLAGS ! TYPEFLAG_FPREDECLID = 8 # enum tagTYPEFLAGS ! TYPEFLAG_FHIDDEN = 16 # enum tagTYPEFLAGS ! TYPEFLAG_FCONTROL = 32 # enum tagTYPEFLAGS ! TYPEFLAG_FDUAL = 64 # enum tagTYPEFLAGS ! TYPEFLAG_FNONEXTENSIBLE = 128 # enum tagTYPEFLAGS ! TYPEFLAG_FOLEAUTOMATION = 256 # enum tagTYPEFLAGS ! TYPEFLAG_FRESTRICTED = 512 # enum tagTYPEFLAGS ! TYPEFLAG_FAGGREGATABLE = 1024 # enum tagTYPEFLAGS ! TYPEFLAG_FREPLACEABLE = 2048 # enum tagTYPEFLAGS ! TYPEFLAG_FDISPATCHABLE = 4096 # enum tagTYPEFLAGS ! TYPEFLAG_FREVERSEBIND = 8192 # enum tagTYPEFLAGS ! TYPEFLAG_FPROXY = 16384 # enum tagTYPEFLAGS TYPEFLAGS = tagTYPEFLAGS # typedef class ITypeLib(IUnknown): # c:/vc98/include/OAIDL.H 4460 --- 86,233 ---- VARFLAGS = tagVARFLAGS ! tagSYSKIND = c_int # enum ! SYS_WIN16 = 0 ! SYS_WIN32 = 1 ! SYS_MAC = 2 ! SYS_WIN64 = 3 ! SYSKIND = tagSYSKIND # typedef + tagTYPEKIND = c_int # enum + TKIND_ENUM = 0 + TKIND_RECORD = 1 + TKIND_MODULE = 2 + TKIND_INTERFACE = 3 + TKIND_DISPATCH = 4 + TKIND_COCLASS = 5 + TKIND_ALIAS = 6 + TKIND_UNION = 7 + TKIND_MAX = 8 + TYPEKIND = tagTYPEKIND # typedef VARENUM = c_int # enum ! VT_EMPTY = 0 ! VT_NULL = 1 ! VT_I2 = 2 ! VT_I4 = 3 ! VT_R4 = 4 ! VT_R8 = 5 ! VT_CY = 6 ! VT_DATE = 7 ! VT_BSTR = 8 ! VT_DISPATCH = 9 ! VT_ERROR = 10 ! VT_BOOL = 11 ! VT_VARIANT = 12 ! VT_UNKNOWN = 13 ! VT_DECIMAL = 14 ! VT_I1 = 16 ! VT_UI1 = 17 ! VT_UI2 = 18 ! VT_UI4 = 19 ! VT_I8 = 20 ! VT_UI8 = 21 ! VT_INT = 22 ! VT_UINT = 23 ! VT_VOID = 24 ! VT_HRESULT = 25 ! VT_PTR = 26 ! VT_SAFEARRAY = 27 ! VT_CARRAY = 28 ! VT_USERDEFINED = 29 ! VT_LPSTR = 30 ! VT_LPWSTR = 31 ! VT_RECORD = 36 ! VT_INT_PTR = 37 ! VT_UINT_PTR = 38 ! VT_FILETIME = 64 ! VT_BLOB = 65 ! VT_STREAM = 66 ! VT_STORAGE = 67 ! VT_STREAMED_OBJECT = 68 ! VT_STORED_OBJECT = 69 ! VT_BLOB_OBJECT = 70 ! VT_CF = 71 ! VT_CLSID = 72 ! VT_VERSIONED_STREAM = 73 ! VT_BSTR_BLOB = 4095 ! VT_VECTOR = 4096 ! VT_ARRAY = 8192 ! VT_BYREF = 16384 ! VT_RESERVED = 32768 ! VT_ILLEGAL = 65535 ! VT_ILLEGALMASKED = 4095 ! VT_TYPEMASK = 4095 tagTYPEFLAGS = c_int # enum ! TYPEFLAG_FAPPOBJECT = 1 ! TYPEFLAG_FCANCREATE = 2 ! TYPEFLAG_FLICENSED = 4 ! TYPEFLAG_FPREDECLID = 8 ! TYPEFLAG_FHIDDEN = 16 ! TYPEFLAG_FCONTROL = 32 ! TYPEFLAG_FDUAL = 64 ! TYPEFLAG_FNONEXTENSIBLE = 128 ! TYPEFLAG_FOLEAUTOMATION = 256 ! TYPEFLAG_FRESTRICTED = 512 ! TYPEFLAG_FAGGREGATABLE = 1024 ! TYPEFLAG_FREPLACEABLE = 2048 ! TYPEFLAG_FDISPATCHABLE = 4096 ! TYPEFLAG_FREVERSEBIND = 8192 ! TYPEFLAG_FPROXY = 16384 TYPEFLAGS = tagTYPEFLAGS # typedef + tagDESCKIND = c_int # enum + DESCKIND_NONE = 0 + DESCKIND_FUNCDESC = 1 + DESCKIND_VARDESC = 2 + DESCKIND_TYPECOMP = 3 + DESCKIND_IMPLICITAPPOBJ = 4 + DESCKIND_MAX = 5 + DESCKIND = tagDESCKIND # typedef + + tagINVOKEKIND = c_int # enum + INVOKE_FUNC = 1 + INVOKE_PROPERTYGET = 2 + INVOKE_PROPERTYPUT = 4 + INVOKE_PROPERTYPUTREF = 8 + INVOKEKIND = tagINVOKEKIND # typedef + + tagVARKIND = c_int # enum + VAR_PERINSTANCE = 0 # enum tagVARKIND + VAR_STATIC = 1 # enum tagVARKIND + VAR_CONST = 2 # enum tagVARKIND + VAR_DISPATCH = 3 # enum tagVARKIND + VARKIND = tagVARKIND # typedef + + tagFUNCKIND = c_int # enum + FUNC_VIRTUAL = 0 + FUNC_PUREVIRTUAL = 1 + FUNC_NONVIRTUAL = 2 + FUNC_STATIC = 3 + FUNC_DISPATCH = 4 + FUNCKIND = tagFUNCKIND # typedef + + tagCALLCONV = c_int # enum + CC_FASTCALL = 0 + CC_CDECL = 1 + CC_MSCPASCAL = 2 + CC_PASCAL = 2 + CC_MACPASCAL = 3 + CC_STDCALL = 4 + CC_FPFASTCALL = 5 + CC_SYSCALL = 6 + CC_MPWCDECL = 7 + CC_MPWPASCAL = 8 + CC_MAX = 9 + CALLCONV = tagCALLCONV # typedef + + tagREGKIND = c_int # enum + REGKIND_DEFAULT = 0 + REGKIND_REGISTER = 1 + REGKIND_NONE = 2 + REGKIND = tagREGKIND # typedef + + ################################################################ + class ITypeLib(IUnknown): # c:/vc98/include/OAIDL.H 4460 *************** *** 310,324 **** - tagTYPEKIND = c_int # enum - TKIND_ENUM = 0 # enum tagTYPEKIND - TKIND_RECORD = 1 # enum tagTYPEKIND - TKIND_MODULE = 2 # enum tagTYPEKIND - TKIND_INTERFACE = 3 # enum tagTYPEKIND - TKIND_DISPATCH = 4 # enum tagTYPEKIND - TKIND_COCLASS = 5 # enum tagTYPEKIND - TKIND_ALIAS = 6 # enum tagTYPEKIND - TKIND_UNION = 7 # enum tagTYPEKIND - TKIND_MAX = 8 # enum tagTYPEKIND - TYPEKIND = tagTYPEKIND # typedef class tagTLIBATTR(Structure): pass --- 383,386 ---- *************** *** 345,356 **** IID = GUID # typedef - tagDESCKIND = c_int # enum - DESCKIND_NONE = 0 # enum tagDESCKIND - DESCKIND_FUNCDESC = 1 # enum tagDESCKIND - DESCKIND_VARDESC = 2 # enum tagDESCKIND - DESCKIND_TYPECOMP = 3 # enum tagDESCKIND - DESCKIND_IMPLICITAPPOBJ = 4 # enum tagDESCKIND - DESCKIND_MAX = 5 # enum tagDESCKIND - DESCKIND = tagDESCKIND # typedef class tagBINDPTR(Union): pass --- 407,410 ---- *************** *** 361,370 **** ] - tagSYSKIND = c_int # enum - SYS_WIN16 = 0 # enum tagSYSKIND - SYS_WIN32 = 1 # enum tagSYSKIND - SYS_MAC = 2 # enum tagSYSKIND - SYS_WIN64 = 3 # enum tagSYSKIND - SYSKIND = tagSYSKIND # typedef # tagTLIBATTR tagTLIBATTR._fields_ = [ --- 415,418 ---- *************** *** 428,437 **** EXCEPINFO = tagEXCEPINFO # typedef - tagINVOKEKIND = c_int # enum - INVOKE_FUNC = 1 # enum tagINVOKEKIND - INVOKE_PROPERTYGET = 2 # enum tagINVOKEKIND - INVOKE_PROPERTYPUT = 4 # enum tagINVOKEKIND - INVOKE_PROPERTYPUTREF = 8 # enum tagINVOKEKIND - INVOKEKIND = tagINVOKEKIND # typedef ITypeInfo._methods_ = [ STDMETHOD(HRESULT, 'GetTypeAttr', [POINTER(POINTER(TYPEATTR))]), --- 476,479 ---- *************** *** 760,763 **** --- 802,806 ---- assert sizeof(_py_N10tagVARIANT5__200E) == 16, sizeof(_py_N10tagVARIANT5__200E) assert alignment(_py_N10tagVARIANT5__200E) == 8, alignment(_py_N10tagVARIANT5__200E) + # tagVARIANT tagVARIANT._fields_ = [ *************** *** 766,778 **** assert sizeof(tagVARIANT) == 16, sizeof(tagVARIANT) assert alignment(tagVARIANT) == 8, alignment(tagVARIANT) class _py_N10tagVARDESC5__205E(Union): ! pass ! # _py_N10tagVARDESC5__205E ! _py_N10tagVARDESC5__205E._fields_ = [ ! ('oInst', DWORD), ! ('lpvarValue', POINTER(VARIANT)), ! ] assert sizeof(_py_N10tagVARDESC5__205E) == 4, sizeof(_py_N10tagVARDESC5__205E) assert alignment(_py_N10tagVARDESC5__205E) == 4, alignment(_py_N10tagVARDESC5__205E) class tagELEMDESC(Structure): pass --- 809,821 ---- assert sizeof(tagVARIANT) == 16, sizeof(tagVARIANT) assert alignment(tagVARIANT) == 8, alignment(tagVARIANT) + class _py_N10tagVARDESC5__205E(Union): ! _fields_ = [ ! ('oInst', DWORD), ! ('lpvarValue', POINTER(VARIANT)), ! ] assert sizeof(_py_N10tagVARDESC5__205E) == 4, sizeof(_py_N10tagVARDESC5__205E) assert alignment(_py_N10tagVARDESC5__205E) == 4, alignment(_py_N10tagVARDESC5__205E) + class tagELEMDESC(Structure): pass *************** *** 809,818 **** ELEMDESC = tagELEMDESC # typedef - tagVARKIND = c_int # enum - VAR_PERINSTANCE = 0 # enum tagVARKIND - VAR_STATIC = 1 # enum tagVARKIND - VAR_CONST = 2 # enum tagVARKIND - VAR_DISPATCH = 3 # enum tagVARKIND - VARKIND = tagVARKIND # typedef # tagVARDESC tagVARDESC._fields_ = [ --- 852,855 ---- *************** *** 828,852 **** assert alignment(tagVARDESC) == 4, alignment(tagVARDESC) - tagFUNCKIND = c_int # enum - FUNC_VIRTUAL = 0 # enum tagFUNCKIND - FUNC_PUREVIRTUAL = 1 # enum tagFUNCKIND - FUNC_NONVIRTUAL = 2 # enum tagFUNCKIND - FUNC_STATIC = 3 # enum tagFUNCKIND - FUNC_DISPATCH = 4 # enum tagFUNCKIND - FUNCKIND = tagFUNCKIND # typedef - - tagCALLCONV = c_int # enum - CC_FASTCALL = 0 # enum tagCALLCONV - CC_CDECL = 1 # enum tagCALLCONV - CC_MSCPASCAL = 2 # enum tagCALLCONV - CC_PASCAL = 2 # enum tagCALLCONV - CC_MACPASCAL = 3 # enum tagCALLCONV - CC_STDCALL = 4 # enum tagCALLCONV - CC_FPFASTCALL = 5 # enum tagCALLCONV - CC_SYSCALL = 6 # enum tagCALLCONV - CC_MPWCDECL = 7 # enum tagCALLCONV - CC_MPWPASCAL = 8 # enum tagCALLCONV - CC_MAX = 9 # enum tagCALLCONV - CALLCONV = tagCALLCONV # typedef # tagFUNCDESC tagFUNCDESC._fields_ = [ --- 865,868 ---- *************** *** 928,931 **** --- 944,949 ---- ] + ################################################################ + from ctypes.decorators import stdcall @ stdcall(HRESULT, "oleaut32", *************** *** 936,945 **** return p - tagREGKIND = c_int # enum - REGKIND_DEFAULT = 0 # enum tagREGKIND - REGKIND_REGISTER = 1 # enum tagREGKIND - REGKIND_NONE = 2 # enum tagREGKIND - REGKIND = tagREGKIND # typedef - @ stdcall(HRESULT, "oleaut32", [c_wchar_p, REGKIND, POINTER(POINTER(ITypeLib))]) --- 954,957 ---- *************** *** 949,955 **** return p ! if __name__ == "__main__": ! import ctypes ! print ctypes.__file__ ! p = LoadTypeLibEx("aaa.bbb") ! print p.AddRef() --- 961,967 ---- return p ! ##if __name__ == "__main__": ! ## import ctypes ! ## print ctypes.__file__ ! ## p = LoadTypeLibEx("aaa.bbb") ! ## print p.AddRef() |
From: Thomas H. <th...@us...> - 2005-02-07 12:06:38
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29608 Modified Files: tlbparser.py Log Message: Minor fixes. Index: tlbparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/tlbparser.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** tlbparser.py 4 Feb 2005 21:19:41 -0000 1.1 --- tlbparser.py 7 Feb 2005 12:06:26 -0000 1.2 *************** *** 27,31 **** HRESULT_type = typedesc.Typedef("HRESULT", ulong_type) ! VARIANT_type = typedesc.Typedef("VARIANT", None) IDISPATCH_type = typedesc.Typedef("IDispatch", None) IUNKNOWN_type = typedesc.Typedef("IUnknown", None) --- 27,31 ---- HRESULT_type = typedesc.Typedef("HRESULT", ulong_type) ! VARIANT_type = typedesc.Structure("VARIANT", align=64, members=[], bases=[], size=128) IDISPATCH_type = typedesc.Typedef("IDispatch", None) IUNKNOWN_type = typedesc.Typedef("IUnknown", None) *************** *** 174,179 **** func = typedesc.Function(func_name, returns, attributes, extern=1) ! if doc is not None: ! func.doc = doc func.dllname = dllname self.items[func_name] = func --- 174,179 ---- func = typedesc.Function(func_name, returns, attributes, extern=1) ! if func_doc is not None: ! func.doc = str(func_doc) func.dllname = dllname self.items[func_name] = func *************** *** 186,190 **** for i in range(ta.cVars): vd = tinfo.GetVarDesc(i) ! name, var_dic = tinfo.GetDocumentation(vd.memid)[0:2] vt = vd._.lpvarValue[0].n1.n2.vt assert vd.varkind == automation.VAR_CONST --- 186,190 ---- for i in range(ta.cVars): vd = tinfo.GetVarDesc(i) ! name, var_doc = tinfo.GetDocumentation(vd.memid)[0:2] vt = vd._.lpvarValue[0].n1.n2.vt assert vd.varkind == automation.VAR_CONST *************** *** 321,324 **** --- 321,326 ---- elif var.n1.n2.vt == automation.VT_BOOL: default = bool(var.n1.n2.n3.boolVal) + elif var.n1.n2.vt == automation.VT_R4: + default = var.n1.n2.n3.fltVal else: raise "NYI", var.n1.n2.vt *************** *** 410,414 **** coclass_name, doc = tinfo.GetDocumentation(-1)[0:2] coclass = typedesc.CoClass(coclass_name, str(ta.guid), self.idl_flags(ta.wTypeFlags)) ! coclass.doc = str(doc) self.items[coclass_name] = coclass for i in range(ta.cImplTypes): --- 412,417 ---- coclass_name, doc = tinfo.GetDocumentation(-1)[0:2] coclass = typedesc.CoClass(coclass_name, str(ta.guid), self.idl_flags(ta.wTypeFlags)) ! if doc is not None: ! coclass.doc = str(doc) self.items[coclass_name] = coclass for i in range(ta.cImplTypes): *************** *** 418,421 **** --- 421,425 ---- flags = tinfo.GetImplTypeFlags(i) coclass.add_interface(itf, flags) + return coclass # TKIND_ALIAS = 6 *************** *** 495,499 **** import sys ! path = r"hnetcfg.dll" ## path = r"simpdata.tlb" ## path = r"nscompat.tlb" --- 499,503 ---- import sys ! ## path = r"hnetcfg.dll" ## path = r"simpdata.tlb" ## path = r"nscompat.tlb" *************** *** 501,512 **** ## path = r"stdole32.tlb" ## path = "msscript.ocx" ! ## path = r"x.tlb" ! path = r"shdocvw.dll" ## path = r"c:\Programme\Microsoft Office\Office\MSO97.DLL" ## path = r"c:\Programme\Microsoft Office\Office\MSWORD8.OLB" ! ## path = r"msi.dll" ! ## path = r"PICCLP32.OCX" ## path = r"C:\Dokumente und Einstellungen\thomas\Desktop\tlb\win.tlb" ## path = r"C:\Dokumente und Einstellungen\thomas\Desktop\tlb\win32.tlb" --- 505,515 ---- ## path = r"stdole32.tlb" ## path = "msscript.ocx" ! ## path = r"shdocvw.dll" ## path = r"c:\Programme\Microsoft Office\Office\MSO97.DLL" ## path = r"c:\Programme\Microsoft Office\Office\MSWORD8.OLB" ! ## path = r"msi.dll" # DispProperty ! ## path = r"PICCLP32.OCX" # DispProperty ## path = r"C:\Dokumente und Einstellungen\thomas\Desktop\tlb\win.tlb" ## path = r"C:\Dokumente und Einstellungen\thomas\Desktop\tlb\win32.tlb" *************** *** 521,525 **** ## path = r"c:\Programme\Gemeinsame Dateien\Microsoft Shared\Speech\sapi.dll" ! path = r"c:\tss5\include\fpanel.tlb" known_symbols = {} --- 524,529 ---- ## path = r"c:\Programme\Gemeinsame Dateien\Microsoft Shared\Speech\sapi.dll" ! ## path = r"c:\tss5\include\fpanel.tlb" ! path = "auto.tlb" known_symbols = {} |
From: Thomas H. <th...@us...> - 2005-02-04 21:19:50
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29278 Added Files: typedesc.py tlbparser.py helpers.py codegenerator.py Log Message: The code generation work now continues is the comtypes.tools package. --- NEW FILE: tlbparser.py --- from comtypes import automation import typedesc ################################ def PTR(typ): return typedesc.PointerType(typ, 32, 32) # basic C data types, with size and alingment in bits char_type = typedesc.FundamentalType("char", 8, 8) uchar_type = typedesc.FundamentalType("unsigned char", 8, 8) wchar_t_type = typedesc.FundamentalType("wchar_t", 16, 16) short_type = typedesc.FundamentalType("short int", 16, 16) ushort_type = typedesc.FundamentalType("short unsigned int", 16, 16) int_type = typedesc.FundamentalType("int", 32, 32) uint_type = typedesc.FundamentalType("unsigned int", 32, 32) long_type = typedesc.FundamentalType("long int", 32, 32) ulong_type = typedesc.FundamentalType("long unsigned int", 32, 32) longlong_type = typedesc.FundamentalType("long long int", 64, 64) ulonglong_type = typedesc.FundamentalType("long long unsigned int", 64, 64) float_type = typedesc.FundamentalType("float", 32, 32) double_type = typedesc.FundamentalType("double", 64, 64) # basic COM data types BSTR_type = typedesc.Typedef("BSTR", PTR(wchar_t_type)) SCODE_type = typedesc.Typedef("SCODE", int_type) VARIANT_BOOL_type = typedesc.Typedef("VARIANT_BOOL", short_type) HRESULT_type = typedesc.Typedef("HRESULT", ulong_type) VARIANT_type = typedesc.Typedef("VARIANT", None) IDISPATCH_type = typedesc.Typedef("IDispatch", None) IUNKNOWN_type = typedesc.Typedef("IUnknown", None) SAFEARRAY_type = typedesc.Typedef("SAFEARRAY", None) # faked COM data types CURRENCY_type = float_type # wrong DATE_type = double_type # not *that* wrong... DECIMAL_type = double_type # wrong - it's a 12 byte structure (or was it 16 bytes?) COMTYPES = { automation.VT_I2: short_type, # 2 automation.VT_I4: int_type, # 3 automation.VT_R4: float_type, # 4 automation.VT_R8: double_type, # 5 automation.VT_CY: CURRENCY_type, # 6 automation.VT_DATE: DATE_type, # 7 automation.VT_BSTR: BSTR_type, # 8 automation.VT_DISPATCH: PTR(IDISPATCH_type), # 9 automation.VT_ERROR: SCODE_type, # 10 automation.VT_BOOL: VARIANT_BOOL_type, # 11 automation.VT_VARIANT: VARIANT_type, # 12 automation.VT_UNKNOWN: PTR(IUNKNOWN_type), # 13 automation.VT_DECIMAL: DECIMAL_type, # 14 automation.VT_I1: char_type, # 16 automation.VT_UI1: uchar_type, # 17 automation.VT_UI2: ushort_type, # 18 automation.VT_UI4: ulong_type, # 19 automation.VT_I8: longlong_type, # 20 automation.VT_UI8: ulonglong_type, # 21 automation.VT_INT: int_type, # 22 automation.VT_UINT: uint_type, # 23 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 ################################################################ class TlbParser(object): def __init__(self, path): self.tlib = automation.LoadTypeLibEx(path, regkind=automation.REGKIND_REGISTER) self.items = {} def make_type(self, tdesc, tinfo): try: return COMTYPES[tdesc.vt] except KeyError: pass if tdesc.vt == automation.VT_CARRAY: typ = self.make_type(tdesc._.lpadesc[0].tdescElem, tinfo) for i in range(tdesc._.lpadesc[0].cDims): typ = typedesc.ArrayType(typ, tdesc._.lpadesc[0].rgbounds[i].lLbound, tdesc._.lpadesc[0].rgbounds[i].cElements-1) return typ elif tdesc.vt == automation.VT_PTR: typ = self.make_type(tdesc._.lptdesc[0], tinfo) return typedesc.PointerType(typ, 32, 32) elif tdesc.vt == automation.VT_USERDEFINED: ti = tinfo.GetRefTypeInfo(tdesc._.hreftype) result = self.parse_typeinfo(ti) assert result is not None, ti.GetDocumentation(-1)[0] return result # VT_SAFEARRAY ??? raise "NYI", tdesc.vt ################################################################ # TKIND_ENUM = 0 def ParseEnum(self, tinfo, ta): ta = tinfo.GetTypeAttr() enum_name, doc, helpcntext, helpfile = tinfo.GetDocumentation(-1) enum = typedesc.Enumeration(enum_name, 32, 32) self.items[enum_name] = enum for i in range(ta.cVars): vd = tinfo.GetVarDesc(i) name = tinfo.GetDocumentation(vd.memid)[0] # XXX should be handled by VARIANT assert vd._.lpvarValue[0].n1.n2.vt == automation.VT_I4 assert vd.varkind == automation.VAR_CONST num_val = vd._.lpvarValue[0].n1.n2.n3.iVal v = typedesc.EnumValue(name, num_val, enum) enum.add_value(v) return enum # TKIND_RECORD = 1 def ParseRecord(self, tinfo, ta): members = [] # will be filled later struct_name, doc, helpcntext, helpfile = tinfo.GetDocumentation(-1) struct = typedesc.Structure(struct_name, align=ta.cbAlignment*8, members=members, bases=[], size=ta.cbSizeInstance*8) self.items[struct_name] = struct for i in range(ta.cVars): vd = tinfo.GetVarDesc(i) name = tinfo.GetDocumentation(vd.memid)[0] offset = vd._.oInst * 8 assert vd.varkind == automation.VAR_PERINSTANCE typ = self.make_type(vd.elemdescVar.tdesc, tinfo) field = typedesc.Field(name, typ, None, # bits offset) members.append(field) return struct # TKIND_MODULE = 2 def ParseModule(self, tinfo, ta): assert 0 == ta.cImplTypes # functions for i in range(ta.cFuncs): fd = tinfo.GetFuncDesc(i) dllname, func_name, ordinal = tinfo.GetDllEntry(fd.memid, fd.invkind) func_doc = tinfo.GetDocumentation(fd.memid)[1] assert 0 == fd.cParamsOpt # XXX returns = self.make_type(fd.elemdescFunc.tdesc, tinfo) if fd.callconv == automation.CC_CDECL: attributes = "__cdecl__" elif fd.callconv == automation.CC_STDCALL: attributes = "__stdcall__" else: raise "NYI", fd.callconv func = typedesc.Function(func_name, returns, attributes, extern=1) if doc is not None: func.doc = doc func.dllname = dllname self.items[func_name] = func for i in range(fd.cParams): argtype = self.make_type(fd.lprgelemdescParam[i].tdesc, tinfo) func.add_argument(argtype) # constants for i in range(ta.cVars): vd = tinfo.GetVarDesc(i) name, var_dic = tinfo.GetDocumentation(vd.memid)[0:2] vt = vd._.lpvarValue[0].n1.n2.vt assert vd.varkind == automation.VAR_CONST # XXX Should be handled by VARIANT if vt == automation.VT_I4: typ = self.make_type(vd.elemdescVar.tdesc, tinfo) num_val = vd._.lpvarValue[0].n1.n2.n3.iVal v = typedesc.Variable(name, typ, repr(num_val)) self.items[name] = v elif vt == automation.VT_BSTR: typ = self.make_type(vd.elemdescVar.tdesc, tinfo) str_val = vd._.lpvarValue[0].n1.n2.n3.bstrVal v = typedesc.Variable(name, typ, '''"%s"''' % str_val) self.items[name] = v else: print "VT", vt if var_doc is not None: v.doc = var_doc # TKIND_INTERFACE = 3 def ParseInterface(self, tinfo, ta): itf_name, doc = tinfo.GetDocumentation(-1)[0:2] assert ta.cImplTypes <= 1 if ta.cImplTypes: hr = tinfo.GetRefTypeOfImplType(0) tibase = tinfo.GetRefTypeInfo(hr) base = self.parse_typeinfo(tibase) else: base = None members = [] itf = typedesc.ComInterface(itf_name, members=members, base=base, iid=str(ta.guid), idlflags=self.idl_flags(ta.wTypeFlags)) self.items[itf_name] = itf assert ta.cVars == 0, "vars on an Interface?" for i in range(ta.cFuncs): fd = tinfo.GetFuncDesc(i) func_name = tinfo.GetDocumentation(fd.memid)[0] returns = self.make_type(fd.elemdescFunc.tdesc, tinfo) names = tinfo.GetNames(fd.memid, fd.cParams+1) names.append("rhs") names = names[:fd.cParams + 1] assert len(names) == fd.cParams + 1 flags = self.func_flags(fd.wFuncFlags) flags += self.inv_kind(fd.invkind) mth = typedesc.ComMethod(fd.invkind, func_name, returns, flags) for p in range(fd.cParams): typ = self.make_type(fd.lprgelemdescParam[p].tdesc, tinfo) name = names[p+1] flags = fd.lprgelemdescParam[p]._.paramdesc.wParamFlags if flags & automation.PARAMFLAG_FHASDEFAULT: # XXX should be handled by VARIANT itself var = fd.lprgelemdescParam[p]._.paramdesc.pparamdescex[0].varDefaultValue if var.n1.n2.vt == automation.VT_BSTR: default = var.n1.n2.n3.bstrVal elif var.n1.n2.vt == automation.VT_I4: default = var.n1.n2.n3.iVal elif var.n1.n2.vt == automation.VT_BOOL: default = bool(var.n1.n2.n3.boolVal) else: raise "NYI", var.n1.n2.vt else: default = None mth.add_argument(typ, name, self.param_flags(flags), default) itf.members.append(mth) return itf # TKIND_DISPATCH = 4 def ParseDispatch(self, tinfo, ta): itf_name, doc = tinfo.GetDocumentation(-1)[0:2] assert ta.cImplTypes == 1 hr = tinfo.GetRefTypeOfImplType(0) tibase = tinfo.GetRefTypeInfo(hr) base = self.parse_typeinfo(tibase) members = [] itf = typedesc.DispInterface(itf_name, members=members, base=base, iid=str(ta.guid), idlflags=self.idl_flags(ta.wTypeFlags)) itf.doc = str(doc) self.items[itf_name] = itf flags = ta.wTypeFlags & (automation.TYPEFLAG_FDISPATCHABLE | automation.TYPEFLAG_FDUAL) if flags == automation.TYPEFLAG_FDISPATCHABLE: # dual interface basemethods = 0 else: # pure dispinterface, does only include dispmethods basemethods = 7 assert ta.cFuncs >= 7, "where are the IDispatch methods?" for i in range(ta.cVars): vd = tinfo.GetVarDesc(i) assert vd.varkind == automation.VAR_DISPATCH var_name, doc = tinfo.GetDocumentation(vd.memid)[0:2] typ = self.make_type(vd.elemdescVar.tdesc, tinfo) mth = typedesc.DispProperty(vd.memid, var_name, typ, self.var_flags(vd.wVarFlags)) mth.doc = str(doc) itf.members.append(mth) for i in range(basemethods, ta.cFuncs): fd = tinfo.GetFuncDesc(i) func_name = tinfo.GetDocumentation(fd.memid)[0] returns = self.make_type(fd.elemdescFunc.tdesc, tinfo) names = tinfo.GetNames(fd.memid, fd.cParams+1) names.append("rhs") names = names[:fd.cParams + 1] assert len(names) == fd.cParams + 1 # function name first, then parameter names flags = self.func_flags(fd.wFuncFlags) flags += self.inv_kind(fd.invkind) mth = typedesc.DispMethod(fd.memid, fd.invkind, func_name, returns, flags) doc = tinfo.GetDocumentation(fd.memid)[1] if doc is not None: mth.doc = str(doc) for p in range(fd.cParams): typ = self.make_type(fd.lprgelemdescParam[p].tdesc, tinfo) name = names[p+1] flags = fd.lprgelemdescParam[p]._.paramdesc.wParamFlags if flags & automation.PARAMFLAG_FHASDEFAULT: # XXX should be handled by VARIANT itself var = fd.lprgelemdescParam[p]._.paramdesc.pparamdescex[0].varDefaultValue if var.n1.n2.vt == automation.VT_BSTR: default = var.n1.n2.n3.bstrVal elif var.n1.n2.vt == automation.VT_I4: default = var.n1.n2.n3.iVal elif var.n1.n2.vt == automation.VT_BOOL: default = bool(var.n1.n2.n3.boolVal) else: raise "NYI", var.n1.n2.vt else: default = None mth.add_argument(typ, name, self.param_flags(flags), default) itf.members.append(mth) return itf def inv_kind(self, invkind): NAMES = {automation.DISPATCH_METHOD: [], automation.DISPATCH_PROPERTYPUT: ["propput"], automation.DISPATCH_PROPERTYPUTREF: ["propputref"], automation.DISPATCH_PROPERTYGET: ["propget"]} return NAMES[invkind] def func_flags(self, flags): # map FUNCFLAGS values to idl attributes NAMES = {automation.FUNCFLAG_FRESTRICTED: "restricted", automation.FUNCFLAG_FSOURCE: "source", automation.FUNCFLAG_FBINDABLE: "bindable", automation.FUNCFLAG_FREQUESTEDIT: "requestedit", automation.FUNCFLAG_FDISPLAYBIND: "displaybind", automation.FUNCFLAG_FDEFAULTBIND: "defaultbind", automation.FUNCFLAG_FHIDDEN: "hidden", automation.FUNCFLAG_FUSESGETLASTERROR: "usesgetlasterror", automation.FUNCFLAG_FDEFAULTCOLLELEM: "defaultcollelem", automation.FUNCFLAG_FUIDEFAULT: "uidefault", automation.FUNCFLAG_FNONBROWSABLE: "nonbrowsable", # automation.FUNCFLAG_FREPLACEABLE: "???", automation.FUNCFLAG_FIMMEDIATEBIND: "immediatebind"} return [NAMES[bit] for bit in NAMES if bit & flags] def param_flags(self, flags): # map PARAMFLAGS values to idl attributes NAMES = {automation.PARAMFLAG_FIN: "in", automation.PARAMFLAG_FOUT: "out", automation.PARAMFLAG_FLCID: "lcid", automation.PARAMFLAG_FRETVAL: "retval", automation.PARAMFLAG_FOPT: "optional", # automation.PARAMFLAG_FHASDEFAULT: "", # automation.PARAMFLAG_FHASCUSTDATA: "", } return [NAMES[bit] for bit in NAMES if bit & flags] def idl_flags(self, flags): # map TYPEFLAGS values to idl attributes NAMES = {automation.TYPEFLAG_FAPPOBJECT: "appobject", # automation.TYPEFLAG_FCANCREATE: automation.TYPEFLAG_FLICENSED: "licensed", # automation.TYPEFLAG_FPREDECLID: automation.TYPEFLAG_FHIDDEN: "hidden", automation.TYPEFLAG_FCONTROL: "control", automation.TYPEFLAG_FDUAL: "dual", automation.TYPEFLAG_FNONEXTENSIBLE: "nonextensible", automation.TYPEFLAG_FOLEAUTOMATION: "oleautomation", automation.TYPEFLAG_FRESTRICTED: "restricted", automation.TYPEFLAG_FAGGREGATABLE: "aggregatable", # automation.TYPEFLAG_FREPLACEABLE: # automation.TYPEFLAG_FDISPATCHABLE # computed, no flag for this automation.TYPEFLAG_FREVERSEBIND: "reversebind", automation.TYPEFLAG_FPROXY: "proxy", } return [NAMES[bit] for bit in NAMES if bit & flags] def var_flags(self, flags): NAMES = {automation.VARFLAG_FREADONLY: "readonly", automation.VARFLAG_FSOURCE: "source", automation.VARFLAG_FBINDABLE: "bindable", automation.VARFLAG_FREQUESTEDIT: "requestedit", automation.VARFLAG_FDISPLAYBIND: "displaybind", automation.VARFLAG_FDEFAULTBIND: "defaultbind", automation.VARFLAG_FHIDDEN: "hidden", automation.VARFLAG_FRESTRICTED: "restricted", automation.VARFLAG_FDEFAULTCOLLELEM: "defaultcollelem", automation.VARFLAG_FUIDEFAULT: "uidefault", automation.VARFLAG_FNONBROWSABLE: "nonbrowsable", automation.VARFLAG_FREPLACEABLE: "replaceable", automation.VARFLAG_FIMMEDIATEBIND: "immediatebind" } return [NAMES[bit] for bit in NAMES if bit & flags] # TKIND_COCLASS = 5 def ParseCoClass(self, tinfo, ta): # possible ta.wTypeFlags: helpstring, helpcontext, licensed, # version, control, hidden, and appobject coclass_name, doc = tinfo.GetDocumentation(-1)[0:2] coclass = typedesc.CoClass(coclass_name, str(ta.guid), self.idl_flags(ta.wTypeFlags)) coclass.doc = str(doc) self.items[coclass_name] = coclass for i in range(ta.cImplTypes): hr = tinfo.GetRefTypeOfImplType(i) ti = tinfo.GetRefTypeInfo(hr) itf = self.parse_typeinfo(ti) flags = tinfo.GetImplTypeFlags(i) coclass.add_interface(itf, flags) # TKIND_ALIAS = 6 def ParseAlias(self, tinfo, ta): name = tinfo.GetDocumentation(-1)[0] typ = self.make_type(ta.tdescAlias, tinfo) alias = typedesc.Typedef(name, typ) self.items[name] = alias return alias # TKIND_UNION = 7 def ParseUnion(self, tinfo, ta): union_name, doc, helpcntext, helpfile = tinfo.GetDocumentation(-1) members = [] union = typedesc.Union(union_name, align=ta.cbAlignment*8, members=members, bases=[], size=ta.cbSizeInstance*8) self.items[union_name] = union for i in range(ta.cVars): vd = tinfo.GetVarDesc(i) name = tinfo.GetDocumentation(vd.memid)[0] offset = vd._.oInst * 8 assert vd.varkind == automation.VAR_PERINSTANCE typ = self.make_type(vd.elemdescVar.tdesc, tinfo) field = typedesc.Field(name, typ, None, # bits offset) members.append(field) return union ################################################################ def parse_typeinfo(self, tinfo): name = tinfo.GetDocumentation(-1)[0] try: return self.items[name] except KeyError: pass ta = tinfo.GetTypeAttr() tkind = ta.typekind if tkind == automation.TKIND_ENUM: # 0 return self.ParseEnum(tinfo, ta) elif tkind == automation.TKIND_RECORD: # 1 return self.ParseRecord(tinfo, ta) elif tkind == automation.TKIND_MODULE: # 2 return self.ParseModule(tinfo, ta) elif tkind == automation.TKIND_INTERFACE: # 3 return self.ParseInterface(tinfo, ta) elif tkind == automation.TKIND_DISPATCH: # 4 return self.ParseDispatch(tinfo, ta) elif tkind == automation.TKIND_COCLASS: # 5 return self.ParseCoClass(tinfo, ta) elif tkind == automation.TKIND_ALIAS: # 6 return self.ParseAlias(tinfo, ta) elif tkind == automation.TKIND_UNION: # 7 return self.ParseUnion(tinfo, ta) else: raise "NYI", tkind ################################################################ def parse(self): for i in range(self.tlib.GetTypeInfoCount()): tinfo = self.tlib.GetTypeInfo(i) self.parse_typeinfo(tinfo) return self.items ################################################################ coclass = typedesc.FundamentalType("CoClass", 32, 32) # fake for codegen def main(): import sys path = r"hnetcfg.dll" ## path = r"simpdata.tlb" ## path = r"nscompat.tlb" ## path = r"mshtml.tlb" ## path = r"stdole32.tlb" ## path = "msscript.ocx" ## path = r"x.tlb" path = r"shdocvw.dll" ## path = r"c:\Programme\Microsoft Office\Office\MSO97.DLL" ## path = r"c:\Programme\Microsoft Office\Office\MSWORD8.OLB" ## path = r"msi.dll" ## path = r"PICCLP32.OCX" ## 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" known_symbols = {} for name in ("comtypes.automation", "comtypes", "ctypes"): mod = __import__(name) for submodule in name.split(".")[1:]: mod = getattr(mod, submodule) for name in mod.__dict__: known_symbols[name] = mod.__name__ p = TlbParser(path) items = p.parse() items["CoClass"] = coclass 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__": main() --- NEW FILE: helpers.py --- from ctypes import HRESULT, POINTER from comtypes import BSTR # COMMETHOD and DISPMETHOD return what's required to create # WINFUNCTYPE templates and instances: (restype, name, argtypes) # # Calling WINFUNCTYPE with (restype, *argtypes) returns the template. # # Calling the template with (vtbl_index, name, class) returns an unbound method # usable for client COM method class. # # Calling the template with (callable) returns a C callable usable as # COM method implementation. def COMMETHOD(idlflags, restype, name, *argtypes): # where do the idlflags go? if "propget" in idlflags: name = "_get_%s" % name elif "propput" in idlflags: name = "_set_%s" % name return restype, name, [a[2] for a in argtypes] def DISPMETHOD(idlflags, restype, name, *argtypes): # where do the idlflags go? assert isinstance(idlflags[0], int) if restype is not None: argtypes = argtypes + ((["out"], "_result_", POINTER(restype)),) if "propget" in idlflags: name = "_get_%s" % name elif "propput" in idlflags: name = "_set_%s" % name argtypes = [a[2] for a in argtypes] return HRESULT, name, argtypes def DISPPROPERTY(idlflags, typ, name): # fake return typ, name, [] --- NEW FILE: codegenerator.py --- # Extended code generator able to generate code for everything # contained in COM type libraries. import typedesc import ctypes.wrap.codegenerator class Generator(ctypes.wrap.codegenerator.Generator): ################################################################ # top-level typedesc generators # def CoClass(self, coclass): for itf, idlflags in coclass.interfaces: self.generate(itf) print >> self.stream, "class %s(CoClass):" % coclass.name doc = getattr(coclass, "doc", None) if doc: print >> self.stream, " %r" % doc print >> self.stream, " _clsid_ = GUID(%r)" % coclass.clsid print >> self.stream, " _idlflags_ = %s" % coclass.idlflags implemented = [i[0].name for i in coclass.interfaces if i[1] & 2 == 0] sources = [i[0].name for i in coclass.interfaces if i[1] & 2] if implemented: print >> self.stream, " _com_interfaces_ = [%s]" % ", ".join(implemented) if sources: print >> self.stream, " _outgoing_interfaces_ = [%s]" % ", ".join(sources) print >> self.stream def ComInterface(self, itf): self.generate(itf.get_head()) self.generate(itf.get_body()) def ComInterfaceHead(self, head): self.generate(head.itf.base) basename = self.type_name(head.itf.base) print >> self.stream, "class %s(%s):" % (head.itf.name, basename) print >> self.stream, " _iid_ = GUID(%r)" % head.itf.iid print >> self.stream, " _idlflags_ = %s" % head.itf.idlflags def ComInterfaceBody(self, body): # make sure we can generate the body for m in body.itf.members: for a in m.arguments: self.generate(a[0]) self.generate(m.returns) print >> self.stream, "%s._methods_ = [" % body.itf.name for m in body.itf.members: if isinstance(m, typedesc.ComMethod): self.make_ComMethod(m) else: raise TypeError, "what's this?" print >> self.stream, "]" def DispInterface(self, itf): self.generate(itf.get_head()) self.generate(itf.get_body()) def DispInterfaceHead(self, head): self.generate(head.itf.base) basename = self.type_name(head.itf.base) print >> self.stream, "class %s(%s):" % (head.itf.name, basename) doc = getattr(head.itf, "doc", None) if doc: print >> self.stream, " %r" % doc print >> self.stream, " _iid_ = GUID(%r)" % head.itf.iid print >> self.stream, " _idlflags_ = %s" % head.itf.idlflags # code prop_map = {} for m in head.itf.members: is_property = self.make_DispMethodWrapper(m) if is_property is not None: name, kind = is_property prop_map.setdefault(name, []).append(kind) for name, kinds in prop_map.items(): if "propget" in kinds: getter = "_get_%s" % name if "propput" in kinds: setter = "_set_%s" % name elif "propputref" in kinds: setter = "_putref_%s" % name else: setter = None print >> self.stream, " %s = property(%s, %s)" % (name, getter, setter) print >> self.stream def DispInterfaceBody(self, body): # make sure we can generate the body for m in body.itf.members: if isinstance(m, typedesc.DispMethod): for a in m.arguments: self.generate(a[0]) self.generate(m.returns) elif isinstance(m, typedesc.DispProperty): self.generate(m.typ) else: raise TypeError, m print >> self.stream, "%s._methods_ = [" % body.itf.name for m in body.itf.members: if isinstance(m, typedesc.DispMethod): self.make_DispMethod(m) elif isinstance(m, typedesc.DispProperty): self.make_DispProperty(m) else: raise TypeError, m print >> self.stream, "]" ################################################################ # non-toplevel method generators # def make_ComMethod(self, m): # typ, name, idlflags, default args = [self.type_name(a[0]) for a in m.arguments] code = " COMMETHOD(%r, %s, '%s'" % ( m.idlflags, self.type_name(m.returns), m.name) if not m.arguments: print >> self.stream, "%s)," % code else: print >> self.stream, "%s," % code self.stream.write(" ") arglist = [] for typ, name, idlflags, default in m.arguments: if default is not None: arglist.append("( %r, '%s', %s, %r )" % ( idlflags, name, self.type_name(typ), default)) else: arglist.append("( %r, '%s', %s )" % ( idlflags, name, self.type_name(typ))) self.stream.write(",\n ".join(arglist)) print >> self.stream, ")," def make_DispMethod(self, m): # typ, name, idlflags, default args = [self.type_name(a[0]) for a in m.arguments] ## code = " DISPMETHOD(%r,\n %s, '%s'" % ( code = " DISPMETHOD(%r, %s, '%s'" % ( [m.dispid] + m.idlflags, self.type_name(m.returns), m.name) if not m.arguments: print >> self.stream, "%s)," % code else: print >> self.stream, "%s," % code self.stream.write(" ") arglist = [] for typ, name, idlflags, default in m.arguments: if default is not None: arglist.append("( %r, '%s', %s, %r )" % ( idlflags, name, self.type_name(typ), default)) else: arglist.append("( %r, '%s', %s )" % ( idlflags, name, self.type_name(typ), )) self.stream.write(",\n ".join(arglist)) print >> self.stream, ")," ## print >> self.stream, "\n )," def make_DispProperty(self, prop): print >> self.stream, " DISPPROPERTY(%r, %s, '%s')," % ( [prop.dispid] + prop.idlflags, self.type_name(prop.typ), prop.name) ################################################################ # Python method implementation generators. # def make_DispPropertyWrapper(self, p): type_name = self.type_name(p.typ) print >> self.stream, " def _get_%s(self):" % p.name print >> self.stream, " _result_ = %s()" % type_name print >> self.stream, " self.__com_get_%s(byref(_result))" % p.name print >> self.stream, " return _result_.value" getter = "_get_%s" % p.name if "readonly" in p.idlflags: setter = None else: setter = "_set_%s" % p.name print >> self.stream, " def _set_%s(self, rhs):" % p.name print >> self.stream, " self.__com_set_%s(rhs)" % p.name doc = getattr(p, "doc", None) print >> self.stream, " %s = property(%s, %s, doc=%r)" % \ (p.name, getter, setter, doc) print >> self.stream return None def make_DispMethodWrapper(self, m): if isinstance(m, typedesc.DispProperty): return self.DispPropertyWrapper(m) funcname = m.name if "propget" in m.idlflags: funcname = "_get_%s" % funcname elif "propput" in m.idlflags: funcname = "_set_%s" % funcname elif "propputref" in m.idlflags: funcname = "_putref_%s" % funcname else: pass args = m.arguments[:] if self.type_name(m.returns) != 'None': # return type != void typ = typedesc.PointerType(m.returns, 32, 32) args.append((typ, "_result_", ["out"], None)) # add with paramflag_fout inargs = [] for typ, name, idlflags, default in args: if "in" in idlflags: if default is not None: inargs.append("%s=%r" % (name, default)) elif "optional" in idlflags: inargs.append("%s=%s" % (name, "MISSING")) else: inargs.append(name) allargs = [] flocals = [] for typ, name, idlflags, default in args: # XXX What about [in, out] parameters? if "out" in idlflags: assert isinstance(typ, typedesc.PointerType) flocals.append((name, self.type_name(typ.typ))) allargs.append("byref(%s)" % name) else: allargs.append(name) # Now that POINTER(<com_interface>) instances have a .value property # which returns the com pointer itself, we can do this FOR ALL types: outargs = ["%s.value" % name for (typ, name, idlflags, default) in args if "out" in idlflags] print >> self.stream, " def %s(%s):" % (funcname, ", ".join(["self"] + inargs)) doc = getattr(m, "doc", None) if doc: print >> self.stream, " %r" % doc for n, t in flocals: print >> self.stream, " %s = %s()" % (n, t) if outargs: print >> self.stream, " self.__com_%s(%s)" % (funcname, ", ".join(allargs)) print >> self.stream, " return %s" % ", ".join(outargs) else: print >> self.stream, " return self.__com_%s(%s)" % (funcname, ", ".join(allargs)) is_property = None # check if this could be a Python property if "propget" in m.idlflags: if len(inargs) == 0: # 'propget' can only be a Python property if it has no args is_property = m.name, "propget" else: print >> self.stream, " %s = %s" % (m.name, funcname) elif "propput" in m.idlflags: if len(inargs) == 1: # 'propput' can only be a Python property if it has no args is_property = m.name, "propput" else: print >> self.stream, " %s = %s" % (m.name, funcname) elif "propputref" in m.idlflags: if len(inargs) == 1: # 'propputref' can only be a Python property if it has no args # XXX is_property = m.name, "propputref" else: print >> self.stream, " %s = %s" % (m.name, funcname) print >> self.stream return is_property # shortcut for development if __name__ == "__main__": import tlbparser tlbparser.main() --- NEW FILE: typedesc.py --- # More type descriptions from parsed COM typelibaries. from ctypes.wrap.typedesc import * class ComMethod(object): # custom COM method, parsed from typelib def __init__(self, invkind, name, returns, idlflags): self.invkind = invkind self.name = name self.returns = returns self.idlflags = idlflags self.arguments = [] def add_argument(self, typ, name, idlflags, default): self.arguments.append((typ, name, idlflags, default)) class DispMethod(object): # dispatchable COM method, parsed from typelib def __init__(self, dispid, invkind, name, returns, idlflags): self.dispid = dispid self.invkind = invkind self.name = name self.returns = returns self.idlflags = idlflags self.arguments = [] def add_argument(self, typ, name, idlflags, default): self.arguments.append((typ, name, idlflags, default)) class DispProperty(object): # dispatchable COM property, parsed from typelib def __init__(self, dispid, name, typ, idlflags): self.dispid = dispid self.name = name self.typ = typ self.idlflags = idlflags class DispInterfaceHead(object): def __init__(self, itf): self.itf = itf class DispInterfaceBody(object): def __init__(self, itf): self.itf = itf class DispInterface(object): def __init__(self, name, members, base, iid, idlflags): self.name = name self.members = members self.base = base self.iid = iid self.idlflags = idlflags self.itf_head = DispInterfaceHead(self) self.itf_body = DispInterfaceBody(self) def get_body(self): return self.itf_body def get_head(self): return self.itf_head class ComInterfaceHead(object): def __init__(self, itf): self.itf = itf class ComInterfaceBody(object): def __init__(self, itf): self.itf = itf class ComInterface(object): def __init__(self, name, members, base, iid, idlflags): self.name = name self.members = members self.base = base self.iid = iid self.idlflags = idlflags self.itf_head = ComInterfaceHead(self) self.itf_body = ComInterfaceBody(self) def get_body(self): return self.itf_body def get_head(self): return self.itf_head class CoClass(object): def __init__(self, name, clsid, idlflags): self.name = name self.clsid = clsid self.idlflags = idlflags self.interfaces = [] def add_interface(self, itf, idlflags): self.interfaces.append((itf, idlflags)) |
From: Thomas H. <th...@us...> - 2005-02-04 21:18:57
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29065 Modified Files: automation.py Log Message: Hacked a custom from_param classmethod for POINTER(VARIANT). This works around a problem in InternetExplorer which requires VARIANT* as [in] parameters. I wonder if this is a problem of IE only, and if it applies to VARIANT only... Index: automation.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/automation.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** automation.py 4 Feb 2005 19:33:21 -0000 1.5 --- automation.py 4 Feb 2005 21:18:49 -0000 1.6 *************** *** 396,399 **** --- 396,427 ---- pass VARIANT = tagVARIANT # typedef + + def from_param(self, var): + # XXX + # InternetExplorer sometimes(?) requires POINTER(VARIANT) + # as [in] parameters, in the Navigate2 call. But the method gets + # a simple string value. + # + # We could use from_param to accept simple values, convert them to VARIANT, + # and finally pass a byref() to that to the function call. + if isinstance(var, POINTER(VARIANT)): + return var + if isinstance(var, VARIANT): + return byref(var) + elif isinstance(var, basestring): + v = VARIANT() + v.n1.n2.vt = VT_BSTR + v.n1.n2.n3.bstrVal = var + return byref(v) + elif isinstance(var, (int, long)): + v = VARIANT() + v.n1.n2.vt = VT_I4 + v.n1.n2.n3.iVal = var + return byref(v) + raise TypeError, var + + POINTER(VARIANT).from_param = classmethod(from_param) + + class tagEXCEPINFO(Structure): pass |
From: Thomas H. <th...@us...> - 2005-02-04 21:17:19
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28703 Modified Files: __init__.py Log Message: Added a trivial CoClass which can call CoCreateInstance. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/__init__.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** __init__.py 3 Feb 2005 14:08:27 -0000 1.7 --- __init__.py 4 Feb 2005 21:17:10 -0000 1.8 *************** *** 134,138 **** return self.__com_Release() ! __all__ = "IUnknown GUID HRESULT BSTR STDMETHOD".split() if __name__ == "__main__": --- 134,151 ---- return self.__com_Release() ! class CoClass(object): ! # creation, and so on ! ! def create_instance(self): ! oledll.ole32.CoInitialize(None) ! p = POINTER(self._com_interfaces_[0])() ! oledll.ole32.CoCreateInstance(byref(self._clsid_), ! None, ! 7, # CLSCTX ! byref(p._iid_), ! byref(p)) ! return p ! ! __all__ = ["CoClass", "IUnknown", "GUID", "HRESULT", "BSTR", "STDMETHOD"] if __name__ == "__main__": |
From: Thomas H. <th...@us...> - 2005-02-04 19:33:40
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3721 Modified Files: automation.py Log Message: Add VARFLAGS. Index: automation.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/automation.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** automation.py 3 Feb 2005 19:39:14 -0000 1.4 --- automation.py 4 Feb 2005 19:33:21 -0000 1.5 *************** *** 40,43 **** --- 40,59 ---- DISPATCH_METHOD = 1 + tagVARFLAGS = c_int # enum + VARFLAG_FREADONLY = 1 + VARFLAG_FSOURCE = 2 + VARFLAG_FBINDABLE = 4 + VARFLAG_FREQUESTEDIT = 8 + VARFLAG_FDISPLAYBIND = 16 + VARFLAG_FDEFAULTBIND = 32 + VARFLAG_FHIDDEN = 64 + VARFLAG_FRESTRICTED = 128 + VARFLAG_FDEFAULTCOLLELEM = 256 + VARFLAG_FUIDEFAULT = 512 + VARFLAG_FNONBROWSABLE = 1024 + VARFLAG_FREPLACEABLE = 2048 + VARFLAG_FIMMEDIATEBIND = 4096 + VARFLAGS = tagVARFLAGS + UINT = c_uint # typedef LONG = c_long # typedef |
From: Thomas H. <th...@us...> - 2005-02-04 19:22:14
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv481 Modified Files: tlbparser.py Log Message: IDLflags are now passed as list of strings to the typedesc module. Index: tlbparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/tlbparser.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** tlbparser.py 3 Feb 2005 10:57:26 -0000 1.3 --- tlbparser.py 4 Feb 2005 19:22:05 -0000 1.4 *************** *** 27,37 **** HRESULT_type = typedesc.Typedef("HRESULT", ulong_type) ! VARIANT_type = typedesc.Typedef("VARIANT", None) # ! IDISPATCH_type = typedesc.Typedef("IDispatch", None) # ! IUNKNOWN_type = typedesc.Typedef("IUnknown", None) # ! # faked COM data types CURRENCY_type = float_type # wrong ! DATE_type = double_type # not toally wrong... DECIMAL_type = double_type # wrong - it's a 12 byte structure (or was it 16 bytes?) --- 27,38 ---- HRESULT_type = typedesc.Typedef("HRESULT", ulong_type) ! VARIANT_type = typedesc.Typedef("VARIANT", None) ! IDISPATCH_type = typedesc.Typedef("IDispatch", None) ! IUNKNOWN_type = typedesc.Typedef("IUnknown", None) ! SAFEARRAY_type = typedesc.Typedef("SAFEARRAY", None) + # faked COM data types CURRENCY_type = float_type # wrong ! DATE_type = double_type # not *that* wrong... DECIMAL_type = double_type # wrong - it's a 12 byte structure (or was it 16 bytes?) *************** *** 59,73 **** automation.VT_INT: int_type, # 22 automation.VT_UINT: uint_type, # 23 ! automation.VT_VOID: typedesc.Typedef("None", None), # 24 automation.VT_HRESULT: HRESULT_type, # 25 ! ! automation.VT_SAFEARRAY: typedesc.Typedef("SAFEARRAY", None), # 27 ! automation.VT_LPSTR: PTR(char_type), # 30 automation.VT_LPWSTR: PTR(wchar_t_type), # 31 } - #automation.VT_PTR = 26 # enum VARENUM - #automation.VT_CARRAY = 28 # enum VARENUM #automation.VT_USERDEFINED = 29 # enum VARENUM --- 60,72 ---- automation.VT_INT: int_type, # 22 automation.VT_UINT: uint_type, # 23 ! 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 *************** *** 77,91 **** #automation.VT_BYREF = 16384 # enum VARENUM - known_symbols = {#"VARIANT": "comtypes", - "None": "XXX", - } - - for name in ("comtypes.automation", "comtypes", "ctypes"): - mod = __import__(name) - for submodule in name.split(".")[1:]: - mod = getattr(mod, submodule) - for name in mod.__dict__: - known_symbols[name] = mod.__name__ - ################################################################ --- 76,79 ---- *************** *** 229,233 **** base=base, iid=str(ta.guid), ! wTypeFlags=ta.wTypeFlags) self.items[itf_name] = itf --- 217,221 ---- base=base, iid=str(ta.guid), ! idlflags=self.idl_flags(ta.wTypeFlags)) self.items[itf_name] = itf *************** *** 242,247 **** names = names[:fd.cParams + 1] assert len(names) == fd.cParams + 1 ! mth = typedesc.ComMethod(fd.invkind, func_name, returns, fd.wFuncFlags) ! assert fd.cParamsOpt == 0, "optional parameters not yet implemented" for p in range(fd.cParams): typ = self.make_type(fd.lprgelemdescParam[p].tdesc, tinfo) --- 230,237 ---- names = names[:fd.cParams + 1] assert len(names) == fd.cParams + 1 ! flags = self.func_flags(fd.wFuncFlags) ! flags += self.inv_kind(fd.invkind) ! mth = typedesc.ComMethod(fd.invkind, func_name, returns, flags) ! ## assert fd.cParamsOpt == 0, "optional parameters not yet implemented" for p in range(fd.cParams): typ = self.make_type(fd.lprgelemdescParam[p].tdesc, tinfo) *************** *** 260,264 **** else: default = None ! mth.add_argument(typ, name, flags, default) itf.members.append(mth) --- 250,254 ---- else: default = None ! mth.add_argument(typ, name, self.param_flags(flags), default) itf.members.append(mth) *************** *** 278,282 **** base=base, iid=str(ta.guid), ! wTypeFlags=ta.wTypeFlags) self.items[itf_name] = itf --- 268,273 ---- base=base, iid=str(ta.guid), ! idlflags=self.idl_flags(ta.wTypeFlags)) ! itf.doc = str(doc) self.items[itf_name] = itf *************** *** 293,299 **** vd = tinfo.GetVarDesc(i) assert vd.varkind == automation.VAR_DISPATCH ! var_name = tinfo.GetDocumentation(vd.memid)[0] typ = self.make_type(vd.elemdescVar.tdesc, tinfo) ! mth = typedesc.DispProperty(vd.memid, vd.varkind, var_name, typ, vd.wVarFlags) itf.members.append(mth) --- 284,291 ---- vd = tinfo.GetVarDesc(i) assert vd.varkind == automation.VAR_DISPATCH ! var_name, doc = tinfo.GetDocumentation(vd.memid)[0:2] typ = self.make_type(vd.elemdescVar.tdesc, tinfo) ! mth = typedesc.DispProperty(vd.memid, var_name, typ, self.var_flags(vd.wVarFlags)) ! mth.doc = str(doc) itf.members.append(mth) *************** *** 306,310 **** names = names[:fd.cParams + 1] assert len(names) == fd.cParams + 1 # function name first, then parameter names ! mth = typedesc.DispMethod(fd.memid, fd.invkind, func_name, returns, fd.wFuncFlags) doc = tinfo.GetDocumentation(fd.memid)[1] if doc is not None: --- 298,304 ---- names = names[:fd.cParams + 1] assert len(names) == fd.cParams + 1 # function name first, then parameter names ! flags = self.func_flags(fd.wFuncFlags) ! flags += self.inv_kind(fd.invkind) ! mth = typedesc.DispMethod(fd.memid, fd.invkind, func_name, returns, flags) doc = tinfo.GetDocumentation(fd.memid)[1] if doc is not None: *************** *** 326,340 **** else: default = None ! mth.add_argument(typ, name, flags, default) itf.members.append(mth) return itf # TKIND_COCLASS = 5 def ParseCoClass(self, tinfo, ta): # possible ta.wTypeFlags: helpstring, helpcontext, licensed, # version, control, hidden, and appobject ! coclass_name = tinfo.GetDocumentation(-1)[0] ! coclass = typedesc.CoClass(coclass_name, str(ta.guid), ta.wTypeFlags) self.items[coclass_name] = coclass for i in range(ta.cImplTypes): --- 320,409 ---- else: default = None ! mth.add_argument(typ, name, self.param_flags(flags), default) itf.members.append(mth) return itf + def inv_kind(self, invkind): + NAMES = {automation.DISPATCH_METHOD: [], + automation.DISPATCH_PROPERTYPUT: ["propput"], + automation.DISPATCH_PROPERTYPUTREF: ["propputref"], + automation.DISPATCH_PROPERTYGET: ["propget"]} + return NAMES[invkind] + + def func_flags(self, flags): + # map FUNCFLAGS values to idl attributes + NAMES = {automation.FUNCFLAG_FRESTRICTED: "restricted", + automation.FUNCFLAG_FSOURCE: "source", + automation.FUNCFLAG_FBINDABLE: "bindable", + automation.FUNCFLAG_FREQUESTEDIT: "requestedit", + automation.FUNCFLAG_FDISPLAYBIND: "displaybind", + automation.FUNCFLAG_FDEFAULTBIND: "defaultbind", + automation.FUNCFLAG_FHIDDEN: "hidden", + automation.FUNCFLAG_FUSESGETLASTERROR: "usesgetlasterror", + automation.FUNCFLAG_FDEFAULTCOLLELEM: "defaultcollelem", + automation.FUNCFLAG_FUIDEFAULT: "uidefault", + automation.FUNCFLAG_FNONBROWSABLE: "nonbrowsable", + # automation.FUNCFLAG_FREPLACEABLE: "???", + automation.FUNCFLAG_FIMMEDIATEBIND: "immediatebind"} + return [NAMES[bit] for bit in NAMES if bit & flags] + + def param_flags(self, flags): + # map PARAMFLAGS values to idl attributes + NAMES = {automation.PARAMFLAG_FIN: "in", + automation.PARAMFLAG_FOUT: "out", + automation.PARAMFLAG_FLCID: "lcid", + automation.PARAMFLAG_FRETVAL: "retval", + automation.PARAMFLAG_FOPT: "optional", + # automation.PARAMFLAG_FHASDEFAULT: "", + # automation.PARAMFLAG_FHASCUSTDATA: "", + } + return [NAMES[bit] for bit in NAMES if bit & flags] + + def idl_flags(self, flags): + # map TYPEFLAGS values to idl attributes + NAMES = {automation.TYPEFLAG_FAPPOBJECT: "appobject", + # automation.TYPEFLAG_FCANCREATE: + automation.TYPEFLAG_FLICENSED: "licensed", + # automation.TYPEFLAG_FPREDECLID: + automation.TYPEFLAG_FHIDDEN: "hidden", + automation.TYPEFLAG_FCONTROL: "control", + automation.TYPEFLAG_FDUAL: "dual", + automation.TYPEFLAG_FNONEXTENSIBLE: "nonextensible", + automation.TYPEFLAG_FOLEAUTOMATION: "oleautomation", + automation.TYPEFLAG_FRESTRICTED: "restricted", + automation.TYPEFLAG_FAGGREGATABLE: "aggregatable", + # automation.TYPEFLAG_FREPLACEABLE: + # automation.TYPEFLAG_FDISPATCHABLE # computed, no flag for this + automation.TYPEFLAG_FREVERSEBIND: "reversebind", + automation.TYPEFLAG_FPROXY: "proxy", + } + return [NAMES[bit] for bit in NAMES if bit & flags] + + def var_flags(self, flags): + NAMES = {automation.VARFLAG_FREADONLY: "readonly", + automation.VARFLAG_FSOURCE: "source", + automation.VARFLAG_FBINDABLE: "bindable", + automation.VARFLAG_FREQUESTEDIT: "requestedit", + automation.VARFLAG_FDISPLAYBIND: "displaybind", + automation.VARFLAG_FDEFAULTBIND: "defaultbind", + automation.VARFLAG_FHIDDEN: "hidden", + automation.VARFLAG_FRESTRICTED: "restricted", + automation.VARFLAG_FDEFAULTCOLLELEM: "defaultcollelem", + automation.VARFLAG_FUIDEFAULT: "uidefault", + automation.VARFLAG_FNONBROWSABLE: "nonbrowsable", + automation.VARFLAG_FREPLACEABLE: "replaceable", + automation.VARFLAG_FIMMEDIATEBIND: "immediatebind" + } + return [NAMES[bit] for bit in NAMES if bit & flags] + + # TKIND_COCLASS = 5 def ParseCoClass(self, tinfo, ta): # possible ta.wTypeFlags: helpstring, helpcontext, licensed, # version, control, hidden, and appobject ! coclass_name, doc = tinfo.GetDocumentation(-1)[0:2] ! coclass = typedesc.CoClass(coclass_name, str(ta.guid), self.idl_flags(ta.wTypeFlags)) ! coclass.doc = str(doc) self.items[coclass_name] = coclass for i in range(ta.cImplTypes): *************** *** 419,429 **** import sys ! ## path = r"hnetcfg.dll" ## path = r"simpdata.tlb" ## path = r"nscompat.tlb" ## path = r"mshtml.tlb" ! path = r"stdole32.tlb" ! ## path = r"c:\tss5\include\MeasurementModule.tlb" ! ## path = r"c:\tss5\include\fpanel.tlb" ## path = "msscript.ocx" ## path = r"x.tlb" --- 488,496 ---- import sys ! path = r"hnetcfg.dll" ## path = r"simpdata.tlb" ## path = r"nscompat.tlb" ## path = r"mshtml.tlb" ! ## path = r"stdole32.tlb" ## path = "msscript.ocx" ## path = r"x.tlb" *************** *** 433,450 **** ## path = r"c:\Programme\Microsoft Office\Office\MSWORD8.OLB" ## path = r"msi.dll" - ## path = r"c:\tss5\include\ITDPersist.tlb" ## path = r"PICCLP32.OCX" - ## path = r"Macromed\Flash\swflash.ocx" ## 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" p = TlbParser(path) items = p.parse() --- 500,526 ---- ## path = r"c:\Programme\Microsoft Office\Office\MSWORD8.OLB" ## path = r"msi.dll" ## path = r"PICCLP32.OCX" ## 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" + known_symbols = {} + + for name in ("comtypes.automation", "comtypes", "ctypes"): + mod = __import__(name) + for submodule in name.split(".")[1:]: + mod = getattr(mod, submodule) + for name in mod.__dict__: + known_symbols[name] = mod.__name__ + p = TlbParser(path) items = p.parse() *************** *** 452,455 **** --- 528,532 ---- gen = Generator(sys.stdout) + print >> gen.imports, "from helpers import *" loops = gen.generate_code(items.values(), known_symbols, []) |
From: Thomas H. <th...@us...> - 2005-02-04 19:18:26
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31992 Removed Files: typedesc.py Log Message: Moved the code gen stuff into the ctypes.wrap package. --- typedesc.py DELETED --- |
From: Thomas H. <th...@us...> - 2005-02-04 19:14:49
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30779 Removed Files: gccxmlparser.py cparser_config.py cparser.py codegenerator.py Log Message: Moved the code gen stuff into the ctypes.wrap package. --- gccxmlparser.py DELETED --- --- cparser.py DELETED --- --- codegenerator.py DELETED --- --- cparser_config.py DELETED --- |
From: Thomas H. <th...@us...> - 2005-02-04 19:04:38
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28080 Modified Files: xml2py.py h2xml.py Log Message: The scripts are now in the ctypes.wrap package. Index: xml2py.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/xml2py.py,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** xml2py.py 24 Jan 2005 10:01:42 -0000 1.14 --- xml2py.py 4 Feb 2005 19:04:25 -0000 1.15 *************** *** 1,173 **** ! import sys, re ! from optparse import OptionParser ! from codegenerator import generate_code ! import typedesc ! ! ################################################################ ! windows_dll_names = """\ ! imagehlp ! user32 ! kernel32 ! gdi32 ! advapi32 ! oleaut32 ! ole32 ! imm32 ! comdlg32 ! shell32 ! version ! winmm ! mpr ! winscard ! winspool.drv ! urlmon ! crypt32 ! cryptnet ! ws2_32 ! opengl32 ! glu32 ! mswsock ! msvcrt ! msimg32 ! netapi32 ! rpcrt4""".split() ! ! ##rpcndr ! ##ntdll ! ! def main(args=None): ! if args is None: ! args = sys.argv ! ! def windows_dlls(option, opt, value, parser): ! parser.values.dlls.extend(windows_dll_names) ! ! parser = OptionParser("usage: %prog xmlfile [options]") ! parser.add_option("-d", ! action="store_true", ! dest="use_decorators", ! help="use Python 2.4 function decorators", ! default=False) ! ! parser.add_option("-k", ! action="store", ! dest="kind", ! help="kind of type descriptions to include: " ! "d = #defines, " ! "e = enumerations, " ! "f = functions, " ! "s = structures, " ! "t = typedefs", ! metavar="TYPEKIND", ! default=None) ! ! parser.add_option("-l", ! dest="dlls", ! help="libraries to search for exported functions", ! action="append", ! default=[]) ! ! parser.add_option("-o", ! dest="output", ! help="output filename (if not specified, standard output will be used)", ! default="-") ! ! parser.add_option("-r", ! dest="expressions", ! metavar="EXPRESSION", ! action="append", ! help="regular expression for symbols to include " ! "(if neither symbols nor expressions are specified," ! "everything will be included)", ! default=None) ! ! parser.add_option("-s", ! dest="symbols", ! metavar="SYMBOL", ! action="append", ! help="symbol to include " ! "(if neither symbols nor expressions are specified," ! "everything will be included)", ! default=None) ! ! parser.add_option("-v", ! action="store_true", ! dest="verbose", ! help="verbose output", ! default=False) ! ! parser.add_option("-w", ! action="callback", ! callback=windows_dlls, ! help="add all standard windows dlls to the searched dlls list") ! ! ## try: ! ## import comtypes ! ## except ImportError: ! ## default_modules = ["ctypes", "ctypes.com"] ! ## else: ! ## default_modules = ["ctypes", "comtypes"] ! default_modules = ["ctypes"] ! ! parser.add_option("-m", ! dest="modules", ! metavar="module", ! help="Python module(s) containing symbols which will " ! "be imported instead of generated", ! action="append", ! default=default_modules) ! ! options, files = parser.parse_args(args[1:]) ! ! if len(files) != 1: ! parser.error("Exactly one input file must be specified") ! ! if options.output == "-": ! stream = sys.stdout ! else: ! stream = open(options.output, "w") ! ! if options.expressions: ! options.expressions = map(re.compile, options.expressions) ! ! stream.write("# generated by 'xml2py'\n") ! stream.write("# flags '%s'\n" % " ".join(sys.argv[1:])) ! ! known_symbols = {} ! ! from ctypes import CDLL ! dlls = [CDLL(name) for name in options.dlls] ! ! for name in options.modules: ! mod = __import__(name) ! for submodule in name.split(".")[1:]: ! mod = getattr(mod, submodule) ! for name in mod.__dict__: ! known_symbols[name] = mod.__name__ ! ! if options.kind: ! types = [] ! for char in options.kind: ! typ = {"a": [typedesc.Alias], ! "d": [typedesc.Variable], ! "e": [typedesc.Enumeration, typedesc.EnumValue], ! "f": [typedesc.Function], ! "m": [typedesc.Macro], ! "s": [typedesc.Structure], ! "t": [typedesc.Typedef], ! }[char] ! types.extend(typ) ! options.kind = tuple(types) ! ! generate_code(files[0], stream, ! symbols=options.symbols, ! expressions=options.expressions, ! verbose=options.verbose, ! use_decorators=options.use_decorators, ! known_symbols=known_symbols, ! searched_dlls=dlls, ! types=options.kind) ! if __name__ == "__main__": sys.exit(main()) --- 1,5 ---- ! import sys if __name__ == "__main__": + from ctypes.wrap.xml2py import main sys.exit(main()) Index: h2xml.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/h2xml.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** h2xml.py 24 Jan 2005 09:16:38 -0000 1.9 --- h2xml.py 4 Feb 2005 19:04:27 -0000 1.10 *************** *** 1,86 **** - """h2xml - convert C include file(s) into an xml file by running gccxml.""" - import sys, os, tempfile - import cparser - from optparse import OptionParser - - if sys.platform == "win32": - - def _locate_gccxml(): - import _winreg - for subkey in (r"Software\gccxml", r"Software\Kitware\GCC_XML"): - for root in (_winreg.HKEY_CURRENT_USER, _winreg.HKEY_LOCAL_MACHINE): - try: - hkey = _winreg.OpenKey(root, subkey, 0, _winreg.KEY_READ) - except WindowsError, detail: - if detail.errno != 2: - raise - else: - return _winreg.QueryValueEx(hkey, "loc")[0] + r"\bin" - - loc = _locate_gccxml() - if loc: - os.environ["PATH"] = loc - - ################################################################ - - def main(): - - def add_option(option, opt, value, parser): - parser.values.gccxml_options.extend((opt, value)) - - parser = OptionParser("usage: %prog includefile ... [options]") - ## parser.add_option("-h", action="help") - parser.add_option("-q", "--quiet", - dest="quiet", - action="store_true", - default=False) - - parser.add_option("-D", - type="string", - action="callback", - callback=add_option, - dest="gccxml_options", - help="macros to define", - metavar="NAME[=VALUE]", - default=[]) - parser.add_option("-U", - type="string", - action="callback", - callback=add_option, - help="macros to undefine", - metavar="NAME") - - parser.add_option("-I", - type="string", - action="callback", - callback=add_option, - dest="gccxml_options", - help="additional include directories", - metavar="DIRECTORY") - - parser.add_option("-o", - dest="xmlfile", - help="XML output filename", - default=None) - options, files = parser.parse_args() - - if not files: - print "Error: no files to process" - print >> sys.stderr, __doc__ - return 1 - - options.flags = options.gccxml_options - - options.verbose = not options.quiet - - try: - parser = cparser.IncludeParser() - parser.parse(files, options) - except cparser.CompilerError, detail: - import traceback - traceback.print_exc() - ## print detail - sys.exit(1) if __name__ == "__main__": main() --- 1,4 ---- if __name__ == "__main__": + from ctypes.wrap.h2xml import main main() |
From: Thomas H. <th...@us...> - 2005-02-04 18:15:30
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18342 Modified Files: decorators.py Log Message: Add docstrings. Index: decorators.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/decorators.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** decorators.py 4 Feb 2005 18:05:29 -0000 1.5 --- decorators.py 4 Feb 2005 18:15:18 -0000 1.6 *************** *** 77,82 **** --- 77,96 ---- def stdcall(restype, dll, argtypes, logging=False): + """stdcall(restype, dll, argtypes, logging=False) -> decorator. + + The decorator, when applied to a function, attaches an '_api_' + attribute to the function. Calling this attribute calls the + function exported from the dll, using the MS '__stdcall' calling + convention. + + restype - result type + dll - name or instance of a dll + argtypes - list of argument types + logging - if this is True, the result of each function call + is printed to stderr. + """ def decorate(func): if isinstance(dll, basestring): + # this call should cache the result this_dll = ctypes.CDLL(dll) else: *************** *** 101,106 **** --- 115,134 ---- def cdecl(restype, dll, argtypes, logging=False): + """cdecl(restype, dll, argtypes, logging=False) -> decorator. + + The decorator, when applied to a function, attaches an '_api_' + attribute to the function. Calling this attribute calls the + function exported from the dll, using the standard C calling + convention. + + restype - result type + dll - name or instance of a dll/shared library + argtypes - list of argument types + logging - if this is True, the result of each function call + is printed to stderr. + """ def decorate(func): if isinstance(dll, basestring): + # this call should cache the result this_dll = ctypes.CDLL(dll) else: |
From: Thomas H. <th...@us...> - 2005-02-04 18:08:06
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17048 Modified Files: __init__.py Log Message: The decorators are now exposed by the ctypes module. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** __init__.py 28 Jan 2005 18:07:43 -0000 1.52 --- __init__.py 4 Feb 2005 18:07:44 -0000 1.53 *************** *** 438,439 **** --- 438,443 ---- from _ctypes import memmove, memset, string_at, cast + + from decorators import cdecl + if _os.name == "nt": + from decorators import stdcall |