Beispiel #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)
 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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
 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)
Beispiel #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)