Пример #1
0
 def test_timeuuid_low_high(self):
     for uuid_str in get_str_uuids(100):
         uu = UUID(uuid_str)
         low = timeuuid_from_time(uu.time, UUIDType.LOWEST)
         high = timeuuid_from_time(uu.time, UUIDType.HIGHEST)
         self.assertTrue(low < high)
         for i in xrange(5000):
             rand = timeuuid_from_time(uu.time, UUIDType.RANDOM)
             self.assertTrue(low < rand)
             self.assertTrue(high > rand)
Пример #2
0
 def test_timeuuid_low_high(self):
   for uuid_str in get_str_uuids(100):
     uu = UUID(uuid_str)
     low = timeuuid_from_time(uu.time, UUIDType.LOWEST)
     high = timeuuid_from_time(uu.time, UUIDType.HIGHEST)
     self.assertTrue(low < high)
     for i in xrange(5000):
       rand = timeuuid_from_time(uu.time, UUIDType.RANDOM)
       self.assertTrue(low < rand)
       self.assertTrue(high > rand)
Пример #3
0
def uuid_from_kronos_time(time, _type=UUIDType.RANDOM):
    """
  Generate a UUID with the specified time.
  If `lowest` is true, return the lexicographically first UUID for the specified
  time.
  """
    return timeuuid_from_time(int(time) + UUID_TIME_OFFSET, type=_type)
Пример #4
0
def uuid_from_kronos_time(time, _type=UUIDType.RANDOM):
  """
  Generate a UUID with the specified time.
  If `lowest` is true, return the lexicographically first UUID for the specified
  time.
  """
  return timeuuid_from_time(int(time) + UUID_TIME_OFFSET, type=_type)
Пример #5
0
from timeuuid import timeuuid_from_time
from timeuuid import UUIDType

UUID_TIME_OFFSET = 0x01b21dd213814000L


def uuid_to_kronos_time(uuid):
    """
  UUIDs contain a time field. Convert it to kronos time and return.
  """
    return uuid.time - UUID_TIME_OFFSET


def uuid_from_kronos_time(time, _type=UUIDType.RANDOM):
    """
  Generate a UUID with the specified time.
  If `lowest` is true, return the lexicographically first UUID for the specified
  time.
  """
    return timeuuid_from_time(int(time) + UUID_TIME_OFFSET, type=_type)


LOWEST_UUID = timeuuid_from_time(0, UUIDType.LOWEST)
HIGHEST_UUID = timeuuid_from_time(2**60 - 1, UUIDType.HIGHEST)
Пример #6
0
 def test_timeuuid_from_time(self):
     for uuid_str in get_str_uuids(10000):
         uu = UUID(uuid_str)
         for t in (UUIDType.LOWEST, UUIDType.HIGHEST, UUIDType.RANDOM):
             tuu = timeuuid_from_time(uu.time, type=t)
             self.assertEqual(uu.time, tuu.time)
Пример #7
0
 def test_timeuuid_from_time(self):
   for uuid_str in get_str_uuids(10000):
     uu = UUID(uuid_str)
     for t in (UUIDType.LOWEST, UUIDType.HIGHEST, UUIDType.RANDOM):
       tuu = timeuuid_from_time(uu.time, type=t)
       self.assertEqual(uu.time, tuu.time)
Пример #8
0
from timeuuid import timeuuid_from_time
from timeuuid import UUIDType

UUID_TIME_OFFSET = 0x01b21dd213814000L


def uuid_to_kronos_time(uuid):
  """
  UUIDs contain a time field. Convert it to kronos time and return.
  """
  return uuid.time - UUID_TIME_OFFSET


def uuid_from_kronos_time(time, _type=UUIDType.RANDOM):
  """
  Generate a UUID with the specified time.
  If `lowest` is true, return the lexicographically first UUID for the specified
  time.
  """
  return timeuuid_from_time(int(time) + UUID_TIME_OFFSET, type=_type)


LOWEST_UUID = timeuuid_from_time(0, UUIDType.LOWEST)
HIGHEST_UUID = timeuuid_from_time(2 ** 60 - 1, UUIDType.HIGHEST)