o ?Og4 @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) ZdevZalphaaZbetabcZRCZrcplpz([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//opt/alt/python310/lib64/python3.10/platform.py_comparable_versions  rsC(__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..Zlibcglibc)osconfstrrlentupleAttributeErrorrOSErrorsys executablerhasattrpathr"openread _libc_searchsearchendmaxgroups)r1librZ chunksizeverpartsVfZbinaryposmchunkZlibcinitr)Z glibcversionZsoZthreadsZ soversionrrrlibc_versx           # # ##rCcCs^|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)rbuildlZstringsrrr _norm_versions   rMz'(?:([\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)r<zcommand /c verz cmd /c verT)stdinstderrtextshellrD) r0platform subprocess check_outputDEVNULLr/CalledProcessErrorstrip _ver_outputmatchr:rM) systemreleaserZsupported_platformsrXcmdinfoZwhyrArrr _syscmd_vers6           rcZ2000ZXPZ 2003ServerZpost2003Vista78z8.1zpost8.1Z10Zpost10) )r)rgrrgr!)rgNrrjrrjr!rjrErjN)rr)rNZ 2008ServerZ 2008ServerR2Z 2012ServerZ 2012ServerR2Zpost2012ServerR2)rhrirkrlrmrncCs tdvS)N)ZIoTUAPZ NanoServerZWindowsCoreHeadlessZ IoTEdgeOS) win32_editionrrrr win32_is_iotSs rpcCszzddl}Wn tyddl}YnwWn ty YdSwz%d}||j|}||ddWdWS1s?wYWdStyPYdSw)Nr,SOFTWARE\Microsoft\Windows NT\CurrentVersionZ EditionId)winreg ImportError_winreg OpenKeyExHKEY_LOCAL_MACHINE QueryValueExr/)rrcvkeykeyrrrroVs*     $ roc 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!rDrEz {0}.{1}.{2}zSP{} z Service Pack ZSPZ product_typerqZ CurrentType)r0rzrsrHrrcrrZplatform_versionformat_WIN32_CLIENT_RELEASESrZservice_pack_majorr.getattr_WIN32_SERVER_RELEASESrrrtrurvrwr/) r`rcsdptyperzwinvermajorminorrKrrrxryrrr win32_verhsf            rcCsd}tj|s dSzddl}Wn tyYdSwt|d }||}Wdn1s0wY|d}d}tj}|dvrFd}|||fS)Nz0/System/Library/CoreServices/SystemVersion.plistrr#ZProductVersionrrr)ZppczPower MacintoshZPowerPC) r*r3existsplistlibrsr4loadunamemachine)fnrr?r r` 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)r`rrrbrrrmac_vers  rcCsBddlm}z||}|dur|WS|WSty |YSw)Nr)System) java.langrZ getPropertyr.)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)rrsr) r`vendorvminfoosinfojavaZvm_nameZ vm_releaseZ vm_vendoros_name os_versionos_archrrrjava_vers$               rcCs|dkr?|dkr |||fS|d}|r5zt|d}Wn ty%Ynw|d}t||d<d|}|dkr"sz_platform.. _/\:;"()unknownrrz--rVN)rJfilterr,replace)argsrWZcleanedrrr _platforms(             rcCsFzddl}Wn ty|YSwz|WSty"|YSw)z8 Helper to determine the node name of this machine. rN)socketrsZ gethostnamer/)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. )r*r3abspathislinknormpathrJdirnamereadlink)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. )rQrOrPrNC)LC_ALLfilez-b)rSenvzlatin-1) r0rWrXrdictr*environrYrZr/r[r%)targetrrXroutputrrr _syscmd_fileWs    r)r WindowsPE)rr)rMSDOScCs|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 ''. NrrrOzMicrosoft WindowsrZ Microsoftz6.0rErdrrZ16bitrJava, ZOpenVMS0) _uname_cacher*rr.r0rWranyrrrcrrJrrHr) r_rr`rrZinfosrrrrrZvalsrrrr.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. )rr_rrrrr_r_cCr)z Returns the computer's network name (which may not be fully qualified) An empty string is returned if the value cannot be determined. )rrrrrrrsrcCr)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`rr`cCr)z Returns the system's release version, e.g. '#3 on degas' An empty string is returned if the value cannot be determined. )rrrrrrrrrcCr)zt Returns the machine type, e.g. 'i386' An empty string is returned if the value cannot be determined. )rrrrrrrrrcCr)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|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. 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:rW_sys_version_parser_pypy_sys_version_parserr2rrrr,rFrJ) sys_versionrrr^rZ alt_versionZcompilerZbuildnoZ builddateZ buildtimerbranchZrevisionrLrrr _sys_versions                rcC 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_implementationG rcCr)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_versionTs rcCsttddS)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_tuple^s rcCr)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_branchis rcCr)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_revisionwrrcCstddS)zh Returns a tuple (buildno, builddate) stating the Python build number and date as strings. rrjrrrrr python_buildsrcCr)zS Returns a string identifying the compiler used for compiling Python. rjrrrrrpython_compilers rcCsXt||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. NrZDarwinrZmacOSr)LinuxwithrZon) _platform_cacherrrrrrrCrrr0r1)aliasedterserr_rr`rrrZ macos_releaseZrelZversrrrWZlibcnameZ libcversionrrrrrrrrrrrrWsP      rWzA^(?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)NrZlinux)NAMEZIDZ PRETTY_NAMEz\1rr)_os_release_liner^_os_release_unescapesubgroup)linesrblineZmorrr_parse_os_releases  r(c 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 r)_os_release_cache_os_release_candidatesr4r(r/errnorJcopy)r, candidater?errrfreedesktop_os_releases$  r0__main__rz--terseZ nonaliasedz --nonaliased)Nrrr)r)rrrrN)rrrr)rrr)rrrrr)rr)MrZ __copyright__ __version__ collectionsr*rer0rXrrrcompilerrASCIIr6rCrMr]rcr}rrprorrrrrrrrrrrr1rrrr namedtuplerrrr_rr`rrrr r r r rrrrrrrrrrrWr"r#r+r*r(r0rargvrrprintexitrrrrsY    G   2  3  #*  $L  ,Y      h     O