from allmydata.util import log
from allmydata.util.assertutil import precondition, _assert
from allmydata.util.deferredutil import eventually_callback, eventually_errback, eventual_chain, gatherResults
+from allmydata.util.listutil import concat
from allmydata.storage.common import si_b2a, NUM_RE
return self._do_request('DELETE object', self._delete_object, object_name)
-def concat(seqs):
- """
- O(n), rather than O(n^2), concatenation of list-like things, returning a list.
- I can't believe this isn't built in.
- """
- total_len = 0
- for seq in seqs:
- total_len += len(seq)
- result = [None]*total_len
- i = 0
- for seq in seqs:
- for x in seq:
- result[i] = x
- i += 1
- _assert(i == total_len, i=i, total_len=total_len)
- return result
-
-
class ContainerListMixin:
"""
S3 has a limitation of 1000 object entries returned on each list (GET Bucket) request.
import time, os.path, platform, re, simplejson, struct, itertools, urllib
-from collections import deque
from cStringIO import StringIO
import thread
class CloudCommon(unittest.TestCase, ShouldFailMixin, WorkdirMixin):
- def test_concat(self):
- x = deque([[1, 2], (), xrange(3, 6)])
- self.failUnlessEqual(cloud_common.concat(x), [1, 2, 3, 4, 5])
-
def test_list_objects_truncated_badly(self):
# If a container misbehaves by not producing listings with increasing keys,
# that should cause an incident.
def foo(): pass # keep the line number constant
import os, time, sys
+from collections import deque
from StringIO import StringIO
+
from twisted.trial import unittest
from twisted.internet import defer, reactor
from twisted.python.failure import Failure
from allmydata.util import base32, idlib, humanreadable, mathutil, hashutil
from allmydata.util import assertutil, fileutil, deferredutil, abbreviate
from allmydata.util import limiter, time_format, pollmixin, cachedir
-from allmydata.util import statistics, dictutil, pipeline
+from allmydata.util import statistics, dictutil, listutil, pipeline
from allmydata.util import log as tahoe_log
from allmydata.util.spans import Spans, overlap, DataSpans
self.failUnlessEqual(d["one"], 1)
self.failUnlessEqual(d.get_aux("one"), None)
+
+class ListUtil(unittest.TestCase):
+ def test_concat(self):
+ x = deque([[1, 2], (), xrange(3, 6)])
+ self.failUnlessEqual(listutil.concat(x), [1, 2, 3, 4, 5])
+
+
class Pipeline(unittest.TestCase):
def pause(self, *args, **kwargs):
d = defer.Deferred()
--- /dev/null
+
+from allmydata.util.assertutil import _assert
+
+
+def concat(seqs):
+ """
+ O(n), rather than O(n^2), concatenation of list-like things, returning a list.
+ I can't believe this isn't built in.
+ """
+ total_len = 0
+ for seq in seqs:
+ total_len += len(seq)
+ result = [None]*total_len
+ i = 0
+ for seq in seqs:
+ for x in seq:
+ result[i] = x
+ i += 1
+ _assert(i == total_len, i=i, total_len=total_len)
+ return result