<s> """<STR_LIT>""" <EOL> __revision__ = "<STR_LIT>" <EOL> import sys , os , string , re <EOL> from distutils . errors import DistutilsPlatformError <EOL> from distutils . dep_util import newer <EOL> from distutils . spawn import spawn <EOL> from distutils import log <EOL> def get_platform ( ) : <EOL> """<STR_LIT>""" <EOL> if os . name != "<STR_LIT>" or not hasattr ( os , '<STR_LIT>' ) : <EOL> return sys . platform <EOL> ( osname , host , release , version , machine ) = os . uname ( ) <EOL> osname = string . lower ( osname ) <EOL> osname = string . replace ( osname , '<STR_LIT:/>' , '<STR_LIT>' ) <EOL> machine = string . replace ( machine , '<STR_LIT:U+0020>' , '<STR_LIT:_>' ) <EOL> machine = string . replace ( machine , '<STR_LIT:/>' , '<STR_LIT:->' ) <EOL> if osname [ : <NUM_LIT:5> ] == "<STR_LIT>" : <EOL> return "<STR_LIT>" % ( osname , machine ) <EOL> elif osname [ : <NUM_LIT:5> ] == "<STR_LIT>" : <EOL> if release [ <NUM_LIT:0> ] >= "<STR_LIT:5>" : <EOL> osname = "<STR_LIT>" <EOL> release = "<STR_LIT>" % ( int ( release [ <NUM_LIT:0> ] ) - <NUM_LIT:3> , release [ <NUM_LIT:2> : ] ) <EOL> elif osname [ : <NUM_LIT:4> ] == "<STR_LIT>" : <EOL> return "<STR_LIT>" % ( osname , release ) <EOL> elif osname [ : <NUM_LIT:3> ] == "<STR_LIT>" : <EOL> return "<STR_LIT>" % ( osname , version , release ) <EOL> elif osname [ : <NUM_LIT:6> ] == "<STR_LIT>" : <EOL> osname = "<STR_LIT>" <EOL> rel_re = re . compile ( r'<STR_LIT>' ) <EOL> m = rel_re . match ( release ) <EOL> if m : <EOL> release = m . group ( ) <EOL> elif osname [ : <NUM_LIT:6> ] == "<STR_LIT>" : <EOL> from distutils . sysconfig import get_config_vars <EOL> cfgvars = get_config_vars ( ) <EOL> macver = os . environ . get ( '<STR_LIT>' ) <EOL> if not macver : <EOL> macver = cfgvars . get ( '<STR_LIT>' ) <EOL> if not macver : <EOL> try : <EOL> f = open ( '<STR_LIT>' ) <EOL> except IOError : <EOL> pass <EOL> else : <EOL> m = re . search ( <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' , f . read ( ) ) <EOL> f . close ( ) <EOL> if m is not None : <EOL> macver = '<STR_LIT:.>' . join ( m . group ( <NUM_LIT:1> ) . split ( '<STR_LIT:.>' ) [ : <NUM_LIT:2> ] ) <EOL> if macver : <EOL> from distutils . sysconfig import get_config_vars <EOL> release = macver <EOL> osname = "<STR_LIT>" <EOL> if ( release + '<STR_LIT:.>' ) >= '<STR_LIT>' and get_config_vars ( ) . get ( '<STR_LIT>' , '<STR_LIT>' ) . strip ( ) : <EOL> machine = '<STR_LIT>' <EOL> elif machine in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> machine = '<STR_LIT>' <EOL> return "<STR_LIT>" % ( osname , release , machine ) <EOL> def convert_path ( pathname ) : <EOL> """<STR_LIT>""" <EOL> if os . sep == '<STR_LIT:/>' : <EOL> return pathname <EOL> if not pathname : <EOL> return pathname <EOL> if pathname [ <NUM_LIT:0> ] == '<STR_LIT:/>' : <EOL> raise ValueError , "<STR_LIT>" % pathname <EOL> if pathname [ - <NUM_LIT:1> ] == '<STR_LIT:/>' : <EOL> raise ValueError , "<STR_LIT>" % pathname <EOL> paths = string . split ( pathname , '<STR_LIT:/>' ) <EOL> while '<STR_LIT:.>' in paths : <EOL> paths . remove ( '<STR_LIT:.>' ) <EOL> if not paths : <EOL> return os . curdir <EOL> return apply ( os . path . join , paths ) <EOL> def change_root ( new_root , pathname ) : <EOL> """<STR_LIT>""" <EOL> if os . name == '<STR_LIT>' or os . name == '<STR_LIT>' : <EOL> if not os . path . isabs ( pathname ) : <EOL> return os . path . join ( new_root , pathname ) <EOL> else : <EOL> return os . path . join ( new_root , pathname [ <NUM_LIT:1> : ] ) <EOL> elif os . name == '<STR_LIT>' : <EOL> ( drive , path ) = os . path . splitdrive ( pathname ) <EOL> if path [ <NUM_LIT:0> ] == '<STR_LIT:\\>' : <EOL> path = path [ <NUM_LIT:1> : ] <EOL> return os . path . join ( new_root , path ) <EOL> elif os . name == '<STR_LIT>' : <EOL> ( drive , path ) = os . path . splitdrive ( pathname ) <EOL> if path [ <NUM_LIT:0> ] == os . sep : <EOL> path = path [ <NUM_LIT:1> : ] <EOL> return os . path . join ( new_root , path ) <EOL> elif os . name == '<STR_LIT>' : <EOL> if not os . path . isabs ( pathname ) : <EOL> return os . path . join ( new_root , pathname ) <EOL> else : <EOL> elements = string . split ( pathname , "<STR_LIT::>" , <NUM_LIT:1> ) <EOL> pathname = "<STR_LIT::>" + elements [ <NUM_LIT:1> ] <EOL> return os . path . join ( new_root , pathname ) <EOL> else : <EOL> raise DistutilsPlatformError , "<STR_LIT>" % os . name <EOL> _environ_checked = <NUM_LIT:0> <EOL> def check_environ ( ) : <EOL> """<STR_LIT>""" <EOL> global _environ_checked <EOL> if _environ_checked : <EOL> return <EOL> if os . name == '<STR_LIT>' and not os . environ . has_key ( '<STR_LIT>' ) : <EOL> import pwd <EOL> os . environ [ '<STR_LIT>' ] = pwd . getpwuid ( os . getuid ( ) ) [ <NUM_LIT:5> ] <EOL> if not os . environ . has_key ( '<STR_LIT>' ) : <EOL> os . environ [ '<STR_LIT>' ] = get_platform ( ) <EOL> _environ_checked = <NUM_LIT:1> <EOL> def subst_vars ( s , local_vars ) : <EOL> """<STR_LIT>""" <EOL> check_environ ( ) <EOL> def _subst ( match , local_vars = local_vars ) : <EOL> var_name = match . group ( <NUM_LIT:1> ) <EOL> if local_vars . has_key ( var_name ) : <EOL> return str ( local_vars [ var_name ] ) <EOL> else : <EOL> return os . environ [ var_name ] <EOL> try : <EOL> return re . sub ( r'<STR_LIT>' , _subst , s ) <EOL> except KeyError , var : <EOL> raise ValueError , "<STR_LIT>" % var <EOL> def grok_environment_error ( exc , prefix = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( exc , '<STR_LIT:filename>' ) and hasattr ( exc , '<STR_LIT>' ) : <EOL> if exc . filename : <EOL> error = prefix + "<STR_LIT>" % ( exc . filename , exc . strerror ) <EOL> else : <EOL> error = prefix + "<STR_LIT:%s>" % exc . strerror <EOL> else : <EOL> error = prefix + str ( exc [ - <NUM_LIT:1> ] ) <EOL> return error <EOL> _wordchars_re = _squote_re = _dquote_re = None <EOL> def _init_regex ( ) : <EOL> global _wordchars_re , _squote_re , _dquote_re <EOL> _wordchars_re = re . compile ( r'<STR_LIT>' % string . whitespace ) <EOL> _squote_re = re . compile ( r"<STR_LIT>" ) <EOL> _dquote_re = re . compile ( r'<STR_LIT>' ) <EOL> def split_quoted ( s ) : <EOL> """<STR_LIT>""" <EOL> if _wordchars_re is None : _init_regex ( ) <EOL> s = string . strip ( s ) <EOL> words = [ ] <EOL> pos = <NUM_LIT:0> <EOL> while s : <EOL> m = _wordchars_re . match ( s , pos ) <EOL> end = m . end ( ) <EOL> if end == len ( s ) : <EOL> words . append ( s [ : end ] ) <EOL> break <EOL> if s [ end ] in string . whitespace : <EOL> words . append ( s [ : end ] ) <EOL> s = string . lstrip ( s [ end : ] ) <EOL> pos = <NUM_LIT:0> <EOL> elif s [ end ] == '<STR_LIT:\\>' : <EOL> s = s [ : end ] + s [ end + <NUM_LIT:1> : ] <EOL> pos = end + <NUM_LIT:1> <EOL> else : <EOL> if s [ end ] == "<STR_LIT:'>" : <EOL> m = _squote_re . match ( s , end ) <EOL> elif s [ end ] == '<STR_LIT:">' : <EOL> m = _dquote_re . match ( s , end ) <EOL> else : <EOL> raise RuntimeError , "<STR_LIT>" % s [ end ] <EOL> if m is None : <EOL> raise ValueError , "<STR_LIT>" % s [ end ] <EOL> ( beg , end ) = m . span ( ) <EOL> s = s [ : beg ] + s [ beg + <NUM_LIT:1> : end - <NUM_LIT:1> ] + s [ end : ] <EOL> pos = m . end ( ) - <NUM_LIT:2> <EOL> if pos >= len ( s ) : <EOL> words . append ( s ) <EOL> break <EOL> return words <EOL> def execute ( func , args , msg = None , verbose = <NUM_LIT:0> , dry_run = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> if msg is None : <EOL> msg = "<STR_LIT>" % ( func . __name__ , args ) <EOL> if msg [ - <NUM_LIT:2> : ] == '<STR_LIT>' : <EOL> msg = msg [ <NUM_LIT:0> : - <NUM_LIT:2> ] + '<STR_LIT:)>' <EOL> log . info ( msg ) <EOL> if not dry_run : <EOL> apply ( func , args ) <EOL> def strtobool ( val ) : <EOL> """<STR_LIT>""" <EOL> val = string . lower ( val ) <EOL> if val in ( '<STR_LIT:y>' , '<STR_LIT:yes>' , '<STR_LIT:t>' , '<STR_LIT:true>' , '<STR_LIT>' , '<STR_LIT:1>' ) : <EOL> return <NUM_LIT:1> <EOL> elif val in ( '<STR_LIT:n>' , '<STR_LIT>' , '<STR_LIT:f>' , '<STR_LIT:false>' , '<STR_LIT>' , '<STR_LIT:0>' ) : <EOL> return <NUM_LIT:0> <EOL> else : <EOL> raise ValueError , "<STR_LIT>" % ( val , ) <EOL> def byte_compile ( py_files , <EOL> optimize = <NUM_LIT:0> , force = <NUM_LIT:0> , <EOL> prefix = None , base_dir = None , <EOL> verbose = <NUM_LIT:1> , dry_run = <NUM_LIT:0> , <EOL> direct = None ) : <EOL> """<STR_LIT>""" <EOL> if direct is None : <EOL> direct = ( __debug__ and optimize == <NUM_LIT:0> ) <EOL> if not direct : <EOL> try : <EOL> from tempfile import mkstemp <EOL> ( script_fd , script_name ) = mkstemp ( "<STR_LIT>" ) <EOL> except ImportError : <EOL> from tempfile import mktemp <EOL> ( script_fd , script_name ) = None , mktemp ( "<STR_LIT>" ) <EOL> log . info ( "<STR_LIT>" , script_name ) <EOL> if not dry_run : <EOL> if script_fd is not None : <EOL> script = os . fdopen ( script_fd , "<STR_LIT:w>" ) <EOL> else : <EOL> script = open ( script_name , "<STR_LIT:w>" ) <EOL> script . write ( """<STR_LIT>""" ) <EOL> script . write ( string . join ( map ( repr , py_files ) , "<STR_LIT>" ) + "<STR_LIT>" ) <EOL> script . write ( """<STR_LIT>""" % ( optimize , force , prefix , base_dir , verbose ) ) <EOL> script . close ( ) <EOL> cmd = [ sys . executable , script_name ] <EOL> if optimize == <NUM_LIT:1> : <EOL> cmd . insert ( <NUM_LIT:1> , "<STR_LIT>" ) <EOL> elif optimize == <NUM_LIT:2> : <EOL> cmd . insert ( <NUM_LIT:1> , "<STR_LIT>" ) <EOL> spawn ( cmd , dry_run = dry_run ) <EOL> execute ( os . remove , ( script_name , ) , "<STR_LIT>" % script_name , <EOL> dry_run = dry_run ) <EOL> else : <EOL> from py_compile import compile <EOL> for file in py_files : <EOL> if file [ - <NUM_LIT:3> : ] != "<STR_LIT>" : <EOL> continue <EOL> if sys . platform . startswith ( '<STR_LIT>' ) : <EOL> cfile = file [ : - <NUM_LIT:3> ] + '<STR_LIT>' <EOL> else : <EOL> cfile = file + ( __debug__ and "<STR_LIT:c>" or "<STR_LIT:o>" ) <EOL> dfile = file <EOL> if prefix : <EOL> if file [ : len ( prefix ) ] != prefix : <EOL> raise ValueError , ( "<STR_LIT>" <EOL> % ( file , prefix ) ) <EOL> dfile = dfile [ len ( prefix ) : ] <EOL> if base_dir : <EOL> dfile = os . path . join ( base_dir , dfile ) <EOL> cfile_base = os . path . basename ( cfile ) <EOL> if direct : <EOL> if force or newer ( file , cfile ) : <EOL> log . info ( "<STR_LIT>" , file , cfile_base ) <EOL> if not dry_run : <EOL> compile ( file , cfile , dfile ) <EOL> else : <EOL> log . debug ( "<STR_LIT>" , <EOL> file , cfile_base ) <EOL> def rfc822_escape ( header ) : <EOL> """<STR_LIT>""" <EOL> lines = string . split ( header , '<STR_LIT:\n>' ) <EOL> lines = map ( string . strip , lines ) <EOL> header = string . join ( lines , '<STR_LIT:\n>' + <NUM_LIT:8> * '<STR_LIT:U+0020>' ) <EOL> return header </s>
