home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 April / com_0405_1.iso / opensource / BTpp-0.5.4-bin.exe / $INSTDIR / BT++.exe / os.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-04-19  |  15.1 KB  |  568 lines

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