[pywin32-checkins] pywin32/com/win32com/client dynamic.py, 1.23, 1.24
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2008-11-11 00:56:13
|
Update of /cvsroot/pywin32/pywin32/com/win32com/client In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv24103 Modified Files: dynamic.py Log Message: syntax modernizations ported from py3k branch Index: dynamic.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/client/dynamic.py,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** dynamic.py 3 Oct 2008 01:03:56 -0000 1.23 --- dynamic.py 11 Nov 2008 00:56:06 -0000 1.24 *************** *** 17,22 **** """ import traceback ! import string ! import new import pythoncom --- 17,21 ---- """ import traceback ! import types import pythoncom *************** *** 24,29 **** import build ! from types import StringType, IntType, TupleType, ListType ! from pywintypes import UnicodeType, IIDType import win32com.client # Needed as code we eval() references it. --- 23,27 ---- import build ! from pywintypes import IIDType import win32com.client # Needed as code we eval() references it. *************** *** 68,72 **** dispatchType = pythoncom.TypeIIDs[pythoncom.IID_IDispatch] iunkType = pythoncom.TypeIIDs[pythoncom.IID_IUnknown] ! _GoodDispatchType=[StringType,IIDType,UnicodeType] _defaultDispatchItem=build.DispatchItem --- 66,70 ---- dispatchType = pythoncom.TypeIIDs[pythoncom.IID_IDispatch] iunkType = pythoncom.TypeIIDs[pythoncom.IID_IUnknown] ! _GoodDispatchType=[str, IIDType, unicode] _defaultDispatchItem=build.DispatchItem *************** *** 86,95 **** # displayed to the user in repr() etc. if userName is None: ! if type(IDispatch) == StringType: userName = IDispatch ! elif type(IDispatch) == UnicodeType: # We always want the displayed name to be a real string userName = IDispatch.encode("ascii", "replace") ! elif type(userName) == UnicodeType: # As above - always a string... userName = userName.encode("ascii", "replace") --- 84,93 ---- # displayed to the user in repr() etc. if userName is None: ! if isinstance(IDispatch, str): userName = IDispatch ! elif isinstance(IDispatch, unicode): # We always want the displayed name to be a real string userName = IDispatch.encode("ascii", "replace") ! elif type(userName) == unicode: # As above - always a string... userName = userName.encode("ascii", "replace") *************** *** 171,175 **** allArgs = (dispid,LCID,invkind,1) + args return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None) ! raise TypeError, "This dispatch object does not define a default method" def __nonzero__(self): --- 169,173 ---- allArgs = (dispid,LCID,invkind,1) + args return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None) ! raise TypeError("This dispatch object does not define a default method") def __nonzero__(self): *************** *** 203,207 **** if invkind: return self._oleobj_.Invoke(dispid, LCID, invkind, 1) ! raise TypeError, "This dispatch object does not define a Count method" def _NewEnum(self): --- 201,205 ---- if invkind: return self._oleobj_.Invoke(dispid, LCID, invkind, 1) ! raise TypeError("This dispatch object does not define a Count method") def _NewEnum(self): *************** *** 217,221 **** # Improved __getitem__ courtesy Syver Enstad # Must check _NewEnum before Item, to ensure b/w compat. ! if isinstance(index, IntType): if self.__dict__['_enum_'] is None: self.__dict__['_enum_'] = self._NewEnum() --- 215,219 ---- # Improved __getitem__ courtesy Syver Enstad # Must check _NewEnum before Item, to ensure b/w compat. ! if isinstance(index, int): if self.__dict__['_enum_'] is None: self.__dict__['_enum_'] = self._NewEnum() *************** *** 226,230 **** if invkind is not None: return self._get_good_object_(self._oleobj_.Invoke(dispid, LCID, invkind, 1, index)) ! raise TypeError, "This object does not support enumeration" def __setitem__(self, index, *args): --- 224,228 ---- if invkind is not None: return self._get_good_object_(self._oleobj_.Invoke(dispid, LCID, invkind, 1, index)) ! raise TypeError("This object does not support enumeration") def __setitem__(self, index, *args): *************** *** 238,249 **** allArgs = (dispid,LCID,invkind,0,index) + args return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None) ! raise TypeError, "This dispatch object does not define a default method" def _find_dispatch_type_(self, methodName): ! if self._olerepr_.mapFuncs.has_key(methodName): item = self._olerepr_.mapFuncs[methodName] return item.desc[4], item.dispid ! if self._olerepr_.propMapGet.has_key(methodName): item = self._olerepr_.propMapGet[methodName] return item.desc[4], item.dispid --- 236,247 ---- allArgs = (dispid,LCID,invkind,0,index) + args return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None) ! raise TypeError("This dispatch object does not define a default method") def _find_dispatch_type_(self, methodName): ! if methodName in self._olerepr_.mapFuncs: item = self._olerepr_.mapFuncs[methodName] return item.desc[4], item.dispid ! if methodName in self._olerepr_.propMapGet: item = self._olerepr_.propMapGet[methodName] return item.desc[4], item.dispid *************** *** 274,278 **** # make a new instance of (probably this) class. return self._wrap_dispatch_(ob, userName, ReturnCLSID) ! elif self._unicode_to_string_ and UnicodeType==type(ob): return str(ob) else: --- 272,276 ---- # make a new instance of (probably this) class. return self._wrap_dispatch_(ob, userName, ReturnCLSID) ! elif self._unicode_to_string_ and unicode==type(ob): return str(ob) else: *************** *** 285,289 **** if ob is None: # Quick exit! return None ! elif type(ob)==TupleType: return tuple(map(lambda o, s=self, oun=userName, rc=ReturnCLSID: s._get_good_single_object_(o, oun, rc), ob)) else: --- 283,287 ---- if ob is None: # Quick exit! return None ! elif type(ob)==tuple: return tuple(map(lambda o, s=self, oun=userName, rc=ReturnCLSID: s._get_good_single_object_(o, oun, rc), ob)) else: *************** *** 294,298 **** methodName = build.MakePublicAttributeName(name) # translate keywords etc. methodCodeList = self._olerepr_.MakeFuncMethod(self._olerepr_.mapFuncs[name], methodName,0) ! methodCode = string.join(methodCodeList,"\n") try: # print "Method code for %s is:\n" % self._username_, methodCode --- 292,296 ---- methodName = build.MakePublicAttributeName(name) # translate keywords etc. methodCodeList = self._olerepr_.MakeFuncMethod(self._olerepr_.mapFuncs[name], methodName,0) ! methodCode = "\n".join(methodCodeList) try: # print "Method code for %s is:\n" % self._username_, methodCode *************** *** 308,312 **** # Save the function in map. fn = self._builtMethods_[name] = tempNameSpace[name] ! newMeth = new.instancemethod(fn, self, self.__class__) return newMeth except: --- 306,310 ---- # Save the function in map. fn = self._builtMethods_[name] = tempNameSpace[name] ! newMeth = types.MethodType(fn, self, self.__class__) return newMeth except: *************** *** 318,322 **** """Cleanup object - like a close - to force cleanup when you dont want to rely on Python's reference counting.""" ! for childCont in self._mapCachedItems_.values(): childCont._Release_() self._mapCachedItems_ = {} --- 316,320 ---- """Cleanup object - like a close - to force cleanup when you dont want to rely on Python's reference counting.""" ! for childCont in self._mapCachedItems_.itervalues(): childCont._Release_() self._mapCachedItems_ = {} *************** *** 336,340 **** return self._get_good_object_(self._oleobj_.Invoke(*(dispId, LCID, item.desc[4], 0) + (args) )) except KeyError: ! raise AttributeError, name def _print_details_(self): --- 334,338 ---- return self._get_good_object_(self._oleobj_.Invoke(*(dispId, LCID, item.desc[4], 0) + (args) )) except KeyError: ! raise AttributeError(name) def _print_details_(self): *************** *** 343,357 **** try: print "Methods:" ! for method in self._olerepr_.mapFuncs.keys(): print "\t", method print "Props:" ! for prop, entry in self._olerepr_.propMap.items(): ! print "\t%s = 0x%x - %s" % (prop, entry.dispid, `entry`) print "Get Props:" ! for prop, entry in self._olerepr_.propMapGet.items(): ! print "\t%s = 0x%x - %s" % (prop, entry.dispid, `entry`) print "Put Props:" ! for prop, entry in self._olerepr_.propMapPut.items(): ! print "\t%s = 0x%x - %s" % (prop, entry.dispid, `entry`) except: traceback.print_exc() --- 341,355 ---- try: print "Methods:" ! for method in self._olerepr_.mapFuncs.iterkeys(): print "\t", method print "Props:" ! for prop, entry in self._olerepr_.propMap.iteritems(): ! print "\t%s = 0x%x - %s" % (prop, entry.dispid, repr(entry)) print "Get Props:" ! for prop, entry in self._olerepr_.propMapGet.iteritems(): ! print "\t%s = 0x%x - %s" % (prop, entry.dispid, repr(entry)) print "Put Props:" ! for prop, entry in self._olerepr_.propMapPut.iteritems(): ! print "\t%s = 0x%x - %s" % (prop, entry.dispid, repr(entry)) except: traceback.print_exc() *************** *** 428,432 **** enum = self._oleobj_.InvokeTypes(pythoncom.DISPID_NEWENUM,LCID,invkind,(13, 10),()) except pythoncom.com_error: ! raise AttributeError, "This object can not function as an iterator" # We must return a callable object. class Factory: --- 426,430 ---- enum = self._oleobj_.InvokeTypes(pythoncom.DISPID_NEWENUM,LCID,invkind,(13, 10),()) except pythoncom.com_error: ! raise AttributeError("This object can not function as an iterator") # We must return a callable object. class Factory: *************** *** 439,446 **** if attr[0]=='_' and attr[-1]=='_': # Fast-track. ! raise AttributeError, attr # If a known method, create new instance and return. try: ! return new.instancemethod(self._builtMethods_[attr], self, self.__class__) except KeyError: pass --- 437,444 ---- if attr[0]=='_' and attr[-1]=='_': # Fast-track. ! raise AttributeError(attr) # If a known method, create new instance and return. try: ! return types.MethodType(self._builtMethods_[attr], self, self.__class__) except KeyError: pass *************** *** 451,455 **** # means we create the actual method object - which also means # this code will never be asked for that method name again. ! if self._olerepr_.mapFuncs.has_key(attr): return self._make_method_(attr) --- 449,453 ---- # means we create the actual method object - which also means # this code will never be asked for that method name again. ! if attr in self._olerepr_.mapFuncs: return self._make_method_(attr) *************** *** 465,469 **** try: if self.__LazyMap__(attr): ! if self._olerepr_.mapFuncs.has_key(attr): return self._make_method_(attr) retEntry = self._olerepr_.propMap.get(attr) if retEntry is None: --- 463,467 ---- try: if self.__LazyMap__(attr): ! if attr in self._olerepr_.mapFuncs: return self._make_method_(attr) retEntry = self._olerepr_.propMap.get(attr) if retEntry is None: *************** *** 493,505 **** self._olerepr_.mapFuncs[attr] = retEntry return self._make_method_(attr) ! raise pythoncom.com_error, details debug_attr_print("OLE returned ", ret) return self._get_good_object_(ret) # no where else to look. ! raise AttributeError, "%s.%s" % (self._username_, attr) def __setattr__(self, attr, value): ! if self.__dict__.has_key(attr): # Fast-track - if already in our dict, just make the assignment. # XXX - should maybe check method map - if someone assigns to a method, # it could mean something special (not sure what, tho!) --- 491,503 ---- self._olerepr_.mapFuncs[attr] = retEntry return self._make_method_(attr) ! raise debug_attr_print("OLE returned ", ret) return self._get_good_object_(ret) # no where else to look. ! raise AttributeError("%s.%s" % (self._username_, attr)) def __setattr__(self, attr, value): ! if attr in self.__dict__: # Fast-track - if already in our dict, just make the assignment. # XXX - should maybe check method map - if someone assigns to a method, # it could mean something special (not sure what, tho!) *************** *** 507,515 **** return # Allow property assignment. ! debug_attr_print("SetAttr called for %s.%s=%s on DispatchContainer" % (self._username_, attr, `value`)) if self._olerepr_: # Check the "general" property map. ! if self._olerepr_.propMap.has_key(attr): entry = self._olerepr_.propMap[attr] invoke_type = _GetDescInvokeType(entry, pythoncom.INVOKE_PROPERTYPUT) --- 505,513 ---- return # Allow property assignment. ! debug_attr_print("SetAttr called for %s.%s=%s on DispatchContainer" % (self._username_, attr, repr(value))) if self._olerepr_: # Check the "general" property map. ! if attr in self._olerepr_.propMap: entry = self._olerepr_.propMap[attr] invoke_type = _GetDescInvokeType(entry, pythoncom.INVOKE_PROPERTYPUT) *************** *** 517,521 **** return # Check the specific "put" map. ! if self._olerepr_.propMapPut.has_key(attr): entry = self._olerepr_.propMapPut[attr] invoke_type = _GetDescInvokeType(entry, pythoncom.INVOKE_PROPERTYPUT) --- 515,519 ---- return # Check the specific "put" map. ! if attr in self._olerepr_.propMapPut: entry = self._olerepr_.propMapPut[attr] invoke_type = _GetDescInvokeType(entry, pythoncom.INVOKE_PROPERTYPUT) *************** *** 527,531 **** if self.__LazyMap__(attr): # Check the "general" property map. ! if self._olerepr_.propMap.has_key(attr): entry = self._olerepr_.propMap[attr] invoke_type = _GetDescInvokeType(entry, pythoncom.INVOKE_PROPERTYPUT) --- 525,529 ---- if self.__LazyMap__(attr): # Check the "general" property map. ! if attr in self._olerepr_.propMap: entry = self._olerepr_.propMap[attr] invoke_type = _GetDescInvokeType(entry, pythoncom.INVOKE_PROPERTYPUT) *************** *** 533,537 **** return # Check the specific "put" map. ! if self._olerepr_.propMapPut.has_key(attr): entry = self._olerepr_.propMapPut[attr] invoke_type = _GetDescInvokeType(entry, pythoncom.INVOKE_PROPERTYPUT) --- 531,535 ---- return # Check the specific "put" map. ! if attr in self._olerepr_.propMapPut: entry = self._olerepr_.propMapPut[attr] invoke_type = _GetDescInvokeType(entry, pythoncom.INVOKE_PROPERTYPUT) *************** *** 552,554 **** except pythoncom.com_error: pass ! raise AttributeError, "Property '%s.%s' can not be set." % (self._username_, attr) --- 550,552 ---- except pythoncom.com_error: pass ! raise AttributeError("Property '%s.%s' can not be set." % (self._username_, attr)) |