home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import pythoncom
- import winerror
- from win32com.server.exception import Exception
- error = 'testDynamic error'
- iid = pythoncom.MakeIID('{b48969a0-784b-11d0-ae71-d23f56000000}')
-
- class VeryPermissive:
-
- def _dynamic_(self, name, lcid, wFlags, args):
- if wFlags & pythoncom.DISPATCH_METHOD:
- return apply(getattr(self, name), args)
- if wFlags & pythoncom.DISPATCH_PROPERTYGET:
-
- try:
- ret = self.__dict__[name]
- if type(ret) == type(()):
- ret = list(ret)
-
- return ret
- except KeyError:
- wFlags & pythoncom.DISPATCH_METHOD
- wFlags & pythoncom.DISPATCH_METHOD
- raise Exception(scode = winerror.DISP_E_MEMBERNOTFOUND)
- except:
- wFlags & pythoncom.DISPATCH_METHOD<EXCEPTION MATCH>KeyError
-
-
- wFlags & pythoncom.DISPATCH_METHOD
- if wFlags & (pythoncom.DISPATCH_PROPERTYPUT | pythoncom.DISPATCH_PROPERTYPUTREF):
- setattr(self, name, args[0])
- return None
- raise Exception(scode = winerror.E_INVALIDARG, desc = 'invalid wFlags')
-
-
- def write(self, *args):
- if len(args) == 0:
- raise Exception(scode = winerror.DISP_E_BADPARAMCOUNT)
- len(args) == 0
- for arg in args[:-1]:
- print str(arg),
-
- print str(args[-1])
-
-
-
- def Test():
- import win32com.server.util as win32com
- import win32com.server.policy as win32com
- ob = win32com.server.util.wrap(VeryPermissive(), usePolicy = win32com.server.policy.DynamicPolicy)
-
- try:
- handle = pythoncom.RegisterActiveObject(ob, iid, 0)
- except pythoncom.com_error:
- details = None
- print 'Warning - could not register the object in the ROT:', details
- handle = None
-
-
- try:
- import win32com.client.dynamic as win32com
- client = win32com.client.dynamic.Dispatch(iid)
- client.ANewAttr = 'Hello'
- if client.ANewAttr != 'Hello':
- raise error, 'Could not set dynamic property'
- client.ANewAttr != 'Hello'
- v = [
- 'Hello',
- 'From',
- 'Python',
- 1.4]
- client.TestSequence = v
- if v != list(client.TestSequence):
- raise error, 'Dynamic sequences not working! %r/%r' % (repr(v), repr(client.testSequence))
- v != list(client.TestSequence)
- client.write('This', 'output', 'has', 'come', 'via', 'COM')
- client._FlagAsMethod('NotReallyAMethod')
- if not callable(client.NotReallyAMethod):
- raise error, "Method I flagged as callable isn't!"
- callable(client.NotReallyAMethod)
- client = None
- finally:
- if handle is not None:
- pythoncom.RevokeActiveObject(handle)
-
-
-
- if __name__ == '__main__':
- Test()
-
-