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 / macpath.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-04-19  |  5.9 KB  |  229 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.2)
  3.  
  4. import os
  5. from stat import *
  6. __all__ = [
  7.     'normcase',
  8.     'isabs',
  9.     'join',
  10.     'splitdrive',
  11.     'split',
  12.     'splitext',
  13.     'basename',
  14.     'dirname',
  15.     'commonprefix',
  16.     'getsize',
  17.     'getmtime',
  18.     'getatime',
  19.     'islink',
  20.     'exists',
  21.     'isdir',
  22.     'isfile',
  23.     'walk',
  24.     'expanduser',
  25.     'expandvars',
  26.     'normpath',
  27.     'abspath']
  28.  
  29. def normcase(path):
  30.     return path.lower()
  31.  
  32.  
  33. def isabs(s):
  34.     if ':' in s:
  35.         pass
  36.     return s[0] != ':'
  37.  
  38.  
  39. def join(s, *p):
  40.     path = s
  41.     for t in p:
  42.         if not s or isabs(t):
  43.             path = t
  44.             continue
  45.         
  46.         if t[:1] == ':':
  47.             t = t[1:]
  48.         
  49.         if ':' not in path:
  50.             path = ':' + path
  51.         
  52.         if path[-1:] != ':':
  53.             path = path + ':'
  54.         
  55.         path = path + t
  56.     
  57.     return path
  58.  
  59.  
  60. def split(s):
  61.     if ':' not in s:
  62.         return ('', s)
  63.     
  64.     colon = 0
  65.     for i in range(len(s)):
  66.         if s[i] == ':':
  67.             colon = i + 1
  68.         
  69.     
  70.     (path, file) = (s[:colon - 1], s[colon:])
  71.     if path and not (':' in path):
  72.         path = path + ':'
  73.     
  74.     return (path, file)
  75.  
  76.  
  77. def splitext(p):
  78.     (root, ext) = ('', '')
  79.     for c in p:
  80.         if c == ':':
  81.             (root, ext) = (root + ext + c, '')
  82.         elif c == '.':
  83.             if ext:
  84.                 (root, ext) = (root + ext, c)
  85.             else:
  86.                 ext = c
  87.         elif ext:
  88.             ext = ext + c
  89.         else:
  90.             root = root + c
  91.     
  92.     return (root, ext)
  93.  
  94.  
  95. def splitdrive(p):
  96.     return ('', p)
  97.  
  98.  
  99. def dirname(s):
  100.     return split(s)[0]
  101.  
  102.  
  103. def basename(s):
  104.     return split(s)[1]
  105.  
  106.  
  107. def isdir(s):
  108.     
  109.     try:
  110.         st = os.stat(s)
  111.     except os.error:
  112.         return 0
  113.  
  114.     return S_ISDIR(st[ST_MODE])
  115.  
  116.  
  117. def getsize(filename):
  118.     st = os.stat(filename)
  119.     return st[ST_SIZE]
  120.  
  121.  
  122. def getmtime(filename):
  123.     st = os.stat(filename)
  124.     return st[ST_MTIME]
  125.  
  126.  
  127. def getatime(filename):
  128.     st = os.stat(filename)
  129.     return st[ST_ATIME]
  130.  
  131.  
  132. def islink(s):
  133.     return 0
  134.  
  135.  
  136. def isfile(s):
  137.     
  138.     try:
  139.         st = os.stat(s)
  140.     except os.error:
  141.         return 0
  142.  
  143.     return S_ISREG(st[ST_MODE])
  144.  
  145.  
  146. def exists(s):
  147.     
  148.     try:
  149.         st = os.stat(s)
  150.     except os.error:
  151.         return 0
  152.  
  153.     return 1
  154.  
  155.  
  156. def commonprefix(m):
  157.     if not m:
  158.         return ''
  159.     
  160.     prefix = m[0]
  161.     for item in m:
  162.         for i in range(len(prefix)):
  163.             if prefix[:i + 1] != item[:i + 1]:
  164.                 prefix = prefix[:i]
  165.                 if i == 0:
  166.                     return ''
  167.                 
  168.                 break
  169.             
  170.         
  171.     
  172.     return prefix
  173.  
  174.  
  175. def expandvars(path):
  176.     return path
  177.  
  178.  
  179. def expanduser(path):
  180.     return path
  181.  
  182. norm_error = 'macpath.norm_error: path cannot be normalized'
  183.  
  184. def normpath(s):
  185.     if ':' not in s:
  186.         return ':' + s
  187.     
  188.     comps = s.split(':')
  189.     i = 1
  190.     while i < len(comps) - 1:
  191.         if comps[i] == '' and comps[i - 1] != '':
  192.             if i > 1:
  193.                 del comps[i - 1:i + 1]
  194.                 i = i - 1
  195.             else:
  196.                 raise norm_error, 'Cannot use :: immediately after volume name'
  197.         else:
  198.             i = i + 1
  199.     s = ':'.join(comps)
  200.     if s[-1] == ':' and len(comps) > 2 and s != ':' * len(s):
  201.         s = s[:-1]
  202.     
  203.     return s
  204.  
  205.  
  206. def walk(top, func, arg):
  207.     
  208.     try:
  209.         names = os.listdir(top)
  210.     except os.error:
  211.         return None
  212.  
  213.     func(arg, top, names)
  214.     for name in names:
  215.         name = join(top, name)
  216.         if isdir(name):
  217.             walk(name, func, arg)
  218.         
  219.     
  220.  
  221.  
  222. def abspath(path):
  223.     if not isabs(path):
  224.         path = join(os.getcwd(), path)
  225.     
  226.     return normpath(path)
  227.  
  228. realpath = abspath
  229.