[pywin32-checkins] pywin32/com/win32com/client dynamic.py,1.19,1.20
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2004-04-09 11:36:06
|
Update of /cvsroot/pywin32/pywin32/com/win32com/client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28570 Modified Files: dynamic.py Log Message: Fix IBindCtx handling, so we get all information about the specified attribute name, not one random bit of information as decided by the other side. Also, use .get() instead of catching KeyErrors for many dict lookups. Index: dynamic.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/client/dynamic.py,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** dynamic.py 23 Oct 2003 07:21:53 -0000 1.19 --- dynamic.py 9 Apr 2004 11:22:45 -0000 1.20 *************** *** 46,49 **** --- 46,56 ---- ] + ALL_INVOKE_TYPES = [ + pythoncom.INVOKE_PROPERTYGET, + pythoncom.INVOKE_PROPERTYPUT, + pythoncom.INVOKE_PROPERTYPUTREF, + pythoncom.INVOKE_FUNC + ] + def debug_print(*args): if debugging: *************** *** 84,87 **** --- 91,98 ---- return (_GetGoodDispatch(IDispatch, clsctx), userName) + def _GetDescInvokeType(entry, default_invoke_type): + if not entry or not entry.desc: return default_invoke_type + return entry.desc[4] + def Dispatch(IDispatch, userName = None, createClass = None, typeinfo = None, UnicodeToString=NeedUnicodeConversions, clsctx = pythoncom.CLSCTX_SERVER): IDispatch, userName = _GetGoodDispatchAndUserName(IDispatch,userName,clsctx) *************** *** 271,275 **** else: return self._get_good_single_object_(ob) ! def _make_method_(self, name): "Make a method object - Assumes in olerepr funcmap" --- 282,286 ---- else: return self._get_good_single_object_(ob) ! def _make_method_(self, name): "Make a method object - Assumes in olerepr funcmap" *************** *** 351,376 **** if self._lazydata_ is None: return 0 res = 0 - i = 0 typeinfo, typecomp = self._lazydata_ olerepr = self._olerepr_ ! try: ! x,t = typecomp.Bind(attr,i) ! if x==1: #it's a FUNCDESC ! r = olerepr._AddFunc_(typeinfo,t,0) ! elif x==2: #it's a VARDESC ! r = olerepr._AddVar_(typeinfo,t,0) ! else: #not found or TYPEDESC/IMPLICITAPP ! r=None ! ! if not r is None: ! key, map = r[0],r[1] ! item = map[key] ! if map==olerepr.propMapPut: ! olerepr._propMapPutCheck_(key,item) ! elif map==olerepr.propMapGet: ! olerepr._propMapGetCheck_(key,item) ! res = 1 ! except: ! pass return res --- 362,390 ---- if self._lazydata_ is None: return 0 res = 0 typeinfo, typecomp = self._lazydata_ olerepr = self._olerepr_ ! # We need to explicitly check each invoke type individually - simply ! # specifying '0' will bind to "any member", which may not be the one ! # we are actually after (ie, we may be after prop_get, but returned ! # the info for the prop_put.) ! for i in ALL_INVOKE_TYPES: ! try: ! x,t = typecomp.Bind(attr,i) ! if x==1: #it's a FUNCDESC ! r = olerepr._AddFunc_(typeinfo,t,0) ! elif x==2: #it's a VARDESC ! r = olerepr._AddVar_(typeinfo,t,0) ! else: #not found or TYPEDESC/IMPLICITAPP ! r=None ! if not r is None: ! key, map = r[0],r[1] ! item = map[key] ! if map==olerepr.propMapPut: ! olerepr._propMapPutCheck_(key,item) ! elif map==olerepr.propMapGet: ! olerepr._propMapGetCheck_(key,item) ! res = 1 ! except: ! pass return res *************** *** 433,440 **** if self._olerepr_ and self._oleobj_: # first check general property map, then specific "put" map. ! if self._olerepr_.propMap.has_key(attr): ! retEntry = self._olerepr_.propMap[attr] ! if retEntry is None and self._olerepr_.propMapGet.has_key(attr): ! retEntry = self._olerepr_.propMapGet[attr] # Not found so far - See what COM says. if retEntry is None: --- 447,453 ---- if self._olerepr_ and self._oleobj_: # first check general property map, then specific "put" map. ! retEntry = self._olerepr_.propMap.get(attr) ! if retEntry is None: ! retEntry = self._olerepr_.propMapGet.get(attr) # Not found so far - See what COM says. if retEntry is None: *************** *** 442,449 **** if self.__LazyMap__(attr): if self._olerepr_.mapFuncs.has_key(attr): return self._make_method_(attr) ! if self._olerepr_.propMap.has_key(attr): ! retEntry = self._olerepr_.propMap[attr] ! if retEntry is None and self._olerepr_.propMapGet.has_key(attr): ! retEntry = self._olerepr_.propMapGet[attr] if retEntry is None: retEntry = build.MapEntry(self.__AttrToID__(attr), (attr,)) --- 455,461 ---- 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: ! retEntry = self._olerepr_.propMapGet.get(attr) if retEntry is None: retEntry = build.MapEntry(self.__AttrToID__(attr), (attr,)) *************** *** 461,467 **** # If we are still here, and have a retEntry, get the OLE item if not retEntry is None: debug_attr_print("Getting property Id 0x%x from OLE object" % retEntry.dispid) try: ! ret = self._oleobj_.Invoke(retEntry.dispid,0,pythoncom.DISPATCH_PROPERTYGET,1) except pythoncom.com_error, details: if details[0] in ERRORS_BAD_CONTEXT: --- 473,480 ---- # If we are still here, and have a retEntry, get the OLE item if not retEntry is None: + invoke_type = _GetDescInvokeType(retEntry, pythoncom.INVOKE_PROPERTYGET) debug_attr_print("Getting property Id 0x%x from OLE object" % retEntry.dispid) try: ! ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1) except pythoncom.com_error, details: if details[0] in ERRORS_BAD_CONTEXT: *************** *** 470,474 **** return self._make_method_(attr) raise pythoncom.com_error, details - self._olerepr_.propMap[attr] = retEntry debug_attr_print("OLE returned ", ret) return self._get_good_object_(ret) --- 483,486 ---- *************** *** 485,496 **** # 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): ! self._oleobj_.Invoke(self._olerepr_.propMap[attr].dispid, 0, pythoncom.DISPATCH_PROPERTYPUT, 0, value) return # Check the specific "put" map. if self._olerepr_.propMapPut.has_key(attr): ! self._oleobj_.Invoke(self._olerepr_.propMapPut[attr].dispid, 0, pythoncom.DISPATCH_PROPERTYPUT, 0, value) return --- 497,513 ---- # 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) ! self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value) 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) ! self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value) return *************** *** 500,508 **** # Check the "general" property map. if self._olerepr_.propMap.has_key(attr): ! self._oleobj_.Invoke(self._olerepr_.propMap[attr].dispid, 0, pythoncom.DISPATCH_PROPERTYPUT, 0, value) return # Check the specific "put" map. if self._olerepr_.propMapPut.has_key(attr): ! self._oleobj_.Invoke(self._olerepr_.propMapPut[attr].dispid, 0, pythoncom.DISPATCH_PROPERTYPUT, 0, value) return try: --- 517,529 ---- # Check the "general" property map. if self._olerepr_.propMap.has_key(attr): ! entry = self._olerepr_.propMap[attr] ! invoke_type = _GetDescInvokeType(entry, pythoncom.INVOKE_PROPERTYPUT) ! self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value) 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) ! self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value) return try: *************** *** 513,517 **** if entry is not None: try: ! self._oleobj_.Invoke(entry.dispid, 0, pythoncom.DISPATCH_PROPERTYPUT, 0, value) self._olerepr_.propMap[attr] = entry debug_attr_print("__setattr__ property %s (id=0x%x) in Dispatch container %s" % (attr, entry.dispid, self._username_)) --- 534,539 ---- if entry is not None: try: ! invoke_type = _GetDescInvokeType(entry, pythoncom.INVOKE_PROPERTYPUT) ! self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value) self._olerepr_.propMap[attr] = entry debug_attr_print("__setattr__ property %s (id=0x%x) in Dispatch container %s" % (attr, entry.dispid, self._username_)) |