/usr/share/pyshared/carrot/utils.py is in python-carrot 0.10.7-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | from uuid import UUID, uuid4, _uuid_generate_random
try:
import ctypes
except ImportError:
ctypes = None
def gen_unique_id():
"""Generate a unique id, having - hopefully - a very small chance of
collission.
For now this is provided by :func:`uuid.uuid4`.
"""
# Workaround for http://bugs.python.org/issue4607
if ctypes and _uuid_generate_random:
buffer = ctypes.create_string_buffer(16)
_uuid_generate_random(buffer)
return str(UUID(bytes=buffer.raw))
return str(uuid4())
def _compat_rl_partition(S, sep, direction=None):
if direction is None:
direction = S.split
items = direction(sep, 1)
if len(items) == 1:
return items[0], sep, ''
return items[0], sep, items[1]
def _compat_partition(S, sep):
"""``partition(S, sep) -> (head, sep, tail)``
Search for the separator ``sep`` in ``S``, and return the part before
it, the separator itself, and the part after it. If the separator is not
found, return ``S`` and two empty strings.
"""
return _compat_rl_partition(S, sep, direction=S.split)
def _compat_rpartition(S, sep):
"""``rpartition(S, sep) -> (tail, sep, head)``
Search for the separator ``sep`` in ``S``, starting at the end of ``S``,
and return the part before it, the separator itself, and the part
after it. If the separator is not found, return two empty
strings and ``S``.
"""
return _compat_rl_partition(S, sep, direction=S.rsplit)
def partition(S, sep):
if hasattr(S, 'partition'):
return S.partition(sep)
else: # Python <= 2.4:
return _compat_partition(S, sep)
def rpartition(S, sep):
if hasattr(S, 'rpartition'):
return S.rpartition(sep)
else: # Python <= 2.4:
return _compat_rpartition(S, sep)
|