1
from uuid import UUID, uuid4, _uuid_generate_random
9
"""Generate a unique id, having - hopefully - a very small chance of
12
For now this is provided by :func:`uuid.uuid4`.
14
# Workaround for http://bugs.python.org/issue4607
15
if ctypes and _uuid_generate_random:
16
buffer = ctypes.create_string_buffer(16)
17
_uuid_generate_random(buffer)
18
return str(UUID(bytes=buffer.raw))
22
def _compat_rl_partition(S, sep, direction=str.split):
23
items = direction(S, sep, 1)
25
return items[0], sep, ''
26
return items[0], sep, items[1]
29
def _compat_partition(S, sep):
30
"""``partition(S, sep) -> (head, sep, tail)``
32
Search for the separator ``sep`` in ``S``, and return the part before
33
it, the separator itself, and the part after it. If the separator is not
34
found, return ``S`` and two empty strings.
37
return _compat_rl_partition(S, sep, direction=str.split)
40
def _compat_rpartition(S, sep):
41
"""``rpartition(S, sep) -> (tail, sep, head)``
43
Search for the separator ``sep`` in ``S``, starting at the end of ``S``,
44
and return the part before it, the separator itself, and the part
45
after it. If the separator is not found, return two empty
49
return _compat_rl_partition(S, sep, direction=str.rsplit)
52
partition = str.partition
53
rpartition = str.rpartition
54
except AttributeError: # Python <= 2.4
55
partition = _compat_partition
56
rpartition = _compat_rpartition