B
    u9a	s                 @   sr  d dl Z d dlZd dlmZ dZddddg\ZZZZe	Z
eZG dd	 d	eZG d
d dZdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd aadayd dlZW n ek
r   dZY nX d d! Zd"d# Zd$d% Z d&d' Z!da"e eegZ#eeeeeegZ$dd(d)d*Z%da&d7d+d,Z'd-d. Z(d/d0 Z)d1d2 Z*ed3Z+ed4Z,ed5Z-ed6Z.dS )8    N)EnumzKa-Ping Yee <ping@zesty.ca>zreserved for NCS compatibilityzspecified in RFC 4122z$reserved for Microsoft compatibilityzreserved for future definitionc               @   s   e Zd ZdZdZdZdS )SafeUUIDr   N)__name__
__module____qualname__ZsafeZunsafeunknown r	   r	   /usr/lib/python3.7/uuid.pyr   ?   s   r   c               @   s2  e Zd Zd;ejdddZdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zedd Zedd  Zed!d" Zed#d$ Zed%d& Zed'd( Zed)d* Zed+d, Zed-d. Zed/d0 Zed1d2 Zed3d4 Zed5d6 Zed7d8 Z ed9d: Z!dS )<UUIDN)is_safec            C   s  |||||g d dkr td|d k	rl|dddd}|ddd}t|dkrbtd	t|d
}|d k	rt|d
krtd|dd d |ddd  |ddd  |dd   }|d k	rt|d
krtdtj|dd}|d k	rt|dkrtd|\}}	}
}}}d|  kr0dk s:n tdd|	  krRdk s\n tdd|
  krtdk s~n tdd|  krdk sn tdd|  krdk sn tdd|  krdk sn td |d> |B }|d!> |	d"> B |
d#> B |d$> B |B }|d k	rDd|  kr:d%d&> k sDn td'|d k	rd%|  krfdkspn td(|d)M }|d*O }|d+M }||d,> O }|| jd-< || jd.< d S )/N   zGone of the hex, bytes, bytes_le, fields, or int arguments must be givenzurn: zuuid:z{}-    z$badly formed hexadecimal UUID string   z bytes_le is not a 16-char string   r            zbytes is not a 16-char stringbig)	byteorder   zfields is not a 6-tupler   l        z*field 1 out of range (need a 32-bit value)i   z*field 2 out of range (need a 16-bit value)z*field 3 out of range (need a 16-bit value)   z*field 4 out of range (need an 8-bit value)z*field 5 out of range (need an 8-bit value)l          z*field 6 out of range (need a 48-bit value)`   P   @   0         z*int is out of range (need a 128-bit value)zillegal version numberl        l            l          L   intr   )	count	TypeErrorreplacestriplen
ValueErrorint_
from_bytes__dict__)selfhexbytesbytes_lefieldsr!   versionr   time_lowtime_midtime_hi_versionclock_seq_hi_variantclock_seq_lownode	clock_seqr	   r	   r
   __init__y   s\     
6
$


zUUID.__init__c             C   s*   | j }| jtjkr&| }| jj|d< |S )Nr   )r*   r   r   r   copyvalue)r+   stater	   r	   r
   __getstate__   s
    zUUID.__getstate__c             C   s0   | j | d|kr t|d ntj| j d< d S )Nr   )r*   updater   r   )r+   r;   r	   r	   r
   __setstate__   s    zUUID.__setstate__c             C   s   t |tr| j|jkS tS )N)
isinstancer   r!   NotImplemented)r+   otherr	   r	   r
   __eq__   s    
zUUID.__eq__c             C   s   t |tr| j|jk S tS )N)r?   r   r!   r@   )r+   rA   r	   r	   r
   __lt__   s    
zUUID.__lt__c             C   s   t |tr| j|jkS tS )N)r?   r   r!   r@   )r+   rA   r	   r	   r
   __gt__   s    
zUUID.__gt__c             C   s   t |tr| j|jkS tS )N)r?   r   r!   r@   )r+   rA   r	   r	   r
   __le__   s    
zUUID.__le__c             C   s   t |tr| j|jkS tS )N)r?   r   r!   r@   )r+   rA   r	   r	   r
   __ge__   s    
zUUID.__ge__c             C   s
   t | jS )N)hashr!   )r+   r	   r	   r
   __hash__   s    zUUID.__hash__c             C   s   | j S )N)r!   )r+   r	   r	   r
   __int__   s    zUUID.__int__c             C   s   d| j jt| f S )Nz%s(%r))	__class__r   str)r+   r	   r	   r
   __repr__  s    zUUID.__repr__c             C   s   t dd S )NzUUID objects are immutable)r#   )r+   namer:   r	   r	   r
   __setattr__  s    zUUID.__setattr__c             C   sD   d| j  }d|d d |dd |dd |dd |dd  f S )Nz%032xz%s-%s-%s-%s-%sr      r      )r!   )r+   r,   r	   r	   r
   __str__  s    
zUUID.__str__c             C   s   | j ddS )Nr   r   )r!   to_bytes)r+   r	   r	   r
   r-     s    z
UUID.bytesc             C   s<   | j }|dd d |ddd  |ddd  |dd   S )Nr   r   r   r   r   )r-   )r+   r-   r	   r	   r
   r.     s    (zUUID.bytes_lec             C   s   | j | j| j| j| j| jfS )N)r1   r2   r3   r4   r5   r6   )r+   r	   r	   r
   r/     s    zUUID.fieldsc             C   s
   | j d? S )Nr   )r!   )r+   r	   r	   r
   r1     s    zUUID.time_lowc             C   s   | j d? d@ S )Nr   i  )r!   )r+   r	   r	   r
   r2      s    zUUID.time_midc             C   s   | j d? d@ S )Nr   i  )r!   )r+   r	   r	   r
   r3   $  s    zUUID.time_hi_versionc             C   s   | j d? d@ S )N8      )r!   )r+   r	   r	   r
   r4   (  s    zUUID.clock_seq_hi_variantc             C   s   | j d? d@ S )Nr   rT   )r!   )r+   r	   r	   r
   r5   ,  s    zUUID.clock_seq_lowc             C   s   | j d@ d> | jd> B | jB S )Ni  r   r   )r3   r2   r1   )r+   r	   r	   r
   time0  s    z	UUID.timec             C   s   | j d@ d> | jB S )N?   r   )r4   r5   )r+   r	   r	   r
   r7   5  s    zUUID.clock_seqc             C   s
   | j d@ S )Nl    )r!   )r+   r	   r	   r
   r6   :  s    z	UUID.nodec             C   s
   d| j  S )Nz%032x)r!   )r+   r	   r	   r
   r,   >  s    zUUID.hexc             C   s   dt |  S )Nz	urn:uuid:)rK   )r+   r	   r	   r
   urnB  s    zUUID.urnc             C   s2   | j d@ stS | j d@ stS | j d@ s*tS tS d S )Nl            l            l            )r!   RESERVED_NCSRFC_4122RESERVED_MICROSOFTRESERVED_FUTURE)r+   r	   r	   r
   variantF  s    


zUUID.variantc             C   s    | j tkrt| jd? d@ S d S )Nr       )r\   rY   r!   )r+   r	   r	   r
   r0   Q  s    
zUUID.version)NNNNNN)"r   r   r   r   r   r8   r<   r>   rB   rC   rD   rE   rF   rH   rI   rL   rN   rQ   propertyr-   r.   r/   r1   r2   r3   r4   r5   rU   r7   r6   r,   rW   r\   r0   r	   r	   r	   r
   r   E   s<   4 T	r   c       	      G   s   dd l }dd l}dd l}|| }|d krP|jd}|j| |d}|d krPd S t|j}d|d< |j|f| |j	|j
|d}|S )Nr   )z/sbinz	/usr/sbin)pathCLC_ALL)stdoutstderrenv)osshutil
subprocessZwhichpathsepjoindictenvironPopenPIPEZDEVNULL)	commandargsre   rf   rg   
executabler_   rd   procr	   r	   r
   _popenW  s    

rr   c             C   s
   | d@  S )Nl        r	   )macr	   r	   r
   _is_universaly  s    rt   c             C   s   d }yt | f|  }|s d S | x|jD ]}|   }xptt|D ]`}|| |krPy6||| }	t|	ddd}
t	|
r|
S |p|
}W qP t
tfk
r   Y qPX qPW q.W W d Q R X W n tk
r   Y nX |pd S )N   :    r   )rr   splitrb   lowerrstripranger&   r!   r$   rt   r'   
IndexErrorOSError)rn   ro   Zhw_identifiersZ	get_indexfirst_local_macrq   linewordsiwordrs   r	   r	   r
   	_find_mac|  s*    r   c              C   s2   d} x(dD ] }t d|| dd }|r(|S d S W d S )N)s   hwaddrs   ethers   address:s   lladdr)r   z-az-avZifconfigc             S   s   | d S )Nr   r	   )r   r	   r	   r
   <lambda>  rv   z#_ifconfig_getnode.<locals>.<lambda>)r   )keywordsro   rs   r	   r	   r
   _ifconfig_getnode  s    
r   c              C   s    t dddgdd } | r| S d S )NZiplinks
   link/etherc             S   s   | d S )Nr   r	   )r   r	   r	   r
   r     rv   z_ip_getnode.<locals>.<lambda>)r   )rs   r	   r	   r
   _ip_getnode  s    r   c              C   s   dd l } dd l}y|| }W n tk
r6   d S X tdd| |gdd }|rZ|S tdd| |gdd }|r||S tdd| d| gdd }|r|S d S )	Nr   Zarpz-anc             S   s   dS )Nr   r	   )r   r	   r	   r
   r     rv   z_arp_getnode.<locals>.<lambda>c             S   s   | d S )Nr   r	   )r   r	   r	   r
   r     rv   z(%s)c             S   s   | d S )N   r	   )r   r	   r	   r
   r     rv   )re   socketZgethostbynameZgethostnamer|   r   fsencode)re   r   Zip_addrrs   r	   r	   r
   _arp_getnode  s     
r   c               C   s   t dddgdd S )NZlanscanz-ais   lan0c             S   s   dS )Nr   r	   )r   r	   r	   r
   r     rv   z"_lanscan_getnode.<locals>.<lambda>)r   r	   r	   r	   r
   _lanscan_getnode  s    r   c              C   s  d } yt dd}|sd S | |j   }y|d}W n tk
rR   d S X x|jD ]v}yX|  }|| }t|dkr|ddkrt	|
ddd}t|r|S | p|} W q\ ttfk
r   Y q\X q\W W d Q R X W n tk
r   Y nX | p d S )	NZnetstatz-ias   Address   ru   r   rv   r   )rr   rb   readlinery   rw   indexr'   r&   r"   r!   r$   rt   r{   r|   )r}   rq   r   r   r~   r   rs   r	   r	   r
   _netstat_getnode  s2    
r   c           
   C   s.  dd l } dd l}dd l}d }dddg}y:dd l}|d}|jj|d |d|j	
d W n   Y nX x|D ]}y$|j| j|ddg|jd	d
}W n tk
r   wtY nX |b xZ|jD ]P}	|	dd   }
|d|
rt|
ddd}t|r|S |p|}qW W d Q R X qtW |p,d S )Nr   r   zc:\windows\system32zc:\winnt\system32i,  mbcsZipconfigz/allZoem)rb   encoding:r   z((?:[0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]r   r   )re   rerg   ctypescreate_string_bufferwindllZkernel32ZGetSystemDirectoryAinsertr:   decoderl   r_   ri   rm   r|   rb   rw   r%   rx   	fullmatchr!   r$   rt   )re   r   rg   r}   dirsr   bufferdirrq   r~   r:   rs   r	   r	   r
   _ipconfig_getnode  s4    



r   c        	      C   s6  dd l } dd l}d }| }|j|_|  |_}|  | |dkrLd S |	  xt
|jD ]}|  |j|_t|j| |_| |dkrq`|  |j|_t|j| |_dd|_|  |_}| |dkrq`|	  |jd d }t|dkrq`t|d}t|r|S |p&|}q`W |p4d S )Nr   *r   r   r   )	win32wnetnetbiosZNCBZNCBENUMZCommandZ	LANA_ENUMZBufferZ_packZNetbiosZ_unpackrz   lengthZResetZNCBRESETordZlanaZLana_numZNCBASTATljustZCallnameZADAPTER_STATUSZadapter_addressr&   r!   r)   rt   )	r   r   r}   ZncbZadaptersr   statusr-   rs   r	   r	   r
   _netbios_getnode  s>    
r   c           
      s~  t d k	rd S da tjdkr8tt jdd dk r8ntd k	rPtj	a
tja d S ydd ldd ldg} tjds~| d x| D ]~}yj|}W n tk
r   wY nX t|d	r|jfd
da
da P qt|dr|j d  _ fdda
P qW yjj}W n   d }Y nX t|dt|dd aW n> tk
rx } zdd l}|d| t W d d }~X Y nX d S )NFdarwin.r   	   Zuuidwincuuid_generate_time_safec                 s     d}  | }t| j|fS )Nr   )r   r-   raw)_bufferZres)_uuid_generate_time_safer   r	   r
   _generate_time_safe_  s    
r   Tuuid_generate_timec                 s     d}  |  t| jd fS )Nr   )r   r-   r   )r   )_uuid_generate_timer   r	   r
   r   j  s    
ZUuidCreateSequentialZ
UuidCreatez/Could not find fallback ctypes uuid functions: )_has_uuid_generate_time_safesysplatformr!   re   unamereleaserw   _uuidZgenerate_time_safer   Zhas_uuid_generate_time_safer   Zctypes.util
startswithappendZCDLLutilZfind_library	Exceptionhasattrr   r   Zrestyper   Zrpcrt4getattr_UuidCreatewarningswarnImportWarning)Z	_libnamesZlibnamelibexcr   r	   )r   r   r   r
   _load_system_functions1  sP    &





r   c              C   s   t   t \} }t| djS )N)r-   )r   r   r   r6   )	uuid_time_r	   r	   r
   _unix_getnode  s    
r   c              C   s:   dd l } t  | d}t|dkr6tt|jdjS d S )Nr   r   )r-   )r   r   r   r   r   bytes_r   r6   )r   r   r	   r	   r
   _windll_getnode  s
    
r   c              C   s   dd l } | ddB S )Nr   r   l        )randomgetrandbits)r   r	   r	   r
   _random_getnode  s    r   )gettersc             C   sv   t d k	rt S tjdkrt} nt} xP| tg D ]B}y
| a W n   w,Y nX t d k	r,dt   krfdk r,n q,t S q,W d S )Nwin32r   l          )_noder   r   _NODE_GETTERS_WIN32_NODE_GETTERS_UNIXr   )r   getterr	   r	   r
   getnode  s    	

 r   c             C   s  t   td k	rd| |  kr"d krdn n>t \}}yt|}W n tk
rV   tj}Y nX t||dS dd l}t| d }t|d d }td k	r|tkrtd }|a|d krdd l	}|
d}|d@ }	|d	? d
@ }
|d? d@ }|d@ }|d? d@ }| d krt } t|	|
|||| fddS )N)r-   r   r   g    eAd   l    @'Hwr      l    r   i  r   i  rT   r   rV   )r/   r0   )r   r   r   r'   r   r   rU   r!   _last_timestampr   r   r   )r6   r7   r   Zsafely_generatedr   rU   ZnanosecondsZ	timestampr   r1   r2   r3   r5   r4   r	   r	   r
   uuid1  s4     


r   c             C   s8   ddl m} || jt|d  }t|d d ddS )Nr   )md5zutf-8r   r   )r-   r0   )hashlibr   r-   digestr   )	namespacerM   r   rG   r	   r	   r
   uuid3  s    r   c               C   s   t tdddS )Nr   r   )r-   r0   )r   re   urandomr	   r	   r	   r
   uuid4  s    r   c             C   s8   ddl m} || jt|d  }t|d d ddS )Nr   )sha1zutf-8r   r   )r-   r0   )r   r   r-   r   r   )r   rM   r   rG   r	   r	   r
   uuid5  s    r   z$6ba7b810-9dad-11d1-80b4-00c04fd430c8z$6ba7b811-9dad-11d1-80b4-00c04fd430c8z$6ba7b812-9dad-11d1-80b4-00c04fd430c8z$6ba7b814-9dad-11d1-80b4-00c04fd430c8)NN)/re   r   enumr   
__author__rX   rY   rZ   r[   r!   r(   r-   r   r   r   rr   rt   r   r   r   r   r   r   r   r   r   r   r   r   ImportErrorr   r   r   r   r   r   r   r   r   r   r   r   r   ZNAMESPACE_DNSZNAMESPACE_URLZNAMESPACE_OIDZNAMESPACE_X500r	   r	   r	   r
   <module>/   sZ     "
$
T


'