home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2740 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.9 KB  |  93 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import pythoncom
  5. import winerror
  6. from win32com.server.exception import Exception
  7. error = 'testDynamic error'
  8. iid = pythoncom.MakeIID('{b48969a0-784b-11d0-ae71-d23f56000000}')
  9.  
  10. class VeryPermissive:
  11.     
  12.     def _dynamic_(self, name, lcid, wFlags, args):
  13.         if wFlags & pythoncom.DISPATCH_METHOD:
  14.             return apply(getattr(self, name), args)
  15.         if wFlags & pythoncom.DISPATCH_PROPERTYGET:
  16.             
  17.             try:
  18.                 ret = self.__dict__[name]
  19.                 if type(ret) == type(()):
  20.                     ret = list(ret)
  21.                 
  22.                 return ret
  23.             except KeyError:
  24.                 wFlags & pythoncom.DISPATCH_METHOD
  25.                 wFlags & pythoncom.DISPATCH_METHOD
  26.                 raise Exception(scode = winerror.DISP_E_MEMBERNOTFOUND)
  27.             except:
  28.                 wFlags & pythoncom.DISPATCH_METHOD<EXCEPTION MATCH>KeyError
  29.             
  30.  
  31.         wFlags & pythoncom.DISPATCH_METHOD
  32.         if wFlags & (pythoncom.DISPATCH_PROPERTYPUT | pythoncom.DISPATCH_PROPERTYPUTREF):
  33.             setattr(self, name, args[0])
  34.             return None
  35.         raise Exception(scode = winerror.E_INVALIDARG, desc = 'invalid wFlags')
  36.  
  37.     
  38.     def write(self, *args):
  39.         if len(args) == 0:
  40.             raise Exception(scode = winerror.DISP_E_BADPARAMCOUNT)
  41.         len(args) == 0
  42.         for arg in args[:-1]:
  43.             print str(arg),
  44.         
  45.         print str(args[-1])
  46.  
  47.  
  48.  
  49. def Test():
  50.     import win32com.server.util as win32com
  51.     import win32com.server.policy as win32com
  52.     ob = win32com.server.util.wrap(VeryPermissive(), usePolicy = win32com.server.policy.DynamicPolicy)
  53.     
  54.     try:
  55.         handle = pythoncom.RegisterActiveObject(ob, iid, 0)
  56.     except pythoncom.com_error:
  57.         details = None
  58.         print 'Warning - could not register the object in the ROT:', details
  59.         handle = None
  60.  
  61.     
  62.     try:
  63.         import win32com.client.dynamic as win32com
  64.         client = win32com.client.dynamic.Dispatch(iid)
  65.         client.ANewAttr = 'Hello'
  66.         if client.ANewAttr != 'Hello':
  67.             raise error, 'Could not set dynamic property'
  68.         client.ANewAttr != 'Hello'
  69.         v = [
  70.             'Hello',
  71.             'From',
  72.             'Python',
  73.             1.4]
  74.         client.TestSequence = v
  75.         if v != list(client.TestSequence):
  76.             raise error, 'Dynamic sequences not working! %r/%r' % (repr(v), repr(client.testSequence))
  77.         v != list(client.TestSequence)
  78.         client.write('This', 'output', 'has', 'come', 'via', 'COM')
  79.         client._FlagAsMethod('NotReallyAMethod')
  80.         if not callable(client.NotReallyAMethod):
  81.             raise error, "Method I flagged as callable isn't!"
  82.         callable(client.NotReallyAMethod)
  83.         client = None
  84.     finally:
  85.         if handle is not None:
  86.             pythoncom.RevokeActiveObject(handle)
  87.         
  88.  
  89.  
  90. if __name__ == '__main__':
  91.     Test()
  92.  
  93.