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

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