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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import os
  6. import re
  7. import fnmatch
  8. __all__ = [
  9.     'glob',
  10.     'iglob']
  11.  
  12. def glob(pathname):
  13.     return list(iglob(pathname))
  14.  
  15.  
  16. def iglob(pathname):
  17.     if not has_magic(pathname):
  18.         if os.path.lexists(pathname):
  19.             yield pathname
  20.         
  21.         return None
  22.     (dirname, basename) = os.path.split(pathname)
  23.     if not dirname:
  24.         for name in glob1(os.curdir, basename):
  25.             yield name
  26.             has_magic(pathname)
  27.         
  28.         return None
  29.     if has_magic(basename):
  30.         glob_in_dir = glob1
  31.     else:
  32.         glob_in_dir = glob0
  33.     for dirname in dirs:
  34.         for name in glob_in_dir(dirname, basename):
  35.             yield os.path.join(dirname, name)
  36.         
  37.     
  38.  
  39.  
  40. def glob1(dirname, pattern):
  41.     if not dirname:
  42.         dirname = os.curdir
  43.     
  44.     if isinstance(pattern, unicode) and not isinstance(dirname, unicode):
  45.         if not sys.getfilesystemencoding():
  46.             pass
  47.         dirname = unicode(dirname, sys.getdefaultencoding())
  48.     
  49.     
  50.     try:
  51.         names = os.listdir(dirname)
  52.     except os.error:
  53.         return []
  54.  
  55.     if pattern[0] != '.':
  56.         names = filter((lambda x: x[0] != '.'), names)
  57.     
  58.     return fnmatch.filter(names, pattern)
  59.  
  60.  
  61. def glob0(dirname, basename):
  62.     if basename == '':
  63.         if os.path.isdir(dirname):
  64.             return [
  65.                 basename]
  66.     elif os.path.lexists(os.path.join(dirname, basename)):
  67.         return [
  68.             basename]
  69.     return []
  70.  
  71. magic_check = re.compile('[*?[]')
  72.  
  73. def has_magic(s):
  74.     return magic_check.search(s) is not None
  75.  
  76.