a hB@sdZdZddddZddZgd\ZZZZ dd l Z e j d krNe Z d d ZGd ddeZddZddZddZd ZZZddZddZddZd addZd)ddZdd Zd!d"Zd#d$Zed%Z ed&Z!ed'Z"ed(Z#d S)*aUUUID objects (universally unique identifiers) according to RFC 4122. This module provides immutable UUID objects (class UUID) and the functions uuid1(), uuid3(), uuid4(), uuid5() for generating version 1, 3, 4, and 5 UUIDs as specified in RFC 4122. If all you want is a unique ID, you should probably call uuid1() or uuid4(). Note that uuid1() may compromise privacy since it creates a UUID containing the computer's network address. uuid4() creates a random UUID. Typical usage: >>> import uuid # make a UUID based on the host ID and current time >>> uuid.uuid1() UUID('a8098c1a-f86e-11da-bd1a-00112444be1e') # make a UUID using an MD5 hash of a namespace UUID and a name >>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org') UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e') # make a random UUID >>> uuid.uuid4() UUID('16fd2706-8baf-433b-82eb-8c7fada847da') # make a UUID using a SHA-1 hash of a namespace UUID and a name >>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org') UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d') # make a UUID from a string of hex digits (braces and hyphens ignored) >>> x = uuid.UUID('{00010203-0405-0607-0809-0a0b0c0d0e0f}') # convert a UUID to a string of hex digits in standard form >>> str(x) '00010203-0405-0607-0809-0a0b0c0d0e0f' # get the raw 16 bytes of the UUID >>> x.bytes '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f' # make a UUID from a 16-byte string >>> uuid.UUID(bytes=x.bytes) UUID('00010203-0405-0607-0809-0a0b0c0d0e0f') This module works with Python 2.3 or higher.zKa-Ping Yee z$Date: 2006/08/24 19:08:53 $/-z$Revision: 1.2 $)zreserved for NCS compatibilityzspecified in RFC 4122z$reserved for Microsoft compatibilityzreserved for future definitionN)cCs||k||kSN)xyrr7/usr/lib/python3.9/site-packages/setroubleshoot/uuid.py=r c@s*eZdZdZd-ddZddZddZd d Zd d Zd dZ ddZ ddZ e e Z ddZe eZddZe eZddZe eZddZe eZddZe eZddZe eZdd Ze eZd!d"Ze eZd#d$Ze eZd%d&Z e e Z!d'd(Z"e e"Z#d)d*Z$e e$Z%d+d,Z&e e&Z'dS).UUIDaTInstances of the UUID class represent UUIDs as specified in RFC 4122. UUID objects are immutable, hashable, and usable as dictionary keys. Converting a UUID to a string with str() yields something in the form '12345678-1234-1234-1234-123456789abc'. The UUID constructor accepts four possible forms: a similar string of hexadecimal digits, or a string of 16 raw bytes as an argument named 'bytes', or a tuple of six integer fields (with 32-bit, 16-bit, 16-bit, 8-bit, 8-bit, and 48-bit values respectively) as an argument named 'fields', or a single 128-bit integer as an argument named 'int'. UUIDs have these read-only attributes: bytes the UUID as a 16-byte string fields a tuple of the six integer fields of the UUID, which are also available as six individual attributes and two derived attributes: time_low the first 32 bits of the UUID time_mid the next 16 bits of the UUID time_hi_version the next 16 bits of the UUID clock_seq_hi_variant the next 8 bits of the UUID clock_seq_low the next 8 bits of the UUID node the last 48 bits of the UUID time the 60-bit timestamp clock_seq the 14-bit sequence number hex the UUID as a 32-character hexadecimal string int the UUID as a 128-bit integer urn the UUID as a URN as specified in RFC 4122 variant the UUID variant (one of the constants RESERVED_NCS, RFC_4122, RESERVED_MICROSOFT, or RESERVED_FUTURE) version the UUID version number (1 through 5, meaningful only when the variant is RFC_4122) Nc Cs||||gddkrtd|durj|dddd}|ddd}t|d kr`td t|d }|durt|d krtd td ttt |d }|durt|dkrtd|\}}}} } } d|krtdksntdd|kr tdksntdd|kr0tdks:ntdd| krVtdks`ntdd| kr|tdksntdd| krtdksntd| td>| B} |td>|td>B|td>B| td>B| B}|dur$d|krd td!>ks$ntd"|durd |krFd#ksPntd$|d%td>M}|d&td>O}|d'td>M}||td(>O}||j d)<dS)*aCreate a UUID from either a string of 32 hexadecimal digits, a string of 16 bytes as the 'bytes' argument, a tuple of six integers (32-bit time_low, 16-bit time_mid, 16-bit time_hi_version, 8-bit clock_seq_hi_variant, 8-bit clock_seq_low, 48-bit node) as the 'fields' argument, or a single 128-bit integer as the 'int' argument. When a string of hex digits is given, curly braces, hyphens, and a URN prefix are all optional. For example, these expressions all yield the same UUID: UUID('{12345678-1234-5678-1234-567812345678}') UUID('12345678123456781234567812345678') UUID('urn:uuid:12345678-1234-5678-1234-567812345678') UUID(bytes='\x12\x34\x56\x78'*4) UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678)) UUID(int=0x12345678123456781234567812345678) Exactly one of 'hex', 'bytes', 'fields', or 'int' must be given. The 'version' argument is optional; if given, the resulting UUID will have its variant and version number set according to RFC 4122, overriding bits in the given 'hex', 'bytes', 'fields', or 'int'. Nrz+need just one of hex, bytes, fields, or intzurn:zuuid:z{}r z$badly formed hexadecimal UUID stringzbytes is not a 16-char stringz@%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02xzfields is not a 6-tuplerlz*field 1 out of range (need a 32-bit value)iz*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)lz*field 6 out of range (need a 48-bit value)`P@0rz*int is out of range (need a 128-bit value)zillegal version numberiiLint) count TypeErrorreplacestriplen ValueErrorlongtuplemapord__dict__) selfhexbytesfieldsrversiontime_lowtime_midtime_hi_versionclock_seq_hi_variant clock_seq_lownode clock_seqrrr __init__jsb        " z UUID.__init__cCst|tr|j|jkStSr) isinstancer rNotImplemented)r(otherrrr __lt__s  z UUID.__lt__cCs t|jSr)hashrr(rrr __hash__sz UUID.__hash__cCs|jSrrr:rrr __int__sz UUID.__int__cCs dt|S)NzUUID(%r)strr:rrr __repr__sz UUID.__repr__cCs tddS)NzUUID objects are immutable)r)r(namevaluerrr __setattr__szUUID.__setattr__cCsDd|j}d|dd|dd|dd|dd|ddfS)N%032xz%s-%s-%s-%s-%sr rr<)r(r)rrr __str__s 2z UUID.__str__cCs0d}tdddD]}t|j|?d@|}q|S)Nrrrr)rangechrr)r(r*shiftrrr get_bytesszUUID.get_bytescCs|j|j|j|j|j|jfSr)r-r.r/r0r1r2r:rrr get_fieldss  zUUID.get_fieldscCs|jtd?S)Nrrr#r:rrr get_time_lowszUUID.get_time_lowcCs|jtd?d@S)NrrNr:rrr get_time_midszUUID.get_time_midcCs|jtd?d@S)NrrPrNr:rrr get_time_hi_versionszUUID.get_time_hi_versioncCs|jtd?d@S)N8rHrNr:rrr get_clock_seq_hi_variantszUUID.get_clock_seq_hi_variantcCs|jtd?d@S)NrrHrNr:rrr get_clock_seq_lowszUUID.get_clock_seq_lowcCs&|jd@td>|jtd>B|jBS)Nrr)r/r#r.r-r:rrr get_times  z UUID.get_timecCs|jtd@td>|jBS)N?r)r0r#r1r:rrr get_clock_seqszUUID.get_clock_seqcCs |jd@S)Nlr<r:rrr get_nodesz UUID.get_nodecCs d|jS)NrDr<r:rrr get_hexsz UUID.get_hexcCs dt|S)Nz urn:uuid:r>r:rrr get_urnsz UUID.get_urncCsJ|jdtd>@stS|jdtd>@s,tS|jdtd>@sBtStSdS)Nrri@i )rr# RESERVED_NCSRFC_4122RESERVED_MICROSOFTRESERVED_FUTUREr:rrr get_variantszUUID.get_variantcCs$|jtkr t|jtd?d@SdS)Nr)variantr^rr#r:rrr get_versions zUUID.get_version)NNNNN)(__name__ __module__ __qualname____doc__r4r8r;r=r@rCrGrLpropertyr*rMr+rOr-rQr.rRr/rTr0rUr1rWtimerYr3rZr2r[r)r\Zurnrarcrdr,rrrr r @sL) F r c Csddl}dD]}z||j|d}Wnty>Yq Yn0|D]T}|}tt|D]6}||dvr`t ||d ddd Sq`qDq dS) z5Get the hardware address on Unix by running ifconfig.rN)rz/sbin/z /usr/sbinZifconfig)ZhwaddrZetherr:rr) ospopenpathjoinIOErrorlowersplitrIr!rr)rldpipelinewordsirrr _ifconfig_getnodes    rxc Csddl}ddl}gd}z:ddl}|d}|jj|d|d|j dWn Yn0|D]~}z| |j |dd}Wnt yYqdYn0|D]@}|dd }|d |rt|d d d SqqddS)z|dtd>|dtd >|d td>|d td >|d SdS)ztGet the hardware address on Windows using NetBIOS calls. See http://support.microsoft.com/kb/118623 for details.rN*r(rrrrr) win32wnetnetbiosZNCBZNCBENUMZCommandZ LANA_ENUMZBufferZ_packZNetbiosZ_unpackrIlengthZResetZNCBRESETr&ZlanaZLana_numZNCBASTATljustZCallnameZADAPTER_STATUSr%Zadapter_addressr#)rrZncbZadaptersrwstatusr*rrr _netbios_getnodeBsB  rcCsttttjdjS)z.Get the hardware address on Unix using ctypes.r*)_uuid_generate_time_bufferr rawr2rrrr _unixdll_getnodedsrcCsttdkrttjdjSdS)z1Get the hardware address on Windows using ctypes.rrN) _UuidCreaterr rr2rrrr _windll_getnodejs rcCs$ddl}|ddtd>tdBS)zCGet a random node ID, with eighth bit set as suggested by RFC 4122.rNrrl)random randranger#rrrr _random_getnodepsrcCsrtdur tSddl}|jdkr*tttg}nttg}|tgD]0}z |aWnYq}|td @}|td ?td @}|td ?td @}|td@} |td?td@} |durt }t|||| | |fddS)aGenerate a UUID from a host ID, sequence number, and the current time. If 'node' is not given, getnode() is used to obtain the hardware address. If 'clock_seq' is given, it is used as the sequence number; otherwise a random 14-bit sequence number is chosen.NrrgeAdl@'Hw rlrrPrrVrHrrX)r+r,) rrr rrjrr#rrr) r2r3rjZ nanosecondsZ timestamprr-r.r/r1r0rrr uuid1s*   rcCs0ddl}||j|}t|ddddS)zAGenerate a UUID from the MD5 hash of a namespace UUID and a name.rNrrr*r,)md5r*digestr ) namespacerArmy_hashrrr uuid3srcsptrttttjdSzddl}t|dddWSddlfddtdD}t|ddYS0dS) zGenerate a random UUID.rrNrrrcsg|]}tdqS)r)rJr).0rwrrr r zuuid4..)_uuid_generate_randomrr rrlurandomrrI)rlr*rrr uuid4s rcCs0ddl}||j|}t|ddddS)zCGenerate a UUID from the SHA-1 hash of a namespace UUID and a name.rNrrr)shar*rr )rrArrrrr uuid5srz$6ba7b810-9dad-11d1-80b4-00c04fd430c8z$6ba7b811-9dad-11d1-80b4-00c04fd430c8z$6ba7b812-9dad-11d1-80b4-00c04fd430c8z$6ba7b814-9dad-11d1-80b4-00c04fd430c8)NN)$rh __author__rrrZ__date__ __version__r]r^r_r`r version_inforr#cmpobjectr rxrrrrrrrrrrrrrrZ NAMESPACE_DNSZ NAMESPACE_URLZ NAMESPACE_OIDZNAMESPACE_X500rrrr s6/  ]