[ctypes-commit] ctypes/comtypes __init__.py,1.25.2.15,1.25.2.16
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2005-07-28 08:33:24
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26036 Modified Files: Tag: branch_1_0 __init__.py Log Message: Start implementing dispmethods in the compointer metaclass. Pass 'lcid' IDL flag value to the _ctypes layer. Add defval values to paramflags (in COMMETHOD), when they are given. Needed for 'lcid' parameters. Make named properties callable (temporarily). Fix a problem in test_wmi, when accessing an IEnumVARIANT: keep a reference to the 'parent' object. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/__init__.py,v retrieving revision 1.25.2.15 retrieving revision 1.25.2.16 diff -C2 -d -r1.25.2.15 -r1.25.2.16 *** __init__.py 7 Jul 2005 14:45:52 -0000 1.25.2.15 --- __init__.py 28 Jul 2005 08:33:15 -0000 1.25.2.16 *************** *** 131,136 **** setattr(self, name, accessor) elif what == "DISPMETHOD": # DISPMETHOD ! # method ! pass def _disp_property(self, memid, idlflags): --- 131,165 ---- setattr(self, name, accessor) elif what == "DISPMETHOD": # DISPMETHOD ! # argspec is a tuple of (idlflags, type, name[, ! # defval]) items. ! method = self._disp_method(memid, name, idlflags, restype, argspec) ! ## not in 2.3 method.__name__ = name ! if method is not None: ! setattr(self, name, method) ! ! def _disp_method(self, memid, name, idlflags, restype, argspec): ! if 'propget' in idlflags: ! ## if argspec: # has parameters ! ## print name, idlflags, restype, argspec ! ## raise NotImplementedError, 'propget %s' % name ! return ! if 'propput' in idlflags: ! ## if len(argspec) > 1: # has parameters ! ## print name, idlflags, restype, argspec ! ## raise NotImplementedError, 'propput %s' % name ! return ! args = [] ! for a in argspec: ! if len(a) == 4: ! args.append("%s=%r" % (a[2], a[3])) ! else: ! args.append(a[2]) ! ## print " def %s(self, %s):" % (name, ", ".join(args)) ! ## print " return self.Invoke(%s, %s)" % (memid, ", ".join([a[2] for a in argspec])) ! def func(obj, *args, **kw): ! result = self.Invoke(obj, memid, _invkind=1, *args, **kw) # DISPATCH_METHOD ! # Hm, seems we should call AddRef(). ! return cast(result, restype) ! return func def _disp_property(self, memid, idlflags): *************** *** 196,200 **** assert name.startswith("_get_") nargs = len([flags for flags in paramflags ! if flags[0] & 1]) # XXX or should we do this? # nargs = len([flags for flags in paramflags --- 225,229 ---- assert name.startswith("_get_") nargs = len([flags for flags in paramflags ! if flags[0] & 7 in (0, 1)]) # XXX or should we do this? # nargs = len([flags for flags in paramflags *************** *** 206,210 **** assert name.startswith("_set_") nargs = len([flags for flags in paramflags ! if flags[0] & 1]) - 1 propname = name[len("_set_"):] setters[propname, doc, nargs] = func --- 235,239 ---- assert name.startswith("_set_") nargs = len([flags for flags in paramflags ! if flags[0] & 7 in (0, 1)]) - 1 propname = name[len("_set_"):] setters[propname, doc, nargs] = func *************** *** 258,261 **** --- 287,293 ---- self.setter(self.im_inst, index, value) + def __call__(self, *args): + return self.getter(self.im_inst, *args) + class named_property(object): def __init__(self, getter, setter, doc): *************** *** 375,387 **** "in": 1, "out": 2, "retval": 8, "optional": 16, - # PARAMFLAG_HASDEFAULT: 0x20 } def _encode_idl(names): # sum up all values found in _PARAMFLAGS, ignoring all others. ! result = sum([_PARAMFLAGS.get(n, 0) for n in names]) ! return result & 3 # that's what _ctypes accept _NOTHING = object() --- 407,418 ---- "in": 1, "out": 2, + "lcid": 4, "retval": 8, "optional": 16, } def _encode_idl(names): # sum up all values found in _PARAMFLAGS, ignoring all others. ! return sum([_PARAMFLAGS.get(n, 0) for n in names]) _NOTHING = object() *************** *** 389,393 **** return idl, typ, name, defval ! # will be overwritten with VARIANT when comtypes.automation is imported. _VARIANT_type_hack = None --- 420,425 ---- return idl, typ, name, defval ! # will be overwritten with the real VARIANT type when ! # comtypes.automation is imported. _VARIANT_type_hack = None *************** *** 409,412 **** --- 441,446 ---- pflags = _encode_idl(idl) if "optional" in idl: + # XXX It would be better is defval would be given by the + # code generation for 'optional' values. if defval is _NOTHING: # XXX We don't want to make this module import *************** *** 439,445 **** ## warnings.warn(msg, IDLWarning, stacklevel=2) defval = typ() ! paramflags.append((pflags, argname, defval)) ! else: paramflags.append((pflags, argname)) argtypes.append(typ) if "propget" in idlflags: --- 473,480 ---- ## warnings.warn(msg, IDLWarning, stacklevel=2) defval = typ() ! if defval is _NOTHING: paramflags.append((pflags, argname)) + else: + paramflags.append((pflags, argname, defval)) argtypes.append(typ) if "propget" in idlflags: *************** *** 518,522 **** raise TypeError, "unsubscriptable object" try: ! result = mth(index + 1) except WindowsError, detail: raise IndexError, "invalid index" --- 553,557 ---- raise TypeError, "unsubscriptable object" try: ! result = mth(index) except WindowsError, detail: raise IndexError, "invalid index" *************** *** 539,543 **** # QueryInterface() it to IEnumVARIANT from comtypes.automation import IEnumVARIANT ! return enum.QueryInterface(IEnumVARIANT) # Some magic to implement an __iter__ method. Raises --- 574,581 ---- # QueryInterface() it to IEnumVARIANT from comtypes.automation import IEnumVARIANT ! result = enum.QueryInterface(IEnumVARIANT) ! # Hm, is there a comtypes problem? Or are we using com incorrectly? ! result.__parent = self ! return result # Some magic to implement an __iter__ method. Raises |