a DOg @sdZdZdZddlZddlZddlZddlZddlZddlZddl Z ddddddd d d d d Z e d Z d dZ e dejZd}ddZd~ddZe dZdddZddddddd 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@eAdxkrdyejBvppdzejBvZCd{ejBvod|ejBvZDeEe@eDeCeFddS)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]L}|dvrzt|d}d}WntyJt|d}Yn0|||fq|S)Nz._+-rdr) _component_resplitint ValueError _ver_stagesgetextend)versionresultvtr-/opt/alt/python39/lib64/python3.9/platform.py_comparable_versions  rsC(__libc_init)|(GLIBC_([0-9.]+))|(libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)@c Cs|durXz0td}|jdd}t|dkr6t|WSWntttfyPYn0tj }t }t tj drttj |}t|dj}||}d} | t|krd |vsd |vrt|| } nd} | r| t|kr||} | r |t| t|d d| }d} q| sqd d | D\} } }}}}| rD|sDd}n| rv|dkr^d}|}n||||kr|}n\|r|dkrd}|r|r||||kr|}|r|t| d|kr||}| } qWdn1s0Y||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|]}|dur|dn|qS)Nlatin1)decode).0srrr szlibc_ver..Zlibcglibc)osconfstrrlentupleAttributeErrorrOSErrorsys executablerhasattrpathr"openread _libc_searchsearchendmaxgroups)r1librZ chunksizeverpartsVfZbinaryposmchunkZlibcinitr)Z glibcversionZsoZthreadsZ soversionrrrlibc_vers^          *rCcCs^|d}|r||zttttt|}WntyF|}Yn0d|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}Wn6t|jfyv}zWYd}~q WYd}~q d}~00qq |||fS|}t |}|dur| \}}}|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)stdinstderrtextshellrD) r0platform subprocess check_outputDEVNULLr/CalledProcessErrorstrip _ver_outputmatchr:rM) systemreleaserZsupported_platformsrXcmdinfoZwhyrArrr _syscmd_vers2   "      rcZ2000ZXPZ 2003ServerZpost2003Vista78z8.1zpost8.1Z10Zpost10) )r)rgrrgr!)rgNrrjrrjr!rjrErjN)rr)rNZ 2008ServerZ 2008ServerR2Z 2012ServerZ 2012ServerR2Zpost2012ServerR2)rhrirkrlrmrncCs tdvS)N)ZIoTUAPZ NanoServerZWindowsCoreHeadlessZ IoTEdgeOS) win32_editionrrrr win32_is_iotSsrpcCsz,z ddl}Wnty(ddl}Yn0Wnty>Yn^0zHd}||j|"}||ddWdWS1s|0YWntyYn0dS)Nr,SOFTWARE\Microsoft\Windows NT\CurrentVersionZ EditionId)winreg ImportError_winreg OpenKeyExHKEY_LOCAL_MACHINE QueryValueExr/)rrcvkeykeyrrrroVs   4 roc Cszddlm}Wnty.||||fYS0|}z tttdd\}}}Wn*ty|jpt|dd\}}}Yn0d |||}t ||fpt |dfp|}|dd||fkrzd |j }Wn6t y |ddd krd |dd}Yn0t|d ddkrDt ||fpBt |dfpB|}z.z ddl} Wntynddl} Yn0WntyYn`0zHd } | | j|  } | | d d}Wdn1s0YWntyYn0||||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`rcsdptyperzZwinvermajorminorrKrrrxryrrr win32_verhsR      4rcCsd}tj|sdSz ddl}Wnty4YdS0t|d}||}Wdn1s`0Y|d}d}tj}|dvrd}|||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 rcCsFddlm}z||}|dur&|WS|WSty@|YS0dS)Nr)System) java.langrZ getPropertyr.)namedefaultrvaluerrr _java_getprops   rc Csz ddl}Wnty*||||fYS0td|}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}|rjzt|d}WntyJYn 0|d}t||d<d|}|dkrxd}qd}n,|dkrd }|r|d }qd }n |d vrd }|||fS)z Returns (system, release, version) aliased to common marketing names used for some systems. It also does some reordering of the information in some cases where it would otherwise cause confusion. ZSunOS5rDrrE6ZSolarisZIRIX64ZIRIXz (64bit)64bitrOrPWindows)rrrrIrJ)r_r`rrLrrrr system_aliass.       rcGsdddtt|D}|dd}|dd}|dd}|dd}|d d}|d d}|d d}|d d}|d d}|dd}||krq|}q|ddkr|dd}q|S)zq Helper to format the platform string in a filename compatible format e.g. "system-version-machine". -css|]}|VqdSN)r\)r&xrrr ,z_platform.. _/\:;"()unknownrz--rVN)rJfilterr,replace)argsrWZcleanedrrr _platform&s"           rcCsJz ddl}Wnty"|YS0z |WStyD|YS0dS)z8 Helper to determine the node name of this machine. rN)socketrsZ gethostnamer/)rrrrr_nodeFs     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_symlinksUs   rc Csxtjdvr|Sddl}t|}ttjdd}z|jdd|g|j|d}Wnt |j fyd|YS0|sn|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_fileas    r)r WindowsPE)rr)rMSDOScCs|s&ddl}|d}t|dd}|r6t|d}nd}|sx|tjkrxtjtvrpttj\}}|rh|}|rp|}||fSd|vrd|vr||fSd |vrd }nd |vrd }n d |vrd}d|vrd}n8d|vrd|vrd}qd}nd|vrd}nd|vrd}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)structZcalcsizerIrr0r1rW_default_architecture)r1bitslinkagersizeZfileoutr rLrrr architecturesH   rcCstjddptjddS)NZPROCESSOR_ARCHITEW6432rZPROCESSOR_ARCHITECTURE)r*rrrrrr_get_machine_win32s rc@s0eZdZeddZddZddZddZd S) _ProcessorcCs t|dtj|j}|pdS)NZget_r)r~r0rWfrom_subprocess)clsfuncrrrrsz_Processor.getcCstjdtS)NZPROCESSOR_IDENTIFIER)r*rrrrrrr get_win32sz_Processor.get_win32cCsDz ddl}WntyYn"0|dd\}}|dkrsY   G   2  3  #4  $O   *Y      h      L