MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / __init__

Method __init__

tools/python-3.11.9-amd64/Lib/uuid.py:139–223  ·  view source on GitHub ↗

r"""Create a UUID from either a string of 32 hexadecimal digits, a string of 16 bytes as the 'bytes' argument, a string of 16 bytes in little-endian order as the 'bytes_le' argument, a tuple of six integers (32-bit time_low, 16-bit time_mid, 16-bit time_hi_version,

(self, hex=None, bytes=None, bytes_le=None, fields=None,
                       int=None, version=None,
                       *, is_safe=SafeUUID.unknown)

Source from the content-addressed store, hash-verified

137 __slots__ = ('int', 'is_safe', '__weakref__')
138
139 def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None,
140 int=None, version=None,
141 *, is_safe=SafeUUID.unknown):
142 r"""Create a UUID from either a string of 32 hexadecimal digits,
143 a string of 16 bytes as the 'bytes' argument, a string of 16 bytes
144 in little-endian order as the 'bytes_le' argument, a tuple of six
145 integers (32-bit time_low, 16-bit time_mid, 16-bit time_hi_version,
146 8-bit clock_seq_hi_variant, 8-bit clock_seq_low, 48-bit node) as
147 the 'fields' argument, or a single 128-bit integer as the 'int'
148 argument. When a string of hex digits is given, curly braces,
149 hyphens, and a URN prefix are all optional. For example, these
150 expressions all yield the same UUID:
151
152 UUID('{12345678-1234-5678-1234-567812345678}')
153 UUID('12345678123456781234567812345678')
154 UUID('urn:uuid:12345678-1234-5678-1234-567812345678')
155 UUID(bytes='\x12\x34\x56\x78'*4)
156 UUID(bytes_le='\x78\x56\x34\x12\x34\x12\x78\x56' +
157 '\x12\x34\x56\x78\x12\x34\x56\x78')
158 UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678))
159 UUID(int=0x12345678123456781234567812345678)
160
161 Exactly one of 'hex', 'bytes', 'bytes_le', 'fields', or 'int' must
162 be given. The 'version' argument is optional; if given, the resulting
163 UUID will have its variant and version set according to RFC 4122,
164 overriding the given 'hex', 'bytes', 'bytes_le', 'fields', or 'int'.
165
166 is_safe is an enum exposed as an attribute on the instance. It
167 indicates whether the UUID has been generated in a way that is safe
168 for multiprocessing applications, via uuid_generate_time_safe(3).
169 """
170
171 if [hex, bytes, bytes_le, fields, int].count(None) != 4:
172 raise TypeError('one of the hex, bytes, bytes_le, fields, '
173 'or int arguments must be given')
174 if hex is not None:
175 hex = hex.replace('urn:', '').replace('uuid:', '')
176 hex = hex.strip('{}').replace('-', '')
177 if len(hex) != 32:
178 raise ValueError('badly formed hexadecimal UUID string')
179 int = int_(hex, 16)
180 if bytes_le is not None:
181 if len(bytes_le) != 16:
182 raise ValueError('bytes_le is not a 16-char string')
183 bytes = (bytes_le[4-1::-1] + bytes_le[6-1:4-1:-1] +
184 bytes_le[8-1:6-1:-1] + bytes_le[8:])
185 if bytes is not None:
186 if len(bytes) != 16:
187 raise ValueError('bytes is not a 16-char string')
188 assert isinstance(bytes, bytes_), repr(bytes)
189 int = int_.from_bytes(bytes) # big endian
190 if fields is not None:
191 if len(fields) != 6:
192 raise ValueError('fields is not a 6-tuple')
193 (time_low, time_mid, time_hi_version,
194 clock_seq_hi_variant, clock_seq_low, node) = fields
195 if not 0 <= time_low < 1<<32:
196 raise ValueError('field 1 out of range (need a 32-bit value)')

Callers

nothing calls this directly

Calls 5

stripMethod · 0.80
from_bytesMethod · 0.80
countMethod · 0.45
replaceMethod · 0.45
__setattr__Method · 0.45

Tested by

no test coverage detected