m %UIc@s/dZdZdZdkZdkZdkZdkZeidZei ddddZ dZ eid Z eid Z ddddCdZdfdYZdddZddZeidZddddDdZddZdddddZddZdZddEddZd ZdddFdGd!Zd"Zd#Zdd$Zeei d%p.ei i!ei i"ei#ei i$d&Z%n ei i&Z%d'Z'dd(Z(dd)Z)hddH<ddI<ddJe?d>jo]d?ei@jp d@ei@jZAdAei@jo dBei@jZBe>eBeAGHeiCd<ndS(Ks8 This module tries to retrieve as much platform-identifying data as possible. It makes this information available via function APIs. If called from the command line, it prints the platform information concatenated as single string to stdout. The output format is useable as part of a filename. s Copyright (c) 1999-2000, Marc-Andre Lemburg; mailto:mal@lemburg.com Copyright (c) 2000-2003, eGenix.com Software GmbH; mailto:info@egenix.com Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee or royalty is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation or portions thereof, including modifications, that you make. EGENIX.COM SOFTWARE GMBH DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE ! s1.0.2NsC(__libc_init)|(GLIBC_([0-9.]+))|(libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)ticCsit|d}|i|}d} x.ti|| } | p(|i|}|pPnd} q'n| i \}} } } }}|o| o d}n| o8|djod}| }qD| |jo | }qDng| o_|djoNd}||jo |}n|o&|t| |jo||}q@qDn| i} q'W|i||fS(s Tries to determine the libc version that the file executable (which defaults to the Python interpreter) is linked against. Returns a tuple of strings (lib,version) which default to the given parameters in case the lookup fails. Note that the function has intimate knowledge of how different libc versions add symbols to the executable and thus is probably only useable for executables compiled using gcc. The file is read and scanned in chunks of chunksize bytes. trbiitlibctglibcN(topent executabletftreadt chunksizetbinarytpost _libc_searchtsearchtmtgroupstlibcinitRt glibcversiontsotthreadst soversiontlibtversiontlentendtclose(RRRRR RRRRR R RRR((t%/data/zmath/lib/python2.4/platform.pytlibc_verws@        c Cstiidotdi}d}x|D]} ti | }t |djo|\}} nq2|djoti| }q2|djo ti | d}|d}q2q2W|||fSntiidortdi}x]|D]Q} ti | d} t | djo&| dd jod | d |fSqqWntiid otid }xDtt |d d d D]&}||d djo ||=qqW|o/|id}|d d }|||fSqn|||fS(s Tries some special tricks to get the distribution information in case the default method fails. Currently supports older SuSE Linux, Caldera OpenLinux and Slackware Linux distributions. s/var/adm/inst-log/infotSuSEitMIN_DIST_VERSIONt DIST_IDENTt-s/etc/.installedit OpenLinuxis/usr/lib/setupiisslack-version-t slackwareN(tostpathtexistsRt readlinestinfotdistnametlinetstringtsplitttvRttagtvaluetstripRtvaluestidtpkgtisdirtlistdirtverfilestrangetntsort( R&RR/R%R*R+R5R3R.R,R'R0((Rt_dist_try_hardersF  $ s(\w+)[-_](release|version)s([\d.]+)[^(]*(?:\((.+)\))?RtdebiantredhattmandrakecCspytid} Wn#tij o|||fSnXxb| D]J} ti | }|o.|i \} }| |jo | }Pqq@q@Wt|||Std| d}|i} |iti| }|o8|i \}} |o |}n| o | }qcnOtiti| }|o/|d}t|djo|d}qcn|||fS(sQ Tries to determine the name of the Linux OS distribution name. The function first looks for a distribution release file in /etc and then reverts to _dist_try_harder() in case no suitable files are found. Returns a tuple (distname,version,id) which default to the args given as parameters. s/etcs/etc/triiN(R!R2tetcterrorR&RR/tfilet_release_filenametmatchR Rt _distnametdummytsupported_distsR7RRtreadlinet firstlineRt_release_versionR t_versiont_idR(R)R-tlR(R&RR/RCRBRR RGRIR<R>RARHRE((Rtdists<       t_popencBsbtZdZdZeZeZdZdedZdZ dZ e i e i dZeZRS(s Fairly portable (alternative) popen implementation. This is mostly needed in case os.popen() is not available, or doesn't work as advertised, e.g. in Win9X GUI programs like PythonWin or IDLE. Writing to the pipe is currently not supported. RR;cCss|djo tdndk}|i|_}ti|d|t |d|_ ||_ ||_dS(NR;s)popen()-emulation only supports read modes > %sR( tmodet ValueErrorttempfiletmktemptselfttmpfileR!tsystemtcmdRtpipetbufsize(RPRSRLRURQRN((Rt__init__s    cCs |iiS(N(RPRTR(RP((RR&scCs%|idj o|iiSndS(N(RPRUtNoneRTR$(RP((RR$*scCs\|io|ii}nd}|io+y||iWqX|j oqXXn|S(Ni(RPRTRtrcRQtremoveR=(RPRYR=RX((RR/s   (t__name__t __module__t__doc__RQRWRTRURLRVRR$R!tunlinkR=Rt__del__(((RRK s   R;cCsd}tiidddjo0y dk}Wntj oqRX|i}n|djohttdoNti}ti djo1y|dWqti j o t }qXqqt }n|djo|||Sn||||SdS(s! Portable popen() interface. tOSRt Windows_NTNtpopentwin32(RWRaR!tenvirontgett win32pipet ImportErrorthasattrtsystplatformR=RKRURSRL(RSRLRURaRe((RRaAs(      cCsti|d}|o|i|nytt|}Wnt j o |}nXtt |}ti |d d}|S(s Normalize the version and build strings and return a single version string using the format major.minor.build (or patchlevel). t.iN( R(R)RRItbuildtappendtmaptinttintsRMtstringststrtjoin(RRkRIRpRo((Rt _norm_versionbs s((?:([\w ]+) ([\w.]+) .*Version ([\d.]+))Rbtwin16tdostos2c CsCti|jo|||fSnxdD]u}y9t|}|i }|i ot i dnWn2t i j o }q(q(tj o }q(q(XPq(W|||fSti|}ti|}|oc|i\}}}|ddjo|d }n|ddjo|d }nt|}n|||fS( s2 Tries to figure out the OS version used and returns a tuple (system,release,version). It uses the "ver" shell command for this which is known to exists on Windows, DOS and OS/2. XXX Others too ? In case this fails, the given parameters are used as defaults. tverscommand /c vers cmd /c verscommand failediRjN(Rwscommand /c vers cmd /c ver(RhRitsupported_platformsRRtreleaseRRSRaRTRR%RR!R=twhytIOErrorR(R-t _ver_outputR@R RRs( RRRyRRxR%RTRSR Rz((Rt _syscmd_verws4     cCs0dkl}y|||SWn |SnXdS(se Read a value for name from the registry key. In case this fails, default is returned. (sRegQueryValueExN(twin32apitRegQueryValueExtkeytnametdefault(RRRR((Rt_win32_getvalues  cCsy dk}Wn#tj o||||fSnXdkl}l}l}l }dk l } l }l }|\} } }} }d| | |d@f}|d djod|d}n| |jo}d }| d joO| d jo d }qC| d jo d}qC| djo d}qCd}q| djo d}qn| |jo}d}| d jo d}q| djoO| d jo d}q| djo d}q| djo d}qd}qn,|pd| | f}n||||fSy || |}||dWn||||fSnXt|dd d } t|d|dfd }t|| }||||||fS(!s Get additional version information from the Windows Registry and return a tuple (version,csd,ptype) referring to version number, CSD level and OS type (multi/single processor). As a hint: ptype returns 'Uniprocessor Free' on single processor NT machines and 'Multiprocessor Free' on multi processor machines. The 'Free' refers to the OS version being free of debugging code. It could also state 'Checked' which means the OS version uses debugging code, i.e. code that checks arguments, ranges, etc. (Thomas Heller). Note: this function only works if Mark Hammond's win32 package is installed and obviously only runs on Win32 compatible platforms. N(sRegQueryValueExs RegOpenKeyExs RegCloseKeys GetVersionEx(sHKEY_LOCAL_MACHINEsVER_PLATFORM_WIN32_NTsVER_PLATFORM_WIN32_WINDOWSs%i.%i.%iii s Service Pack tSPs)SOFTWARE\Microsoft\Windows\CurrentVersioniit95i t98iZtMetpostMeit2000s,SOFTWARE\Microsoft\Windows NT\CurrentVersiontNTitXPit 2003Servertpost2003s%i.%it SystemRoottCurrentBuildNumberRt CurrentType(Ri(R~RfRyRtcsdtptypeRt RegOpenKeyExt RegCloseKeyt GetVersionExtwin32contHKEY_LOCAL_MACHINEtVER_PLATFORM_WIN32_NTtVER_PLATFORM_WIN32_WINDOWStmajtmintbuildnotplattregkeyt keyCurVerRRkRs(RyRRRRRRRRRRkRRRRRRRR~((Rt win32_versh                        cCswdkl}dk}g}|i}xK|D]C}y|||Wq,t|ifj o||q,Xq,W|S(N(sgestalt( tgestalttMacOSRIRlt selectorstselectort RuntimeErrortErrorR(RRRRIRRRl((Rt_mac_ver_lookups   cCst|dS(Ni(thextbcd(R((Rt_bcd2str+scCsydk} dk}Wn tj o|||fSnXtd!\}} } |oC|d@d?}|d@d?} |d @}d t || |f}n| ot| d @d ?}| d @d?} | d@d?}| d@d?}| d@}d t || |f} t |}hdd<dd<dd<dd /dev/nullN(Ruswin32swin16sos2(RhRiRR!RatoptionRtAttributeErrorR=R(R-RtoutputRRX(RRRRXR((Rt _syscmd_unames  cCst|}ytid|}Wn ttifj o |SnXti |i }|i }| p|o|Sn|SdS(s& Interface to the system's file command. The function uses the -b option of the file command to have it ommit the filename in its output and if possible the -L option to have the command follow symlinks. It returns default in case the command should fail. sfile %s 2> /dev/nullN(RttargetR!RaRRR=RR(R-RRRRX(RRRRXR((Rt _syscmd_file!s    t WindowsPERtMSDOSs[\s,]c Cs|p\dk}y|id}Wn%|ij o|id}nXt|dd}nt|d}| oj|t ijoZt i t i o9t t i \}}|o |}n|o |}qn||fSnt|d}d|jo||fSnd |jo d }n/d |jo d }nd |jo d}nd|jo d}n]d|jo!d|jo d}qd}n/d|jo d}nd|jo d}n||fS(s Queries the given executable (defaults to the Python interpreter binary) for various architecture information. Returns a tuple (bits,linkage) which contains information about the bit architecture and the linkage format used for the executable. Both values are returned as strings. Values that cannot be determined are returned as given by the parameter presets. If bits is given as '', the sizeof(pointer) (or sizeof(long) on Python version < 1.5.2) is used as indicator for the supported pointer size. The function relies on the system's "file" command to do the actual work. This is available on most if not all Unix platforms. On some non-Unix platforms where the "file" command does not exist and the executable is set to the Python interpreter binary defaults from _default_architecture are used. NtPRIitbitRiRs32-bitt32bittN32tn32bits64-bitRtELFtPERRtCOFFsMS-DOSR(tbitststructtcalcsizetsizeR=RqRRRRht_default_architecturethas_keyRitbRItlinkaget_architecture_splittfileout( RRRRRR RIRR((Rt architectureCsL                   cCstdj otSnyti\}}}}}Wnt j ost i }d}d}t }d}d}d} |djo1t\}}}}|o|o d} qn| o0t|\}}}|djo d}qn|djo2|p!|djo d}qd }nd}qS|d d joBt\}} }}d }ti|d }|p | }qqStidjo%t\}\}} }}d}qSnX|djo| p |djo|}d}ny dk}Wntj oqSX|idd\} } | djo d}qSd}nt"dd}|djo d}n|djo d}n|djo d}n|djo d}n|djo d}n|djo d}n||||||fatS(si Fairly portable uname interface. Returns a tuple of strings (system,node,release,version,machine,processor) identifying the underlying platform. Note that unlike the os.uname function this also returns possible processor information as an additional tuple entry. Entries which cannot be determined are set to ''. RiRbisMicrosoft WindowsRRtRt16bitiRtJavas, tmacRtOpenVMSt0NsSYI$_CPUitAlphatVAXs-pR(swin32swin16(#t _uname_cacheRWR!tunameRRtnodeRyRRRRhRiRt processortuse_syscmd_verRRRR}RRRRR(RrRRRRtvms_libRftgetsyitcsidt cpu_numberR(RRRRRRRRRRRRRRRRRyR((RRs                             cCs tdS(s Returns the system/OS name, e.g. 'Linux', 'Windows' or 'Java'. An empty string is returned if the value cannot be determined. iN(R(((RRRscCs tdS(s Returns the computer's network name (which may not be fully qualified) An empty string is returned if the value cannot be determined. iN(R(((RRscCs tdS(s Returns the system's release, e.g. '2.2.0' or 'NT' An empty string is returned if the value cannot be determined. iN(R(((RRyscCs tdS(s Returns the system's release version, e.g. '#3 on degas' An empty string is returned if the value cannot be determined. iN(R(((RR!scCs tdS(st Returns the machine type, e.g. 'i386' An empty string is returned if the value cannot be determined. iN(R(((RR*scCs tdS(s Returns the (true) processor name, e.g. 'amdk6' An empty string is returned if the value cannot be determined. Note that many platforms do not provide this information or simply return the same value as for machine(), e.g. NetBSD does this. iN(R(((RR3s s?([\w.+]+)\s*\(#(\d+),\s*([\w ]+),\s*([\w :]+)\)\s*\[([^\]]+)\]?cCstdj otSntitii\}}}}}t |}|d|}t i |d}t|djo#|idt i|d}n||||fatS(s Returns a parsed version of Python's sys.version as tuple (version, buildno, builddate, compiler) referring to the Python version, build number, build date/time as string and the compiler identification string. Note that unlike the Python sys.version, the returned value for the Python version will always include the patchlevel (it defaults to '.0'). RRjiRN(t_sys_version_cacheRWt_sys_version_parserR@RhRRRt builddatet buildtimetcompilerRnR(R)RIRRlRr(RRRIRRR ((Rt _sys_versionFs  '  cCs tdS(s Returns the Python version as string 'major.minor.patchlevel' Note that unlike the Python sys.version, the returned value will always include the patchlevel (it defaults to 0). iN(R!(((Rtpython_versionascCstitddS(s Returns the Python version as tuple (major, minor, patchlevel) of strings. Note that unlike the Python sys.version, the returned value will always include the patchlevel (it defaults to 0). iRjN(R(R)R!(((Rtpython_version_tuplekscCstdd!S(sh Returns a tuple (buildno, builddate) stating the Python build number and date as strings. iiN(R!(((Rt python_buildvscCs tdS(sS Returns a string identifying the compiler used for compiling Python. iN(R!(((Rtpython_compiler~sic Cspti||fd}|dj o|Snt\} }}} } }| |jo d}n|ot | || \} }} n| djoKt| \}}} }|ot| |}q\t| || | }n| d jotd\}}}|o-| o%t| || |d|||}q\tti\}}t| || |d||}n| djo]t\}}}\}}} |ot| || }q\t| || d||| }n| djo0|ot| |}q\t| || }nK|ot| |}n1t%ti\}}t| || |||}|t||f<|S( s Returns a single string identifying the underlying platform with as much useful information as possible (but no more :). The output is intended to be human readable rather than machine parseable. It may look different on different platforms and this is intended. If "aliased" is true, the function will use aliases for various platforms that report system names which differ from their common names, e.g. SunOS will be reported as Solaris. The system_alias() function is used to implement this. Setting terse to true causes the function to return only the absolute minimum information needed to identify the platform. RRtLinuxtwithR tonRN(R&((t_platform_cacheRdtaliasedtterseRWtresultRRRRRyRRRRRtreltversRRRRiRJR&t distversiontdistidRRhRtlibcnamet libcversionRR;tvRRRRR RR(R*R+RR.RR,R0R1RiRRRRRRR-R/RRRRRR&R;R3RyRR2((RRisR        t__main__R+s--terset nonaliaseds --nonaliased(sSuSER8R9R:(swin32swin16sdossos2(RRR(RRR(RRR(Rs WindowsPE(RsWindows(RsMSDOS(DR\t __copyright__t __version__RhR(R!tretcompileR RRR7R?RFRJRKRWRaRsR|R}RRRRRRRRRRRgR"RRrRRRRRRRRR)R R RRRRRRyRRRRRR!R"R#R$R%R)RiRZtargvR+R*texit(3RJR"R+R R$RR|RsR?RRR7RRRR RiRRRRRR8RRR%R7RR(RFRhRR)R}RKR6RRRRRRaRR#R*R!RR RRyR!R((Rt? snL$0 2/6! 4 f 1 # 6 $ .   !T l    R