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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __docformat__ = 'restructuredtext en'
  5. from types import FunctionType
  6. from twisted.python import log
  7.  
  8. class CannedObject(object):
  9.     pass
  10.  
  11.  
  12. class CannedFunction(CannedObject):
  13.     
  14.     def __init__(self, f):
  15.         self._checkType(f)
  16.         self.code = f.func_code
  17.  
  18.     
  19.     def _checkType(self, obj):
  20.         pass
  21.  
  22.     
  23.     def getFunction(self, g = None):
  24.         if g is None:
  25.             g = globals()
  26.         
  27.         newFunc = FunctionType(self.code, g)
  28.         return newFunc
  29.  
  30.  
  31.  
  32. def can(obj):
  33.     if isinstance(obj, FunctionType):
  34.         return CannedFunction(obj)
  35.     return obj
  36.  
  37.  
  38. def canDict(obj):
  39.     if isinstance(obj, dict):
  40.         for k, v in obj.iteritems():
  41.             obj[k] = can(v)
  42.         
  43.         return obj
  44.     return obj
  45.  
  46.  
  47. def canSequence(obj):
  48.     if isinstance(obj, (list, tuple)):
  49.         t = type(obj)
  50.         return []([ can(i) for i in obj ])
  51.     return obj
  52.  
  53.  
  54. def uncan(obj, g = None):
  55.     if isinstance(obj, CannedFunction):
  56.         return obj.getFunction(g)
  57.     return obj
  58.  
  59.  
  60. def uncanDict(obj, g = None):
  61.     if isinstance(obj, dict):
  62.         for k, v in obj.iteritems():
  63.             obj[k] = uncan(v, g)
  64.         
  65.         return obj
  66.     return obj
  67.  
  68.  
  69. def uncanSequence(obj, g = None):
  70.     if isinstance(obj, (list, tuple)):
  71.         t = type(obj)
  72.         return []([ uncan(i, g) for i in obj ])
  73.     return obj
  74.  
  75.  
  76. def rebindFunctionGlobals(f, glbls):
  77.     return FunctionType(f.func_code, glbls)
  78.  
  79.