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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os as _os
  5. import sys as _sys
  6. __version__ = '1.1.0'
  7. from _ctypes import Union, Structure, Array
  8. from _ctypes import _Pointer
  9. from _ctypes import CFuncPtr as _CFuncPtr
  10. from _ctypes import __version__ as _ctypes_version
  11. from _ctypes import RTLD_LOCAL, RTLD_GLOBAL
  12. from _ctypes import ArgumentError
  13. from struct import calcsize as _calcsize
  14. if __version__ != _ctypes_version:
  15.     raise Exception('Version number mismatch', __version__, _ctypes_version)
  16. __version__ != _ctypes_version
  17. if _os.name in ('nt', 'ce'):
  18.     from _ctypes import FormatError
  19.  
  20. DEFAULT_MODE = RTLD_LOCAL
  21. if _os.name == 'posix' and _sys.platform == 'darwin':
  22.     if int(_os.uname()[2].split('.')[0]) < 8:
  23.         DEFAULT_MODE = RTLD_GLOBAL
  24.     
  25.  
  26. from _ctypes import FUNCFLAG_CDECL as _FUNCFLAG_CDECL, FUNCFLAG_PYTHONAPI as _FUNCFLAG_PYTHONAPI, FUNCFLAG_USE_ERRNO as _FUNCFLAG_USE_ERRNO, FUNCFLAG_USE_LASTERROR as _FUNCFLAG_USE_LASTERROR
  27.  
  28. def create_string_buffer(init, size = None):
  29.     if isinstance(init, (str, unicode)):
  30.         if size is None:
  31.             size = len(init) + 1
  32.         
  33.         buftype = c_char * size
  34.         buf = buftype()
  35.         buf.value = init
  36.         return buf
  37.     if isinstance(init, (int, long)):
  38.         buftype = c_char * init
  39.         buf = buftype()
  40.         return buf
  41.     raise TypeError(init)
  42.  
  43.  
  44. def c_buffer(init, size = None):
  45.     return create_string_buffer(init, size)
  46.  
  47. _c_functype_cache = { }
  48.  
  49. def CFUNCTYPE(restype, *argtypes, **kw):
  50.     flags = _FUNCFLAG_CDECL
  51.     if kw.pop('use_errno', False):
  52.         flags |= _FUNCFLAG_USE_ERRNO
  53.     
  54.     if kw.pop('use_last_error', False):
  55.         flags |= _FUNCFLAG_USE_LASTERROR
  56.     
  57.     if kw:
  58.         raise ValueError('unexpected keyword argument(s) %s' % kw.keys())
  59.     kw
  60.     
  61.     try:
  62.         return _c_functype_cache[(restype, argtypes, flags)]
  63.     except KeyError:
  64.         
  65.         class CFunctionType(None, 'CFunctionType', (_CFuncPtr,)):
  66.             _argtypes_ = argtypes
  67.             _restype_ = restype
  68.             _flags_ = flags
  69.  
  70.         _c_functype_cache[(restype, argtypes, flags)] = CFunctionType
  71.         return CFunctionType
  72.  
  73.  
  74. if _os.name in ('nt', 'ce'):
  75.     from _ctypes import LoadLibrary as _dlopen
  76.     from _ctypes import FUNCFLAG_STDCALL as _FUNCFLAG_STDCALL
  77.     if _os.name == 'ce':
  78.         _FUNCFLAG_STDCALL = _FUNCFLAG_CDECL
  79.     
  80.     _win_functype_cache = { }
  81.     
  82.     def WINFUNCTYPE(restype, *argtypes, **kw):
  83.         flags = _FUNCFLAG_STDCALL
  84.         if kw.pop('use_errno', False):
  85.             flags |= _FUNCFLAG_USE_ERRNO
  86.         
  87.         if kw.pop('use_last_error', False):
  88.             flags |= _FUNCFLAG_USE_LASTERROR
  89.         
  90.         if kw:
  91.             raise ValueError('unexpected keyword argument(s) %s' % kw.keys())
  92.         kw
  93.         
  94.         try:
  95.             return _win_functype_cache[(restype, argtypes, flags)]
  96.         except KeyError:
  97.             
  98.             class WinFunctionType(None, 'WinFunctionType', (_CFuncPtr,)):
  99.                 _argtypes_ = argtypes
  100.                 _restype_ = restype
  101.                 _flags_ = flags
  102.  
  103.             _win_functype_cache[(restype, argtypes, flags)] = WinFunctionType
  104.             return WinFunctionType
  105.  
  106.  
  107.     if WINFUNCTYPE.__doc__:
  108.         WINFUNCTYPE.__doc__ = CFUNCTYPE.__doc__.replace('CFUNCTYPE', 'WINFUNCTYPE')
  109.     
  110. elif _os.name == 'posix':
  111.     from _ctypes import dlopen as _dlopen
  112.  
  113. from _ctypes import sizeof, byref, addressof, alignment, resize
  114. from _ctypes import get_errno, set_errno
  115. from _ctypes import _SimpleCData
  116.  
  117. def _check_size(typ, typecode = None):
  118.     calcsize = calcsize
  119.     import struct
  120.     if typecode is None:
  121.         typecode = typ._type_
  122.     
  123.     actual = sizeof(typ)
  124.     required = calcsize(typecode)
  125.     if actual != required:
  126.         raise SystemError('sizeof(%s) wrong: %d instead of %d' % (typ, actual, required))
  127.     actual != required
  128.  
  129.  
  130. class py_object(_SimpleCData):
  131.     _type_ = 'O'
  132.     
  133.     def __repr__(self):
  134.         
  135.         try:
  136.             return super(py_object, self).__repr__()
  137.         except ValueError:
  138.             return '%s(<NULL>)' % type(self).__name__
  139.  
  140.  
  141.  
  142. _check_size(py_object, 'P')
  143.  
  144. class c_short(_SimpleCData):
  145.     _type_ = 'h'
  146.  
  147. _check_size(c_short)
  148.  
  149. class c_ushort(_SimpleCData):
  150.     _type_ = 'H'
  151.  
  152. _check_size(c_ushort)
  153.  
  154. class c_long(_SimpleCData):
  155.     _type_ = 'l'
  156.  
  157. _check_size(c_long)
  158.  
  159. class c_ulong(_SimpleCData):
  160.     _type_ = 'L'
  161.  
  162. _check_size(c_ulong)
  163. if _calcsize('i') == _calcsize('l'):
  164.     c_int = c_long
  165.     c_uint = c_ulong
  166. else:
  167.     
  168.     class c_int(_SimpleCData):
  169.         _type_ = 'i'
  170.  
  171.     _check_size(c_int)
  172.     
  173.     class c_uint(_SimpleCData):
  174.         _type_ = 'I'
  175.  
  176.     _check_size(c_uint)
  177.  
  178. class c_float(_SimpleCData):
  179.     _type_ = 'f'
  180.  
  181. _check_size(c_float)
  182.  
  183. class c_double(_SimpleCData):
  184.     _type_ = 'd'
  185.  
  186. _check_size(c_double)
  187.  
  188. class c_longdouble(_SimpleCData):
  189.     _type_ = 'g'
  190.  
  191. if sizeof(c_longdouble) == sizeof(c_double):
  192.     c_longdouble = c_double
  193.  
  194. if _calcsize('l') == _calcsize('q'):
  195.     c_longlong = c_long
  196.     c_ulonglong = c_ulong
  197. else:
  198.     
  199.     class c_longlong(_SimpleCData):
  200.         _type_ = 'q'
  201.  
  202.     _check_size(c_longlong)
  203.     
  204.     class c_ulonglong(_SimpleCData):
  205.         _type_ = 'Q'
  206.  
  207.     _check_size(c_ulonglong)
  208.  
  209. class c_ubyte(_SimpleCData):
  210.     _type_ = 'B'
  211.  
  212. c_ubyte.__ctype_le__ = c_ubyte.__ctype_be__ = c_ubyte
  213. _check_size(c_ubyte)
  214.  
  215. class c_byte(_SimpleCData):
  216.     _type_ = 'b'
  217.  
  218. c_byte.__ctype_le__ = c_byte.__ctype_be__ = c_byte
  219. _check_size(c_byte)
  220.  
  221. class c_char(_SimpleCData):
  222.     _type_ = 'c'
  223.  
  224. c_char.__ctype_le__ = c_char.__ctype_be__ = c_char
  225. _check_size(c_char)
  226.  
  227. class c_char_p(_SimpleCData):
  228.     _type_ = 'z'
  229.     if _os.name == 'nt':
  230.         
  231.         def __repr__(self):
  232.             if not windll.kernel32.IsBadStringPtrA(self, -1):
  233.                 return '%s(%r)' % (self.__class__.__name__, self.value)
  234.             return '%s(%s)' % (self.__class__.__name__, cast(self, c_void_p).value)
  235.  
  236.     else:
  237.         
  238.         def __repr__(self):
  239.             return '%s(%s)' % (self.__class__.__name__, cast(self, c_void_p).value)
  240.  
  241.  
  242. _check_size(c_char_p, 'P')
  243.  
  244. class c_void_p(_SimpleCData):
  245.     _type_ = 'P'
  246.  
  247. c_voidp = c_void_p
  248. _check_size(c_void_p)
  249.  
  250. class c_bool(_SimpleCData):
  251.     _type_ = '?'
  252.  
  253. from _ctypes import POINTER, pointer, _pointer_type_cache
  254.  
  255. try:
  256.     from _ctypes import set_conversion_mode
  257. except ImportError:
  258.     pass
  259.  
  260. if _os.name in ('nt', 'ce'):
  261.     set_conversion_mode('mbcs', 'ignore')
  262. else:
  263.     set_conversion_mode('ascii', 'strict')
  264.  
  265. class c_wchar_p(_SimpleCData):
  266.     _type_ = 'Z'
  267.  
  268.  
  269. class c_wchar(_SimpleCData):
  270.     _type_ = 'u'
  271.  
  272. POINTER(c_wchar).from_param = c_wchar_p.from_param
  273.  
  274. def create_unicode_buffer(init, size = None):
  275.     if isinstance(init, (str, unicode)):
  276.         if size is None:
  277.             size = len(init) + 1
  278.         
  279.         buftype = c_wchar * size
  280.         buf = buftype()
  281.         buf.value = init
  282.         return buf
  283.     if isinstance(init, (int, long)):
  284.         buftype = c_wchar * init
  285.         buf = buftype()
  286.         return buf
  287.     raise TypeError(init)
  288.  
  289. POINTER(c_char).from_param = c_char_p.from_param
  290.  
  291. def SetPointerType(pointer, cls):
  292.     if _pointer_type_cache.get(cls, None) is not None:
  293.         raise RuntimeError('This type already exists in the cache')
  294.     _pointer_type_cache.get(cls, None) is not None
  295.     if id(pointer) not in _pointer_type_cache:
  296.         raise RuntimeError("What's this???")
  297.     id(pointer) not in _pointer_type_cache
  298.     pointer.set_type(cls)
  299.     _pointer_type_cache[cls] = pointer
  300.     del _pointer_type_cache[id(pointer)]
  301.  
  302.  
  303. def ARRAY(typ, len):
  304.     return typ * len
  305.  
  306.  
  307. class CDLL(object):
  308.     _func_flags_ = _FUNCFLAG_CDECL
  309.     _func_restype_ = c_int
  310.     
  311.     def __init__(self, name, mode = DEFAULT_MODE, handle = None, use_errno = False, use_last_error = False):
  312.         self._name = name
  313.         flags = self._func_flags_
  314.         if use_errno:
  315.             flags |= _FUNCFLAG_USE_ERRNO
  316.         
  317.         if use_last_error:
  318.             flags |= _FUNCFLAG_USE_LASTERROR
  319.         
  320.         
  321.         class _FuncPtr('_FuncPtr', (_CFuncPtr,)):
  322.             _flags_ = flags
  323.             _restype_ = self._func_restype_
  324.  
  325.         self._FuncPtr = _FuncPtr
  326.         if handle is None:
  327.             self._handle = _dlopen(self._name, mode)
  328.         else:
  329.             self._handle = handle
  330.  
  331.     
  332.     def __repr__(self):
  333.         return "<%s '%s', handle %x at %x>" % (self.__class__.__name__, self._name, self._handle & _sys.maxint * 2 + 1, id(self) & _sys.maxint * 2 + 1)
  334.  
  335.     
  336.     def __getattr__(self, name):
  337.         if name.startswith('__') and name.endswith('__'):
  338.             raise AttributeError(name)
  339.         name.endswith('__')
  340.         func = self.__getitem__(name)
  341.         setattr(self, name, func)
  342.         return func
  343.  
  344.     
  345.     def __getitem__(self, name_or_ordinal):
  346.         func = self._FuncPtr((name_or_ordinal, self))
  347.         if not isinstance(name_or_ordinal, (int, long)):
  348.             func.__name__ = name_or_ordinal
  349.         
  350.         return func
  351.  
  352.  
  353.  
  354. class PyDLL(CDLL):
  355.     _func_flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI
  356.  
  357. if _os.name in ('nt', 'ce'):
  358.     
  359.     class WinDLL(CDLL):
  360.         _func_flags_ = _FUNCFLAG_STDCALL
  361.  
  362.     from _ctypes import _check_HRESULT, _SimpleCData
  363.     
  364.     class HRESULT(_SimpleCData):
  365.         _type_ = 'l'
  366.         _check_retval_ = _check_HRESULT
  367.  
  368.     
  369.     class OleDLL(CDLL):
  370.         _func_flags_ = _FUNCFLAG_STDCALL
  371.         _func_restype_ = HRESULT
  372.  
  373.  
  374.  
  375. class LibraryLoader(object):
  376.     
  377.     def __init__(self, dlltype):
  378.         self._dlltype = dlltype
  379.  
  380.     
  381.     def __getattr__(self, name):
  382.         if name[0] == '_':
  383.             raise AttributeError(name)
  384.         name[0] == '_'
  385.         dll = self._dlltype(name)
  386.         setattr(self, name, dll)
  387.         return dll
  388.  
  389.     
  390.     def __getitem__(self, name):
  391.         return getattr(self, name)
  392.  
  393.     
  394.     def LoadLibrary(self, name):
  395.         return self._dlltype(name)
  396.  
  397.  
  398. cdll = LibraryLoader(CDLL)
  399. pydll = LibraryLoader(PyDLL)
  400. if _os.name in ('nt', 'ce'):
  401.     pythonapi = PyDLL('python dll', None, _sys.dllhandle)
  402. elif _sys.platform == 'cygwin':
  403.     pythonapi = PyDLL('libpython%d.%d.dll' % _sys.version_info[:2])
  404. else:
  405.     pythonapi = PyDLL(None)
  406. if _os.name in ('nt', 'ce'):
  407.     windll = LibraryLoader(WinDLL)
  408.     oledll = LibraryLoader(OleDLL)
  409.     if _os.name == 'nt':
  410.         GetLastError = windll.kernel32.GetLastError
  411.     else:
  412.         GetLastError = windll.coredll.GetLastError
  413.     from _ctypes import get_last_error, set_last_error
  414.     
  415.     def WinError(code = None, descr = None):
  416.         if code is None:
  417.             code = GetLastError()
  418.         
  419.         if descr is None:
  420.             descr = FormatError(code).strip()
  421.         
  422.         return WindowsError(code, descr)
  423.  
  424.  
  425. _pointer_type_cache[None] = c_void_p
  426. if sizeof(c_uint) == sizeof(c_void_p):
  427.     c_size_t = c_uint
  428. elif sizeof(c_ulong) == sizeof(c_void_p):
  429.     c_size_t = c_ulong
  430. elif sizeof(c_ulonglong) == sizeof(c_void_p):
  431.     c_size_t = c_ulonglong
  432.  
  433. from _ctypes import _memmove_addr, _memset_addr, _string_at_addr, _cast_addr
  434. memmove = CFUNCTYPE(c_void_p, c_void_p, c_void_p, c_size_t)(_memmove_addr)
  435. memset = CFUNCTYPE(c_void_p, c_void_p, c_int, c_size_t)(_memset_addr)
  436.  
  437. def PYFUNCTYPE(restype, *argtypes):
  438.     
  439.     class CFunctionType('CFunctionType', (_CFuncPtr,)):
  440.         _argtypes_ = argtypes
  441.         _restype_ = restype
  442.         _flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI
  443.  
  444.     return CFunctionType
  445.  
  446. _cast = PYFUNCTYPE(py_object, c_void_p, py_object, py_object)(_cast_addr)
  447.  
  448. def cast(obj, typ):
  449.     return _cast(obj, obj, typ)
  450.  
  451. _string_at = PYFUNCTYPE(py_object, c_void_p, c_int)(_string_at_addr)
  452.  
  453. def string_at(ptr, size = -1):
  454.     return _string_at(ptr, size)
  455.  
  456.  
  457. try:
  458.     from _ctypes import _wstring_at_addr
  459. except ImportError:
  460.     pass
  461.  
  462. _wstring_at = PYFUNCTYPE(py_object, c_void_p, c_int)(_wstring_at_addr)
  463.  
  464. def wstring_at(ptr, size = -1):
  465.     return _wstring_at(ptr, size)
  466.  
  467. if _os.name in ('nt', 'ce'):
  468.     
  469.     def DllGetClassObject(rclsid, riid, ppv):
  470.         
  471.         try:
  472.             ccom = __import__('comtypes.server.inprocserver', globals(), locals(), [
  473.                 '*'])
  474.         except ImportError:
  475.             return -2147221231
  476.  
  477.         return ccom.DllGetClassObject(rclsid, riid, ppv)
  478.  
  479.     
  480.     def DllCanUnloadNow():
  481.         
  482.         try:
  483.             ccom = __import__('comtypes.server.inprocserver', globals(), locals(), [
  484.                 '*'])
  485.         except ImportError:
  486.             return 0
  487.  
  488.         return ccom.DllCanUnloadNow()
  489.  
  490.  
  491. from ctypes._endian import BigEndianStructure, LittleEndianStructure
  492. c_int8 = c_byte
  493. c_uint8 = c_ubyte
  494. for kind in [
  495.     c_short,
  496.     c_int,
  497.     c_long,
  498.     c_longlong]:
  499.     if sizeof(kind) == 2:
  500.         c_int16 = kind
  501.         continue
  502.     if sizeof(kind) == 4:
  503.         c_int32 = kind
  504.         continue
  505.     if sizeof(kind) == 8:
  506.         c_int64 = kind
  507.         continue
  508.  
  509. for kind in [
  510.     c_ushort,
  511.     c_uint,
  512.     c_ulong,
  513.     c_ulonglong]:
  514.     if sizeof(kind) == 2:
  515.         c_uint16 = kind
  516.         continue
  517.     if sizeof(kind) == 4:
  518.         c_uint32 = kind
  519.         continue
  520.     if sizeof(kind) == 8:
  521.         c_uint64 = kind
  522.         continue
  523.  
  524. del kind
  525. CFUNCTYPE(c_int)((lambda : pass))
  526.