YfC@sdZdZdZddlZddlZddlZddlZddlZddlZy ej Z Wn0e k rej dkrdZ nd Z YnXd Z ejd ejZejd d d ddZddZejdejZejdejZejdejZdZd$d%Zd d d ed&d'd(Zd)d*Zd d d ed+d,Zd-dd.d/Zd d0d1Zejd2Zd d d dd3d4Zdd6dd7dd9dd:dd<dd=dd>dd@ddAddCddDi Z dd9ddEddFddGddHddIiZ!d d d d dJdKZ"dLdMZ#d dd dNdOZ$dPdQZ%d d dddRdSZ&dTdUZ'dVdWZ(d dXdYZ)dZd[Z*d d\d]Z+d d^d_Z,ddddddiZ-ejd d dcddZ.ej/dedfZ0da1dgdhZ2didjZ3dkdlZ4dmdnZ5dodpZ6dqdrZ7dsdtZ8ejduejZ9ejdvejZ:ejdwZ;ejdxZ<iZ=ddydzZ>d{d|Z?d}d~Z@ddZAddZBddZCddZDddZEiZFddddZ eGdkrdejHkp`dejHkZIdejHko~dejHkZJeKe eJeIejLddS)a8 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. a Copyright (c) 1999-2000, Marc-Andre Lemburg; mailto:mal@lemburg.com Copyright (c) 2000-2010, 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 ! z1.0.7Ndoswin32win16ZNULz /dev/nullz/etcsC(__libc_init)|(GLIBC_([0-9.]+))|(libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)i@c Csttjdr$tjj|}t|d[}|j|}d}x<d|ksfd|kr{tj||}nd}|s|j|}|sPd}qNdd|jD\}} } } } } |r| rd }n| r|d krd }| }qz| |krz| }n]| rz|d krzd }| rM| |krM| }| rz|t |  d| krz|| }|j }qNWWdQRX||fS) a 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. realpathrbrslibcsGLIBCNcSs1g|]'}|dk r'|jdn|qS)Nlatin1)decode).0sr -/opt/alt/python35/lib64/python3.5/platform.py s zlibc_ver..Zlibcglibc) hasattrospathropenread _libc_searchsearchgroupslenend) executablelibversionZ chunksizefZbinaryposmZlibcinitrZ glibcversionZsoZthreadsZ soversionr r r libc_versD "       # r c Cstjjdrd}xtdD]v}|j}t|dkr%|\}}nq%|dkrv|j}q%|dkr%|jd}|d}q%W|||fStjjdrxVtdD]H}|jd}t|dkr|dd krd |d |fSqWtjjd rtjd } xEt t| d ddD]'} | | d d dkrU| | =qUW| r| j d}| dd d }|||fS|||fS)z 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. z/var/adm/inst-log/infoSuSEZMIN_DIST_VERSIONZ DIST_IDENT-z/etc/.installedrZ OpenLinuxz/usr/lib/setupNzslack-version- slackwarer'r') rrexistsrsplitrstripisdirlistdirrangesort) distnameridlineZtvtagvaluevaluesZpkgZverfilesnr r r _dist_try_harders:     "#   r6z(\w+)[-_](release|version)z'(.+) release ([\d.]+)[^(]*(?:\((.+)\))?z1([^0-9]+)(?: release )?([\d.]+)[^(]*(?:\((.+)\))?r!debianfedoraredhatcentosmandrakemandrivarocksr& yellowdoggentoo UnitedLinux turbolinuxarchmageiacCsd}d}tj|}|dk r7t|jStj|}|dk rbt|jS|jj}|r|d}t|dkr|d}d||fS)Nrrr$)_lsb_release_versionmatchtupler_release_versionr*r)r) firstlinerr0rlr r r _parse_release_files    rJr$cCs8ddl}|jdtddt|||||S)NrzFdist() and linux_distribution() functions are deprecated in Python 3.5 stacklevelr")warningswarnPendingDeprecationWarning_linux_distribution)r/rr0supported_distsfull_distribution_namerLr r r linux_distribution,s    rRcCs,ytjt}Wntk r4|||fSYnX|jx^|D]F}tj|}|dk rF|j\}} ||krF|}PqFWt|||St tj j t|ddddd} | j } WdQRXt | \}} } |r|r|}| r| }| r| }|||fS)a 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. supported_dists may be given to define the set of Linux distributions to look for. It defaults to a list of currently supported Linux distributions identified by their release file name. If full_distribution_name is true (default), the full distribution read from the OS is returned. Otherwise the short name taken from supported_dists is used. Returns a tuple (distname, version, id) which default to the args given as parameters. Nrencodingzutf-8errorssurrogateescape)rr, _UNIXCONFDIROSErrorr._release_filenamerErr6rrjoinreadlinerJ)r/rr0rPrQZetcfilerZ _distnameZdummyrrHZ_versionZ_idr r r rO6s0      rOcCs>ddl}|jdtddt|||d|ddS)aS 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. rNzFdist() and linux_distribution() functions are deprecated in Python 3.5rKr"rPrQ)rLrMrNrO)r/rr0rPrLr r r distls    r]rScCs5ddl}|jdtddtj|||S)z! Portable popen() interface. rNzuse os.popen insteadrKr")rLrMDeprecationWarningrpopen)cmdmodebufsizerLr r r r_s r_c Cs|jd}|r"|j|ytt|}Wntk rO|}YnXttt|}dj|dd}|S)z Normalize the version and build strings and return a single version string using the format major.minor.build (or patchlevel). .N)r)appendmapint ValueErrorliststrrZ)rbuildrIZintsZstringsr r r _norm_versions   rlz'(?:([\w ]+) ([\w.]+) .*\[.* ([\d.]+)\])c Cs2tj|kr|||fSx~dD]i}y7tj|}|j}|jr_tdWn(tk r}zw#WYdd}~Xq#XPq#W|||fS|j}tj |}|dk r%|j \}}}|d dkr|dd }|d dkr|dd }t |}|||fS) a+ 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. XXX Others too ? In case this fails, the given parameters are used as defaults. vercommand /c ver cmd /c verzcommand failedNr$rc)rmrnror'r'r'r') sysplatformrr_rcloserXr* _ver_outputrErrl) systemreleaserZsupported_platformsr`pipeinfoZwhyrr r r _syscmd_vers,        rxZ2000ZXPr"Z 2003ServerZpost2003Vista78rdz8.1zpost8.1 Z10Zpost10Z 2008ServerZ 2008ServerR2Z 2012ServerZ 2012ServerR2Zpost2012ServerR2c(Csyddlm}Wn"tk r8||||fSYnXy&ddlm}m}m}m}Wn4tk rddlm}m}m}m}YnX|} | j p| dd\} } } dj | | | }t j | | fpt j | dfp|}| dd| | fkrwydj | j }Wn<tk rv|ddd krrd |dd}YnXt| d ddkrtj | | fptj | dfp|}d} z5y&||d } || d d}WnYnXWd| r || X||||fS)Nr)getwindowsversion) OpenKeyEx QueryValueExCloseKeyHKEY_LOCAL_MACHINErdz {0}.{1}.{2}r"zSP{} z Service Pack ZSPZ product_typez,SOFTWARE\Microsoft\Windows NT\CurrentVersionZ CurrentType)rpr ImportErrorwinregrrrr_winregZ_platform_versionformat_WIN32_CLIENT_RELEASESgetZservice_pack_majorAttributeErrorgetattr_WIN32_SERVER_RELEASES)rurcsdptyperrrrrZwinverZmajminrkkeyr r r win32_versD & ' "    rcCsd}tjj|sdSyddl}Wntk rDdSYnXt|d}|j|}WdQRX|d}d }tjj}|d krd}|||fS) Nz0/System/Library/CoreServices/SystemVersion.plistrrZProductVersionrppcPower MacintoshZPowerPC)rrr)rr) rrr(plistlibrrloadunamemachine)fnrrZplru versioninforr r r _mac_ver_xml%s    rcCs&t}|dk r|S|||fS)a< Get MacOS version information and return it as tuple (release, versioninfo, machine) with versioninfo being a tuple (version, dev_stage, non_release_version). Entries which cannot be determined are set to the parameter values which default to ''. All tuple entries are strings. N)r)rurrrwr r r mac_ver;s  rc CsTddlm}y'|j|}|dkr2|S|SWntk rO|SYnXdS)Nr)System) java.langrZ getPropertyr)namedefaultrr3r r r _java_getpropNs  rc Csyddl}Wn"tk r4||||fSYnXtd|}td|}|\}}}td|}td|}td|}|||f}|\}} } td| } td |}td | } || | f}||||fS) a] Version interface for Jython. Returns a tuple (release, vendor, vminfo, osinfo) with vminfo being a tuple (vm_name, vm_release, vm_vendor) and osinfo being a tuple (os_name, os_version, os_arch). Values which cannot be determined are set to the defaults given as parameters (which all default to ''). rNz java.vendorz java.versionz java.vm.namezjava.vm.vendorzjava.vm.versionz java.os.archz java.os.namezjava.os.version)rrr) ruvendorvminfoosinfojavaZvm_nameZ vm_releaseZ vm_vendoros_name os_versionos_archr r r java_verYs"  rc Cs|dkrd|||fS|dkr|dkrB|||fS|jd}|ryt|d}Wntk rYn*X|d}t||dsz_platform.. _/\:;"()unknownrz--r$Nr'r')rZfilterrreplace)argsrqZcleanedr r r _platforms$%  rcCsTyddl}Wntk r(|SYnXy|jSWntk rO|SYnXdS)z8 Helper to determine the node name of this machine. rN)socketrZ gethostnamerX)rrr r r _nodes   rcCsetjj|}xLtjj|r`tjjtjjtjj|tj|}qW|S)zT In case filepath is a symlink, follow it until a real file is reached. )rrabspathislinknormpathrZdirnamereadlink)filepathr r r _follow_symlinkss  1rc Cstjdkr|Sytjd|tf}Wnttfk rN|SYnX|jj}|j }| sz|r~|S|SdS)z. Interface to the system's uname command. rrrzuname %s 2> %sN)rrr) rprqrr_DEV_NULLrrXrr*rr)Zoptionrroutputrcr r r _syscmd_unames   rc Cstjd kr|St|}y+tjd|gdtjdtj}Wnttfk rh|SYnX|j dj d}|j }| s|r|S|Sd S) z Interface to the system's file command. The function uses the -b option of the file command to have it omit the filename in its output. Follow the symlinks. It returns default in case the command should fail. rrrr\stdoutstderrrzlatin-1N)rrr) rprqr subprocessPopenPIPEZSTDOUTrrXZ communicater wait)targetrprocrrr r r _syscmd_files     r WindowsPErMSDOSc Cs|s`ddl}y|jd}Wn$|jk rK|jd}YnXt|dd}|rxt|d}nd}| r|tjkrtjtkrttj\}}|r|}|r|}||fSd|kr||fSd |krd }n'd |krd }nd |kr*d}d|kr?d}nTd|krid|kr`d}qd}n*d|kr~d}nd|krd}n||fS)a 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. rNPrIZbitrrz32-bit32bitZN32Zn32bitz64-bitrZELFZPErrZCOFFzMS-DOSr) structZcalcsizeerrorrjrrprrq_default_architecture)rbitslinkagersizeZfileoutbrIr r r architecture"sL                   r uname_resultz-system node release version machine processorcCs}d}tdk rtSd}ytj\}}}}}Wntk rUd}YnX|sttd|||||f r6|rtj}d}d}t}d}d}|dkrAt \}}}} |r|rd}|s&dtj krtj j dd}ntj j dd}|sAtj j d|}|rt |\}}}|d krqd }nC|d kr|d krd }d |dd krd}nd}|dkr|s|dkrd}nd}d }nL|dddkr6t \}} } } d}dj| }|s6| }|dkr| sU|dkra|}d}yddl} Wntk rYn4X| jdd\}}|dkrd}nd}|stdd}|dkrd}|dkrd}|dkrd}|dkrd}|dkr(d}|dkr:d}|d kr^|d kr^d }d}t||||||atS)an 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 ''. rNrr$rZPROCESSOR_ARCHITEW6432ZPROCESSOR_ARCHITECTUREZPROCESSOR_IDENTIFIERzMicrosoft WindowsrZ Microsoftz6.0rdr{rrZ16bitrJavaz, ZOpenVMS0zSYI$_CPUZAlphaZVAXz-pr)rr) _uname_cacherrrrirrprqrrenvironrrxrrZvms_librZgetsyirr)Z no_os_uname processorrtnoderurrZuse_syscmd_verrrrrrrZcsidZ cpu_numberr r r r{s    +                      rcCs tjS)z Returns the system/OS name, e.g. 'Linux', 'Windows' or 'Java'. An empty string is returned if the value cannot be determined. )rrtr r r r rtsrtcCs tjS)z Returns the computer's network name (which may not be fully qualified) An empty string is returned if the value cannot be determined. )rrr r r r rsrcCs tjS)z Returns the system's release, e.g. '2.2.0' or 'NT' An empty string is returned if the value cannot be determined. )rrur r r r rusrucCs tjS)z Returns the system's release version, e.g. '#3 on degas' An empty string is returned if the value cannot be determined. )rrr r r r r!srcCs tjS)zt Returns the machine type, e.g. 'i386' An empty string is returned if the value cannot be determined. )rrr r r r r*srcCs tjS)a 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. )rrr r r r r3s rzL([\w.+]+)\s*\(#?([^,]+)(?:,\s*([\w ]*)(?:,\s*([\w :]*))?)?\)\s*\[([^\]]+)\]?z;IronPython\s*([\d\.]+)(?: \(([\d\.]+)\))? on (.NET [\d\.]+)zU([\d.]+)\s*\(IronPython\s*[\d.]+\s*\(([\d.]+)\) on ([\w.]+ [\d.]+(?: \(\d+-bit\))?)\)zE([\w.+]+)\s*\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*\[PyPy [^\]]+\]?cCs|dkrtj}tj|d}|dk r7|Sd|krd}|jdrjtj|}ntj|}|dkrtdt ||j \}}}d}d}natj jdrAd}t j|}|dkrtdt ||j \}}}} } |dkr5d}tj }nd|krd}t j|}|dkrtd t ||j \}}}} d}n{t j|}|dkrtd t ||j \}}}} }d }|dkr d}n| r |d | }ttd rDtj\} } } nTttdrhtj\} } } n0ttdrtj\} } } n d} d} |jd} t| dkr| jddj| }||| | |||f}|t|<|S)a Returns a parsed version of Python's sys.version as tuple (name, version, branch, revision, buildno, builddate, compiler) referring to the Python implementation name, version, branch, revision, 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'). The function returns empty strings for tuple entries that cannot be determined. sys_version may be given to parse an alternative version string, e.g. if the version was read from a different Python interpreter. NZ IronPythonz*failed to parse IronPython sys.version: %srrZJythonz&failed to parse Jython sys.version: %sZPyPyz$failed to parse PyPy sys.version: %sz'failed to parse CPython sys.version: %sZCPythonr_git _mercurial subversionrcr"r)rpr_sys_version_cacher startswith_ironpython_sys_version_parserrE _ironpython26_sys_version_parserrhreprrrq_sys_version_parser_pypy_sys_version_parserrrrrr)rrerZ) sys_versionresultrrErZ alt_versionZcompilerZbuildnoZ builddateZ buildtimerZbranchZrevisionrIr r r _sys_version]s|                 rcCs tdS)aR Returns a string identifying the Python implementation. Currently, the following implementations are identified: 'CPython' (C implementation of Python), 'IronPython' (.NET implementation of Python), 'Jython' (Java implementation of Python), 'PyPy' (Python implementation of Python). r)rr r r r python_implementations rcCs tdS)z 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). r$)rr r r r python_versionsrcCsttdjdS)z 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). r$rc)rFrr)r r r r python_version_tuples rcCs tdS)z Returns a string identifying the Python implementation branch. For CPython this is the Subversion branch from which the Python binary was built. If not available, an empty string is returned. r")rr r r r python_branchs rcCs tdS)z Returns a string identifying the Python implementation revision. For CPython this is the Subversion revision from which the Python binary was built. If not available, an empty string is returned. rd)rr r r r python_revisions rcCstddS)zh Returns a tuple (buildno, builddate) stating the Python build number and date as strings. rrz)rr r r r python_buildsrcCs tdS)zS Returns a string identifying the compiler used for compiling Python. rz)rr r r r python_compiler srcCs|tj||fd}|dk r(|St\}}}}}}||krUd}|rvt|||\}}}|dkrt|\} } } } |rt||} qht|||| } n|d krztj-tjddt t d\}}}WdQRX|rC| rCt||||d|||} qht t j \}}t||||d||} n|dkrt\}}}\}}}|s| rt|||} qht|||d |||} n|d kr |r t||} qht|||} nH|r8t||} n0tt j \}}t||||||} | t||f<| S) a 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. NrrLinuxignorez?dist\(\) and linux_distribution\(\) functions are deprecated .*withrZonZMacOS)r)_platform_cacherrrrrrLcatch_warningsfilterwarningsrNr]r rprrr)aliasedterserrtrrurrrZrelZversrrrqr/Z distversionZdistidZlibcnameZ libcversionrSvrrrrrrr r r rqs\           rq__main__rz--terseZ nonaliasedz --nonaliased)rrr)r!r7r8r9r:r;r<r=r&r>r?r@rArBrCr')rrr)ryr)ryr$)ryr")ryN)rzr)rzr$)rzr")rzrd)rzN)r~r)r~N)ryr")rzr)rzr$)rzr")rzrd)rzN)rrr)rrr)rrr)rr)rr)rr)M__doc__Z __copyright__ __version__ collectionsrprrerrLdevnullrrrqrWcompileASCIIrrr r6rYrDrGZ_supported_distsrJrRrOr]r_rlrsrxrrrrrrrrrrrrrrr namedtuplerrrrtrrurrrrrrrrrrrrrrrrr__name__argvrrprintexitr r r r  sf 0        7 0       6  0  0  # 6   T       k   [