3 h>`B@sdZdZdjdjddZdjdZddd d g\ZZZZ d d l Z e j d,krRe Z ddZGdddeZddZddZddZd ZZZddZddZddZd addZd-d d!Zd"d#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 definitionNcCs||k||kS)N)xyrr/usr/lib/python3.6/uuid.py=sr 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||||gjddkrtd|dk rj|jddjdd}|jdjdd}t|d kr`td t|d }|dk rt|d krtd td d ttt |d }|dk rt|dkrtd|\}}}} } } d|kotd&knstdd|ko td'knstdd|ko4td(knsDtdd| ko\td)knsltdd| kotd*knstdd| kotd+knstd| td>| B} |td>|td>B|td>B| td>B| B}|dk r6d|ko&dtd>kns6td|dk rd|koTdknsdtd |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%02xzfields is not a 6-tuplerrz*field 1 out of range (need a 32-bit value)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)0z*field 6 out of range (need a 48-bit value)`P@z*int is out of range (need a 128-bit value)zillegal version numberiiiLintliirl) count TypeErrorreplacestriplen ValueErrorlongtuplemapord__dict__) selfhexbytesfieldsrversiontime_lowtime_midtime_hi_versionclock_seq_hi_variant clock_seq_lownode clock_seqrrr __init__jsR          4 $ z UUID.__init__cCst|tr|j|jkStS)N) isinstancer rNotImplemented)r%otherrrr __lt__s  z UUID.__lt__cCs t|jS)N)hashr)r%rrr __hash__sz UUID.__hash__cCs|jS)N)r)r%rrr __int__sz UUID.__int__cCs dt|S)NzUUID(%r))str)r%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)Nz%032xz%s-%s-%s-%s-%sr r)r)r%r&rrr __str__s z UUID.__str__cCs4d}x*tdddD]}t|j|?d@|}qW|S)Nr rrr)rangechrr)r%r'Zshiftrrr get_bytesszUUID.get_bytescCs|j|j|j|j|j|jfS)N)r*r+r,r-r.r/)r%rrr get_fieldss zUUID.get_fieldscCs|jtd?S)Nr)rr )r%rrr get_time_lowszUUID.get_time_lowcCs|jtd?d@S)Nri)rr )r%rrr get_time_midszUUID.get_time_midcCs|jtd?d@S)Nri)rr )r%rrr get_time_hi_versionszUUID.get_time_hi_versioncCs|jtd?d@S)N8rA)rr )r%rrr get_clock_seq_hi_variantszUUID.get_clock_seq_hi_variantcCs|jtd?d@S)NrrA)rr )r%rrr get_clock_seq_lowszUUID.get_clock_seq_lowcCs&|jd@td>|jtd>B|jBS)Nirr )r,r r+r*)r%rrr get_timesz UUID.get_timecCs|jtd@td>|jBS)N?r)r-r r.)r%rrr get_clock_seqszUUID.get_clock_seqcCs |jd@S)Nl)r)r%rrr get_nodesz UUID.get_nodecCs d|jS)Nz%032x)r)r%rrr get_hexsz UUID.get_hexcCs dt|S)Nz urn:uuid:)r9)r%rrr get_urnsz UUID.get_urncCsJ|jdtd>@stS|jdtd>@s,tS|jdtd>@sBtStSdS)Niri@i )rr RESERVED_NCSRFC_4122RESERVED_MICROSOFTRESERVED_FUTURE)r%rrr get_variantszUUID.get_variantcCs$|jtkr t|jtd?d@SdS)Nr)variantrSrr )r%rrr get_versions zUUID.get_version)NNNNN)(__name__ __module__ __qualname____doc__r1r5r7r8r:r=r@rDpropertyr'rEr(rFr*rGr+rHr,rJr-rKr.rLtimerNr0rOr/rPr&rQZurnrVrXrYr)rrrr r @sJ( E r cCsddl}xd D]}y|j|jj|d}Wntk r@wYnXxT|D]L}|jj}x:tt|D]*}||d krft ||d j d dd SqfWqHWqWdS)z5Get the hardware address on Unix by running ifconfig.rNr /sbin/ /usr/sbinZifconfighwaddretherr:r)r r`ra)rbrc) ospopenpathjoinIOErrorlowersplitrBrrr)redpipelineZwordsirrr _ifconfig_getnodes    rpc Csddl}ddl}dddg}y:ddl}|jd}|jjj|d|jd|jj dWn YnXx|D]z}y|j |j j |dd }Wnt k rwhYnXx@|D]8}|jd djj}|jd |rt|jd ddSqWqhWdS)z|dtd>|dtd >|d td>|d td >|d SWdS)ztGet the hardware address on Windows using NetBIOS calls. See http://support.microsoft.com/kb/118623 for details.rN*r(rr rrr) win32wnetnetbiosZNCBZNCBENUMZCommandZ LANA_ENUMZBufferZ_packZNetbiosZ_unpackrBZlengthZResetZNCBRESETr#ZlanaZLana_numZNCBASTATljustZCallnameZADAPTER_STATUSr"Zadapter_addressr )rrZncbZadaptersroZstatusr'rrr _netbios_getnodeBs2  rcCsttttjdjS)z.Get the hardware address on Unix using ctypes.)r')_uuid_generate_time_bufferr rawr/rrrr _unixdll_getnodedsrcCsttdkrttjdjSdS)z1Get the hardware address on Windows using ctypes.r)r'N) _UuidCreaterr rr/rrrr _windll_getnodejs rcCs$ddl}|jddtd>tdBS)zCGet a random node ID, with eighth bit set as suggested by RFC 4122.rNrrl)random randranger )rrrr _random_getnodepsrc Csptdk r tSddl}|jdkr*tttg}nttg}x8|tgD]*}y |aWnw>YnXtdk r>tSq>WdS)a!Get the hardware address as a 48-bit integer. The first time this runs, it may launch a separate program, which could be quite slow. If all attempts to obtain the hardware address fail, we choose a random 48-bit number with its eighth bit set to 1 as recommended in RFC 4122.NrZwin32) _nodesysplatformrrrzrrpr)rZgettersgetterrrr getnodexs   rc Cstr0||kodknr0ttttjdSddl}t|jd}t|dtd}|dkr~ddl}|jdtd>}|td @}|td ?td @}|td ?td @}|td@} |td?td@} |dkrt }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.N)r'rgeAdl@'Hw rlr irirArrM)r(r)) rrr rr_rr rrr) r/r0r_Z nanosecondsZ timestamprr*r+r,r.r-rrr uuid1s$   rcCs0ddl}|j|j|j}t|ddddS)zAGenerate a UUID from the MD5 hash of a namespace UUID and a name.rNrr)r'r))md5r'digestr ) namespacer;rmy_hashrrr uuid3src shtrttttjdSyddl}t|jdddSddlfddtdD}t|ddSdS) zGenerate a random UUID.)r'rNrr)r'r)csg|]}tjdqS)r)rCr).0ro)rrr szuuid4..)_uuid_generate_randomrr rreurandomrrB)rer'r)rr uuid4s rcCs0ddl}|j|j|j}t|ddddS)zCGenerate a UUID from the SHA-1 hash of a namespace UUID and a name.rNrr)r'r))shar'rr )rr;rrrrr uuid5srz$6ba7b810-9dad-11d1-80b4-00c04fd430c8z$6ba7b811-9dad-11d1-80b4-00c04fd430c8z$6ba7b812-9dad-11d1-80b4-00c04fd430c8z$6ba7b814-9dad-11d1-80b4-00c04fd430c8)r)NN)$r] __author__rkrZ__date__ __version__rRrSrTrUr version_inforr Zcmpobjectr rprzrrrrrrrrrrrrrZ NAMESPACE_DNSZ NAMESPACE_URLZ NAMESPACE_OIDZNAMESPACE_X500rrrr .s8  ]