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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.7)
  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.         return None
  21.     (dirname, basename) = None.path.split(pathname)
  22.     if not dirname:
  23.         for name in glob1(os.curdir, basename):
  24.             yield name
  25.         
  26.         return None
  27.     if None(dirname):
  28.         dirs = iglob(dirname)
  29.     else:
  30.         dirs = [
  31.             dirname]
  32.     if has_magic(basename):
  33.         glob_in_dir = glob1
  34.     else:
  35.         glob_in_dir = glob0
  36.     for dirname in dirs:
  37.         for name in glob_in_dir(dirname, basename):
  38.             yield os.path.join(dirname, name)
  39.         
  40.     
  41.  
  42.  
  43. def glob1(dirname, pattern):
  44.     if not dirname:
  45.         dirname = os.curdir
  46.     if isinstance(pattern, unicode) and not isinstance(dirname, unicode):
  47.         if not sys.getfilesystemencoding():
  48.             pass
  49.         dirname = unicode(dirname, sys.getdefaultencoding())
  50.     
  51.     try:
  52.         names = os.listdir(dirname)
  53.     except os.error:
  54.         return []
  55.  
  56.     if pattern[0] != '.':
  57.         names = filter((lambda x: x[0] != '.'), names)
  58.     return fnmatch.filter(names, pattern)
  59.  
  60.  
  61. def glob0(dirname, basename):
  62.     if basename == '' or os.path.isdir(dirname):
  63.         return [
  64.             basename]
  65.     if os.path.lexists(os.path.join(dirname, basename)):
  66.         return [
  67.             basename]
  68.  
  69. magic_check = re.compile('[*?[]')
  70.  
  71. def has_magic(s):
  72.     return magic_check.search(s) is not None
  73.  
  74.