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

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