#7380: Fix some str/bytearray/bytes issues in uuid docs and implementation.
This commit is contained in:
parent
e231e39c28
commit
1d523e1ae1
|
@ -31,9 +31,9 @@ random UUID.
|
||||||
UUID('{12345678-1234-5678-1234-567812345678}')
|
UUID('{12345678-1234-5678-1234-567812345678}')
|
||||||
UUID('12345678123456781234567812345678')
|
UUID('12345678123456781234567812345678')
|
||||||
UUID('urn:uuid:12345678-1234-5678-1234-567812345678')
|
UUID('urn:uuid:12345678-1234-5678-1234-567812345678')
|
||||||
UUID(bytes='\x12\x34\x56\x78'*4)
|
UUID(bytes=b'\x12\x34\x56\x78'*4)
|
||||||
UUID(bytes_le='\x78\x56\x34\x12\x34\x12\x78\x56' +
|
UUID(bytes_le=b'\x78\x56\x34\x12\x34\x12\x78\x56' +
|
||||||
'\x12\x34\x56\x78\x12\x34\x56\x78')
|
b'\x12\x34\x56\x78\x12\x34\x56\x78')
|
||||||
UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678))
|
UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678))
|
||||||
UUID(int=0x12345678123456781234567812345678)
|
UUID(int=0x12345678123456781234567812345678)
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ Here are some examples of typical usage of the :mod:`uuid` module::
|
||||||
|
|
||||||
# get the raw 16 bytes of the UUID
|
# get the raw 16 bytes of the UUID
|
||||||
>>> x.bytes
|
>>> x.bytes
|
||||||
'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
|
b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
|
||||||
|
|
||||||
# make a UUID from a 16-byte string
|
# make a UUID from a 16-byte string
|
||||||
>>> uuid.UUID(bytes=x.bytes)
|
>>> uuid.UUID(bytes=x.bytes)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from test import support
|
from test import support
|
||||||
|
import builtins
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
def importable(name):
|
def importable(name):
|
||||||
|
@ -176,6 +177,11 @@ class TestUUID(TestCase):
|
||||||
for u in equivalents:
|
for u in equivalents:
|
||||||
for v in equivalents:
|
for v in equivalents:
|
||||||
equal(u, v)
|
equal(u, v)
|
||||||
|
|
||||||
|
# Bug 7380: "bytes" and "bytes_le" should give the same type.
|
||||||
|
equal(type(u.bytes), builtins.bytes)
|
||||||
|
equal(type(u.bytes_le), builtins.bytes)
|
||||||
|
|
||||||
ascending.append(u)
|
ascending.append(u)
|
||||||
|
|
||||||
# Test comparison of UUIDs.
|
# Test comparison of UUIDs.
|
||||||
|
|
|
@ -13,7 +13,7 @@ Typical usage:
|
||||||
>>> import uuid
|
>>> import uuid
|
||||||
|
|
||||||
# make a UUID based on the host ID and current time
|
# make a UUID based on the host ID and current time
|
||||||
>>> uuid.uuid1()
|
>>> uuid.uuid1() # doctest: +SKIP
|
||||||
UUID('a8098c1a-f86e-11da-bd1a-00112444be1e')
|
UUID('a8098c1a-f86e-11da-bd1a-00112444be1e')
|
||||||
|
|
||||||
# make a UUID using an MD5 hash of a namespace UUID and a name
|
# make a UUID using an MD5 hash of a namespace UUID and a name
|
||||||
|
@ -21,7 +21,7 @@ Typical usage:
|
||||||
UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e')
|
UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e')
|
||||||
|
|
||||||
# make a random UUID
|
# make a random UUID
|
||||||
>>> uuid.uuid4()
|
>>> uuid.uuid4() # doctest: +SKIP
|
||||||
UUID('16fd2706-8baf-433b-82eb-8c7fada847da')
|
UUID('16fd2706-8baf-433b-82eb-8c7fada847da')
|
||||||
|
|
||||||
# make a UUID using a SHA-1 hash of a namespace UUID and a name
|
# make a UUID using a SHA-1 hash of a namespace UUID and a name
|
||||||
|
@ -237,7 +237,7 @@ class UUID(object):
|
||||||
bytes = bytearray()
|
bytes = bytearray()
|
||||||
for shift in range(0, 128, 8):
|
for shift in range(0, 128, 8):
|
||||||
bytes.insert(0, (self.int >> shift) & 0xff)
|
bytes.insert(0, (self.int >> shift) & 0xff)
|
||||||
return bytes
|
return bytes_(bytes)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def bytes_le(self):
|
def bytes_le(self):
|
||||||
|
|
Loading…
Reference in New Issue