o w[e& @sdZdZdZddlZddlZddlZddlZddlZddlZddl Z ddddddd d d d d Z e d Z d dZ e dejZdddZdddZe dZ  dddZddddddd d!d"d#d$d% Zdd&d'd(d)d*d+Zd,d-Zd.d/Zdd0d1Zd2d3Zdd5d6Zd7d8Zdd9d:Zd;d<Zd=d>Zdd?d@ZdAdBZ ddCdDZ!dEdFdGdZ"ej#ddfdHdIZ$dJdKZ%GdLdMdMZ&dNdOZ'GdPdQdQe(dRdSZ)da*dTdUZ+dVdWZ,dXdYZ-dZd[Z.d\d]Z/d^d_Z0d`daZ1e dbejZ2e dcejZ3e ddZ4e deZ5iZ6ddfdgZ7dhdiZ8djdkZ9dldmZ:dndoZ;dpdqZiZ?ddvdwZ@e dxZAe dyZBdzZCdaDd{d|ZEd}d~ZFeGdkrjdejHvpPdejHvZIdejHvo[dejHvZJeKe@eJeIeLddSdS)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) devalphaabetabcRCrcplpz([0-9]+|[._+-])c Cs`g}t|D]&}|dvr-z t|d}d}Wnty%t|d}Ynw|||fq|S)Nz._+-rdr) _component_resplitint ValueError _ver_stagesgetextend)versionresultvtr/usr/lib/python3.10/platform.py_comparable_versions  r sC(__libc_init)|(GLIBC_([0-9.]+))|(libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)@c Cs|s*ztd}|jdd}t|dkrt|WSWn tttfy&Ynwtj }t }t tj dr8tj |}t|d}||}d} | t|krd|vsSd |vrZt|| } nd } | rf| t|kr||} | r|t| t|d d | }d} qE| snqd d | D\} } }}}}| r|sd}n=| r|dkrd}|}n2||||kr|}n'|r|dkrd}|r|r||||kr|}|r|t| d |kr||}| } | t|ksKWd ||fSWd ||fSWd ||fS1swY||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. CS_GNU_LIBC_VERSION)maxsplitrealpathrbrslibcsGLIBCNicSs"g|] }|dur |dn|qS)Nlatin1)decode).0srrr szlibc_ver..libcglibc)osconfstrrlentupleAttributeErrorrOSErrorsys executabler hasattrpathr'openread _libc_searchsearchendmaxgroups)r7libr chunksizeverpartsVfbinaryposmchunklibcinitr/ glibcversionsothreads soversionrrrlibc_versx           # # ##rPcCs^|d}|r ||z ttttt|}Wn ty#|}Ynwd|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)rbuildlstringsrrr _norm_versions   r[z'(?:([\w ]+) ([\w.]+) .*\[.* ([\d.]+)\])win32win16dosc Cstj|vr |||fSddl}dD]'}z|j||j|jddd}Wnt|jfy5}zWYd}~qd}~wwn|||fS|}t |}|durm| \}}}|ddkr]|dd}|ddkri|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)rCzcommand /c verz cmd /c verT)stdinstderrtextshellrQ) r6platform subprocess check_outputDEVNULLr5CalledProcessErrorstrip _ver_outputmatchr@r[) systemreleasersupported_platformsrfcmdinfowhyrIrrr _syscmd_vers6           rs2000XP 2003Serverpost2003Vista78z8.1zpost8.110post10) )r)r}r$r}r&)r}Nrrr$rr&rrRrN)rr)rN 2008Server 2008ServerR2 2012Server 2012ServerR2post2012ServerR2)r~rrrrrcCs tdvS)N)IoTUAP NanoServerWindowsCoreHeadless IoTEdgeOS) win32_editionrrrr win32_is_iotSs rcCszzddl}Wn tyddl}YnwWn ty YdSwz%d}||j|}||ddWdWS1s?wYWdStyPYdSw)Nr,SOFTWARE\Microsoft\Windows NT\CurrentVersion EditionId)winreg ImportError_winreg OpenKeyExHKEY_LOCAL_MACHINE QueryValueExr5)rcvkeykeyrrrrVs*     $ rc Cszddlm}Wnty||||fYSw|}ztttdd\}}}Wnty@|jp:|dd\}}}Ynwd |||}t ||fpWt |dfpW|}|dd||fkrzd |j }Wnt y|ddd krd |dd}Ynwt|d ddkrt ||fpt |dfp|}zzddl} Wn tyddl} YnwWn tyYn.wz#d } | | j| } | | d d}Wdn1swYWn tyYnw||||fS)Nr)getwindowsversionr&rQrRz {0}.{1}.{2}zSP{} z Service Pack SP product_typer CurrentType)r6rrrUrrsrrplatform_versionformat_WIN32_CLIENT_RELEASESrservice_pack_majorr4getattr_WIN32_SERVER_RELEASESrrrrrr5) rnrcsdptyperwinvermajorminorrXrrrrrr win32_verhsf            rcCsd}tj|s dSzddl}Wn tyYdSwt|d }||}Wdn1s0wY|d}d}tj}|dvrFd}|||fS)Nz0/System/Library/CoreServices/SystemVersion.plistrr(ProductVersionr!r!r!)ppczPower MacintoshPowerPC) r0r9existsplistlibrr:loadunamemachine)fnrrFrrn versioninforrrr _mac_ver_xmls"       rrcCst}|dur |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)rnrrrqrrrmac_vers  rcCsBddlm}z||}|dur|WS|WSty |YSw)Nr)System) java.langr getPropertyr4)namedefaultrvaluerrr _java_getprops   rc Cszddl}Wnty||||fYSwtd|}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) rnvendorvminfoosinfojavavm_name vm_release vm_vendoros_name os_versionos_archrrrjava_vers$               rcCs|dkr?|dkr |||fS|d}|r5zt|d}Wn ty%Ynw|d}t||d<d|}|dkr"sz_platform.. _/\:;"()unknownr!r$z--rdN)rWfilterr2replace)argsrecleanedrrr _platforms(             rcCsFzddl}Wn ty|YSwz|WSty"|YSw)z8 Helper to determine the node name of this machine. rN)socketr gethostnamer5)rrrrr_node<s    rcCsLtj|}tj|r$tjtjtj|t|}tj|s |S)zT In case filepath is a symlink, follow it until a real file is reached. )r0r9abspathislinknormpathrWdirnamereadlink)filepathrrr_follow_symlinksKs   rc Csxtjdvr|Sddl}t|}ttjdd}z|jdd|g|j|d}Wnt |j fy2|YSw|s7|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. )r_r]r^rNC)LC_ALLfilez-b)raenvzlatin-1) r6rerfrdictr0environrgrhr5rir*)targetrrfroutputrrr _syscmd_fileWs    r)r! WindowsPE)r!r)r!MSDOScCs|sddl}|d}t|dd}|rt|d}nd}|s<|tjkrt }|rC|sht |\}}}|dkrQd}n|dkrh|dkrhd}d|dd krfd }nd}|d vrz|sw|dkrud }nd }d}n|dddkrt \}}} } d}d | }|s|}|dkr|r|dkr|}d}|dkr|dkrd}d }|||||f} t tt| 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 ''. Nr!rr]zMicrosoft Windowsr Microsoftz6.0rRrxrr16bitrJava, OpenVMS0) _uname_cacher0rr4r6reranyrr rsrrWr"rUr!) rmr#rnrrinfosrrrrrvalsrrrr.sZ     rcCtjS)z Returns the system/OS name, e.g. 'Linux', 'Windows' or 'Java'. An empty string is returned if the value cannot be determined. )rrmrrrrrmrmcCrH)z Returns the computer's network name (which may not be fully qualified) An empty string is returned if the value cannot be determined. )rr#rrrrr#sr#cCrH)z Returns the system's release, e.g. '2.2.0' or 'NT' An empty string is returned if the value cannot be determined. )rrnrrrrrnrIrncCrH)z Returns the system's release version, e.g. '#3 on degas' An empty string is returned if the value cannot be determined. )rrrrrrrrIrcCrH)zt Returns the machine type, e.g. 'i386' An empty string is returned if the value cannot be determined. )rrrrrrrrIrcCrH)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. )rr$rrrrr$s r$zL([\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|durtj}t|d}|dur|Sd|vrAd}|dr$t|}nt|}|dur5tdt || \}}}d}d}nytj drmd}t |}|durZtdt || \}}}} } |durid}tj }nMd|vrd}t |}|durtd t || \}}}} d}n+t |}|durtd t || \}}}} }d }|durd}n| r|d | }ttd rtj\} } } nttdrtj\} } } 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. N IronPythonz*failed to parse IronPython sys.version: %sr!rJythonz&failed to parse Jython sys.version: %sPyPyz$failed to parse PyPy sys.version: %sz'failed to parse CPython sys.version: %sCPythonr_git _mercurialrQr&rC)r6r_sys_version_cacher startswith_ironpython_sys_version_parserrl _ironpython26_sys_version_parserrreprr@re_sys_version_parser_pypy_sys_version_parserr8rNrOrr2rSrW) sys_versionrrrlr alt_versioncompilerbuildno builddate buildtimerbranchrevisionrYrrr _sys_versions                r_cC 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). rr_rrrrpython_implementationG rbcCr`)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$rarrrrpython_versionTs rdcCsttddS)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$rQ)r3r_rrrrrpython_version_tuple^s recCr`)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&rarrrr python_branchis rfcCr`)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. rRrarrrrpython_revisionwrcrgcCstddS)zh Returns a tuple (buildno, builddate) stating the Python build number and date as strings. r?rrarrrr python_buildsrhcCr`)zS Returns a string identifying the compiler used for compiling Python. rrarrrrpython_compilers ricCsXt||fd}|dur|St\}}}}}}||krd}|r(t|||\}}}|dkr7td} | r7d}| }|dkrSt|\} } } } |rKt||}nYt|||| }nQ|dvrht\}}t||||d||}n<|d krt\}}}\}}}|sz|st|||}n#t|||d |||}n|rt||}nt t 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. Nr!DarwinrmacOSr)Linuxwithr@on) _platform_cacherrrrrrrPrrr6r7)aliasedterserrmr#rnrrr$ macos_releaserelversrrrelibcname libcversionrrrrrrrrrrrresP      rezA^(?P[a-zA-Z0-9_]+)=(?P["']?)(?P.*)(?P=quote)$z\\([\\\$\"\'`]))z/etc/os-releasez/usr/lib/os-releasecCsHdddd}|D]}t|}|dur!td|d||d<q|S)Nrllinux)NAMEID PRETTY_NAMEz\1rr)_os_release_linerl_os_release_unescapesubgroup)linesrqlinemorrr_parse_os_releases  rc CstdurKd}tD]7}z t|dd }t|aWdn1s wYWtSty?}z |j}WYd}~qd}~wwt|ddttS)zKReturn operation system identification from freedesktop.org os-release Nzutf-8)encodingzUnable to read files rA)_os_release_cache_os_release_candidatesr:rr5errnorWcopy)r candidaterFerrrfreedesktop_os_releases$  r__main__rqz--terse nonaliasedz --nonaliased)Nr!r!r")r!)r!r!r!r\)r!r!r!r!)r!rr!)r!r!rrr)rr)Mr8 __copyright__ __version__ collectionsr0rer6rfr9r'rcompilerr ASCIIr<rPr[rkrsrrrrrrrrrrrrrrrr7rr r r! namedtupler"rDrrmr#rnrrr$rUrRrSrVrPr_rbrdrerfrgrhrirorer|r}rrrrrargvrqrpprintexitrrrrsY    G   2  3  #*  $L  ,Y      h     O