コード例 #1
0
def _in_pairs(iterable):
    # Creates iterator that iterates over the list in pairs:
    # for a, b in _in_pairs([0, 1, 2, 3, 4]):
    #     print(a, b)
    #
    # will print:
    # 0, 1
    # 2, 3
    # 4, None
    shared_iter = iter(iterable)
    # Note that zip_longest is a compat import that uses
    # the itertools izip_longest.  This creates an iterator,
    # this call below does _not_ immediately create the list
    # of pairs.
    return zip_longest(shared_iter, shared_iter)
コード例 #2
0
 def test_result_key_iters(self):
     for i in range(5):
         key_name = 'key/%s/%s' % (i, i)
         self.create_object(key_name)
         key_name2 = 'key/%s' % i
         self.create_object(key_name2)
     time.sleep(3)
     paginator = self.client.get_paginator('list_objects')
     generator = paginator.paginate(MaxKeys=2,
                                    Prefix='key/',
                                    Delimiter='/',
                                    Bucket=self.bucket_name)
     iterators = generator.result_key_iters()
     response = defaultdict(list)
     key_names = [i.result_key for i in iterators]
     for vals in zip_longest(*iterators):
         for k, val in zip(key_names, vals):
             response.setdefault(k.expression, [])
             response[k.expression].append(val)
     self.assertIn('Contents', response)
     self.assertIn('CommonPrefixes', response)