<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> import re <EOL> import fnmatch <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def glob ( pathname ) : <EOL> """<STR_LIT>""" <EOL> return list ( iglob ( pathname ) ) <EOL> def iglob ( pathname ) : <EOL> """<STR_LIT>""" <EOL> if not has_magic ( pathname ) : <EOL> if os . path . lexists ( pathname ) : <EOL> yield pathname <EOL> return <EOL> dirname , basename = os . path . split ( pathname ) <EOL> if not dirname : <EOL> for name in glob1 ( os . curdir , basename ) : <EOL> yield name <EOL> return <EOL> if has_magic ( dirname ) : <EOL> dirs = iglob ( dirname ) <EOL> else : <EOL> dirs = [ dirname ] <EOL> if has_magic ( basename ) : <EOL> glob_in_dir = glob1 <EOL> else : <EOL> glob_in_dir = glob0 <EOL> for dirname in dirs : <EOL> for name in glob_in_dir ( dirname , basename ) : <EOL> yield os . path . join ( dirname , name ) <EOL> def glob1 ( dirname , pattern ) : <EOL> if not dirname : <EOL> dirname = os . curdir <EOL> if isinstance ( pattern , unicode ) and not isinstance ( dirname , unicode ) : <EOL> dirname = unicode ( dirname , sys . getfilesystemencoding ( ) or <EOL> sys . getdefaultencoding ( ) ) <EOL> try : <EOL> names = os . listdir ( dirname ) <EOL> except os . error : <EOL> return [ ] <EOL> if pattern [ <NUM_LIT:0> ] != '<STR_LIT:.>' : <EOL> names = filter ( lambda x : x [ <NUM_LIT:0> ] != '<STR_LIT:.>' , names ) <EOL> return fnmatch . filter ( names , pattern ) <EOL> def glob0 ( dirname , basename ) : <EOL> if basename == '<STR_LIT>' : <EOL> if os . path . isdir ( dirname ) : <EOL> return [ basename ] <EOL> else : <EOL> if os . path . lexists ( os . path . join ( dirname , basename ) ) : <EOL> return [ basename ] <EOL> return [ ] <EOL> magic_check = re . compile ( '<STR_LIT>' ) <EOL> def has_magic ( s ) : <EOL> return magic_check . search ( s ) is not None </s>
