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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.7)
  3.  
  4. import os
  5. import sys
  6. import stat
  7. import genericpath
  8. import warnings
  9. from genericpath import *
  10. __all__ = [
  11.     'normcase',
  12.     'isabs',
  13.     'join',
  14.     'splitdrive',
  15.     'split',
  16.     'splitext',
  17.     'basename',
  18.     'dirname',
  19.     'commonprefix',
  20.     'getsize',
  21.     'getmtime',
  22.     'getatime',
  23.     'getctime',
  24.     'islink',
  25.     'exists',
  26.     'lexists',
  27.     'isdir',
  28.     'isfile',
  29.     'ismount',
  30.     'walk',
  31.     'expanduser',
  32.     'expandvars',
  33.     'normpath',
  34.     'abspath',
  35.     'splitunc',
  36.     'curdir',
  37.     'pardir',
  38.     'sep',
  39.     'pathsep',
  40.     'defpath',
  41.     'altsep',
  42.     'extsep',
  43.     'devnull',
  44.     'realpath',
  45.     'supports_unicode_filenames',
  46.     'relpath']
  47. curdir = '.'
  48. pardir = '..'
  49. extsep = '.'
  50. sep = '\\'
  51. pathsep = ';'
  52. altsep = '/'
  53. defpath = '.;C:\\bin'
  54. if 'ce' in sys.builtin_module_names:
  55.     defpath = '\\Windows'
  56. elif 'os2' in sys.builtin_module_names:
  57.     altsep = '/'
  58. devnull = 'nul'
  59.  
  60. def normcase(s):
  61.     return s.replace('/', '\\').lower()
  62.  
  63.  
  64. def isabs(s):
  65.     s = splitdrive(s)[1]
  66.     if s != '':
  67.         pass
  68.     return s[:1] in '/\\'
  69.  
  70.  
  71. def join(a, *p):
  72.     path = a
  73.     for b in p:
  74.         b_wins = 0
  75.         if path == '':
  76.             b_wins = 1
  77.         elif isabs(b):
  78.             if path[1:2] != ':' or b[1:2] == ':':
  79.                 b_wins = 1
  80.             elif (len(path) > 3 or len(path) == 3) and path[-1] not in '/\\':
  81.                 b_wins = 1
  82.             
  83.         if b_wins:
  84.             path = b
  85.             continue
  86.         if path[-1] in '/\\':
  87.             if b and b[0] in '/\\':
  88.                 path += b[1:]
  89.             else:
  90.                 path += b
  91.         if path[-1] == ':':
  92.             path += b
  93.             continue
  94.         if b:
  95.             if b[0] in '/\\':
  96.                 path += b
  97.             else:
  98.                 path += '\\' + b
  99.         path += '\\'
  100.     
  101.     return path
  102.  
  103.  
  104. def splitdrive(p):
  105.     if p[1:2] == ':':
  106.         return (p[0:2], p[2:])
  107.     return (None, p)
  108.  
  109.  
  110. def splitunc(p):
  111.     if p[1:2] == ':':
  112.         return ('', p)
  113.     firstTwo = None[0:2]
  114.     if firstTwo == '//' or firstTwo == '\\\\':
  115.         normp = normcase(p)
  116.         index = normp.find('\\', 2)
  117.         if index == -1:
  118.             return ('', p)
  119.         index = None.find('\\', index + 1)
  120.         if index == -1:
  121.             index = len(p)
  122.         return (p[:index], p[index:])
  123.     return (None, p)
  124.  
  125.  
  126. def split(p):
  127.     (d, p) = splitdrive(p)
  128.     i = len(p)
  129.     while i and p[i - 1] not in '/\\':
  130.         i = i - 1
  131.     head = p[:i]
  132.     tail = p[i:]
  133.     head2 = head
  134.     while head2 and head2[-1] in '/\\':
  135.         head2 = head2[:-1]
  136.     if not head2:
  137.         pass
  138.     head = head
  139.     return (d + head, tail)
  140.  
  141.  
  142. def splitext(p):
  143.     return genericpath._splitext(p, sep, altsep, extsep)
  144.  
  145. splitext.__doc__ = genericpath._splitext.__doc__
  146.  
  147. def basename(p):
  148.     return split(p)[1]
  149.  
  150.  
  151. def dirname(p):
  152.     return split(p)[0]
  153.  
  154.  
  155. def islink(path):
  156.     return False
  157.  
  158. lexists = exists
  159.  
  160. def ismount(path):
  161.     (unc, rest) = splitunc(path)
  162.     if unc:
  163.         return rest in ('', '/', '\\')
  164.     p = None(path)[1]
  165.     if len(p) == 1:
  166.         pass
  167.     return p[0] in '/\\'
  168.  
  169.  
  170. def walk(top, func, arg):
  171.     warnings.warnpy3k('In 3.x, os.path.walk is removed in favor of os.walk.', stacklevel = 2)
  172.     
  173.     try:
  174.         names = os.listdir(top)
  175.     except os.error:
  176.         return None
  177.  
  178.     func(arg, top, names)
  179.     for name in names:
  180.         name = join(top, name)
  181.         if isdir(name):
  182.             walk(name, func, arg)
  183.             continue
  184.  
  185.  
  186. def expanduser(path):
  187.     if path[:1] != '~':
  188.         return path
  189.     i = None
  190.     n = len(path)
  191.     while i < n and path[i] not in '/\\':
  192.         i = i + 1
  193.     if 'HOME' in os.environ:
  194.         userhome = os.environ['HOME']
  195.     elif 'USERPROFILE' in os.environ:
  196.         userhome = os.environ['USERPROFILE']
  197.     elif 'HOMEPATH' not in os.environ:
  198.         return path
  199.     
  200.     try:
  201.         drive = os.environ['HOMEDRIVE']
  202.     except KeyError:
  203.         drive = ''
  204.  
  205.     userhome = join(drive, os.environ['HOMEPATH'])
  206.     if i != 1:
  207.         userhome = join(dirname(userhome), path[1:i])
  208.     return userhome + path[i:]
  209.  
  210.  
  211. def expandvars(path):
  212.     if '$' not in path and '%' not in path:
  213.         return path
  214.     import string
  215.     varchars = string.ascii_letters + string.digits + '_-'
  216.     res = ''
  217.     index = 0
  218.     pathlen = len(path)
  219.     while index < pathlen:
  220.         c = path[index]
  221.         if c == "'":
  222.             path = path[index + 1:]
  223.             pathlen = len(path)
  224.             
  225.             try:
  226.                 index = path.index("'")
  227.                 res = res + "'" + path[:index + 1]
  228.             except ValueError:
  229.                 res = res + path
  230.                 index = pathlen - 1
  231.             
  232.  
  233.         if c == '%':
  234.             if path[index + 1:index + 2] == '%':
  235.                 res = res + c
  236.                 index = index + 1
  237.             else:
  238.                 path = path[index + 1:]
  239.                 pathlen = len(path)
  240.                 
  241.                 try:
  242.                     index = path.index('%')
  243.                 except ValueError:
  244.                     res = res + '%' + path
  245.                     index = pathlen - 1
  246.  
  247.                 var = path[:index]
  248.                 if var in os.environ:
  249.                     res = res + os.environ[var]
  250.                 else:
  251.                     res = res + '%' + var + '%'
  252.         elif c == '$':
  253.             if path[index + 1:index + 2] == '$':
  254.                 res = res + c
  255.                 index = index + 1
  256.             elif path[index + 1:index + 2] == '{':
  257.                 path = path[index + 2:]
  258.                 pathlen = len(path)
  259.                 
  260.                 try:
  261.                     index = path.index('}')
  262.                     var = path[:index]
  263.                     if var in os.environ:
  264.                         res = res + os.environ[var]
  265.                     else:
  266.                         res = res + '${' + var + '}'
  267.                 except ValueError:
  268.                     res = res + '${' + path
  269.                     index = pathlen - 1
  270.                 
  271.  
  272.             var = ''
  273.             index = index + 1
  274.             c = path[index:index + 1]
  275.             while c != '' and c in varchars:
  276.                 var = var + c
  277.                 index = index + 1
  278.                 c = path[index:index + 1]
  279.             if var in os.environ:
  280.                 res = res + os.environ[var]
  281.             else:
  282.                 res = res + '$' + var
  283.             if c != '':
  284.                 index = index - 1
  285.             
  286.         else:
  287.             res = res + c
  288.         index = index + 1
  289.     return res
  290.  
  291.  
  292. def normpath(path):
  293.     (backslash, dot) = (u'\\', u'.') if isinstance(path, unicode) else ('\\', '.')
  294.     if path.startswith(('\\\\.\\', '\\\\?\\')):
  295.         return path
  296.     path = None.replace('/', '\\')
  297.     (prefix, path) = splitdrive(path)
  298.     if prefix == '':
  299.         while path[:1] == '\\':
  300.             prefix = prefix + backslash
  301.             path = path[1:]
  302.     elif path.startswith('\\'):
  303.         prefix = prefix + backslash
  304.         path = path.lstrip('\\')
  305.     comps = path.split('\\')
  306.     i = 0
  307.     while i < len(comps):
  308.         if comps[i] in ('.', ''):
  309.             del comps[i]
  310.             continue
  311.         if comps[i] == '..':
  312.             if i > 0 and comps[i - 1] != '..':
  313.                 del comps[i - 1:i + 1]
  314.                 i -= 1
  315.             elif i == 0 and prefix.endswith('\\'):
  316.                 del comps[i]
  317.             else:
  318.                 i += 1
  319.         i += 1
  320.     if not prefix and not comps:
  321.         comps.append(dot)
  322.     return prefix + backslash.join(comps)
  323.  
  324.  
  325. try:
  326.     from nt import _getfullpathname
  327. except ImportError:
  328.     
  329.     def abspath(path):
  330.         if not isabs(path):
  331.             if isinstance(path, unicode):
  332.                 cwd = os.getcwdu()
  333.             else:
  334.                 cwd = os.getcwd()
  335.             path = join(cwd, path)
  336.         return normpath(path)
  337.  
  338.  
  339.  
  340. def abspath(path):
  341.     if path:
  342.         
  343.         try:
  344.             path = _getfullpathname(path)
  345.         except WindowsError:
  346.             pass
  347.         
  348.  
  349.     if isinstance(path, unicode):
  350.         path = os.getcwdu()
  351.     else:
  352.         path = os.getcwd()
  353.     return normpath(path)
  354.  
  355. realpath = abspath
  356. if hasattr(sys, 'getwindowsversion'):
  357.     pass
  358. supports_unicode_filenames = sys.getwindowsversion()[3] >= 2
  359.  
  360. def _abspath_split(path):
  361.     abs = abspath(normpath(path))
  362.     (prefix, rest) = splitunc(abs)
  363.     is_unc = bool(prefix)
  364.     if not is_unc:
  365.         (prefix, rest) = splitdrive(abs)
  366.     return (is_unc, prefix, [ x for x in rest.split(sep) if x ])
  367.  
  368.  
  369. def relpath(path, start = curdir):
  370.     if not path:
  371.         raise ValueError('no path specified')
  372.     (start_is_unc, start_prefix, start_list) = _abspath_split(start)
  373.     (path_is_unc, path_prefix, path_list) = _abspath_split(path)
  374.     if path_is_unc ^ start_is_unc:
  375.         raise ValueError('Cannot mix UNC and non-UNC paths (%s and %s)' % (path, start))
  376.     if path_prefix.lower() != start_prefix.lower():
  377.         if path_is_unc:
  378.             raise ValueError('path is on UNC root %s, start on UNC root %s' % (path_prefix, start_prefix))
  379.         raise ValueError('path is on drive %s, start on drive %s' % (path_prefix, start_prefix))
  380.     i = 0
  381.     for e1, e2 in zip(start_list, path_list):
  382.         if e1.lower() != e2.lower():
  383.             break
  384.         i += 1
  385.     
  386.     rel_list = [
  387.         pardir] * (len(start_list) - i) + path_list[i:]
  388.     if not rel_list:
  389.         return curdir
  390.     return None(*rel_list)
  391.  
  392.