Faܷ@sdZdZdZddlZddlZddlZddlZddlZddlZy ej Z Wn0e k rej dkrdZ nd Z YnXd Z ejd ejZejd d d ddZddZejdejZejdejZejdejZdZd%d&Zejd'ejZejd(ejZejd)ejZd d d ed*d+d,Zd-d.Zd d d ed/d0Zd1dd2d3Z d d4d5Z!ejd6Z"d d d dd7d8Z#dd:dd;dd=dd>dd@ddAddBddDddEddGddHi Z$dd=ddIddJddKddLddMiZ%d d d d dNdOZ&dPdQZ'd dd dRdSZ(dTdUZ)d d dddVdWZ*dXdYZ+dZd[Z,d d\d]Z-d^d_Z.d d`daZ/d dbdcZ0ddddddiZ1ejd d dgdhZ2ej3didjZ4da5dkdlZ6dmdnZ7dodpZ8dqdrZ9dsdtZ:dudvZ;dwdxZ<ejdyejZ=ejdzejZ>ejd{Z?ejd|Z@iZAdd}d~ZBddZCddZDddZEddZFddZGddZHddZIiZJddddZ eKdkrdejLkpdejLkZMdejLkodejLkZNeOe eNeMejPddS)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 /usr/lib/python3.5/platform.py s zlibc_ver..Zlibcglibc) hasattrospathropenread _libc_searchsearchgroupslenend) executableZlibversionZ chunksizefZbinaryposmZlibcinitrZ glibcversionZsoZthreadsZ soversionr r r libc_versD "       # rc 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:     "#   r5z(\w+)[-_](release|version)z'(.+) release ([\d.]+)[^(]*(?:\((.+)\))?z1([^0-9]+)(?: release )?([\d.]+)[^(]*(?:\((.+)\))?r debianfedoraredhatcentosmandrakemandrivarocksr% yellowdoggentoo UnitedLinux turbolinuxarchmageiaUbuntucCsd}d}tj|}|dk r7t|jStj|}|dk rbt|jS|jj}|r|d}t|dkr|d}d||fS)Nrrr#)_lsb_release_versionmatchtupler_release_versionr)r(r) firstlinerr/rlr r r _parse_release_files    rJz(?:DISTRIB_ID\s*=)\s*(.*)z(?:DISTRIB_RELEASE\s*=)\s*(.*)z(?:DISTRIB_CODENAME\s*=)\s*(.*)r#cCs8ddl}|jdtddt|||||S)NrzFdist() and linux_distribution() functions are deprecated in Python 3.5 stacklevelr!)warningswarnPendingDeprecationWarning_linux_distribution)r.rr/supported_distsfull_distribution_namerLr r r linux_distribution0s    rRcCs ytdd}x|D]}tj|}|rL|jdj}tj|}|rv|jdj} tj|}|r|jdj} qW|r| r|| | fSWdQRXWnttfk rYnXyt j t } Wnt k r|||fSYnX| j x^| D]F} tj| }|dk r&|j\} }| |kr&| }Pq&Wt|||Stt jjt | 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. z/etc/lsb-releaserr#Nencodingzutf-8errorssurrogateescape)r_distributor_id_file_rergroupr)_release_file_re_codename_file_reEnvironmentErrorUnboundLocalErrorrr+ _UNIXCONFDIROSErrorr-_release_filenamerErr5rjoinreadlinerJ)r.rr/rPrQZ etclsbrelr0rZ _u_distnameZ _u_versionZ_u_idZetcfileZ _distnameZdummyrrHZ_versionZ_idr r r rO:sP        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.rr/rPrLr r r dists    rcrScCs5ddl}|jdtddtj|||S)z! Portable popen() interface. rNzuse os.popen insteadrKr!)rLrMDeprecationWarningrpopen)cmdmodebufsizerLr r r res rec 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 ValueErrorliststrr`)rbuildrIZintsZstringsr r r _norm_versions   rrz'(?:([\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#ri)rsrtrur&r&r&r&) sysplatformrrercloser^r) _ver_outputrErrr) systemreleaserZsupported_platformsrfpipeinfoZwhyrr r r _syscmd_vers,        r~Z2000ZXPr!Z 2003ServerZpost2003Vista78rjz8.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_MACHINErjz {0}.{1}.{2}r!zSP{} z Service Pack ZSPZ product_typez,SOFTWARE\Microsoft\Windows NT\CurrentVersionZ CurrentType)rvr ImportErrorwinregrrrr_winregZ_platform_versionformat_WIN32_CLIENT_RELEASESgetZservice_pack_majorAttributeErrorgetattr_WIN32_SERVER_RELEASES)r{rcsdptyperrrrrZwinverZmajminrqkeyr r r win32_ver sD & ' "    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)fnrrZplr{ 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)r{rrr}r r r mac_verRs  rc CsTddlm}y'|j|}|dkr2|S|SWntk rO|SYnXdS)Nr)System) java.langrZ getPropertyr)namedefaultrr2r r r _java_getpropes  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) r{vendorvminfoosinfojavaZvm_nameZ vm_releaseZ vm_vendoros_name os_versionos_archr r r java_verps"  rc Cs|dkrd|||fS|dkr|dkrB|||fS|jd}|ryt|d}Wntk rYn*X|d}t||dsz_platform.. _/\:;"()unknownrz--r#Nr&r&)r`filterrreplace)argsrwZcleanedr r r _platforms$%  rcCsTyddl}Wntk r(|SYnXy|jSWntk rO|SYnXdS)z8 Helper to determine the node name of this machine. rN)socketrZ gethostnamer^)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. )rrabspathislinknormpathr`dirnamereadlink)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) rvrwrreDEV_NULLrr^rr)rx)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. rrrrbstdoutstderrrzlatin-1N)rrr) rvrwr subprocessPopenPIPEZSTDOUTrr^Z 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) structZcalcsizeerrorrprrvrrw_default_architecture)rbitslinkagersizeZfileoutbrIr r r architecture9sL                   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.0rjrrrZ16bitrJavaz, ZOpenVMS0zSYI$_CPUZAlphaZVAXz-pr)rr) _uname_cacherrrrorrvrwrrenvironrr~rr`vms_librZgetsyirr)Z no_os_uname processorrznoder{rrZuse_syscmd_verrrrrrrZcsidZ cpu_numberr r r rs    +                      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. )rrzr r r r rzsrzcCs 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 r%srcCs 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. )rr{r r r r r{/sr{cCs 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 r8srcCs tjS)zt Returns the machine type, e.g. 'i386' An empty string is returned if the value cannot be determined. )rrr r r r rAsrcCs 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 rJs 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\} } } n0ttdrhtj\} } } 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 _mercurial subversionrir!r)rvr_sys_version_cacher startswith_ironpython_sys_version_parserrE _ironpython26_sys_version_parserrnreprrrw_sys_version_parser_pypy_sys_version_parserrrrr(rrkr`) sys_versionresultrrErZ alt_versionZcompilerZbuildnoZ builddateZ buildtimerZbranchZrevisionrIr r r _sys_versiontsx                 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#ri)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. rj)rr r r r python_revision s rcCstddS)zh Returns a tuple (buildno, builddate) stating the Python build number and date as strings. rr)rr r r r python_buildsrcCs tdS)zS Returns a string identifying the compiler used for compiling Python. r)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_warningsfilterwarningsrNrcrrvrrr)aliasedterserrzrr{rrrZrelZversrrrwr.Z distversionZdistidZlibcnameZ libcversionrSvrrrrrrr r r rw.s\           rw__main__r z--terseZ nonaliasedz --nonaliased)rrr)r r6r7r8r9r:r;r<r%r=r>r?r@rArBrCr&)rrr)rr)rr#)rr!)rN)rr)rr#)rr!)rrj)rN)rr)rN)rr!)rr)rr#)rr!)rrj)rN)rrr)rrr)rrr)rr)rr)rr)Q__doc__Z __copyright__ __version__ collectionsrvrrerrLdevnullrrrwr]compileASCIIrrrr5r_rDrGZ_supported_distsrJIrWrYrZrRrOrcrerrryr~rrrrrrrrrrrrrrr namedtuplerrrrzrr{rrrrrrrrrrrrrrrrr __name__argvr r printexitr r r r  sf 0        7 0       I  0  0  # 6   T       i   [