home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import traceback
- import string
- import new
- import pythoncom
- import winerror
- import build
- from types import StringType, IntType, TupleType, ListType
- from pywintypes import UnicodeType, IIDType
- import win32com.client as win32com
- from win32com.client import NeedUnicodeConversions
- debugging = 0
- debugging_attr = 0
- LCID = 0
- ERRORS_BAD_CONTEXT = [
- winerror.DISP_E_MEMBERNOTFOUND,
- winerror.DISP_E_BADPARAMCOUNT,
- winerror.DISP_E_PARAMNOTOPTIONAL,
- winerror.DISP_E_TYPEMISMATCH,
- winerror.E_INVALIDARG]
- ALL_INVOKE_TYPES = [
- pythoncom.INVOKE_PROPERTYGET,
- pythoncom.INVOKE_PROPERTYPUT,
- pythoncom.INVOKE_PROPERTYPUTREF,
- pythoncom.INVOKE_FUNC]
-
- def debug_print(*args):
- if debugging:
- for arg in args:
- print arg,
-
- print
-
-
-
- def debug_attr_print(*args):
- if debugging_attr:
- for arg in args:
- print arg,
-
- print
-
-
- dispatchType = pythoncom.TypeIIDs[pythoncom.IID_IDispatch]
- iunkType = pythoncom.TypeIIDs[pythoncom.IID_IUnknown]
- _GoodDispatchType = [
- StringType,
- IIDType,
- UnicodeType]
- _defaultDispatchItem = build.DispatchItem
-
- def _GetGoodDispatch(IDispatch, clsctx = pythoncom.CLSCTX_SERVER):
- if type(IDispatch) in _GoodDispatchType:
-
- try:
- IDispatch = pythoncom.connect(IDispatch)
- except pythoncom.ole_error:
- IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
- except:
- None<EXCEPTION MATCH>pythoncom.ole_error
-
-
- None<EXCEPTION MATCH>pythoncom.ole_error
- IDispatch = getattr(IDispatch, '_oleobj_', IDispatch)
- return IDispatch
-
-
- def _GetGoodDispatchAndUserName(IDispatch, userName, clsctx):
- if userName is None:
- if type(IDispatch) == StringType:
- userName = IDispatch
- elif type(IDispatch) == UnicodeType:
- userName = IDispatch.encode('ascii', 'replace')
-
- elif type(userName) == UnicodeType:
- userName = userName.encode('ascii', 'replace')
- else:
- userName = str(userName)
- 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)
- if createClass is None:
- createClass = CDispatch
-
- lazydata = None
-
- try:
- if typeinfo is None:
- typeinfo = IDispatch.GetTypeInfo()
-
-
- try:
- typecomp = typeinfo.GetTypeComp()
- lazydata = (typeinfo, typecomp)
- except pythoncom.com_error:
- pass
-
- except pythoncom.com_error:
- typeinfo = None
-
- olerepr = MakeOleRepr(IDispatch, typeinfo, lazydata)
- return createClass(IDispatch, olerepr, userName, UnicodeToString, lazydata)
-
-
- def MakeOleRepr(IDispatch, typeinfo, typecomp):
- olerepr = None
- if typeinfo is not None:
-
- try:
- attr = typeinfo.GetTypeAttr()
- if attr[5] == pythoncom.TKIND_INTERFACE and attr[11] & pythoncom.TYPEFLAG_FDUAL:
- href = typeinfo.GetRefTypeOfImplType(-1)
- typeinfo = typeinfo.GetRefTypeInfo(href)
- attr = typeinfo.GetTypeAttr()
-
- if typecomp is None:
- olerepr = build.DispatchItem(typeinfo, attr, None, 0)
- else:
- olerepr = build.LazyDispatchItem(attr, None)
- except pythoncom.ole_error:
- pass
- except:
- None<EXCEPTION MATCH>pythoncom.ole_error
-
-
- None<EXCEPTION MATCH>pythoncom.ole_error
- if olerepr is None:
- olerepr = build.DispatchItem()
-
- return olerepr
-
-
- def DumbDispatch(IDispatch, userName = None, createClass = None, UnicodeToString = NeedUnicodeConversions, clsctx = pythoncom.CLSCTX_SERVER):
- (IDispatch, userName) = _GetGoodDispatchAndUserName(IDispatch, userName, clsctx)
- if createClass is None:
- createClass = CDispatch
-
- return createClass(IDispatch, build.DispatchItem(), userName, UnicodeToString)
-
-
- class CDispatch:
-
- def __init__(self, IDispatch, olerepr, userName = None, UnicodeToString = NeedUnicodeConversions, lazydata = None):
- if userName is None:
- userName = '<unknown>'
-
- self.__dict__['_oleobj_'] = IDispatch
- self.__dict__['_username_'] = userName
- self.__dict__['_olerepr_'] = olerepr
- self.__dict__['_mapCachedItems_'] = { }
- self.__dict__['_builtMethods_'] = { }
- self.__dict__['_enum_'] = None
- self.__dict__['_unicode_to_string_'] = UnicodeToString
- self.__dict__['_lazydata_'] = lazydata
-
-
- def __call__(self, *args):
- if self._olerepr_.defaultDispatchName:
- (invkind, dispid) = self._find_dispatch_type_(self._olerepr_.defaultDispatchName)
- else:
- invkind = pythoncom.DISPATCH_METHOD | pythoncom.DISPATCH_PROPERTYGET
- dispid = pythoncom.DISPID_VALUE
- if invkind is not None:
- 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):
- return 1
-
-
- def __repr__(self):
- return '<COMObject %s>' % self._username_
-
-
- def __str__(self):
-
- try:
- return str(self.__call__())
- except pythoncom.com_error:
- details = None
- if details[0] not in ERRORS_BAD_CONTEXT:
- raise
- details[0] not in ERRORS_BAD_CONTEXT
- return self.__repr__()
-
-
-
- def __cmp__(self, other):
- other = getattr(other, '_oleobj_', other)
- return cmp(self._oleobj_, other)
-
-
- def __int__(self):
- return int(self.__call__())
-
-
- def __len__(self):
- (invkind, dispid) = self._find_dispatch_type_('Count')
- if invkind:
- return self._oleobj_.Invoke(dispid, LCID, invkind, 1)
- raise TypeError, 'This dispatch object does not define a Count method'
-
-
- def _NewEnum(self):
-
- try:
- invkind = pythoncom.DISPATCH_METHOD | pythoncom.DISPATCH_PROPERTYGET
- enum = self._oleobj_.InvokeTypes(pythoncom.DISPID_NEWENUM, LCID, invkind, (13, 10), ())
- except pythoncom.com_error:
- return None
-
- import util
- return util.WrapEnum(enum, None)
-
-
- def __getitem__(self, index):
- if isinstance(index, IntType):
- if self.__dict__['_enum_'] is None:
- self.__dict__['_enum_'] = self._NewEnum()
-
- if self.__dict__['_enum_'] is not None:
- return self._get_good_object_(self._enum_.__getitem__(index))
-
- (invkind, dispid) = self._find_dispatch_type_('Item')
- 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):
- if self._olerepr_.defaultDispatchName:
- (invkind, dispid) = self._find_dispatch_type_(self._olerepr_.defaultDispatchName)
- else:
- invkind = pythoncom.DISPATCH_PROPERTYPUT | pythoncom.DISPATCH_PROPERTYPUTREF
- dispid = pythoncom.DISPID_VALUE
- if invkind is not None:
- 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)
-
- try:
- dispid = self._oleobj_.GetIDsOfNames(0, methodName)
- except:
- self._olerepr_.propMapGet.has_key(methodName)
- self._olerepr_.mapFuncs.has_key(methodName)
- return (None, None)
-
- return (pythoncom.DISPATCH_METHOD | pythoncom.DISPATCH_PROPERTYGET, dispid)
-
-
- def _ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCLSID, *args):
- result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
- return self._get_good_object_(result, user, resultCLSID)
-
-
- def _wrap_dispatch_(self, ob, userName = None, returnCLSID = None, UnicodeToString = NeedUnicodeConversions):
- return Dispatch(ob, userName, UnicodeToString = UnicodeToString)
-
-
- def _get_good_single_object_(self, ob, userName = None, ReturnCLSID = None):
- if iunkType == type(ob):
-
- try:
- ob = ob.QueryInterface(pythoncom.IID_IDispatch)
- except pythoncom.com_error:
- pass
- except:
- None<EXCEPTION MATCH>pythoncom.com_error
-
-
- None<EXCEPTION MATCH>pythoncom.com_error
- if dispatchType == type(ob):
- return self._wrap_dispatch_(ob, userName, ReturnCLSID)
- if self._unicode_to_string_ and UnicodeType == type(ob):
- return str(ob)
- return ob
-
-
- def _get_good_object_(self, ob, userName = None, ReturnCLSID = None):
- if ob is None:
- return None
- if type(ob) == TupleType:
- return tuple(map((lambda o, s = self, oun = userName, rc = ReturnCLSID: s._get_good_single_object_(o, oun, rc)), ob))
- return self._get_good_single_object_(ob)
-
-
- def _make_method_(self, name):
- methodName = build.MakePublicAttributeName(name)
- methodCodeList = self._olerepr_.MakeFuncMethod(self._olerepr_.mapFuncs[name], methodName, 0)
- methodCode = string.join(methodCodeList, '\n')
-
- try:
- codeObject = compile(methodCode, '<COMObject %s>' % self._username_, 'exec')
- tempNameSpace = { }
- globNameSpace = globals().copy()
- globNameSpace['Dispatch'] = win32com.client.Dispatch
- exec codeObject in globNameSpace, tempNameSpace
- name = methodName
- fn = self._builtMethods_[name] = tempNameSpace[name]
- newMeth = new.instancemethod(fn, self, self.__class__)
- return newMeth
- except:
- debug_print('Error building OLE definition for code ', methodCode)
- traceback.print_exc()
-
-
-
- def _Release_(self):
- for childCont in self._mapCachedItems_.values():
- childCont._Release_()
-
- self._mapCachedItems_ = { }
- if self._oleobj_:
- self._oleobj_.Release()
- self.__dict__['_oleobj_'] = None
-
- if self._olerepr_:
- self.__dict__['_olerepr_'] = None
-
- self._enum_ = None
-
-
- def _proc_(self, name, *args):
-
- try:
- item = self._olerepr_.mapFuncs[name]
- dispId = item.dispid
- return self._get_good_object_(self._oleobj_.Invoke(*(dispId, LCID, item.desc[4], 0) + args))
- except KeyError:
- raise AttributeError, name
-
-
-
- def _print_details_(self):
- print 'AxDispatch container', self._username_
-
- 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()
-
-
-
- def __LazyMap__(self, attr):
-
- try:
- if self._LazyAddAttr_(attr):
- debug_attr_print('%s.__LazyMap__(%s) added something' % (self._username_, attr))
- return 1
- except AttributeError:
- return 0
-
-
-
- def _LazyAddAttr_(self, attr):
- if self._lazydata_ is None:
- return 0
- res = 0
- (typeinfo, typecomp) = self._lazydata_
- olerepr = self._olerepr_
- for i in ALL_INVOKE_TYPES:
-
- try:
- (x, t) = typecomp.Bind(attr, i)
- if x == 0 and attr[:3] in ('Set', 'Get'):
- (x, t) = typecomp.Bind(attr[3:], i)
-
- if x == 1:
- r = olerepr._AddFunc_(typeinfo, t, 0)
- elif x == 2:
- r = olerepr._AddVar_(typeinfo, t, 0)
- else:
- r = None
- if r is not None:
- key = r[0]
- map = r[1]
- item = map[key]
- if map == olerepr.propMapPut:
- olerepr._propMapPutCheck_(key, item)
- elif map == olerepr.propMapGet:
- olerepr._propMapGetCheck_(key, item)
-
- res = 1
- continue
- continue
-
-
- return res
-
-
- def _FlagAsMethod(self, *methodNames):
- for name in methodNames:
- details = build.MapEntry(self.__AttrToID__(name), (name,))
- self._olerepr_.mapFuncs[name] = details
-
-
-
- def __AttrToID__(self, attr):
- debug_attr_print('Calling GetIDsOfNames for property %s in Dispatch container %s' % (attr, self._username_))
- return self._oleobj_.GetIDsOfNames(0, attr)
-
-
- def __getattr__(self, attr):
- if attr == '__iter__':
-
- try:
- invkind = pythoncom.DISPATCH_METHOD | pythoncom.DISPATCH_PROPERTYGET
- 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'
-
-
- class Factory:
-
- def __init__(self, ob):
- self.ob = ob
-
-
- def __call__(self):
- import win32com.client.util as win32com
- return win32com.client.util.Iterator(self.ob)
-
-
- return Factory(enum)
- if attr[0] == '_' and attr[-1] == '_':
- raise AttributeError, attr
- attr[-1] == '_'
-
- try:
- return new.instancemethod(self._builtMethods_[attr], self, self.__class__)
- except KeyError:
- attr == '__iter__'
- attr == '__iter__'
- except:
- attr == '__iter__'
-
- if self._olerepr_.mapFuncs.has_key(attr):
- return self._make_method_(attr)
- retEntry = None
- if retEntry is not None:
-
- try:
- ret = self._mapCachedItems_[retEntry.dispid]
- debug_attr_print('Cached items has attribute!', ret)
- return ret
- except (KeyError, AttributeError):
- None if self._olerepr_ and self._oleobj_ else None if retEntry is None else attr == '__iter__'
- None if self._olerepr_ and self._oleobj_ else None if retEntry is None else attr == '__iter__'
- debug_attr_print('Attribute %s not in cache' % attr)
- except:
- None if self._olerepr_ and self._oleobj_ else None if retEntry is None else attr == '__iter__'<EXCEPTION MATCH>(KeyError, AttributeError)
-
-
- None if self._olerepr_ and self._oleobj_ else None if retEntry is None else attr == '__iter__'
- if retEntry is not 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:
- None if self._olerepr_ and self._oleobj_ else None if retEntry is None else attr == '__iter__'
- details = None if self._olerepr_ and self._oleobj_ else None if retEntry is None else attr == '__iter__'
- if details[0] in ERRORS_BAD_CONTEXT:
- self._olerepr_.mapFuncs[attr] = retEntry
- return self._make_method_(attr)
- raise pythoncom.com_error, details
- except:
- details[0] in ERRORS_BAD_CONTEXT
-
- debug_attr_print('OLE returned ', ret)
- return self._get_good_object_(ret)
- raise AttributeError, '%s.%s' % (self._username_, attr)
-
-
- def __setattr__(self, attr, value):
- if self.__dict__.has_key(attr):
- self.__dict__[attr] = value
- return None
- debug_attr_print('SetAttr called for %s.%s=%s on DispatchContainer' % (self._username_, attr, `value`))
- raise AttributeError, "Property '%s.%s' can not be set." % (self._username_, attr)
-
-
-