<s> """<STR_LIT>""" <EOL> curdir = '<STR_LIT:@>' <EOL> pardir = '<STR_LIT>' <EOL> extsep = '<STR_LIT:/>' <EOL> sep = '<STR_LIT:.>' <EOL> pathsep = '<STR_LIT:U+002C>' <EOL> defpath = '<STR_LIT>' <EOL> altsep = None <EOL> import os , stat , string <EOL> try : <EOL> import swi <EOL> except ImportError : <EOL> class _swi : <EOL> def swi ( * a ) : <EOL> raise AttributeError , '<STR_LIT>' <EOL> block = swi <EOL> swi = _swi ( ) <EOL> [ _false , _true ] = range ( <NUM_LIT:2> ) <EOL> _roots = [ '<STR_LIT:$>' , '<STR_LIT:&>' , '<STR_LIT:%>' , '<STR_LIT:@>' , '<STR_LIT:\\>' ] <EOL> _allowMOSFSNames = _false <EOL> def _split ( p ) : <EOL> """<STR_LIT>""" <EOL> dash = _allowMOSFSNames and p [ : <NUM_LIT:1> ] == '<STR_LIT:->' <EOL> if dash : <EOL> q = string . find ( p , '<STR_LIT:->' , <NUM_LIT:1> ) + <NUM_LIT:1> <EOL> else : <EOL> if p [ : <NUM_LIT:1> ] == '<STR_LIT::>' : <EOL> q = <NUM_LIT:0> <EOL> else : <EOL> q = string . find ( p , '<STR_LIT::>' ) + <NUM_LIT:1> <EOL> s = string . find ( p , '<STR_LIT:#>' ) <EOL> if s == - <NUM_LIT:1> or s > q : <EOL> s = q <EOL> else : <EOL> for c in p [ dash : s ] : <EOL> if c not in string . ascii_letters : <EOL> q = <NUM_LIT:0> <EOL> break <EOL> r = q <EOL> if p [ q : q + <NUM_LIT:1> ] == '<STR_LIT::>' : <EOL> r = string . find ( p , '<STR_LIT:.>' , q + <NUM_LIT:1> ) + <NUM_LIT:1> <EOL> if r == <NUM_LIT:0> : <EOL> r = len ( p ) <EOL> return ( p [ : q ] , p [ q : r ] , p [ r : ] ) <EOL> def normcase ( p ) : <EOL> """<STR_LIT>""" <EOL> return string . lower ( p ) <EOL> def isabs ( p ) : <EOL> """<STR_LIT>""" <EOL> ( fs , drive , path ) = _split ( p ) <EOL> return drive != '<STR_LIT>' or path [ : <NUM_LIT:1> ] in _roots <EOL> def join ( a , * p ) : <EOL> """<STR_LIT>""" <EOL> j = a <EOL> for b in p : <EOL> ( fs , drive , path ) = _split ( b ) <EOL> if j == '<STR_LIT>' or fs != '<STR_LIT>' or drive != '<STR_LIT>' or path [ : <NUM_LIT:1> ] in _roots : <EOL> j = b <EOL> elif j [ - <NUM_LIT:1> ] == '<STR_LIT::>' : <EOL> j = j + b <EOL> else : <EOL> j = j + '<STR_LIT:.>' + b <EOL> return j <EOL> def split ( p ) : <EOL> """<STR_LIT>""" <EOL> ( fs , drive , path ) = _split ( p ) <EOL> q = string . rfind ( path , '<STR_LIT:.>' ) <EOL> if q != - <NUM_LIT:1> : <EOL> return ( fs + drive + path [ : q ] , path [ q + <NUM_LIT:1> : ] ) <EOL> return ( '<STR_LIT>' , p ) <EOL> def splitext ( p ) : <EOL> """<STR_LIT>""" <EOL> ( tail , head ) = split ( p ) <EOL> if '<STR_LIT:/>' in head : <EOL> q = len ( head ) - string . rfind ( head , '<STR_LIT:/>' ) <EOL> return ( p [ : - q ] , p [ - q : ] ) <EOL> return ( p , '<STR_LIT>' ) <EOL> def splitdrive ( p ) : <EOL> """<STR_LIT>""" <EOL> ( fs , drive , path ) = _split ( p ) <EOL> return ( fs + drive , p ) <EOL> def basename ( p ) : <EOL> """<STR_LIT>""" <EOL> return split ( p ) [ <NUM_LIT:1> ] <EOL> def dirname ( p ) : <EOL> """<STR_LIT>""" <EOL> return split ( p ) [ <NUM_LIT:0> ] <EOL> def commonprefix ( m ) : <EOL> "<STR_LIT>" <EOL> if not m : return '<STR_LIT>' <EOL> s1 = min ( m ) <EOL> s2 = max ( m ) <EOL> n = min ( len ( s1 ) , len ( s2 ) ) <EOL> for i in xrange ( n ) : <EOL> if s1 [ i ] != s2 [ i ] : <EOL> return s1 [ : i ] <EOL> return s1 [ : n ] <EOL> def getsize ( p ) : <EOL> """<STR_LIT>""" <EOL> st = os . stat ( p ) <EOL> return st [ stat . ST_SIZE ] <EOL> def getmtime ( p ) : <EOL> """<STR_LIT>""" <EOL> st = os . stat ( p ) <EOL> return st [ stat . ST_MTIME ] <EOL> getatime = getmtime <EOL> def exists ( p ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return swi . swi ( '<STR_LIT>' , '<STR_LIT>' , p ) != <NUM_LIT:0> <EOL> except swi . error : <EOL> return <NUM_LIT:0> <EOL> lexists = exists <EOL> def isdir ( p ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return swi . swi ( '<STR_LIT>' , '<STR_LIT>' , p ) in [ <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> except swi . error : <EOL> return <NUM_LIT:0> <EOL> def isfile ( p ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return swi . swi ( '<STR_LIT>' , '<STR_LIT>' , p ) in [ <NUM_LIT:1> , <NUM_LIT:3> ] <EOL> except swi . error : <EOL> return <NUM_LIT:0> <EOL> def islink ( p ) : <EOL> """<STR_LIT>""" <EOL> return _false <EOL> ismount = islink <EOL> def samefile ( fa , fb ) : <EOL> """<STR_LIT>""" <EOL> l = <NUM_LIT> <EOL> b = swi . block ( l ) <EOL> swi . swi ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , fa , b , l ) <EOL> fa = b . ctrlstring ( ) <EOL> swi . swi ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , fb , b , l ) <EOL> fb = b . ctrlstring ( ) <EOL> return fa == fb <EOL> def sameopenfile ( a , b ) : <EOL> """<STR_LIT>""" <EOL> return os . fstat ( a ) [ stat . ST_INO ] == os . fstat ( b ) [ stat . ST_INO ] <EOL> def expanduser ( p ) : <EOL> ( fs , drive , path ) = _split ( p ) <EOL> l = <NUM_LIT> <EOL> b = swi . block ( l ) <EOL> if path [ : <NUM_LIT:1> ] != '<STR_LIT:@>' : <EOL> return p <EOL> if fs == '<STR_LIT>' : <EOL> fsno = swi . swi ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> swi . swi ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , fsno , b , l ) <EOL> fsname = b . ctrlstring ( ) <EOL> else : <EOL> if fs [ : <NUM_LIT:1> ] == '<STR_LIT:->' : <EOL> fsname = fs [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> else : <EOL> fsname = fs [ : - <NUM_LIT:1> ] <EOL> fsname = string . split ( fsname , '<STR_LIT:#>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> x = swi . swi ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , b , fsname , l ) <EOL> if x < l : <EOL> urd = b . tostring ( <NUM_LIT:0> , l - x - <NUM_LIT:1> ) <EOL> else : <EOL> x = swi . swi ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , b , fsname , l ) <EOL> if x < l : <EOL> urd = b . tostring ( <NUM_LIT:0> , l - x - <NUM_LIT:1> ) <EOL> else : <EOL> urd = '<STR_LIT:$>' <EOL> return fsname + '<STR_LIT::>' + urd + path [ <NUM_LIT:1> : ] <EOL> def expandvars ( p ) : <EOL> """<STR_LIT>""" <EOL> l = <NUM_LIT> <EOL> b = swi . block ( l ) <EOL> return b . tostring ( <NUM_LIT:0> , swi . swi ( '<STR_LIT>' , '<STR_LIT>' , p , b , l ) ) <EOL> abspath = os . expand <EOL> realpath = abspath <EOL> def normpath ( p ) : <EOL> """<STR_LIT>""" <EOL> ( fs , drive , path ) = _split ( p ) <EOL> rhs = '<STR_LIT>' <EOL> ups = <NUM_LIT:0> <EOL> while path != '<STR_LIT>' : <EOL> ( path , el ) = split ( path ) <EOL> if el == '<STR_LIT>' : <EOL> ups = ups + <NUM_LIT:1> <EOL> else : <EOL> if ups > <NUM_LIT:0> : <EOL> ups = ups - <NUM_LIT:1> <EOL> else : <EOL> if rhs == '<STR_LIT>' : <EOL> rhs = el <EOL> else : <EOL> rhs = el + '<STR_LIT:.>' + rhs <EOL> while ups > <NUM_LIT:0> : <EOL> ups = ups - <NUM_LIT:1> <EOL> rhs = '<STR_LIT>' + rhs <EOL> return fs + drive + rhs <EOL> def walk ( top , func , arg ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> names = os . listdir ( top ) <EOL> except os . error : <EOL> return <EOL> func ( arg , top , names ) <EOL> for name in names : <EOL> name = join ( top , name ) <EOL> if isdir ( name ) and not islink ( name ) : <EOL> walk ( name , func , arg ) </s>
