B
    u9ap                 @   s   d Z dZddlZddlZddlZddlZddlZddlZy
ejZ	W n( e
k
rj   ejdkrbdZ	ndZ	Y nX dZdd	d	d
d
dddddd
ZedZdd ZedejZejdddfddZdd ZedejZedejZedejZdZdd Zdddedfd d!Zd"d# Zdddefd$d%Zdd(d)Zdd*d+Zed,Z dd.d/Z!d0d1d2d3d4d5d6d7d8d9d:d;Z"d2d<d=d>d?d@dAZ#ddBdCZ$dDdE Z%ddGdHZ&dIdJ Z'ddKdLZ(dMdN Z)dOdP Z*ddQdRZ+dSdT Z,ddUdVZ-ddWdXZ.dYdZd[d-Z/ejddfd\d]Z0e1d^d_Z2da3d`da Z4dbdc Z5ddde Z6dfdg Z7dhdi Z8djdk Z9dldm Z:ednejZ;edoejZ<edpZ=edqZ>i Z?ddrdsZ@dtdu ZAdvdw ZBdxdy ZCdzd{ ZDd|d} ZEd~d ZFdd ZGi ZHdddZeIdkrdejJkpdejJkZKdejJkodejJkZLeMeeLeK eNd dS )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 !

z1.0.8    N)doswin32win16ZNULz	/dev/nullz/etc
         (   2      )
ZdevZalphaaZbetabcZRCrcplpz([0-9]+|[._+-])c          	   C   sf   g }x\t | D ]N}|dkryt|d}d}W n  tk
rN   t|d}Y nX |||f qW |S )Nz._+-r   d   r   )_component_resplitint
ValueError_ver_stagesgetextend)versionresultvt r   /usr/lib/python3.7/platform.py_comparable_version   s    
r   sC   (__libc_init)|(GLIBC_([0-9.]+))|(libc(_\w+)?\.so(?:\.(\d[0-9.]*))?) i @  c          	   C   s  t }ttjdrtj| } t| dX}||}d}x@|t|k rzd|ksZd|krht	||}nd }|r|
 t|kr||}	|	r|t|t|d d  |	 }d}q<|sP dd | D \}
}}}}}|
r|sd	}n|r|d
krd
}|}n||||krp|}n\|rp|d
krpd	}|rJ|rF||||krJ|}|rp|t| d  |krp|| }|
 }q<W W d Q R X ||fS )Nrealpathrbr   s   libcs   GLIBCi  c             S   s"   g | ]}|d k	r| dn|qS )Nlatin1)decode).0sr   r   r   
<listcomp>   s   zlibc_ver.<locals>.<listcomp>Zlibcglibc)r   hasattrospathr!   openreadlen_libc_searchsearchendmaxgroups)
executablelibr   Z	chunksizeVfZbinaryposmchunkZlibcinitr(   ZglibcversionZsoZthreadsZ	soversionr   r   r   libc_ver   sJ    


r;   c          	   C   sp  t jdrd} td`}xX|D ]P}| }t|dkr |\}}nq |dkrV| }q |dkr |d}|d }q W W d Q R X | ||fS t jdrtdD}x<|D ]4}|d}	t|	dkr|	d d	krd	|	d
 |fS qW W d Q R X t jdrft d}
x:t	t|
d
 ddD ]"}|
| d d dkr|
|= qW |
rf|

  d} |
d dd  }| ||fS | ||fS )Nz/var/adm/inst-log/infoSuSE   ZMIN_DIST_VERSIONZ
DIST_IDENT-z/etc/.installedr   Z	OpenLinux   z/usr/lib/setup   zslack-version-	slackware)r*   r+   existsr,   r   r.   stripisdirlistdirrangesort)distnamer   idr7   lineZtvtagvaluevaluesZpkgZverfilesnr   r   r   _dist_try_harder   s>    	










rP   z(\w+)[-_](release|version)z'(.+) release ([\d.]+)[^(]*(?:\((.+)\))?z1([^0-9]+)(?: release )?([\d.]+)[^(]*(?:\((.+)\))?)r<   ZdebianZfedoraZredhatZcentosZmandrakeZmandrivaZrocksrB   Z	yellowdogZgentooZUnitedLinuxZ
turbolinuxZarchZmageiac             C   sz   d}d}t | }|d k	r&t| S t| }|d k	rDt| S |   }|rp|d }t|dkrp|d }d||fS )Nr    r   r?   )_lsb_release_versionmatchtupler3   _release_versionrD   r   r.   )	firstliner   rJ   r9   lr   r   r   _parse_release_file0  s    

rW   r?   c             C   s(   dd l }|jdtdd t| ||||S )Nr   zFdist() and linux_distribution() functions are deprecated in Python 3.5r=   )
stacklevel)warningswarnDeprecationWarning_linux_distribution)rI   r   rJ   supported_distsfull_distribution_namerY   r   r   r   linux_distributionK  s
    

r_   c          	   C   s   yt t}W n tk
r(   | ||fS X |  xD|D ]0}t|}|d k	r8| \}}	||kr8|} P q8W t| ||S t	t j
t|dddd}
|
 }W d Q R X t|\}}}|r|r|} |r|}|r|}| ||fS )Nrzutf-8surrogateescape)encodingerrors)r*   rF   _UNIXCONFDIROSErrorrH   _release_filenamerR   r3   rP   r,   r+   joinreadlinerW   )rI   r   rJ   r]   r^   Zetcfiler9   Z	_distnameZdummyr7   rU   Z_versionZ_idr   r   r   r\   U  s0    

r\   c             C   s*   dd l }|jdtdd t| |||ddS )Nr   zFdist() and linux_distribution() functions are deprecated in Python 3.5r=   )rX   )r]   r^   )rY   rZ   r[   r\   )rI   r   rJ   r]   rY   r   r   r   dist  s    
rj   r`   r@   c             C   s&   dd l }|jdtdd t| ||S )Nr   zuse os.popen insteadr=   )rX   )rY   rZ   r[   r*   popen)cmdmodebufsizerY   r   r   r   rk     s    rk   c             C   sd   |  d}|r|| ytt|}W n tk
r>   |}Y nX ttt|}d|d d } | S )N.   )r   appendmapr   r   liststrrg   )r   buildrV   Zintsstringsr   r   r   _norm_version  s    


rw   z'(?:([\w ]+) ([\w.]+) .*\[.* ([\d.]+)\])r   r   r   c       	      C   s   t j|kr| ||fS xddD ]R}y&t|}| }| rBtdW n$ tk
rh } zwW d d }~X Y qX P qW | ||fS | }t	|}|d k	r|
 \} }}|d dkr|d d }|d dkr|d d }t|}| ||fS )N)Zverzcommand /c verz
cmd /c verzcommand failedr@   ro   )sysplatformr*   rk   r-   closere   rD   _ver_outputrR   r3   rw   )	systemreleaser   Zsupported_platformsrl   pipeinfoZwhyr9   r   r   r   _syscmd_ver  s,    





r   Z2000ZXPZ
2003ServerZpost2003Vista78z8.1zpost8.1Z10Zpost10))   r   )r   r?   )r   r=   )r   N)   r   )r   r?   )r   r=   )r   rp   )r   N)r   r   )r   NZ
2008ServerZ2008ServerR2Z
2012ServerZ2012ServerR2Zpost2012ServerR2))r   r=   )r   r   )r   r?   )r   r=   )r   rp   )r   Nc          	   C   s  yddl m} W n tk
r,   | |||fS X | }|jpD|d d \}}}d|||}t||fpxt|d fpx| } |d d ||fkryd|j}W n4 tk
r   |d d dkrd	|dd   }Y nX t	|d
d dkr
t
||fpt
|d fp| } y0ydd l}	W n tk
r6   dd l}	Y nX W n tk
rP   Y n>X y.d}
|	t|
}t|dd }W d Q R X W n   Y nX | |||fS )Nr   )getwindowsversionrp   z{0}.{1}.{2}r=   zSP{}   zService Pack ZSPZproduct_typez,SOFTWARE\Microsoft\Windows NT\CurrentVersionZCurrentType)ry   r   ImportErrorZplatform_versionformat_WIN32_CLIENT_RELEASESr   Zservice_pack_majorAttributeErrorgetattr_WIN32_SERVER_RELEASESwinreg_winregZ	OpenKeyExHKEY_LOCAL_MACHINEZQueryValueEx)r~   r   csdptyper   ZwinverZmajminru   r   Zcvkeykeyr   r   r   	win32_ver  sD    r   c           	   C   s   d} t j| sd S ydd l}W n tk
r4   d S X t| d}||}W d Q R X |d }d}t  j}|dkrxd}|||fS )Nz0/System/Library/CoreServices/SystemVersion.plistr   r"   ZProductVersion)r    r    r    )ZppczPower MacintoshZPowerPC)	r*   r+   rC   plistlibr   r,   loadunamemachine)fnr   r7   r   r~   versioninfor   r   r   r   _mac_ver_xmlE  s    
r   r    r    r    c             C   s   t  }|d k	r|S | ||fS )N)r   )r~   r   r   r   r   r   r   mac_ver[  s    r   c             C   s@   ddl m} y|| }|d kr$|S |S  tk
r:   |S X d S )Nr   )System)	java.langr   ZgetPropertyr   )namedefaultr   rM   r   r   r   _java_getpropn  s    
r   c             C   s   ydd l }W n tk
r(   | |||fS X td|}td| } |\}}}td|}td|}td|}|||f}|\}}	}
td|
}
td|}td	|	}	||	|
f}| |||fS )
Nr   zjava.vendorzjava.versionzjava.vm.namezjava.vm.vendorzjava.vm.versionzjava.os.archzjava.os.namezjava.os.version)r   r   r   )r~   vendorvminfoosinfojavaZvm_nameZ
vm_releaseZ	vm_vendoros_name
os_versionos_archr   r   r   java_very  s"    











r   c             C   s   | dkrd| | |fS | dkr|dk r0| ||fS | d}|ryt|d }W n tk
rb   Y n X |d }t||d< d|}|dk rd	} qd	} n,| d
krd} |r|d }qd}n| dkrd} | ||fS )NZRhapsodyzMacOS X ServerZSunOS5ro   r   rp   6ZSolarisZIRIX64ZIRIXz (64bit)64bit)r   r   Windows)r   r   r   rt   rg   )r}   r~   r   rV   majorr   r   r   system_alias  s2    	



r   c              G   s   d dd tt| D }|dd}|dd}|dd}|dd}|d	d}|d
d}|dd}|dd}|dd}x|dd}||krP |}qW x|d dkr|d d }qW |S )Nr>   c             s   s   | ]}|  V  qd S )N)rD   )r%   xr   r   r   	<genexpr>  s    z_platform.<locals>.<genexpr> _/\:;"()unknownr    z--r@   )rg   filterr.   replace)argsrz   Zcleanedr   r   r   	_platform  s$    r   c             C   sD   ydd l }W n tk
r    | S X y| S  tk
r>   | S X d S )Nr   )socketr   Zgethostnamere   )r   r   r   r   r   _node  s    r   c             C   sF   t j| } x4t j| r@t jt jt j| t | } qW | S )N)r*   r+   abspathislinknormpathrg   dirnamereadlink)filepathr   r   r   _follow_symlinks  s
    "r   c          	   C   sf   t jdkr|S ytd| tf }W n ttfk
r<   |S X |  }|	 }|rZ|r^|S |S d S )N)r   r   r   zuname %s 2> %s)
ry   rz   r*   rk   DEV_NULLr   re   r-   rD   r{   )optionr   r7   outputr   r   r   r   _syscmd_uname  s    
r   c          	   C   sz   t jdkr|S t| } ytjd| gtjtjd}W n ttfk
rJ   |S X |	 d 
d}| }|rn|rr|S |S d S )N)r   r   r   ri   )stdoutstderrr   zlatin-1)ry   rz   r   
subprocessPopenPIPEZSTDOUTr   re   Zcommunicater$   wait)targetr   procr   r   r   r   r   _syscmd_file  s    	

r   )r    	WindowsPE)r    r   )r    MSDOSc             C   s*  |sLdd l }y|d}W n  |jk
r:   |d}Y nX t|d d }| r\t| d}nd}|s| tjkrtjtkrttj \}}|r|}|r|}||fS d|kr||fS d|krd	}nd
|krd}nd|krd}d|krd}n>d|krd|krd}nd}n d|krd}nd|kr"d}n ||fS )Nr   PrV      bitr    r4   z32-bit32bitZN32Zn32bitz64-bitr   ZELFZPEr   r   ZCOFFzMS-DOSr   )	structcalcsizeerrorrt   r   ry   r4   rz   _default_architecture)r4   bitslinkager   sizeZfileoutr   rV   r   r   r   architectureB  sL    




r   uname_resultz-system node release version machine processorc              C   s  d} t d k	rt S d}yt \}}}}}W n tk
rB   d} Y nX | sbttd |||||fs| r~tj}d}d}t }d}d}|dkrt	 \}}}}	|r|rd}|sdtj
krtj
dd}ntj
dd}|stj
d|}|r:t|\}}}|dkrd	}n4|d
kr:|d	kr:d	}d|d d kr6d}nd}|dkrd|s^|dkrZd}nd}d	}n8|d d dkrt \}}
}}d}d|}|s|
}|dkr|r|dkr|}d}ydd l}W n tk
r   Y n&X |dd\}}|dkrd}nd}|stdd}|dkr$d}|dkr2d}|dkr@d}|dkrNd}|dkr\d}|dkrjd}|d
kr|d	krd	}d}t||||||a t S )Nr   r    r?   r   ZPROCESSOR_ARCHITEW6432ZPROCESSOR_ARCHITECTUREZPROCESSOR_IDENTIFIERzMicrosoft Windowsr   Z	Microsoftz6.0rp   r   )r   r   r   Z16bit   r   Javaz, ZOpenVMS0zSYI$_CPU   ZAlphaZVAXz-pr   )_uname_cacher*   r   r   rs   r   ry   rz   r   r   environr   r   r   rg   vms_libr   Zgetsyir   r   )Zno_os_uname	processorr}   noder~   r   r   Zuse_syscmd_verr   r   r   r   r   r   ZcsidZ
cpu_numberr   r   r   r     s    















r   c               C   s   t  jS )N)r   r}   r   r   r   r   r}   %  s    r}   c               C   s   t  jS )N)r   r   r   r   r   r   r   .  s    r   c               C   s   t  jS )N)r   r~   r   r   r   r   r~   8  s    r~   c               C   s   t  jS )N)r   r   r   r   r   r   r   A  s    r   c               C   s   t  jS )N)r   r   r   r   r   r   r   J  s    r   c               C   s   t  jS )N)r   r   r   r   r   r   r   S  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 [^\]]+\]?c             C   s  | d krt j} t| d }|d k	r&|S d| krd}| drHt| }n
t| }|d krjtdt	|  |
 \}}}d}d}nt jdrd}t| }|d krtdt	|  |
 \}}}}	}
|d krd}t j}nd| kr"d}t| }|d krtdt	|  |
 \}}}}	d}n\t| }|d krFtd	t	|  |
 \}}}}	}d
}|d krld}n|	r~|d |	 }tt drt j\}
}}n"tt drt j\}
}}nd}d}|d}t|dkr|d d|}|||||||f}|t| < |S )NZ
IronPythonz*failed to parse IronPython sys.version: %sr    r   ZJythonz&failed to parse Jython sys.version: %sZPyPyz$failed to parse PyPy sys.version: %sz'failed to parse CPython sys.version: %sZCPythonr   _git
_mercurialro   r=   r   )ry   r   _sys_version_cacher   
startswith_ironpython_sys_version_parserrR    _ironpython26_sys_version_parserr   reprr3   rz   _sys_version_parser_pypy_sys_version_parserr)   r   r   r   r.   rq   rg   )sys_versionr   r   rR   r   Zalt_versionZcompilerZbuildnoZ	builddateZ	buildtimer   branchZrevisionrV   r   r   r   _sys_version}  sx    











r   c               C   s
   t  d S )Nr   )r   r   r   r   r   python_implementation  s    r   c               C   s
   t  d S )Nr?   )r   r   r   r   r   python_version  s    r   c               C   s   t t d dS )Nr?   ro   )rS   r   r   r   r   r   r   python_version_tuple  s    	r   c               C   s
   t  d S )Nr=   )r   r   r   r   r   python_branch  s    r   c               C   s
   t  d S )Nrp   )r   r   r   r   r   python_revision  s    r  c               C   s   t  dd S )Nr   r   )r   r   r   r   r   python_build"  s    r  c               C   s
   t  d S )Nr   )r   r   r   r   r   python_compiler*  s    r  c          	   C   s  t | |fd }|d k	r|S t \}}}}}}||kr:d}| rPt|||\}}}|dkrt|\}	}
}}|rxt||}nt||||}n*|dkr
t " tddt	 t
d\}}}W d Q R X |r|st||||d|||}n$ttj\}}t||||d|| }n|dkrXt \}}}\}}}|s4|sBt|||}nt|||d|||}n\|d	kr|rtt||}nt|||}n2|rt||}n ttj\}}t||||||}|t | |f< |S )
Nr    r   )ZLinuxignorez?dist\(\) and linux_distribution\(\) functions are deprecated .*withr   ZonZMacOS)_platform_cacher   r   r   r   r   rY   catch_warningsfilterwarningsr[   rj   r;   ry   r4   r   r   )aliasedterser   r}   r   r~   r   r   r   ZrelZversr   r   rz   rI   ZdistversionZdistidZlibcnameZlibcversionr`   r   r   r   r   r   r   r   r   r   r   rz   6  s\    






rz   __main__r
  z--terseZ
nonaliasedz--nonaliased)r`   r@   )r    )r    r    r    rx   )r    r    r    r    )r    r   r    )r    r    r   r   )r    )r    )r    )N)r   r   )OZ__copyright____version__collectionsry   r*   rer   rY   devnullr   r   rz   rd   r   compiler   r   ASCIIr/   r4   r;   rP   rf   rQ   rT   Z_supported_distsrW   r_   r\   rj   rk   rw   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   
namedtupler   r   r   r}   r   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  __name__argvr
  r	  printexitr   r   r   r   <module>o   s    




:26
	

 
0
0

#6 


T 	
			
h


[
