Beispiel #1
0
 def _nextTID(self, ttid=None, divisor=None):
     """
     Compute the next TID based on the current time and check collisions.
     Also, if ttid is not None, divisor is mandatory adjust it so that
         tid % divisor == ttid % divisor
     while preserving
         min_tid < tid
     If ttid is None, divisor is ignored.
     When constraints allow, prefer decreasing generated TID, to avoid
     fast-forwarding to future dates.
     """
     tid = tidFromTime(time())
     min_tid = self._last_tid
     if tid <= min_tid:
         tid  = addTID(min_tid, 1)
         # We know we won't have room to adjust by decreasing.
         try_decrease = False
     else:
         try_decrease = True
     if ttid is not None:
         assert isinstance(ttid, basestring), repr(ttid)
         assert isinstance(divisor, (int, long)), repr(divisor)
         ref_remainder = u64(ttid) % divisor
         remainder = u64(tid) % divisor
         if ref_remainder != remainder:
             if try_decrease:
                 new_tid = addTID(tid, ref_remainder - divisor - remainder)
                 assert u64(new_tid) % divisor == ref_remainder, (dump(new_tid),
                     ref_remainder)
                 if new_tid <= min_tid:
                     new_tid = addTID(new_tid, divisor)
             else:
                 if ref_remainder > remainder:
                     ref_remainder += divisor
                 new_tid = addTID(tid, ref_remainder - remainder)
             assert min_tid < new_tid, (dump(min_tid), dump(tid), dump(new_tid))
             tid = new_tid
     self._last_tid = tid
     return self._last_tid
Beispiel #2
0
 def _nextTID(self, ttid=None, divisor=None):
     """
     Compute the next TID based on the current time and check collisions.
     Also, if ttid is not None, divisor is mandatory adjust it so that
         tid % divisor == ttid % divisor
     while preserving
         min_tid < tid
     If ttid is None, divisor is ignored.
     When constraints allow, prefer decreasing generated TID, to avoid
     fast-forwarding to future dates.
     """
     tid = tidFromTime(time())
     min_tid = self._last_tid
     if tid <= min_tid:
         tid  = addTID(min_tid, 1)
         # We know we won't have room to adjust by decreasing.
         try_decrease = False
     else:
         try_decrease = True
     if ttid is not None:
         assert isinstance(ttid, basestring), repr(ttid)
         assert isinstance(divisor, (int, long)), repr(divisor)
         ref_remainder = u64(ttid) % divisor
         remainder = u64(tid) % divisor
         if ref_remainder != remainder:
             if try_decrease:
                 new_tid = addTID(tid, ref_remainder - divisor - remainder)
                 assert u64(new_tid) % divisor == ref_remainder, (dump(new_tid),
                     ref_remainder)
                 if new_tid <= min_tid:
                     new_tid = addTID(new_tid, divisor)
             else:
                 if ref_remainder > remainder:
                     ref_remainder += divisor
                 new_tid = addTID(tid, ref_remainder - remainder)
             assert min_tid < new_tid, (dump(min_tid), dump(tid), dump(new_tid))
             tid = new_tid
     self._last_tid = tid
     return self._last_tid
Beispiel #3
0
 def asTID(self, value):
     if '.' in value:
         return tidFromTime(float(value))
     return p64(int(value, 0))
Beispiel #4
0
 def asTID(self, value):
     if '.' in value:
         return tidFromTime(float(value))
     return p64(int(value, 0))