<s> """<STR_LIT>""" <EOL> __copyright__ = """<STR_LIT>""" <EOL> __version__ = '<STR_LIT>' <EOL> import sys , string , os , re <EOL> try : <EOL> DEV_NULL = os . devnull <EOL> except AttributeError : <EOL> if sys . platform in ( '<STR_LIT>' , '<STR_LIT:win32>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> DEV_NULL = '<STR_LIT>' <EOL> else : <EOL> DEV_NULL = '<STR_LIT>' <EOL> _libc_search = re . compile ( r'<STR_LIT>' <EOL> '<STR_LIT:|>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT:|>' <EOL> '<STR_LIT>' ) <EOL> def libc_ver ( executable = sys . executable , lib = '<STR_LIT>' , version = '<STR_LIT>' , <EOL> chunksize = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> if executable == sys . executable : <EOL> return ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if hasattr ( os . path , '<STR_LIT>' ) : <EOL> executable = os . path . realpath ( executable ) <EOL> f = open ( executable , '<STR_LIT:rb>' ) <EOL> binary = f . read ( chunksize ) <EOL> pos = <NUM_LIT:0> <EOL> while <NUM_LIT:1> : <EOL> m = _libc_search . search ( binary , pos ) <EOL> if not m : <EOL> binary = f . read ( chunksize ) <EOL> if not binary : <EOL> break <EOL> pos = <NUM_LIT:0> <EOL> continue <EOL> libcinit , glibc , glibcversion , so , threads , soversion = m . groups ( ) <EOL> if libcinit and not lib : <EOL> lib = '<STR_LIT>' <EOL> elif glibc : <EOL> if lib != '<STR_LIT>' : <EOL> lib = '<STR_LIT>' <EOL> version = glibcversion <EOL> elif glibcversion > version : <EOL> version = glibcversion <EOL> elif so : <EOL> if lib != '<STR_LIT>' : <EOL> lib = '<STR_LIT>' <EOL> if soversion and soversion > version : <EOL> version = soversion <EOL> if threads and version [ - len ( threads ) : ] != threads : <EOL> version = version + threads <EOL> pos = m . end ( ) <EOL> f . close ( ) <EOL> return lib , version <EOL> def _dist_try_harder ( distname , version , id ) : <EOL> """<STR_LIT>""" <EOL> if os . path . exists ( '<STR_LIT>' ) : <EOL> info = open ( '<STR_LIT>' ) . readlines ( ) <EOL> distname = '<STR_LIT>' <EOL> for line in info : <EOL> tv = string . split ( line ) <EOL> if len ( tv ) == <NUM_LIT:2> : <EOL> tag , value = tv <EOL> else : <EOL> continue <EOL> if tag == '<STR_LIT>' : <EOL> version = string . strip ( value ) <EOL> elif tag == '<STR_LIT>' : <EOL> values = string . split ( value , '<STR_LIT:->' ) <EOL> id = values [ <NUM_LIT:2> ] <EOL> return distname , version , id <EOL> if os . path . exists ( '<STR_LIT>' ) : <EOL> info = open ( '<STR_LIT>' ) . readlines ( ) <EOL> for line in info : <EOL> pkg = string . split ( line , '<STR_LIT:->' ) <EOL> if len ( pkg ) >= <NUM_LIT:2> and pkg [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> return '<STR_LIT>' , pkg [ <NUM_LIT:1> ] , id <EOL> if os . path . isdir ( '<STR_LIT>' ) : <EOL> verfiles = os . listdir ( '<STR_LIT>' ) <EOL> for n in range ( len ( verfiles ) - <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> if verfiles [ n ] [ : <NUM_LIT> ] != '<STR_LIT>' : <EOL> del verfiles [ n ] <EOL> if verfiles : <EOL> verfiles . sort ( ) <EOL> distname = '<STR_LIT>' <EOL> version = verfiles [ - <NUM_LIT:1> ] [ <NUM_LIT> : ] <EOL> return distname , version , id <EOL> return distname , version , id <EOL> _release_filename = re . compile ( r'<STR_LIT>' ) <EOL> _lsb_release_version = re . compile ( r'<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> _release_version = re . compile ( r'<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> _supported_dists = ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> def _parse_release_file ( firstline ) : <EOL> version = '<STR_LIT>' <EOL> id = '<STR_LIT>' <EOL> m = _lsb_release_version . match ( firstline ) <EOL> if m is not None : <EOL> return tuple ( m . groups ( ) ) <EOL> m = _release_version . match ( firstline ) <EOL> if m is not None : <EOL> return tuple ( m . groups ( ) ) <EOL> l = string . split ( string . strip ( firstline ) ) <EOL> if l : <EOL> version = l [ <NUM_LIT:0> ] <EOL> if len ( l ) > <NUM_LIT:1> : <EOL> id = l [ <NUM_LIT:1> ] <EOL> return '<STR_LIT>' , version , id <EOL> def linux_distribution ( distname = '<STR_LIT>' , version = '<STR_LIT>' , id = '<STR_LIT>' , <EOL> supported_dists = _supported_dists , <EOL> full_distribution_name = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> etc = os . listdir ( '<STR_LIT>' ) <EOL> except os . error : <EOL> return distname , version , id <EOL> etc . sort ( ) <EOL> for file in etc : <EOL> m = _release_filename . match ( file ) <EOL> if m is not None : <EOL> _distname , dummy = m . groups ( ) <EOL> if _distname in supported_dists : <EOL> distname = _distname <EOL> break <EOL> else : <EOL> return _dist_try_harder ( distname , version , id ) <EOL> f = open ( '<STR_LIT>' + file , '<STR_LIT:r>' ) <EOL> firstline = f . readline ( ) <EOL> f . close ( ) <EOL> _distname , _version , _id = _parse_release_file ( firstline ) <EOL> if _distname and full_distribution_name : <EOL> distname = _distname <EOL> if _version : <EOL> version = _version <EOL> if _id : <EOL> id = _id <EOL> return distname , version , id <EOL> def dist ( distname = '<STR_LIT>' , version = '<STR_LIT>' , id = '<STR_LIT>' , <EOL> supported_dists = _supported_dists ) : <EOL> """<STR_LIT>""" <EOL> return linux_distribution ( distname , version , id , <EOL> supported_dists = supported_dists , <EOL> full_distribution_name = <NUM_LIT:0> ) <EOL> class _popen : <EOL> """<STR_LIT>""" <EOL> tmpfile = '<STR_LIT>' <EOL> pipe = None <EOL> bufsize = None <EOL> mode = '<STR_LIT:r>' <EOL> def __init__ ( self , cmd , mode = '<STR_LIT:r>' , bufsize = None ) : <EOL> if mode != '<STR_LIT:r>' : <EOL> raise ValueError , '<STR_LIT>' <EOL> import tempfile <EOL> self . tmpfile = tmpfile = tempfile . mktemp ( ) <EOL> os . system ( cmd + '<STR_LIT>' % tmpfile ) <EOL> self . pipe = open ( tmpfile , '<STR_LIT:rb>' ) <EOL> self . bufsize = bufsize <EOL> self . mode = mode <EOL> def read ( self ) : <EOL> return self . pipe . read ( ) <EOL> def readlines ( self ) : <EOL> if self . bufsize is not None : <EOL> return self . pipe . readlines ( ) <EOL> def close ( self , <EOL> remove = os . unlink , error = os . error ) : <EOL> if self . pipe : <EOL> rc = self . pipe . close ( ) <EOL> else : <EOL> rc = <NUM_LIT:255> <EOL> if self . tmpfile : <EOL> try : <EOL> remove ( self . tmpfile ) <EOL> except error : <EOL> pass <EOL> return rc <EOL> __del__ = close <EOL> def popen ( cmd , mode = '<STR_LIT:r>' , bufsize = None ) : <EOL> """<STR_LIT>""" <EOL> popen = None <EOL> if os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) == '<STR_LIT>' : <EOL> try : <EOL> import win32pipe <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> popen = win32pipe . popen <EOL> if popen is None : <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> popen = os . popen <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> try : <EOL> popen ( '<STR_LIT>' ) <EOL> except os . error : <EOL> popen = _popen <EOL> else : <EOL> popen = _popen <EOL> if bufsize is None : <EOL> return popen ( cmd , mode ) <EOL> else : <EOL> return popen ( cmd , mode , bufsize ) <EOL> def _norm_version ( version , build = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> l = string . split ( version , '<STR_LIT:.>' ) <EOL> if build : <EOL> l . append ( build ) <EOL> try : <EOL> ints = map ( int , l ) <EOL> except ValueError : <EOL> strings = l <EOL> else : <EOL> strings = map ( str , ints ) <EOL> version = string . join ( strings [ : <NUM_LIT:3> ] , '<STR_LIT:.>' ) <EOL> return version <EOL> _ver_output = re . compile ( r'<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def _syscmd_ver ( system = '<STR_LIT>' , release = '<STR_LIT>' , version = '<STR_LIT>' , <EOL> supported_platforms = ( '<STR_LIT:win32>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> """<STR_LIT>""" <EOL> if sys . platform not in supported_platforms : <EOL> return system , release , version <EOL> for cmd in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> try : <EOL> pipe = popen ( cmd ) <EOL> info = pipe . read ( ) <EOL> if pipe . close ( ) : <EOL> raise os . error , '<STR_LIT>' <EOL> except os . error , why : <EOL> continue <EOL> except IOError , why : <EOL> continue <EOL> else : <EOL> break <EOL> else : <EOL> return system , release , version <EOL> info = string . strip ( info ) <EOL> m = _ver_output . match ( info ) <EOL> if m is not None : <EOL> system , release , version = m . groups ( ) <EOL> if release [ - <NUM_LIT:1> ] == '<STR_LIT:.>' : <EOL> release = release [ : - <NUM_LIT:1> ] <EOL> if version [ - <NUM_LIT:1> ] == '<STR_LIT:.>' : <EOL> version = version [ : - <NUM_LIT:1> ] <EOL> version = _norm_version ( version ) <EOL> return system , release , version <EOL> def _win32_getvalue ( key , name , default = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> from win32api import RegQueryValueEx <EOL> except ImportError : <EOL> import _winreg <EOL> RegQueryValueEx = _winreg . QueryValueEx <EOL> try : <EOL> return RegQueryValueEx ( key , name ) <EOL> except : <EOL> return default <EOL> def win32_ver ( release = '<STR_LIT>' , version = '<STR_LIT>' , csd = '<STR_LIT>' , ptype = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> import win32api <EOL> from win32api import RegQueryValueEx , RegOpenKeyEx , RegCloseKey , GetVersionEx <EOL> from win32con import HKEY_LOCAL_MACHINE , VER_PLATFORM_WIN32_NT , VER_PLATFORM_WIN32_WINDOWS , VER_NT_WORKSTATION <EOL> except ImportError : <EOL> try : <EOL> sys . getwindowsversion <EOL> except AttributeError : <EOL> return release , version , csd , ptype <EOL> else : <EOL> import _winreg <EOL> GetVersionEx = sys . getwindowsversion <EOL> RegQueryValueEx = _winreg . QueryValueEx <EOL> RegOpenKeyEx = _winreg . OpenKeyEx <EOL> RegCloseKey = _winreg . CloseKey <EOL> HKEY_LOCAL_MACHINE = _winreg . HKEY_LOCAL_MACHINE <EOL> VER_PLATFORM_WIN32_WINDOWS = <NUM_LIT:1> <EOL> VER_PLATFORM_WIN32_NT = <NUM_LIT:2> <EOL> VER_NT_WORKSTATION = <NUM_LIT:1> <EOL> VER_NT_SERVER = <NUM_LIT:3> <EOL> REG_SZ = <NUM_LIT:1> <EOL> winver = GetVersionEx ( ) <EOL> maj , min , buildno , plat , csd = winver <EOL> version = '<STR_LIT>' % ( maj , min , buildno & <NUM_LIT> ) <EOL> if hasattr ( winver , "<STR_LIT>" ) : <EOL> if winver . service_pack != "<STR_LIT>" : <EOL> csd = '<STR_LIT>' % winver . service_pack_major <EOL> else : <EOL> if csd [ : <NUM_LIT> ] == '<STR_LIT>' : <EOL> csd = '<STR_LIT>' + csd [ <NUM_LIT> : ] <EOL> if plat == VER_PLATFORM_WIN32_WINDOWS : <EOL> regkey = '<STR_LIT>' <EOL> if maj == <NUM_LIT:4> : <EOL> if min == <NUM_LIT:0> : <EOL> release = '<STR_LIT>' <EOL> elif min == <NUM_LIT:10> : <EOL> release = '<STR_LIT>' <EOL> elif min == <NUM_LIT> : <EOL> release = '<STR_LIT>' <EOL> else : <EOL> release = '<STR_LIT>' <EOL> elif maj == <NUM_LIT:5> : <EOL> release = '<STR_LIT>' <EOL> elif plat == VER_PLATFORM_WIN32_NT : <EOL> regkey = '<STR_LIT>' <EOL> if maj <= <NUM_LIT:4> : <EOL> release = '<STR_LIT>' <EOL> elif maj == <NUM_LIT:5> : <EOL> if min == <NUM_LIT:0> : <EOL> release = '<STR_LIT>' <EOL> elif min == <NUM_LIT:1> : <EOL> release = '<STR_LIT>' <EOL> elif min == <NUM_LIT:2> : <EOL> release = '<STR_LIT>' <EOL> else : <EOL> release = '<STR_LIT>' <EOL> elif maj == <NUM_LIT:6> : <EOL> if hasattr ( winver , "<STR_LIT>" ) : <EOL> product_type = winver . product_type <EOL> else : <EOL> product_type = VER_NT_WORKSTATION <EOL> try : <EOL> key = RegOpenKeyEx ( HKEY_LOCAL_MACHINE , regkey ) <EOL> name , type = RegQueryValueEx ( key , "<STR_LIT>" ) <EOL> if type == REG_SZ and name . find ( "<STR_LIT>" ) != - <NUM_LIT:1> : <EOL> product_type = VER_NT_SERVER <EOL> except WindowsError : <EOL> pass <EOL> if min == <NUM_LIT:0> : <EOL> if product_type == VER_NT_WORKSTATION : <EOL> release = '<STR_LIT>' <EOL> else : <EOL> release = '<STR_LIT>' <EOL> elif min == <NUM_LIT:1> : <EOL> if product_type == VER_NT_WORKSTATION : <EOL> release = '<STR_LIT>' <EOL> else : <EOL> release = '<STR_LIT>' <EOL> elif min == <NUM_LIT:2> : <EOL> if product_type == VER_NT_WORKSTATION : <EOL> release = '<STR_LIT>' <EOL> else : <EOL> release = '<STR_LIT>' <EOL> else : <EOL> release = '<STR_LIT>' <EOL> else : <EOL> if not release : <EOL> release = '<STR_LIT>' % ( maj , min ) <EOL> return release , version , csd , ptype <EOL> try : <EOL> keyCurVer = RegOpenKeyEx ( HKEY_LOCAL_MACHINE , regkey ) <EOL> RegQueryValueEx ( keyCurVer , '<STR_LIT>' ) <EOL> except : <EOL> return release , version , csd , ptype <EOL> build = _win32_getvalue ( keyCurVer , <EOL> '<STR_LIT>' , <EOL> ( '<STR_LIT>' , <NUM_LIT:1> ) ) [ <NUM_LIT:0> ] <EOL> ptype = _win32_getvalue ( keyCurVer , <EOL> '<STR_LIT>' , <EOL> ( ptype , <NUM_LIT:1> ) ) [ <NUM_LIT:0> ] <EOL> version = _norm_version ( version , build ) <EOL> RegCloseKey ( keyCurVer ) <EOL> return release , version , csd , ptype <EOL> def _mac_ver_lookup ( selectors , default = None ) : <EOL> from gestalt import gestalt <EOL> import MacOS <EOL> l = [ ] <EOL> append = l . append <EOL> for selector in selectors : <EOL> try : <EOL> append ( gestalt ( selector ) ) <EOL> except ( RuntimeError , MacOS . Error ) : <EOL> append ( default ) <EOL> return l <EOL> def _bcd2str ( bcd ) : <EOL> return hex ( bcd ) [ <NUM_LIT:2> : ] <EOL> def _mac_ver_gestalt ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> import gestalt <EOL> import MacOS <EOL> except ImportError : <EOL> return None <EOL> sysv , sysa = _mac_ver_lookup ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if sysv : <EOL> major = ( sysv & <NUM_LIT> ) >> <NUM_LIT:8> <EOL> minor = ( sysv & <NUM_LIT> ) >> <NUM_LIT:4> <EOL> patch = ( sysv & <NUM_LIT> ) <EOL> if ( major , minor ) >= ( <NUM_LIT:10> , <NUM_LIT:4> ) : <EOL> major , minor , patch = _mac_ver_lookup ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> release = '<STR_LIT>' % ( major , minor , patch ) <EOL> else : <EOL> release = '<STR_LIT>' % ( _bcd2str ( major ) , minor , patch ) <EOL> if sysa : <EOL> machine = { <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' } . get ( sysa , '<STR_LIT>' ) <EOL> versioninfo = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> return release , versioninfo , machine <EOL> def _mac_ver_xml ( ) : <EOL> fn = '<STR_LIT>' <EOL> if not os . path . exists ( fn ) : <EOL> return None <EOL> try : <EOL> import plistlib <EOL> except ImportError : <EOL> return None <EOL> pl = plistlib . readPlist ( fn ) <EOL> release = pl [ '<STR_LIT>' ] <EOL> versioninfo = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> machine = os . uname ( ) [ <NUM_LIT:4> ] <EOL> if machine in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> machine = '<STR_LIT>' <EOL> return release , versioninfo , machine <EOL> def mac_ver ( release = '<STR_LIT>' , versioninfo = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , machine = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> info = _mac_ver_xml ( ) <EOL> if info is not None : <EOL> return info <EOL> info = _mac_ver_gestalt ( ) <EOL> if info is not None : <EOL> return info <EOL> return release , versioninfo , machine <EOL> def _java_getprop ( name , default ) : <EOL> from java . lang import System <EOL> try : <EOL> value = System . getProperty ( name ) <EOL> if value is None : <EOL> return default <EOL> return value <EOL> except AttributeError : <EOL> return default <EOL> def java_ver ( release = '<STR_LIT>' , vendor = '<STR_LIT>' , vminfo = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , osinfo = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> import java . lang <EOL> except ImportError : <EOL> return release , vendor , vminfo , osinfo <EOL> vendor = _java_getprop ( '<STR_LIT>' , vendor ) <EOL> release = _java_getprop ( '<STR_LIT>' , release ) <EOL> vm_name , vm_release , vm_vendor = vminfo <EOL> vm_name = _java_getprop ( '<STR_LIT>' , vm_name ) <EOL> vm_vendor = _java_getprop ( '<STR_LIT>' , vm_vendor ) <EOL> vm_release = _java_getprop ( '<STR_LIT>' , vm_release ) <EOL> vminfo = vm_name , vm_release , vm_vendor <EOL> os_name , os_version , os_arch = osinfo <EOL> os_arch = _java_getprop ( '<STR_LIT>' , os_arch ) <EOL> os_name = _java_getprop ( '<STR_LIT>' , os_name ) <EOL> os_version = _java_getprop ( '<STR_LIT>' , os_version ) <EOL> osinfo = os_name , os_version , os_arch <EOL> return release , vendor , vminfo , osinfo <EOL> def system_alias ( system , release , version ) : <EOL> """<STR_LIT>""" <EOL> if system == '<STR_LIT>' : <EOL> return '<STR_LIT>' , system + release , version <EOL> elif system == '<STR_LIT>' : <EOL> if release < '<STR_LIT:5>' : <EOL> return system , release , version <EOL> l = string . split ( release , '<STR_LIT:.>' ) <EOL> if l : <EOL> try : <EOL> major = int ( l [ <NUM_LIT:0> ] ) <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> major = major - <NUM_LIT:3> <EOL> l [ <NUM_LIT:0> ] = str ( major ) <EOL> release = string . join ( l , '<STR_LIT:.>' ) <EOL> if release < '<STR_LIT>' : <EOL> system = '<STR_LIT>' <EOL> else : <EOL> system = '<STR_LIT>' <EOL> elif system == '<STR_LIT>' : <EOL> system = '<STR_LIT>' <EOL> if version : <EOL> version = version + '<STR_LIT>' <EOL> else : <EOL> version = '<STR_LIT>' <EOL> elif system in ( '<STR_LIT:win32>' , '<STR_LIT>' ) : <EOL> system = '<STR_LIT>' <EOL> return system , release , version <EOL> def _platform ( * args ) : <EOL> """<STR_LIT>""" <EOL> platform = string . join ( <EOL> map ( string . strip , <EOL> filter ( len , args ) ) , <EOL> '<STR_LIT:->' ) <EOL> replace = string . replace <EOL> platform = replace ( platform , '<STR_LIT:U+0020>' , '<STR_LIT:_>' ) <EOL> platform = replace ( platform , '<STR_LIT:/>' , '<STR_LIT:->' ) <EOL> platform = replace ( platform , '<STR_LIT:\\>' , '<STR_LIT:->' ) <EOL> platform = replace ( platform , '<STR_LIT::>' , '<STR_LIT:->' ) <EOL> platform = replace ( platform , '<STR_LIT:;>' , '<STR_LIT:->' ) <EOL> platform = replace ( platform , '<STR_LIT:">' , '<STR_LIT:->' ) <EOL> platform = replace ( platform , '<STR_LIT:(>' , '<STR_LIT:->' ) <EOL> platform = replace ( platform , '<STR_LIT:)>' , '<STR_LIT:->' ) <EOL> platform = replace ( platform , '<STR_LIT>' , '<STR_LIT>' ) <EOL> while <NUM_LIT:1> : <EOL> cleaned = replace ( platform , '<STR_LIT>' , '<STR_LIT:->' ) <EOL> if cleaned == platform : <EOL> break <EOL> platform = cleaned <EOL> while platform [ - <NUM_LIT:1> ] == '<STR_LIT:->' : <EOL> platform = platform [ : - <NUM_LIT:1> ] <EOL> return platform <EOL> def _node ( default = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> import socket <EOL> except ImportError : <EOL> return default <EOL> try : <EOL> return socket . gethostname ( ) <EOL> except socket . error : <EOL> return default <EOL> if not hasattr ( os . path , '<STR_LIT>' ) : <EOL> def _abspath ( path , <EOL> isabs = os . path . isabs , join = os . path . join , getcwd = os . getcwd , <EOL> normpath = os . path . normpath ) : <EOL> if not isabs ( path ) : <EOL> path = join ( getcwd ( ) , path ) <EOL> return normpath ( path ) <EOL> else : <EOL> _abspath = os . path . abspath <EOL> def _follow_symlinks ( filepath ) : <EOL> """<STR_LIT>""" <EOL> filepath = _abspath ( filepath ) <EOL> while os . path . islink ( filepath ) : <EOL> filepath = os . path . normpath ( <EOL> os . path . join ( os . path . dirname ( filepath ) , os . readlink ( filepath ) ) ) <EOL> return filepath <EOL> def _syscmd_uname ( option , default = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if sys . platform in ( '<STR_LIT>' , '<STR_LIT:win32>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return default <EOL> try : <EOL> f = os . popen ( '<STR_LIT>' % ( option , DEV_NULL ) ) <EOL> except ( AttributeError , os . error ) : <EOL> return default <EOL> output = string . strip ( f . read ( ) ) <EOL> rc = f . close ( ) <EOL> if not output or rc : <EOL> return default <EOL> else : <EOL> return output <EOL> def _syscmd_file ( target , default = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> import subprocess <EOL> if sys . platform in ( '<STR_LIT>' , '<STR_LIT:win32>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return default <EOL> target = _follow_symlinks ( target ) <EOL> try : <EOL> proc = subprocess . Popen ( [ '<STR_LIT:file>' , target ] , <EOL> stdout = subprocess . PIPE , stderr = subprocess . STDOUT ) <EOL> except ( AttributeError , os . error ) : <EOL> return default <EOL> output = proc . communicate ( ) [ <NUM_LIT:0> ] <EOL> rc = proc . wait ( ) <EOL> if not output or rc : <EOL> return default <EOL> else : <EOL> return output <EOL> _default_architecture = { <EOL> '<STR_LIT:win32>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } <EOL> _architecture_split = re . compile ( r'<STR_LIT>' ) . split <EOL> def architecture ( executable = sys . executable , bits = '<STR_LIT>' , linkage = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if not bits : <EOL> import struct <EOL> try : <EOL> size = struct . calcsize ( '<STR_LIT:P>' ) <EOL> except struct . error : <EOL> size = struct . calcsize ( '<STR_LIT:l>' ) <EOL> bits = str ( size * <NUM_LIT:8> ) + '<STR_LIT>' <EOL> if executable : <EOL> output = _syscmd_file ( executable , '<STR_LIT>' ) <EOL> else : <EOL> output = '<STR_LIT>' <EOL> if not output and executable == sys . executable : <EOL> if sys . platform in _default_architecture : <EOL> b , l = _default_architecture [ sys . platform ] <EOL> if b : <EOL> bits = b <EOL> if l : <EOL> linkage = l <EOL> return bits , linkage <EOL> fileout = _architecture_split ( output ) [ <NUM_LIT:1> : ] <EOL> if '<STR_LIT>' not in fileout : <EOL> return bits , linkage <EOL> if '<STR_LIT>' in fileout : <EOL> bits = '<STR_LIT>' <EOL> elif '<STR_LIT>' in fileout : <EOL> bits = '<STR_LIT>' <EOL> elif '<STR_LIT>' in fileout : <EOL> bits = '<STR_LIT>' <EOL> if '<STR_LIT>' in fileout : <EOL> linkage = '<STR_LIT>' <EOL> elif '<STR_LIT>' in fileout : <EOL> if '<STR_LIT>' in fileout : <EOL> linkage = '<STR_LIT>' <EOL> else : <EOL> linkage = '<STR_LIT>' <EOL> elif '<STR_LIT>' in fileout : <EOL> linkage = '<STR_LIT>' <EOL> elif '<STR_LIT>' in fileout : <EOL> linkage = '<STR_LIT>' <EOL> else : <EOL> pass <EOL> return bits , linkage <EOL> _uname_cache = None <EOL> def uname ( ) : <EOL> """<STR_LIT>""" <EOL> global _uname_cache <EOL> no_os_uname = <NUM_LIT:0> <EOL> if _uname_cache is not None : <EOL> return _uname_cache <EOL> processor = '<STR_LIT>' <EOL> try : <EOL> system , node , release , version , machine = os . uname ( ) <EOL> except AttributeError : <EOL> no_os_uname = <NUM_LIT:1> <EOL> if no_os_uname or not filter ( None , ( system , node , release , version , machine ) ) : <EOL> if no_os_uname : <EOL> system = sys . platform <EOL> release = '<STR_LIT>' <EOL> version = '<STR_LIT>' <EOL> node = _node ( ) <EOL> machine = '<STR_LIT>' <EOL> use_syscmd_ver = <NUM_LIT:1> <EOL> if system == '<STR_LIT:win32>' : <EOL> release , version , csd , ptype = win32_ver ( ) <EOL> if release and version : <EOL> use_syscmd_ver = <NUM_LIT:0> <EOL> if not machine : <EOL> if "<STR_LIT>" in os . environ : <EOL> machine = os . environ . get ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> else : <EOL> machine = os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not processor : <EOL> processor = os . environ . get ( '<STR_LIT>' , machine ) <EOL> if use_syscmd_ver : <EOL> system , release , version = _syscmd_ver ( system ) <EOL> if system == '<STR_LIT>' : <EOL> system = '<STR_LIT>' <EOL> elif system == '<STR_LIT>' and release == '<STR_LIT>' : <EOL> system = '<STR_LIT>' <EOL> if '<STR_LIT>' == version [ : <NUM_LIT:3> ] : <EOL> release = '<STR_LIT>' <EOL> else : <EOL> release = '<STR_LIT>' <EOL> if system in ( '<STR_LIT:win32>' , '<STR_LIT>' ) : <EOL> if not version : <EOL> if system == '<STR_LIT:win32>' : <EOL> version = '<STR_LIT>' <EOL> else : <EOL> version = '<STR_LIT>' <EOL> system = '<STR_LIT>' <EOL> elif system [ : <NUM_LIT:4> ] == '<STR_LIT>' : <EOL> release , vendor , vminfo , osinfo = java_ver ( ) <EOL> system = '<STR_LIT>' <EOL> version = string . join ( vminfo , '<STR_LIT:U+002CU+0020>' ) <EOL> if not version : <EOL> version = vendor <EOL> if system == '<STR_LIT>' : <EOL> if not release or release == '<STR_LIT:0>' : <EOL> release = version <EOL> version = '<STR_LIT>' <EOL> try : <EOL> import vms_lib <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> csid , cpu_number = vms_lib . getsyi ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> if ( cpu_number >= <NUM_LIT> ) : <EOL> processor = '<STR_LIT>' <EOL> else : <EOL> processor = '<STR_LIT>' <EOL> if not processor : <EOL> processor = _syscmd_uname ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if system == '<STR_LIT>' : <EOL> system = '<STR_LIT>' <EOL> if node == '<STR_LIT>' : <EOL> node = '<STR_LIT>' <EOL> if release == '<STR_LIT>' : <EOL> release = '<STR_LIT>' <EOL> if version == '<STR_LIT>' : <EOL> version = '<STR_LIT>' <EOL> if machine == '<STR_LIT>' : <EOL> machine = '<STR_LIT>' <EOL> if processor == '<STR_LIT>' : <EOL> processor = '<STR_LIT>' <EOL> if system == '<STR_LIT>' and release == '<STR_LIT>' : <EOL> system = '<STR_LIT>' <EOL> release = '<STR_LIT>' <EOL> _uname_cache = system , node , release , version , machine , processor <EOL> return _uname_cache <EOL> def system ( ) : <EOL> """<STR_LIT>""" <EOL> return uname ( ) [ <NUM_LIT:0> ] <EOL> def node ( ) : <EOL> """<STR_LIT>""" <EOL> return uname ( ) [ <NUM_LIT:1> ] <EOL> def release ( ) : <EOL> """<STR_LIT>""" <EOL> return uname ( ) [ <NUM_LIT:2> ] <EOL> def version ( ) : <EOL> """<STR_LIT>""" <EOL> return uname ( ) [ <NUM_LIT:3> ] <EOL> def machine ( ) : <EOL> """<STR_LIT>""" <EOL> return uname ( ) [ <NUM_LIT:4> ] <EOL> def processor ( ) : <EOL> """<STR_LIT>""" <EOL> return uname ( ) [ <NUM_LIT:5> ] <EOL> _sys_version_parser = re . compile ( <EOL> r'<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> _ironpython_sys_version_parser = re . compile ( <EOL> r'<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> _ironpython26_sys_version_parser = re . compile ( <EOL> r'<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> _pypy_sys_version_parser = re . compile ( <EOL> r'<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> _pyston_sys_version_parser = re . compile ( <EOL> r'<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> _sys_version_cache = { } <EOL> def _sys_version ( sys_version = None ) : <EOL> """<STR_LIT>""" <EOL> if sys_version is None : <EOL> sys_version = sys . version <EOL> result = _sys_version_cache . get ( sys_version , None ) <EOL> if result is not None : <EOL> return result <EOL> if '<STR_LIT>' in sys_version : <EOL> name = '<STR_LIT>' <EOL> if sys_version . startswith ( '<STR_LIT>' ) : <EOL> match = _ironpython_sys_version_parser . match ( sys_version ) <EOL> else : <EOL> match = _ironpython26_sys_version_parser . match ( sys_version ) <EOL> if match is None : <EOL> raise ValueError ( <EOL> '<STR_LIT>' % <EOL> repr ( sys_version ) ) <EOL> version , alt_version , compiler = match . groups ( ) <EOL> buildno = '<STR_LIT>' <EOL> builddate = '<STR_LIT>' <EOL> elif sys . platform . startswith ( '<STR_LIT>' ) : <EOL> name = '<STR_LIT>' <EOL> match = _sys_version_parser . match ( sys_version ) <EOL> if match is None : <EOL> raise ValueError ( <EOL> '<STR_LIT>' % <EOL> repr ( sys_version ) ) <EOL> version , buildno , builddate , buildtime , _ = match . groups ( ) <EOL> compiler = sys . platform <EOL> elif "<STR_LIT>" in sys_version : <EOL> name = "<STR_LIT>" <EOL> match = _pypy_sys_version_parser . match ( sys_version ) <EOL> if match is None : <EOL> raise ValueError ( "<STR_LIT>" % <EOL> repr ( sys_version ) ) <EOL> version , buildno , builddate , buildtime = match . groups ( ) <EOL> compiler = "<STR_LIT>" <EOL> elif "<STR_LIT>" in sys_version : <EOL> name = "<STR_LIT>" <EOL> match = _pyston_sys_version_parser . match ( sys_version ) <EOL> if match is None : <EOL> raise ValueError ( "<STR_LIT>" % <EOL> repr ( sys_version ) ) <EOL> version , buildno = match . groups ( ) <EOL> builddate = "<STR_LIT>" <EOL> compiler = "<STR_LIT>" <EOL> else : <EOL> match = _sys_version_parser . match ( sys_version ) <EOL> if match is None : <EOL> raise ValueError ( <EOL> '<STR_LIT>' % <EOL> repr ( sys_version ) ) <EOL> version , buildno , builddate , buildtime , compiler = match . groups ( ) <EOL> name = '<STR_LIT>' <EOL> builddate = builddate + '<STR_LIT:U+0020>' + buildtime <EOL> if hasattr ( sys , '<STR_LIT>' ) : <EOL> _ , branch , revision = sys . subversion <EOL> else : <EOL> branch = '<STR_LIT>' <EOL> revision = '<STR_LIT>' <EOL> l = string . split ( version , '<STR_LIT:.>' ) <EOL> if len ( l ) == <NUM_LIT:2> : <EOL> l . append ( '<STR_LIT:0>' ) <EOL> version = string . join ( l , '<STR_LIT:.>' ) <EOL> result = ( name , version , branch , revision , buildno , builddate , compiler ) <EOL> _sys_version_cache [ sys_version ] = result <EOL> return result <EOL> def python_implementation ( ) : <EOL> """<STR_LIT>""" <EOL> return _sys_version ( ) [ <NUM_LIT:0> ] <EOL> def python_version ( ) : <EOL> """<STR_LIT>""" <EOL> return _sys_version ( ) [ <NUM_LIT:1> ] <EOL> def python_version_tuple ( ) : <EOL> """<STR_LIT>""" <EOL> return tuple ( string . split ( _sys_version ( ) [ <NUM_LIT:1> ] , '<STR_LIT:.>' ) ) <EOL> def python_branch ( ) : <EOL> """<STR_LIT>""" <EOL> return _sys_version ( ) [ <NUM_LIT:2> ] <EOL> def python_revision ( ) : <EOL> """<STR_LIT>""" <EOL> return _sys_version ( ) [ <NUM_LIT:3> ] <EOL> def python_build ( ) : <EOL> """<STR_LIT>""" <EOL> return _sys_version ( ) [ <NUM_LIT:4> : <NUM_LIT:6> ] <EOL> def python_compiler ( ) : <EOL> """<STR_LIT>""" <EOL> return _sys_version ( ) [ <NUM_LIT:6> ] <EOL> _platform_cache = { } <EOL> def platform ( aliased = <NUM_LIT:0> , terse = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> result = _platform_cache . get ( ( aliased , terse ) , None ) <EOL> if result is not None : <EOL> return result <EOL> system , node , release , version , machine , processor = uname ( ) <EOL> if machine == processor : <EOL> processor = '<STR_LIT>' <EOL> if aliased : <EOL> system , release , version = system_alias ( system , release , version ) <EOL> if system == '<STR_LIT>' : <EOL> rel , vers , csd , ptype = win32_ver ( version ) <EOL> if terse : <EOL> platform = _platform ( system , release ) <EOL> else : <EOL> platform = _platform ( system , release , version , csd ) <EOL> elif system in ( '<STR_LIT>' , ) : <EOL> distname , distversion , distid = dist ( '<STR_LIT>' ) <EOL> if distname and not terse : <EOL> platform = _platform ( system , release , machine , processor , <EOL> '<STR_LIT>' , <EOL> distname , distversion , distid ) <EOL> else : <EOL> libcname , libcversion = libc_ver ( sys . executable ) <EOL> platform = _platform ( system , release , machine , processor , <EOL> '<STR_LIT>' , <EOL> libcname + libcversion ) <EOL> elif system == '<STR_LIT>' : <EOL> r , v , vminfo , ( os_name , os_version , os_arch ) = java_ver ( ) <EOL> if terse or not os_name : <EOL> platform = _platform ( system , release , version ) <EOL> else : <EOL> platform = _platform ( system , release , version , <EOL> '<STR_LIT>' , <EOL> os_name , os_version , os_arch ) <EOL> elif system == '<STR_LIT>' : <EOL> if terse : <EOL> platform = _platform ( system , release ) <EOL> else : <EOL> platform = _platform ( system , release , machine ) <EOL> else : <EOL> if terse : <EOL> platform = _platform ( system , release ) <EOL> else : <EOL> bits , linkage = architecture ( sys . executable ) <EOL> platform = _platform ( system , release , machine , processor , bits , linkage ) <EOL> _platform_cache [ ( aliased , terse ) ] = platform <EOL> return platform <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> terse = ( '<STR_LIT>' in sys . argv or '<STR_LIT>' in sys . argv ) <EOL> aliased = ( not '<STR_LIT>' in sys . argv and not '<STR_LIT>' in sys . argv ) <EOL> print platform ( aliased , terse ) <EOL> sys . exit ( <NUM_LIT:0> ) </s>
