home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- __author__ = 'Greg Stein and Mark Hammond'
- import win32api
- import winerror
- import string
- import sys
- import types
- import win32con
- import pythoncom
- from pythoncom import DISPATCH_METHOD, DISPATCH_PROPERTYGET, DISPATCH_PROPERTYPUT, DISPATCH_PROPERTYPUTREF, DISPID_UNKNOWN, DISPID_VALUE, DISPID_PROPERTYPUT, DISPID_NEWENUM, DISPID_EVALUATE, DISPID_CONSTRUCTOR, DISPID_DESTRUCTOR, DISPID_COLLECT, DISPID_STARTENUM
- S_OK = 0
- from pywintypes import UnicodeType
- IDispatchType = pythoncom.TypeIIDs[pythoncom.IID_IDispatch]
- IUnknownType = pythoncom.TypeIIDs[pythoncom.IID_IUnknown]
- core_has_unicode = hasattr(__builtins__, 'unicode')
- from exception import COMException
- error = __name__ + ' error'
- regSpec = 'CLSID\\%s\\PythonCOM'
- regPolicy = 'CLSID\\%s\\PythonCOMPolicy'
- regDispatcher = 'CLSID\\%s\\PythonCOMDispatcher'
- regAddnPath = 'CLSID\\%s\\PythonCOMPath'
- from sys import exc_info
-
- def CreateInstance(clsid, reqIID):
-
- try:
- addnPaths = string.split(win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT, regAddnPath % clsid), ';')
- for newPath in addnPaths:
- if newPath not in sys.path:
- sys.path.insert(0, newPath)
- continue
- except win32api.error:
- pass
-
-
- try:
- policy = win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT, regPolicy % clsid)
- policy = resolve_func(policy)
- except win32api.error:
- policy = DefaultPolicy
-
-
- try:
- dispatcher = win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT, regDispatcher % clsid)
- if dispatcher:
- dispatcher = resolve_func(dispatcher)
- except win32api.error:
- dispatcher = None
-
- sys.exc_type = None
- sys.exc_value = None
- sys.exc_traceback = None
- if dispatcher:
- retObj = dispatcher(policy, None)
- else:
- retObj = policy(None)
- return retObj._CreateInstance_(clsid, reqIID)
-
-
- class BasicWrapPolicy:
-
- def __init__(self, object):
- if object is not None:
- self._wrap_(object)
-
-
-
- def _CreateInstance_(self, clsid, reqIID):
-
- try:
- classSpec = win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT, regSpec % clsid)
- except win32api.error:
- raise error, 'The object is not correctly registered - %s key can not be read' % regSpec % clsid
-
- myob = call_func(classSpec)
- self._wrap_(myob)
-
- try:
- return pythoncom.WrapObject(self, reqIID)
- except pythoncom.com_error:
- (hr, desc, exc, arg) = None
- IIDToInterfaceName = IIDToInterfaceName
- import win32com.util
- desc = "The object '%r' was created, but does not support the interface '%s'(%s): %s" % (myob, IIDToInterfaceName(reqIID), reqIID, desc)
- raise pythoncom.com_error, (hr, desc, exc, arg)
-
-
-
- def _wrap_(self, object):
- self._name_to_dispid_ = { }
- ob = self._obj_ = object
- if hasattr(ob, '_query_interface_'):
- self._query_interface_ = ob._query_interface_
-
- if hasattr(ob, '_invoke_'):
- self._invoke_ = ob._invoke_
-
- if hasattr(ob, '_invokeex_'):
- self._invokeex_ = ob._invokeex_
-
- if hasattr(ob, '_getidsofnames_'):
- self._getidsofnames_ = ob._getidsofnames_
-
- if hasattr(ob, '_getdispid_'):
- self._getdispid_ = ob._getdispid_
-
- if hasattr(ob, '_com_interfaces_'):
- self._com_interfaces_ = []
- for i in ob._com_interfaces_:
- if type(i) != pythoncom.PyIIDType:
- if i[0] != '{':
- i = pythoncom.InterfaceNames[i]
- else:
- i = pythoncom.MakeIID(i)
-
- self._com_interfaces_.append(i)
-
- else:
- self._com_interfaces_ = []
-
-
- def _QueryInterface_(self, iid):
- if iid in self._com_interfaces_:
- return 1
- return self._query_interface_(iid)
-
-
- def _query_interface_(self, iid):
- return 0
-
-
- def _Invoke_(self, dispid, lcid, wFlags, args):
- if type(dispid) == type(''):
-
- try:
- dispid = self._name_to_dispid_[string.lower(dispid)]
- except KeyError:
- raise COMException(scode = winerror.DISP_E_MEMBERNOTFOUND, desc = 'Member not found')
- except:
- None<EXCEPTION MATCH>KeyError
-
-
- None<EXCEPTION MATCH>KeyError
- return self._invoke_(dispid, lcid, wFlags, args)
-
-
- def _invoke_(self, dispid, lcid, wFlags, args):
- return (S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None))
-
-
- def _GetIDsOfNames_(self, names, lcid):
- if len(names) > 1:
- raise COMException(scode = winerror.DISP_E_INVALID, desc = 'Cannot support member argument names')
- len(names) > 1
- return self._getidsofnames_(names, lcid)
-
-
- def _getidsofnames_(self, names, lcid):
- return (self._getdispid_(names[0], 0),)
-
-
- def _GetDispID_(self, name, fdex):
- return self._getdispid_(name, fdex)
-
-
- def _getdispid_(self, name, fdex):
-
- try:
- return self._name_to_dispid_[string.lower(str(name))]
- except KeyError:
- raise COMException(scode = winerror.DISP_E_UNKNOWNNAME)
-
-
-
- def _InvokeEx_(self, dispid, lcid, wFlags, args, kwargs, serviceProvider):
- if type(dispid) == type(''):
-
- try:
- dispid = self._name_to_dispid_[string.lower(dispid)]
- except KeyError:
- raise COMException(scode = winerror.DISP_E_MEMBERNOTFOUND, desc = 'Member not found')
- except:
- None<EXCEPTION MATCH>KeyError
-
-
- None<EXCEPTION MATCH>KeyError
- return self._invokeex_(dispid, lcid, wFlags, args, kwargs, serviceProvider)
-
-
- def _invokeex_(self, dispid, lcid, wFlags, args, kwargs, serviceProvider):
- raise error, 'This class does not provide _invokeex_ semantics'
-
-
- def _DeleteMemberByName_(self, name, fdex):
- return self._deletememberbyname_(name, fdex)
-
-
- def _deletememberbyname_(self, name, fdex):
- raise COMException(scode = winerror.E_NOTIMPL)
-
-
- def _DeleteMemberByDispID_(self, id):
- return self._deletememberbydispid(id)
-
-
- def _deletememberbydispid_(self, id):
- raise COMException(scode = winerror.E_NOTIMPL)
-
-
- def _GetMemberProperties_(self, id, fdex):
- return self._getmemberproperties_(id, fdex)
-
-
- def _getmemberproperties_(self, id, fdex):
- raise COMException(scode = winerror.E_NOTIMPL)
-
-
- def _GetMemberName_(self, dispid):
- return self._getmembername_(dispid)
-
-
- def _getmembername_(self, dispid):
- raise COMException(scode = winerror.E_NOTIMPL)
-
-
- def _GetNextDispID_(self, fdex, dispid):
- return self._getnextdispid_(fdex, dispid)
-
-
- def _getnextdispid_(self, fdex, dispid):
- ids = self._name_to_dispid_.values()
- ids.sort()
- if DISPID_STARTENUM in ids:
- ids.remove(DISPID_STARTENUM)
-
- if dispid == DISPID_STARTENUM:
- return ids[0]
-
- try:
- return ids[ids.index(dispid) + 1]
- except ValueError:
- dispid == DISPID_STARTENUM
- dispid == DISPID_STARTENUM
- raise COMException(scode = winerror.E_UNEXPECTED)
- except IndexError:
- raise COMException(scode = winerror.S_FALSE)
- except:
- dispid == DISPID_STARTENUM
-
-
-
- def _GetNameSpaceParent_(self):
- return self._getnamespaceparent()
-
-
- def _getnamespaceparent_(self):
- raise COMException(scode = winerror.E_NOTIMPL)
-
-
-
- class MappedWrapPolicy(BasicWrapPolicy):
-
- def _wrap_(self, object):
- BasicWrapPolicy._wrap_(self, object)
- ob = self._obj_
- if hasattr(ob, '_dispid_to_func_'):
- self._dispid_to_func_ = ob._dispid_to_func_
- else:
- self._dispid_to_func_ = { }
- if hasattr(ob, '_dispid_to_get_'):
- self._dispid_to_get_ = ob._dispid_to_get_
- else:
- self._dispid_to_get_ = { }
- if hasattr(ob, '_dispid_to_put_'):
- self._dispid_to_put_ = ob._dispid_to_put_
- else:
- self._dispid_to_put_ = { }
-
-
- def _getmembername_(self, dispid):
- if self._dispid_to_func_.has_key(dispid):
- return self._dispid_to_func_[dispid]
- if self._dispid_to_get_.has_key(dispid):
- return self._dispid_to_get_[dispid]
- if self._dispid_to_put_.has_key(dispid):
- return self._dispid_to_put_[dispid]
- raise COMException(scode = winerror.DISP_E_MEMBERNOTFOUND)
-
-
-
- class DesignatedWrapPolicy(MappedWrapPolicy):
-
- def _wrap_(self, ob):
- tlb_guid = getattr(ob, '_typelib_guid_', None)
- MappedWrapPolicy._wrap_(self, ob)
- if not hasattr(ob, '_public_methods_') and not hasattr(ob, '_typelib_guid_'):
- raise error, 'Object does not support DesignatedWrapPolicy, as it does not have either _public_methods_ or _typelib_guid_ attributes.'
- not hasattr(ob, '_typelib_guid_')
- for dispid, name in self._dispid_to_func_.items():
- self._name_to_dispid_[string.lower(name)] = dispid
-
- for dispid, name in self._dispid_to_get_.items():
- self._name_to_dispid_[string.lower(name)] = dispid
-
- for dispid, name in self._dispid_to_put_.items():
- self._name_to_dispid_[string.lower(name)] = dispid
-
- for dispid, invkind, name in universal_data:
- self._name_to_dispid_[string.lower(name)] = dispid
- if invkind == DISPATCH_METHOD:
- self._dispid_to_func_[dispid] = name
- continue
- None if tlb_guid is not None else []
- if invkind in (DISPATCH_PROPERTYPUT, DISPATCH_PROPERTYPUTREF):
- self._dispid_to_put_[dispid] = name
- continue
- if invkind == DISPATCH_PROPERTYGET:
- self._dispid_to_get_[dispid] = name
- continue
- raise ValueError, 'unexpected invkind: %d (%s)' % (invkind, name)
-
- if hasattr(ob, '_value_'):
- self._dispid_to_get_[DISPID_VALUE] = '_value_'
- self._dispid_to_put_[DISPID_PROPERTYPUT] = '_value_'
-
- if hasattr(ob, '_NewEnum'):
- self._name_to_dispid_['_newenum'] = DISPID_NEWENUM
- self._dispid_to_func_[DISPID_NEWENUM] = '_NewEnum'
-
- if hasattr(ob, '_Evaluate'):
- self._name_to_dispid_['_evaluate'] = DISPID_EVALUATE
- self._dispid_to_func_[DISPID_EVALUATE] = '_Evaluate'
-
- next_dispid = self._allocnextdispid(999)
- if hasattr(ob, '_public_attrs_'):
- if hasattr(ob, '_readonly_attrs_'):
- readonly = ob._readonly_attrs_
- else:
- readonly = []
- for name in ob._public_attrs_:
- dispid = self._name_to_dispid_.get(name.lower())
- if dispid is None:
- dispid = next_dispid
- self._name_to_dispid_[name.lower()] = dispid
- next_dispid = self._allocnextdispid(next_dispid)
-
- self._dispid_to_get_[dispid] = name
- if name not in readonly:
- self._dispid_to_put_[dispid] = name
- continue
-
-
- for name in getattr(ob, '_public_methods_', []):
- dispid = self._name_to_dispid_.get(name.lower())
- if dispid is None:
- dispid = next_dispid
- self._name_to_dispid_[name.lower()] = dispid
- next_dispid = self._allocnextdispid(next_dispid)
-
- self._dispid_to_func_[dispid] = name
-
- self._typeinfos_ = None
-
-
- def _build_typeinfos_(self):
- tlb_guid = getattr(self._obj_, '_typelib_guid_', None)
- if tlb_guid is None:
- return []
- (tlb_major, tlb_minor) = getattr(self._obj_, '_typelib_version_', (1, 0))
- tlb = pythoncom.LoadRegTypeLib(tlb_guid, tlb_major, tlb_minor)
- typecomp = tlb.GetTypeComp()
- for iname in self._obj_._com_interfaces_:
-
- try:
- (type_info, type_comp) = typecomp.BindType(iname)
- if type_info is not None:
- return [
- type_info]
- continue
- except pythoncom.com_error:
- tlb_guid is None
- tlb_guid is None
- continue
-
-
-
- return []
-
-
- def _GetTypeInfoCount_(self):
- if self._typeinfos_ is None:
- self._typeinfos_ = self._build_typeinfos_()
-
- return len(self._typeinfos_)
-
-
- def _GetTypeInfo_(self, index, lcid):
- if self._typeinfos_ is None:
- self._typeinfos_ = self._build_typeinfos_()
-
- if index < 0 or index >= len(self._typeinfos_):
- raise COMException(scode = winerror.DISP_E_BADINDEX)
- index >= len(self._typeinfos_)
- return (0, self._typeinfos_[index])
-
-
- def _allocnextdispid(self, last_dispid):
- while None:
- last_dispid = last_dispid + 1
- if not self._dispid_to_func_.has_key(last_dispid) and not self._dispid_to_get_.has_key(last_dispid) and not self._dispid_to_put_.has_key(last_dispid):
- return last_dispid
- continue
- return None
-
-
- def _invokeex_(self, dispid, lcid, wFlags, args, kwArgs, serviceProvider):
- if wFlags & DISPATCH_METHOD:
-
- try:
- funcname = self._dispid_to_func_[dispid]
- except KeyError:
- if not wFlags & DISPATCH_PROPERTYGET:
- raise COMException(scode = winerror.DISP_E_MEMBERNOTFOUND)
- wFlags & DISPATCH_PROPERTYGET
-
-
- try:
- func = getattr(self._obj_, funcname)
- except AttributeError:
- raise COMException(scode = winerror.DISP_E_MEMBERNOTFOUND)
-
-
- try:
- return func(*args)
- except TypeError:
- v = None
- if str(v).find('arguments') >= 0:
- print '** TypeError %s calling function %r(%r)' % (v, func, args)
-
- raise
- except:
- None<EXCEPTION MATCH>TypeError
-
-
- None<EXCEPTION MATCH>TypeError
- if wFlags & DISPATCH_PROPERTYGET:
-
- try:
- name = self._dispid_to_get_[dispid]
- except KeyError:
- raise COMException(scode = winerror.DISP_E_MEMBERNOTFOUND)
-
- retob = getattr(self._obj_, name)
- if type(retob) == types.MethodType:
- retob = retob(*args)
-
- return retob
- if wFlags & (DISPATCH_PROPERTYPUT | DISPATCH_PROPERTYPUTREF):
-
- try:
- name = self._dispid_to_put_[dispid]
- except KeyError:
- wFlags & DISPATCH_PROPERTYGET
- wFlags & DISPATCH_PROPERTYGET
- raise COMException(scode = winerror.DISP_E_MEMBERNOTFOUND)
- except:
- wFlags & DISPATCH_PROPERTYGET
-
- if type(getattr(self._obj_, name, None)) == types.MethodType and type(getattr(self._obj_, 'Set' + name, None)) == types.MethodType:
- fn = getattr(self._obj_, 'Set' + name)
- fn(*args)
- else:
- setattr(self._obj_, name, args[0])
- return None
- raise COMException(scode = winerror.E_INVALIDARG, desc = 'invalid wFlags')
-
-
-
- class EventHandlerPolicy(DesignatedWrapPolicy):
-
- def _transform_args_(self, args, kwArgs, dispid, lcid, wFlags, serviceProvider):
- ret = []
- for arg in args:
- arg_type = type(arg)
- if arg_type == IDispatchType:
- import win32com.client as win32com
- arg = win32com.client.Dispatch(arg)
- elif arg_type == IUnknownType:
-
- try:
- import win32com.client as win32com
- arg = win32com.client.Dispatch(arg.QueryInterface(pythoncom.IID_IDispatch))
- except pythoncom.error:
- pass
- except:
- None<EXCEPTION MATCH>pythoncom.error
-
-
- None<EXCEPTION MATCH>pythoncom.error
- if not core_has_unicode and arg_type == UnicodeType:
- arg = str(arg)
-
- ret.append(arg)
-
- return (tuple(ret), kwArgs)
-
-
- def _invokeex_(self, dispid, lcid, wFlags, args, kwArgs, serviceProvider):
- (args, kwArgs) = self._transform_args_(args, kwArgs, dispid, lcid, wFlags, serviceProvider)
- return DesignatedWrapPolicy._invokeex_(self, dispid, lcid, wFlags, args, kwArgs, serviceProvider)
-
-
-
- class DynamicPolicy(BasicWrapPolicy):
-
- def _wrap_(self, object):
- BasicWrapPolicy._wrap_(self, object)
- if not hasattr(self._obj_, '_dynamic_'):
- raise error, 'Object does not support Dynamic COM Policy'
- hasattr(self._obj_, '_dynamic_')
- self._next_dynamic_ = self._min_dynamic_ = 1000
- self._dyn_dispid_to_name_ = {
- DISPID_VALUE: '_value_',
- DISPID_NEWENUM: '_NewEnum' }
-
-
- def _getdispid_(self, name, fdex):
- lname = string.lower(str(name))
-
- try:
- return self._name_to_dispid_[lname]
- except KeyError:
- dispid = self._next_dynamic_ = self._next_dynamic_ + 1
- self._name_to_dispid_[lname] = dispid
- self._dyn_dispid_to_name_[dispid] = name
- return dispid
-
-
-
- def _invoke_(self, dispid, lcid, wFlags, args):
- return (S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None))
-
-
- def _invokeex_(self, dispid, lcid, wFlags, args, kwargs, serviceProvider):
-
- try:
- name = str(self._dyn_dispid_to_name_[dispid])
- except KeyError:
- raise COMException(scode = winerror.DISP_E_MEMBERNOTFOUND, desc = 'Member not found')
-
- return self._obj_._dynamic_(name, lcid, wFlags, args)
-
-
- DefaultPolicy = DesignatedWrapPolicy
-
- def resolve_func(spec):
-
- try:
- idx = string.rindex(spec, '.')
- mname = spec[:idx]
- fname = spec[idx + 1:]
- module = _import_module(mname)
- return getattr(module, fname)
- except ValueError:
- return globals()[spec]
-
-
-
- def call_func(spec, *args):
- return resolve_func(spec)(*args)
-
-
- def _import_module(mname):
- __import__(mname)
- return sys.modules[mname]
-
-
- try:
- from dispatcher import DispatcherTrace, DispatcherWin32trace
- except ImportError:
- pass
-
-