<s> """<STR_LIT>""" <EOL> import os <EOL> import stat <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> curdir = '<STR_LIT:.>' <EOL> pardir = '<STR_LIT:..>' <EOL> extsep = '<STR_LIT:.>' <EOL> sep = '<STR_LIT:/>' <EOL> pathsep = '<STR_LIT::>' <EOL> defpath = '<STR_LIT>' <EOL> altsep = None <EOL> devnull = '<STR_LIT>' <EOL> def normcase ( s ) : <EOL> """<STR_LIT>""" <EOL> return s <EOL> def isabs ( s ) : <EOL> """<STR_LIT>""" <EOL> return s . startswith ( '<STR_LIT:/>' ) <EOL> def join ( a , * p ) : <EOL> """<STR_LIT>""" <EOL> path = a <EOL> for b in p : <EOL> if b . startswith ( '<STR_LIT:/>' ) : <EOL> path = b <EOL> elif path == '<STR_LIT>' or path . endswith ( '<STR_LIT:/>' ) : <EOL> path += b <EOL> else : <EOL> path += '<STR_LIT:/>' + b <EOL> return path <EOL> def split ( p ) : <EOL> """<STR_LIT>""" <EOL> i = p . rfind ( '<STR_LIT:/>' ) + <NUM_LIT:1> <EOL> head , tail = p [ : i ] , p [ i : ] <EOL> if head and head != '<STR_LIT:/>' * len ( head ) : <EOL> head = head . rstrip ( '<STR_LIT:/>' ) <EOL> return head , tail <EOL> def splitext ( p ) : <EOL> """<STR_LIT>""" <EOL> i = p . rfind ( '<STR_LIT:.>' ) <EOL> if i <= p . rfind ( '<STR_LIT:/>' ) : <EOL> return p , '<STR_LIT>' <EOL> else : <EOL> return p [ : i ] , p [ i : ] <EOL> def splitdrive ( p ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' , 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 ( filename ) : <EOL> """<STR_LIT>""" <EOL> return os . stat ( filename ) . st_size <EOL> def getmtime ( filename ) : <EOL> """<STR_LIT>""" <EOL> return os . stat ( filename ) . st_mtime <EOL> def getatime ( filename ) : <EOL> """<STR_LIT>""" <EOL> return os . stat ( filename ) . st_atime <EOL> def getctime ( filename ) : <EOL> """<STR_LIT>""" <EOL> return os . stat ( filename ) . st_ctime <EOL> def islink ( path ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> st = os . lstat ( path ) <EOL> except ( os . error , AttributeError ) : <EOL> return False <EOL> return stat . S_ISLNK ( st . st_mode ) <EOL> def exists ( path ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> st = os . stat ( path ) <EOL> except os . error : <EOL> return False <EOL> return True <EOL> def lexists ( path ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> st = os . lstat ( path ) <EOL> except os . error : <EOL> return False <EOL> return True <EOL> def isdir ( path ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> st = os . stat ( path ) <EOL> except os . error : <EOL> return False <EOL> return stat . S_ISDIR ( st . st_mode ) <EOL> def isfile ( path ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> st = os . stat ( path ) <EOL> except os . error : <EOL> return False <EOL> return stat . S_ISREG ( st . st_mode ) <EOL> if not os . _native_posix : <EOL> import java . io . File <EOL> import java . io . IOException <EOL> from org . python . core . Py import newString <EOL> def samefile ( f1 , f2 ) : <EOL> """<STR_LIT>""" <EOL> canon1 = newString ( java . io . File ( _ensure_str ( f1 ) ) . getCanonicalPath ( ) ) <EOL> canon2 = newString ( java . io . File ( _ensure_str ( f2 ) ) . getCanonicalPath ( ) ) <EOL> return canon1 == canon2 <EOL> else : <EOL> def samefile ( f1 , f2 ) : <EOL> """<STR_LIT>""" <EOL> s1 = os . stat ( f1 ) <EOL> s2 = os . stat ( f2 ) <EOL> return samestat ( s1 , s2 ) <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> def sameopenfile ( fp1 , fp2 ) : <EOL> """<STR_LIT>""" <EOL> s1 = os . fstat ( fp1 ) <EOL> s2 = os . fstat ( fp2 ) <EOL> return samestat ( s1 , s2 ) <EOL> __all__ . append ( "<STR_LIT>" ) <EOL> if os . _native_posix : <EOL> def samestat ( s1 , s2 ) : <EOL> """<STR_LIT>""" <EOL> return s1 . st_ino == s2 . st_ino and s1 . st_dev == s2 . st_dev <EOL> def ismount ( path ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> s1 = os . lstat ( path ) <EOL> s2 = os . lstat ( join ( path , '<STR_LIT:..>' ) ) <EOL> except os . error : <EOL> return False <EOL> dev1 = s1 . st_dev <EOL> dev2 = s2 . st_dev <EOL> if dev1 != dev2 : <EOL> return True <EOL> ino1 = s1 . st_ino <EOL> ino2 = s2 . st_ino <EOL> if ino1 == ino2 : <EOL> return True <EOL> return False <EOL> __all__ . extend ( [ "<STR_LIT>" , "<STR_LIT>" ] ) <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> try : <EOL> st = os . lstat ( name ) <EOL> except os . error : <EOL> continue <EOL> if stat . S_ISDIR ( st . st_mode ) : <EOL> walk ( name , func , arg ) <EOL> def expanduser ( path ) : <EOL> """<STR_LIT>""" <EOL> if not path . startswith ( '<STR_LIT>' ) : <EOL> return path <EOL> i = path . find ( '<STR_LIT:/>' , <NUM_LIT:1> ) <EOL> if i < <NUM_LIT:0> : <EOL> i = len ( path ) <EOL> if i == <NUM_LIT:1> : <EOL> if '<STR_LIT>' not in os . environ : <EOL> return path <EOL> else : <EOL> userhome = os . environ [ '<STR_LIT>' ] <EOL> else : <EOL> return path <EOL> userhome = userhome . rstrip ( '<STR_LIT:/>' ) <EOL> return userhome + path [ i : ] <EOL> _varprog = None <EOL> def expandvars ( path ) : <EOL> """<STR_LIT>""" <EOL> global _varprog <EOL> if '<STR_LIT:$>' not in path : <EOL> return path <EOL> if not _varprog : <EOL> import re <EOL> _varprog = re . compile ( r'<STR_LIT>' ) <EOL> i = <NUM_LIT:0> <EOL> while True : <EOL> m = _varprog . search ( path , i ) <EOL> if not m : <EOL> break <EOL> i , j = m . span ( <NUM_LIT:0> ) <EOL> name = m . group ( <NUM_LIT:1> ) <EOL> if name . startswith ( '<STR_LIT:{>' ) and name . endswith ( '<STR_LIT:}>' ) : <EOL> name = name [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> if name in os . environ : <EOL> tail = path [ j : ] <EOL> path = path [ : i ] + os . environ [ name ] <EOL> i = len ( path ) <EOL> path += tail <EOL> else : <EOL> i = j <EOL> return path <EOL> def normpath ( path ) : <EOL> """<STR_LIT>""" <EOL> if path == '<STR_LIT>' : <EOL> return '<STR_LIT:.>' <EOL> initial_slashes = path . startswith ( '<STR_LIT:/>' ) <EOL> if ( initial_slashes and <EOL> path . startswith ( '<STR_LIT>' ) and not path . startswith ( '<STR_LIT>' ) ) : <EOL> initial_slashes = <NUM_LIT:2> <EOL> comps = path . split ( '<STR_LIT:/>' ) <EOL> new_comps = [ ] <EOL> for comp in comps : <EOL> if comp in ( '<STR_LIT>' , '<STR_LIT:.>' ) : <EOL> continue <EOL> if ( comp != '<STR_LIT:..>' or ( not initial_slashes and not new_comps ) or <EOL> ( new_comps and new_comps [ - <NUM_LIT:1> ] == '<STR_LIT:..>' ) ) : <EOL> new_comps . append ( comp ) <EOL> elif new_comps : <EOL> new_comps . pop ( ) <EOL> comps = new_comps <EOL> path = '<STR_LIT:/>' . join ( comps ) <EOL> if initial_slashes : <EOL> path = '<STR_LIT:/>' * initial_slashes + path <EOL> return path or '<STR_LIT:.>' <EOL> def abspath ( path ) : <EOL> """<STR_LIT>""" <EOL> if not isabs ( path ) : <EOL> path = join ( os . getcwd ( ) , path ) <EOL> return normpath ( path ) <EOL> def realpath ( filename ) : <EOL> """<STR_LIT>""" <EOL> if isabs ( filename ) : <EOL> bits = [ '<STR_LIT:/>' ] + filename . split ( '<STR_LIT:/>' ) [ <NUM_LIT:1> : ] <EOL> else : <EOL> bits = [ '<STR_LIT>' ] + filename . split ( '<STR_LIT:/>' ) <EOL> for i in range ( <NUM_LIT:2> , len ( bits ) + <NUM_LIT:1> ) : <EOL> component = join ( * bits [ <NUM_LIT:0> : i ] ) <EOL> if islink ( component ) : <EOL> resolved = _resolve_link ( component ) <EOL> if resolved is None : <EOL> return abspath ( join ( * ( [ component ] + bits [ i : ] ) ) ) <EOL> else : <EOL> newpath = join ( * ( [ resolved ] + bits [ i : ] ) ) <EOL> return realpath ( newpath ) <EOL> return abspath ( filename ) <EOL> if not os . _native_posix : <EOL> def _resolve_link ( path ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return newString ( java . io . File ( abspath ( path ) ) . getCanonicalPath ( ) ) <EOL> except java . io . IOException : <EOL> return None <EOL> else : <EOL> def _resolve_link ( path ) : <EOL> """<STR_LIT>""" <EOL> paths_seen = [ ] <EOL> while islink ( path ) : <EOL> if path in paths_seen : <EOL> return None <EOL> paths_seen . append ( path ) <EOL> resolved = os . readlink ( path ) <EOL> if not isabs ( resolved ) : <EOL> dir = dirname ( path ) <EOL> path = normpath ( join ( dir , resolved ) ) <EOL> else : <EOL> path = normpath ( resolved ) <EOL> return path <EOL> def _ensure_str ( obj ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( obj , basestring ) : <EOL> return obj <EOL> raise TypeError ( '<STR_LIT>' % _type_name ( obj ) ) <EOL> def _type_name ( obj ) : <EOL> """<STR_LIT>""" <EOL> TPFLAGS_HEAPTYPE = <NUM_LIT:1> << <NUM_LIT:9> <EOL> type_name = '<STR_LIT>' <EOL> obj_type = type ( obj ) <EOL> is_heap = obj_type . __flags__ & TPFLAGS_HEAPTYPE == TPFLAGS_HEAPTYPE <EOL> if not is_heap and obj_type . __module__ != '<STR_LIT>' : <EOL> type_name = '<STR_LIT>' % obj_type . __module__ <EOL> type_name += obj_type . __name__ <EOL> return type_name <EOL> supports_unicode_filenames = False </s>
