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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import errno
  6. _names = sys.builtin_module_names
  7. __all__ = [
  8.     'altsep',
  9.     'curdir',
  10.     'pardir',
  11.     'sep',
  12.     'extsep',
  13.     'pathsep',
  14.     'linesep',
  15.     'defpath',
  16.     'name',
  17.     'path',
  18.     'devnull',
  19.     'SEEK_SET',
  20.     'SEEK_CUR',
  21.     'SEEK_END']
  22.  
  23. def _get_exports_list(module):
  24.     
  25.     try:
  26.         return list(module.__all__)
  27.     except AttributeError:
  28.         return _[1]
  29.         []
  30.  
  31.  
  32. if 'posix' in _names:
  33.     name = 'posix'
  34.     linesep = '\n'
  35.     from posix import *
  36.     
  37.     try:
  38.         from posix import _exit
  39.     except ImportError:
  40.         pass
  41.  
  42.     import posixpath as path
  43.     import posix
  44.     __all__.extend(_get_exports_list(posix))
  45.     del posix
  46. elif 'nt' in _names:
  47.     name = 'nt'
  48.     linesep = '\r\n'
  49.     from nt import *
  50.     
  51.     try:
  52.         from nt import _exit
  53.     except ImportError:
  54.         pass
  55.  
  56.     import ntpath as path
  57.     import nt
  58.     __all__.extend(_get_exports_list(nt))
  59.     del nt
  60. elif 'os2' in _names:
  61.     name = 'os2'
  62.     linesep = '\r\n'
  63.     from os2 import *
  64.     
  65.     try:
  66.         from os2 import _exit
  67.     except ImportError:
  68.         pass
  69.  
  70.     if sys.version.find('EMX GCC') == -1:
  71.         import ntpath as path
  72.     else:
  73.         import os2emxpath as path
  74.         from _emx_link import link
  75.     import os2
  76.     __all__.extend(_get_exports_list(os2))
  77.     del os2
  78. elif 'ce' in _names:
  79.     name = 'ce'
  80.     linesep = '\r\n'
  81.     from ce import *
  82.     
  83.     try:
  84.         from ce import _exit
  85.     except ImportError:
  86.         pass
  87.  
  88.     import ntpath as path
  89.     import ce
  90.     __all__.extend(_get_exports_list(ce))
  91.     del ce
  92. elif 'riscos' in _names:
  93.     name = 'riscos'
  94.     linesep = '\n'
  95.     from riscos import *
  96.     
  97.     try:
  98.         from riscos import _exit
  99.     except ImportError:
  100.         pass
  101.  
  102.     import riscospath as path
  103.     import riscos
  104.     __all__.extend(_get_exports_list(riscos))
  105.     del riscos
  106. else:
  107.     raise ImportError, 'no os specific module found'
  108. sys.modules['os.path'] = 'posix' in _names
  109. from os.path import curdir, pardir, sep, pathsep, defpath, extsep, altsep, devnull
  110. del _names
  111. SEEK_SET = 0
  112. SEEK_CUR = 1
  113. SEEK_END = 2
  114.  
  115. def makedirs(name, mode = 511):
  116.     (head, tail) = path.split(name)
  117.     if not tail:
  118.         (head, tail) = path.split(head)
  119.     
  120.     if head and tail and not path.exists(head):
  121.         
  122.         try:
  123.             makedirs(head, mode)
  124.         except OSError:
  125.             e = None
  126.             if e.errno != errno.EEXIST:
  127.                 raise 
  128.             e.errno != errno.EEXIST
  129.  
  130.         if tail == curdir:
  131.             return None
  132.     
  133.     mkdir(name, mode)
  134.  
  135.  
  136. def removedirs(name):
  137.     rmdir(name)
  138.     (head, tail) = path.split(name)
  139.     if not tail:
  140.         (head, tail) = path.split(head)
  141.     
  142.     while head and tail:
  143.         
  144.         try:
  145.             rmdir(head)
  146.         except error:
  147.             break
  148.  
  149.         (head, tail) = path.split(head)
  150.  
  151.  
  152. def renames(old, new):
  153.     (head, tail) = path.split(new)
  154.     if head and tail and not path.exists(head):
  155.         makedirs(head)
  156.     
  157.     rename(old, new)
  158.     (head, tail) = path.split(old)
  159.     if head and tail:
  160.         
  161.         try:
  162.             removedirs(head)
  163.         except error:
  164.             pass
  165.         except:
  166.             None<EXCEPTION MATCH>error
  167.         
  168.  
  169.     None<EXCEPTION MATCH>error
  170.  
  171. __all__.extend([
  172.     'makedirs',
  173.     'removedirs',
  174.     'renames'])
  175.  
  176. def walk(top, topdown = True, onerror = None, followlinks = False):
  177.     join = join
  178.     isdir = isdir
  179.     islink = islink
  180.     import os.path
  181.     
  182.     try:
  183.         names = listdir(top)
  184.     except error:
  185.         err = None
  186.         if onerror is not None:
  187.             onerror(err)
  188.         
  189.         return None
  190.  
  191.     dirs = []
  192.     nondirs = []
  193.     for name in names:
  194.         if isdir(join(top, name)):
  195.             dirs.append(name)
  196.             continue
  197.         nondirs.append(name)
  198.     
  199.     if topdown:
  200.         yield (top, dirs, nondirs)
  201.     
  202.     for name in dirs:
  203.         path = join(top, name)
  204.         if followlinks or not islink(path):
  205.             for x in walk(path, topdown, onerror, followlinks):
  206.                 yield x
  207.             
  208.     
  209.     if not topdown:
  210.         yield (top, dirs, nondirs)
  211.     
  212.  
  213. __all__.append('walk')
  214.  
  215. try:
  216.     environ
  217. except NameError:
  218.     environ = { }
  219.  
  220.  
  221. def execl(file, *args):
  222.     execv(file, args)
  223.  
  224.  
  225. def execle(file, *args):
  226.     env = args[-1]
  227.     execve(file, args[:-1], env)
  228.  
  229.  
  230. def execlp(file, *args):
  231.     execvp(file, args)
  232.  
  233.  
  234. def execlpe(file, *args):
  235.     env = args[-1]
  236.     execvpe(file, args[:-1], env)
  237.  
  238.  
  239. def execvp(file, args):
  240.     _execvpe(file, args)
  241.  
  242.  
  243. def execvpe(file, args, env):
  244.     _execvpe(file, args, env)
  245.  
  246. __all__.extend([
  247.     'execl',
  248.     'execle',
  249.     'execlp',
  250.     'execlpe',
  251.     'execvp',
  252.     'execvpe'])
  253.  
  254. def _execvpe(file, args, env = None):
  255.     if env is not None:
  256.         func = execve
  257.         argrest = (args, env)
  258.     else:
  259.         func = execv
  260.         argrest = (args,)
  261.         env = environ
  262.     (head, tail) = path.split(file)
  263.     if head:
  264.         func(file, *argrest)
  265.         return None
  266.     if 'PATH' in env:
  267.         envpath = env['PATH']
  268.     else:
  269.         envpath = defpath
  270.     PATH = envpath.split(pathsep)
  271.     saved_exc = None
  272.     saved_tb = None
  273.     for dir in PATH:
  274.         fullname = path.join(dir, file)
  275.         
  276.         try:
  277.             func(fullname, *argrest)
  278.         continue
  279.         except error:
  280.             e = None
  281.             tb = sys.exc_info()[2]
  282.             if e.errno != errno.ENOENT and e.errno != errno.ENOTDIR and saved_exc is None:
  283.                 saved_exc = e
  284.                 saved_tb = tb
  285.             
  286.             saved_exc is None
  287.         
  288.  
  289.     
  290.     if saved_exc:
  291.         raise error, saved_exc, saved_tb
  292.     saved_exc
  293.     raise error, e, tb
  294.  
  295.  
  296. try:
  297.     putenv
  298. except NameError:
  299.     pass
  300.  
  301. import UserDict
  302. if name in ('os2', 'nt'):
  303.     
  304.     def unsetenv(key):
  305.         putenv(key, '')
  306.  
  307.  
  308. if name == 'riscos':
  309.     from riscosenviron import _Environ
  310. elif name in ('os2', 'nt'):
  311.     
  312.     class _Environ(UserDict.IterableUserDict):
  313.         
  314.         def __init__(self, environ):
  315.             UserDict.UserDict.__init__(self)
  316.             data = self.data
  317.             for k, v in environ.items():
  318.                 data[k.upper()] = v
  319.             
  320.  
  321.         
  322.         def __setitem__(self, key, item):
  323.             putenv(key, item)
  324.             self.data[key.upper()] = item
  325.  
  326.         
  327.         def __getitem__(self, key):
  328.             return self.data[key.upper()]
  329.  
  330.         
  331.         try:
  332.             unsetenv
  333.         except NameError:
  334.             
  335.             def __delitem__(self, key):
  336.                 del self.data[key.upper()]
  337.  
  338.  
  339.         
  340.         def __delitem__(self, key):
  341.             unsetenv(key)
  342.             del self.data[key.upper()]
  343.  
  344.         
  345.         def clear(self):
  346.             for key in self.data.keys():
  347.                 unsetenv(key)
  348.                 del self.data[key]
  349.             
  350.  
  351.         
  352.         def pop(self, key, *args):
  353.             unsetenv(key)
  354.             return self.data.pop(key.upper(), *args)
  355.  
  356.         
  357.         def has_key(self, key):
  358.             return key.upper() in self.data
  359.  
  360.         
  361.         def __contains__(self, key):
  362.             return key.upper() in self.data
  363.  
  364.         
  365.         def get(self, key, failobj = None):
  366.             return self.data.get(key.upper(), failobj)
  367.  
  368.         
  369.         def update(self, dict = None, **kwargs):
  370.             if dict:
  371.                 
  372.                 try:
  373.                     keys = dict.keys()
  374.                 except AttributeError:
  375.                     for k, v in dict:
  376.                         self[k] = v
  377.                     
  378.  
  379.                 for k in keys:
  380.                     self[k] = dict[k]
  381.                 
  382.             
  383.             if kwargs:
  384.                 self.update(kwargs)
  385.             
  386.  
  387.         
  388.         def copy(self):
  389.             return dict(self)
  390.  
  391.  
  392. else:
  393.     
  394.     class _Environ(UserDict.IterableUserDict):
  395.         
  396.         def __init__(self, environ):
  397.             UserDict.UserDict.__init__(self)
  398.             self.data = environ
  399.  
  400.         
  401.         def __setitem__(self, key, item):
  402.             putenv(key, item)
  403.             self.data[key] = item
  404.  
  405.         
  406.         def update(self, dict = None, **kwargs):
  407.             if dict:
  408.                 
  409.                 try:
  410.                     keys = dict.keys()
  411.                 except AttributeError:
  412.                     for k, v in dict:
  413.                         self[k] = v
  414.                     
  415.  
  416.                 for k in keys:
  417.                     self[k] = dict[k]
  418.                 
  419.             
  420.             if kwargs:
  421.                 self.update(kwargs)
  422.             
  423.  
  424.         
  425.         try:
  426.             unsetenv
  427.         except NameError:
  428.             pass
  429.  
  430.         
  431.         def __delitem__(self, key):
  432.             unsetenv(key)
  433.             del self.data[key]
  434.  
  435.         
  436.         def clear(self):
  437.             for key in self.data.keys():
  438.                 unsetenv(key)
  439.                 del self.data[key]
  440.             
  441.  
  442.         
  443.         def pop(self, key, *args):
  444.             unsetenv(key)
  445.             return self.data.pop(key, *args)
  446.  
  447.         
  448.         def copy(self):
  449.             return dict(self)
  450.  
  451.  
  452. environ = _Environ(environ)
  453.  
  454. def getenv(key, default = None):
  455.     return environ.get(key, default)
  456.  
  457. __all__.append('getenv')
  458.  
  459. def _exists(name):
  460.     
  461.     try:
  462.         eval(name)
  463.         return True
  464.     except NameError:
  465.         return False
  466.  
  467.  
  468. if _exists('fork') and not _exists('spawnv') and _exists('execv'):
  469.     P_WAIT = 0
  470.     P_NOWAIT = P_NOWAITO = 1
  471.     
  472.     def _spawnvef(mode, file, args, env, func):
  473.         pid = fork()
  474.         if not pid:
  475.             
  476.             try:
  477.                 if env is None:
  478.                     func(file, args)
  479.                 else:
  480.                     func(file, args, env)
  481.             _exit(127)
  482.  
  483.         elif mode == P_NOWAIT:
  484.             return pid
  485.         while None:
  486.             (wpid, sts) = waitpid(pid, 0)
  487.             if WIFSTOPPED(sts):
  488.                 continue
  489.                 continue
  490.             if WIFSIGNALED(sts):
  491.                 return -WTERMSIG(sts)
  492.             if WIFEXITED(sts):
  493.                 return WEXITSTATUS(sts)
  494.             raise error, 'Not stopped, signaled or exited???'
  495.             continue
  496.             return None
  497.  
  498.     
  499.     def spawnv(mode, file, args):
  500.         return _spawnvef(mode, file, args, None, execv)
  501.  
  502.     
  503.     def spawnve(mode, file, args, env):
  504.         return _spawnvef(mode, file, args, env, execve)
  505.  
  506.     
  507.     def spawnvp(mode, file, args):
  508.         return _spawnvef(mode, file, args, None, execvp)
  509.  
  510.     
  511.     def spawnvpe(mode, file, args, env):
  512.         return _spawnvef(mode, file, args, env, execvpe)
  513.  
  514.  
  515. if _exists('spawnv'):
  516.     
  517.     def spawnl(mode, file, *args):
  518.         return spawnv(mode, file, args)
  519.  
  520.     
  521.     def spawnle(mode, file, *args):
  522.         env = args[-1]
  523.         return spawnve(mode, file, args[:-1], env)
  524.  
  525.     __all__.extend([
  526.         'spawnv',
  527.         'spawnve',
  528.         'spawnl',
  529.         'spawnle'])
  530.  
  531. if _exists('spawnvp'):
  532.     
  533.     def spawnlp(mode, file, *args):
  534.         return spawnvp(mode, file, args)
  535.  
  536.     
  537.     def spawnlpe(mode, file, *args):
  538.         env = args[-1]
  539.         return spawnvpe(mode, file, args[:-1], env)
  540.  
  541.     __all__.extend([
  542.         'spawnvp',
  543.         'spawnvpe',
  544.         'spawnlp',
  545.         'spawnlpe'])
  546.  
  547. if _exists('fork'):
  548.     if not _exists('popen2'):
  549.         
  550.         def popen2(cmd, mode = 't', bufsize = -1):
  551.             import warnings
  552.             msg = 'os.popen2 is deprecated.  Use the subprocess module.'
  553.             warnings.warn(msg, DeprecationWarning, stacklevel = 2)
  554.             import subprocess
  555.             PIPE = subprocess.PIPE
  556.             p = subprocess.Popen(cmd, shell = isinstance(cmd, basestring), bufsize = bufsize, stdin = PIPE, stdout = PIPE, close_fds = True)
  557.             return (p.stdin, p.stdout)
  558.  
  559.         __all__.append('popen2')
  560.     
  561.     if not _exists('popen3'):
  562.         
  563.         def popen3(cmd, mode = 't', bufsize = -1):
  564.             import warnings
  565.             msg = 'os.popen3 is deprecated.  Use the subprocess module.'
  566.             warnings.warn(msg, DeprecationWarning, stacklevel = 2)
  567.             import subprocess
  568.             PIPE = subprocess.PIPE
  569.             p = subprocess.Popen(cmd, shell = isinstance(cmd, basestring), bufsize = bufsize, stdin = PIPE, stdout = PIPE, stderr = PIPE, close_fds = True)
  570.             return (p.stdin, p.stdout, p.stderr)
  571.  
  572.         __all__.append('popen3')
  573.     
  574.     if not _exists('popen4'):
  575.         
  576.         def popen4(cmd, mode = 't', bufsize = -1):
  577.             import warnings
  578.             msg = 'os.popen4 is deprecated.  Use the subprocess module.'
  579.             warnings.warn(msg, DeprecationWarning, stacklevel = 2)
  580.             import subprocess
  581.             PIPE = subprocess.PIPE
  582.             p = subprocess.Popen(cmd, shell = isinstance(cmd, basestring), bufsize = bufsize, stdin = PIPE, stdout = PIPE, stderr = subprocess.STDOUT, close_fds = True)
  583.             return (p.stdin, p.stdout)
  584.  
  585.         __all__.append('popen4')
  586.     
  587.  
  588. import copy_reg as _copy_reg
  589.  
  590. def _make_stat_result(tup, dict):
  591.     return stat_result(tup, dict)
  592.  
  593.  
  594. def _pickle_stat_result(sr):
  595.     (type, args) = sr.__reduce__()
  596.     return (_make_stat_result, args)
  597.  
  598.  
  599. try:
  600.     _copy_reg.pickle(stat_result, _pickle_stat_result, _make_stat_result)
  601. except NameError:
  602.     pass
  603.  
  604.  
  605. def _make_statvfs_result(tup, dict):
  606.     return statvfs_result(tup, dict)
  607.  
  608.  
  609. def _pickle_statvfs_result(sr):
  610.     (type, args) = sr.__reduce__()
  611.     return (_make_statvfs_result, args)
  612.  
  613.  
  614. try:
  615.     _copy_reg.pickle(statvfs_result, _pickle_statvfs_result, _make_statvfs_result)
  616. except NameError:
  617.     pass
  618.  
  619. if not _exists('urandom'):
  620.     
  621.     def urandom(n):
  622.         
  623.         try:
  624.             _urandomfd = open('/dev/urandom', O_RDONLY)
  625.         except (OSError, IOError):
  626.             raise NotImplementedError('/dev/urandom (or equivalent) not found')
  627.  
  628.         
  629.         try:
  630.             bs = ''
  631.             while n - len(bs) >= 1:
  632.                 bs += read(_urandomfd, n - len(bs))
  633.         finally:
  634.             close(_urandomfd)
  635.  
  636.         return bs
  637.  
  638.  
  639.