def test_pos(self): tz = dateutil.tz.gettz('Etc/GMT+1') dt = datetime.now(tz) sn = _keylib.packs(dt) sp = keylib.packs(dt) eq(sn, sp) dn = _keylib.unpacks(sn) dp = keylib.unpacks(sp) eq(dn, dp)
def test_pos(self): tz = dateutil.tz.gettz('Etc/GMT+1') dt = datetime.now(tz) sn = _keylib.packs('', dt) sp = keylib.packs('', dt) eq(sn, sp) dn = _keylib.unpacks('', sn) dp = keylib.unpacks('', sp) eq(dn, dp)
def test_utc(self): tz = dateutil.tz.gettz('Etc/UTC') dt = datetime.now(tz) sn = _keylib.packs(dt) sp = keylib.packs(dt) eq(sn, sp) dn = _keylib.unpacks(sn) dp = keylib.unpacks(sp) eq(dn, dp)
def _logical_iter(self, it, reverse, prefix_s, prefix): """Generator that wraps a database engine iterator to yield logical records. For compressed records, each physical record may contain multiple physical records. This job's function is to make the distinction invisible to reads.""" # * When iterating forward, if first yielded key lacks collection # prefix, result of iteration is empty. # * When iterating reverse, if first yielded key lacks collection # prefix, discard, then behave as forward. # * Records are discarded in the direction of iteration until # startpred() or not self.prefix. # * Records are yielded following startpred() until not endpred() or # not self.prefix. prefix = prefix or () tup = next(it, None) if tup and tup[0][:len(prefix_s)] == prefix_s: it = itertools.chain((tup,), it) for key, value in it: keys = keylib.unpacks(prefix_s, key) if not keys: return lenk = len(keys) if lenk == 1: key = keylib.Key(*(prefix + keys[0])) yield False, key, self._decompress(value) else: # Batch record. offsets, dstart = decode_offsets(value) data = self._decompress(buffer(value, dstart)) if reverse: stop = -1 step = -1 i = lenk else: stop = lenk step = 1 i = 0 while i != stop: key = keys[-1 - i] offs = offsets[i] size = offsets[i+1] - offs key = keylib.Key(*(prefix + key)) yield True, key, buffer(data, offs, size) i += step
def _dec(self, *args, **kwargs): return keylib.unpacks('', *args, **kwargs)
def test3(self): t = [('index:Item:first_last', 11, 'item')] p = keylib.packs('', t) eq(keylib.unpacks('', p), t)
def test2(self): t = [('index:I', 11, 'item')] p = keylib.packs('', t) eq(keylib.unpacks('', p), t)
def test1(self): t = [('', 11, 'item')] p = keylib.packs('', t) eq(keylib.unpacks('', p), t)
def test_single(self): for val in self.SINGLE_VALS: encoded = keylib.packs('', (val,)) decoded = keylib.unpacks('', encoded) eq([(val,)], decoded, 'input was %r' % (val,))
def test_list(self): lst = [(1,), (2,)] eq(lst, keylib.unpacks(keylib.packs(lst)))
def test_single(self): for val in self.SINGLE_VALS: encoded = keylib.packs((val,)) decoded = keylib.unpacks(encoded) eq([(val,)], decoded, 'input was %r' % (val,))
def test_counter(self): s = keylib.packs(('dave', 1)) eq([('dave', 1)], keylib.unpacks(s))
def test1(self): s = keylib.packs((1, 2, 3, 4)) assert keylib.unpacks(s, s) == _keylib.unpacks(s, s)
def test3(self): t = [('index:Item:first_last', 11, 'item')] p = keylib.packs(t) eq(keylib.unpacks(p), t)
def test2(self): t = [('index:I', 11, 'item')] p = keylib.packs(t) eq(keylib.unpacks(p), t)
def test1(self): t = [('', 11, 'item')] p = keylib.packs(t) eq(keylib.unpacks(p), t)