U e5d @sldZdZdZddlZddlZddlZddlZddddddd d d d d Zed Z d dZ edej Z dwddZ dxddZedZdyddZddddddd d!d"d#d$d% Zdd&d'd(d)d*d+Zd,d-Zd.d/Zdzd0d1Zd2d3Zd{d5d6Zd7d8Zd|d9d:Zd;d<Zd=d>Zd}d?d@ZdAdBZd~dCdDZddEdFZdGdHdIdZ ej!ddfdJdKZ"e#dLdMZ$da%dNdOZ&dPdQZ'dRdSZ(dTdUZ)dVdWZ*dXdYZ+dZd[Z,ed\ej Z-ed]ej Z.ed^Z/ed_Z0iZ1dd`daZ2dbdcZ3dddeZ4dfdgZ5dhdiZ6djdkZ7dldmZ8dndoZ9iZ:ddpdqZ;eduej=koNdvej=kZ?e@e;e?e>eAddS)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.8N (2) ZdevZalphaaZbetabcZRCZrcplpz([0-9]+|[._+-])c Csbg}t|D]N}|dkrzt|d}d}Wn tk rLt|d}YnX|||fq|S)Nz._+-rdr) _component_resplitint ValueError _ver_stagesgetextend)versionresultvtr /usr/lib64/python3.8/platform.py_comparable_versions rsC(__libc_init)|(GLIBC_([0-9.]+))|(libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)@c Cs|dkrZz0td}|jdd}t|dkr6t|WSWntttfk rRYnXtj }t }t tj drvtj |}t|d`}||}d} | t|krd |ksd |krt|| } nd} | r| t|kr||} | r |t| t|d d| }d} q| sqd d | D\} } }}}}| rF|sFd}n| rx|dkr`d}|}n||||kr|}n\|r|dkrd}|r|r||||kr|}|r|t| d|kr||}| } qW5QRX||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. NCS_GNU_LIBC_VERSION)maxsplitrealpathrbrslibcsGLIBCicSs"g|]}|dk r|dn|qS)Nlatin1)decode).0srrr szlibc_ver..Zlibcglibc)osconfstrrlentupleAttributeErrorrOSErrorsys executablerhasattrpathr"openread _libc_searchsearchendmaxgroups)r1librZ chunksizeverpartsVfZbinaryposmchunkZlibcinitr)Z glibcversionZsoZthreadsZ soversionrrrlibc_vers^          rCcCs`|d}|r||zttttt|}Wntk rH|}YnXd|dd}|S)z Normalize the version and build strings and return a single version string using the format major.minor.build (or patchlevel). .N)rappendlistmapstrrrjoin)rbuildlZstringsrrr _norm_versions   rMz'(?:([\w ]+) ([\w.]+) .*\[.* ([\d.]+)\])win32win16dosc Cstj|kr|||fSddl}dD]R}z|j||jddd}Wn0t|jfk rl}z WYq W5d}~XYq Xq~q |||fS|}t |}|dk r| \}}}|ddkr|dd}|ddkr|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. rN)r<zcommand /c verz cmd /c verT)stderrtextshellrD) r0platform subprocess check_outputDEVNULLr/CalledProcessErrorstrip _ver_outputmatchr:rM) systemreleaserZsupported_platformsrWcmdinfoZwhyrArrr _syscmd_vers0         rbZ2000ZXPZ 2003ServerZpost2003Vista78z8.1zpost8.1Z10Zpost10) )r)rfrrfr!)rfNrrirrir!rirEriN)rr)rNZ 2008ServerZ 2008ServerR2Z 2012ServerZ 2012ServerR2Zpost2012ServerR2)rgrhrjrkrlrmcCs tdkS)N)ZIoTUAPZ NanoServerZWindowsCoreHeadlessZ IoTEdgeOS) win32_editionrrrr win32_is_iotOsroc Csz.z ddl}Wntk r*ddl}YnXWntk rBYnTXz(sz_platform.. _/\:;"()unknownrz--rUN)rJfilterr,replace)argsrVZcleanedrrr _platform"s"           rcCsNz ddl}Wntk r$|YSXz |WStk rH|YSXdS)z8 Helper to determine the node name of this machine. rN)socketrrZ gethostnamer/)rrrrr_nodeBs   rcCsBtj|}tj|r>tjtjtj|t|}q |S)zT In case filepath is a symlink, follow it until a real file is reached. )r*r3abspathislinknormpathrJdirnamereadlink)filepathrrr_follow_symlinksQs   rc Cs\tjdkr|Sddl}z|jd|f|jdd}Wnt|jfk rN|YSX|pZ|S)z. Interface to the system's uname command. rQrOrPrNrT)rRrS)r0rVrWrXrYr/rZr[)ZoptionrrWoutputrrr _syscmd_uname\s    rc Csztjdkr|Sddl}t|}ttjdd}z|jdd|g|j|d}Wnt |j fk rf|YSX|sp|S| d 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. rrNC)LC_ALLfilez-b)rRenvzlatin-1) r0rVrWrdictr*environrXrYr/rZr%)targetrrWrrrrr _syscmd_filems    r)r WindowsPE)rr)rMSDOScCs|s&ddl}|d}t|dd}|r6t|d}nd}|sx|tjkrxtjtkrpttj\}}|rh|}|rp|}||fSd|krd|kr||fSd |krd }nd |krd }n d |krd}d|krd}n8d|krd|krd}qd}nd|krd}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. rNPbitrr1z shared objectz32-bit32bitZN32Zn32bitz64-bitrZELFZPErrZCOFFzMS-DOSr)structZcalcsizerIrr0r1rV_default_architecture)r1bitslinkagersizeZfileoutr rLrrr architecturesH   r uname_resultz-system node release version machine processorcCsd}tdk rtSd}zt\}}}}}Wntk rBd}YnX|sbttd|||||fs|r~tj}d}d}t}d}d}|dkrt \}}}} |r|rd}|sdtj krtj dd}ntj dd}|stj d|}|r:t |\}}}|d krd }n4|d kr:|d kr:d }d |dd kr6d}nd}|dkrd|s^|dkrZd}nd}d }n8|dddkrt \}} } } d}d| }|s| }|dkr|r|dkr|}d}z ddl} Wntk rYn&X| dd\}}|dkrd}nd}|stdd}|dkr$d}|dkr2d}|dkr@d}|dkrNd}|dkr\d}|dkrjd}|d kr|d krd }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 ''. rNrrrOZPROCESSOR_ARCHITEW6432ZPROCESSOR_ARCHITECTUREZPROCESSOR_IDENTIFIERzMicrosoft WindowsrZ Microsoftz6.0rErcrrZ16bitrJavaz, ZOpenVMS0zSYI$_CPUZAlphaZVAXz-pr) _uname_cacher*rr.rGrr0rVrrrrrbrrJvms_librrZgetsyirr)Z no_os_uname processorr^noder_rrZuse_syscmd_verrrrrrrZcsidZ cpu_numberrrrrs                  rcCstjS)z Returns the system/OS name, e.g. 'Linux', 'Windows' or 'Java'. An empty string is returned if the value cannot be determined. )rr^rrrrr^usr^cCstjS)z Returns the computer's network name (which may not be fully qualified) An empty string is returned if the value cannot be determined. )rrrrrrr~srcCstjS)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_rrrrr_sr_cCstjS)z Returns the system's release version, e.g. '#3 on degas' An empty string is returned if the value cannot be determined. )rrrrrrrsrcCstjS)zt Returns the machine type, e.g. 'i386' An empty string is returned if the value cannot be determined. )rrrrrrrsrcCstjS)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. )rrrrrrrs 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}t|d}|dk r&|Sd|krd}|drHt|}n t|}|dkrjtdt || \}}}d}d}ntj drd}t |}|dkrtdt || \}}}} } |dkrd}tj }nd|kr"d}t |}|dkr td t || \}}}} d}n\t |}|dkrFtd t || \}}}} }d }|dkrld}n| r~|d | }ttd rtj\} } } n"ttdrtj\} } } nd} d} |d} t| dkr| dd| }||| | |||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 _mercurialrDr!r)r0r_sys_version_cacher startswith_ironpython_sys_version_parserr] _ironpython26_sys_version_parserrreprr:rV_sys_version_parser_pypy_sys_version_parserr2rrrr,rFrJ) sys_versionrrr]rZ alt_versionZcompilerZbuildnoZ builddateZ buildtimerbranchZrevisionrLrrr _sys_versions                   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). rrrrrrpython_implementation5s 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). rrrrrrpython_versionBsrcCsttddS)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). rrD)r-rrrrrrpython_version_tupleLs rcCs tdS)z Returns a string identifying the Python implementation branch. For CPython this is the SCM branch from which the Python binary was built. If not available, an empty string is returned. r!rrrrr python_branchWs rcCs tdS)z Returns a string identifying the Python implementation revision. For CPython this is the SCM revision from which the Python binary was built. If not available, an empty string is returned. rErrrrrpython_revisiones rcCstddS)zh Returns a tuple (buildno, builddate) stating the Python build number and date as strings. rrirrrrr python_buildrsrcCs tdS)zS Returns a string identifying the compiler used for compiling Python. rirrrrrpython_compilerzsrcCsbt||fd}|dk r|St\}}}}}}||kr:d}|rPt|||\}}}|dkrntd} | rnd}| }|dkrt|\} } } } |rt||}nt|||| }n|dkrttj \}}t||||d||}n~|d kr t \}}}\}}}|s|s t|||}nt|||d |||}n2|r2t||}n t tj \}}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. NrZDarwinrZmacOSr)ZLinuxwithrZon) _platform_cacherrrrrrrCr0r1rr)aliasedterserr^rr_rrrZ macos_releaseZrelZversrrrVZlibcnameZ libcversionrrrrrrrrrrrrVsX       rV__main__rz--terseZ nonaliasedz --nonaliased)Nrrr)r)rrrrN)rrrr)rrr)rrrr)r)r)r)N)rr)B__doc__Z __copyright__ __version__ collectionsr*rer0rcompilerrASCIIr6rCrMr\rbr|r~rornrrrrrrrrrrrrr1r namedtuplerrrr^rr_rrrrrrrrrrrrrrrrrrV__name__argvrrprintexitrrrrsY   G   1  3  #4   $P       h      L