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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. from ctypes import *
  6. _array_type = type(c_int * 3)
  7.  
  8. def _other_endian(typ):
  9.     
  10.     try:
  11.         return getattr(typ, _OTHER_ENDIAN)
  12.     except AttributeError:
  13.         if type(typ) == _array_type:
  14.             return _other_endian(typ._type_) * typ._length_
  15.         raise TypeError('This type does not support other endian: %s' % typ)
  16.     except:
  17.         type(typ) == _array_type
  18.  
  19.  
  20.  
  21. class _swapped_meta(type(Structure)):
  22.     
  23.     def __setattr__(self, attrname, value):
  24.         if attrname == '_fields_':
  25.             fields = []
  26.             for desc in value:
  27.                 name = desc[0]
  28.                 typ = desc[1]
  29.                 rest = desc[2:]
  30.                 fields.append((name, _other_endian(typ)) + rest)
  31.             
  32.             value = fields
  33.         
  34.         super(_swapped_meta, self).__setattr__(attrname, value)
  35.  
  36.  
  37. if sys.byteorder == 'little':
  38.     _OTHER_ENDIAN = '__ctype_be__'
  39.     LittleEndianStructure = Structure
  40.     
  41.     class BigEndianStructure(Structure):
  42.         __metaclass__ = _swapped_meta
  43.         _swappedbytes_ = None
  44.  
  45. elif sys.byteorder == 'big':
  46.     _OTHER_ENDIAN = '__ctype_le__'
  47.     BigEndianStructure = Structure
  48.     
  49.     class LittleEndianStructure(Structure):
  50.         __metaclass__ = _swapped_meta
  51.         _swappedbytes_ = None
  52.  
  53. else:
  54.     raise RuntimeError('Invalid byteorder')
  55. return sys.byteorder == 'little'
  56.