home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_262 / functools.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-09-09  |  4.2 KB  |  91 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.7)
  3.  
  4. from _functools import partial, reduce
  5. WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__doc__')
  6. WRAPPER_UPDATES = ('__dict__',)
  7.  
  8. def update_wrapper(wrapper, wrapped, assigned = WRAPPER_ASSIGNMENTS, updated = WRAPPER_UPDATES):
  9.     for attr in assigned:
  10.         setattr(wrapper, attr, getattr(wrapped, attr))
  11.     
  12.     for attr in updated:
  13.         getattr(wrapper, attr).update(getattr(wrapped, attr, { }))
  14.     
  15.     return wrapper
  16.  
  17.  
  18. def wraps(wrapped, assigned = WRAPPER_ASSIGNMENTS, updated = WRAPPER_UPDATES):
  19.     return partial(update_wrapper, wrapped = wrapped, assigned = assigned, updated = updated)
  20.  
  21.  
  22. def total_ordering(cls):
  23.     convert = {
  24.         '__lt__': [
  25.             ('__gt__', (lambda self, other: other < self)),
  26.             ('__le__', (lambda self, other: not (other < self))),
  27.             ('__ge__', (lambda self, other: not (self < other)))],
  28.         '__le__': [
  29.             ('__ge__', (lambda self, other: other <= self)),
  30.             ('__lt__', (lambda self, other: not (other <= self))),
  31.             ('__gt__', (lambda self, other: not (self <= other)))],
  32.         '__gt__': [
  33.             ('__lt__', (lambda self, other: other > self)),
  34.             ('__ge__', (lambda self, other: not (other > self))),
  35.             ('__le__', (lambda self, other: not (self > other)))],
  36.         '__ge__': [
  37.             ('__le__', (lambda self, other: other >= self)),
  38.             ('__gt__', (lambda self, other: not (other >= self))),
  39.             ('__lt__', (lambda self, other: not (self >= other)))] }
  40.     roots = set(dir(cls)) & set(convert)
  41.     if not roots:
  42.         raise ValueError('must define at least one ordering operation: < > <= >=')
  43.     root = max(roots)
  44.     for opname, opfunc in convert[root]:
  45.         if opname not in roots:
  46.             opfunc.__name__ = opname
  47.             opfunc.__doc__ = getattr(int, opname).__doc__
  48.             setattr(cls, opname, opfunc)
  49.             continue
  50.     return cls
  51.  
  52.  
  53. def cmp_to_key(mycmp):
  54.     
  55.     class K((object,)):
  56.         
  57.         def __init__(self, obj, *args):
  58.             self.obj = obj
  59.  
  60.         
  61.         def __lt__(self, other):
  62.             return mycmp(self.obj, other.obj) < 0
  63.  
  64.         
  65.         def __gt__(self, other):
  66.             return mycmp(self.obj, other.obj) > 0
  67.  
  68.         
  69.         def __eq__(self, other):
  70.             return mycmp(self.obj, other.obj) == 0
  71.  
  72.         
  73.         def __le__(self, other):
  74.             return mycmp(self.obj, other.obj) <= 0
  75.  
  76.         
  77.         def __ge__(self, other):
  78.             return mycmp(self.obj, other.obj) >= 0
  79.  
  80.         
  81.         def __ne__(self, other):
  82.             return mycmp(self.obj, other.obj) != 0
  83.  
  84.         
  85.         def __hash__(self):
  86.             raise TypeError('hash not implemented')
  87.  
  88.  
  89.     return K
  90.  
  91.