def CALL_FUNCTION(decompiler, argc, star=None, star2=None): pop = decompiler.stack.pop kwarg, posarg = divmod(argc, 256) args = [] for i in xrange(kwarg): arg = pop() key = pop().value args.append(ast.Keyword(key, arg)) for i in xrange(posarg): args.append(pop()) args.reverse() return decompiler._call_function(args, star, star2)
def test_prefetch(self): for i in xrange(1, 8): Dummy.create(count=i, prop1=[i]) ds = Dummy.gets_by() with patched_db_get as db_get: with patched_db_get_multi as db_get_multi: for d in ds: self.assertEqual(d.count, d.id) self.assertEqual(d.prop1, [str(d.id)]) # visit `count1` field multi times for j in xrange(5): self.assertIsNone(d.count1) self.assertEqual(db_get.call_count, 0) self.assertEqual(db_get_multi.call_count, 4)
def _product_order_by_tuples(key): strs = key l = len(strs) if not l: return [] x = list(product(strs, ('-', ''))) d = len(x) / l pieces = [x[int(i * d):int((i + 1) * d)] for i in xrange(l)] pieces = list(product(*pieces)) return [tuple('%s%s' % (t[1], t[0]) for t in p) for p in pieces]
def test_prefetch(self): for i in xrange(1, 8): Dummy.create(count=i, prop1=[i]) ds = Dummy.gets_by() with patched_db_get as db_get: with patched_db_get_multi as db_get_multi: for d in ds: self.assertEqual(d.count, d.id) self.assertEqual(d.prop1, [str(d.id)]) self.assertEqual(db_get.call_count, 0) self.assertEqual(db_get_multi.call_count, 3)
def _test_multi_thread(self): dummy = Dummy.create(**attrs) def run(): dummy.count += 1 max_workers = 6 with ThreadPoolExecutor(max_workers=max_workers) as exe: fs = [] for _ in xrange(max_workers): fs.append(exe.submit(run)) as_completed(fs) self.assertEqual(dummy.count, 1) # FIXME
def _test_multi_thread0(self): max_workers = 6 dummys = [Dummy.create(**attrs) for _ in xrange(max_workers)] def update(dummy): dummy.name = dummy.id dummy.save() with ThreadPoolExecutor(max_workers=max_workers) as exe: fs = [] for dummy in dummys: fs.append(exe.submit(update, dummy)) as_completed(fs) dummys = Dummy.gets_by() for dummy in dummys: self.assertEqual(str(dummy.id), dummy.name)
def generate_aes_key(length=32): seed = 'abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ=-+_)(*&^%$#@~!1234567890;\'":<>?/.,' # noqa return ''.join(random.choice(seed) for _ in xrange(length))
def _product_index_keys(key): if len(key) == 0: yield StrKey() for i in xrange(1, len(key) + 1): yield StrKey(key[0:i])