summaryrefslogtreecommitdiff
path: root/swift/common/utils.py
diff options
context:
space:
mode:
authorJohn Dickinson <me@not.mn>2015-04-14 08:10:41 -0700
committerJohn Dickinson <me@not.mn>2015-04-14 08:57:15 -0700
commite910f7e07d05dd2c6ada939d5704c3d4944c24b0 (patch)
tree250b33237ccbc07bf4ef5895439a0e8cac2fec11 /swift/common/utils.py
parentdd9d97458ea007024220a78dba8dd663e8b425d7 (diff)
parent8f5d4d24557887b4691fc219cefbc30e478bf7ed (diff)
downloadswift-e910f7e07d05dd2c6ada939d5704c3d4944c24b0.tar.gz
Merge EC feature into master
Co-Authored-By: Alistair Coles <alistair.coles@hp.com> Co-Authored-By: Thiago da Silva <thiago@redhat.com> Co-Authored-By: John Dickinson <me@not.mn> Co-Authored-By: Clay Gerrard <clay.gerrard@gmail.com> Co-Authored-By: Tushar Gohad <tushar.gohad@intel.com> Co-Authored-By: Paul Luse <paul.e.luse@intel.com> Co-Authored-By: Samuel Merritt <sam@swiftstack.com> Co-Authored-By: Christian Schwede <christian.schwede@enovance.com> Co-Authored-By: Yuan Zhou <yuan.zhou@intel.com> Change-Id: I002787f558781bd4d884129b127bc9f108ea9ec4
Diffstat (limited to 'swift/common/utils.py')
-rw-r--r--swift/common/utils.py42
1 files changed, 37 insertions, 5 deletions
diff --git a/swift/common/utils.py b/swift/common/utils.py
index cf7b7e7c5..19dcfd3d6 100644
--- a/swift/common/utils.py
+++ b/swift/common/utils.py
@@ -2236,11 +2236,16 @@ class GreenAsyncPile(object):
Correlating results with jobs (if necessary) is left to the caller.
"""
- def __init__(self, size):
+ def __init__(self, size_or_pool):
"""
- :param size: size pool of green threads to use
+ :param size_or_pool: thread pool size or a pool to use
"""
- self._pool = GreenPool(size)
+ if isinstance(size_or_pool, GreenPool):
+ self._pool = size_or_pool
+ size = self._pool.size
+ else:
+ self._pool = GreenPool(size_or_pool)
+ size = size_or_pool
self._responses = eventlet.queue.LightQueue(size)
self._inflight = 0
@@ -2646,6 +2651,10 @@ def public(func):
def quorum_size(n):
"""
+ quorum size as it applies to services that use 'replication' for data
+ integrity (Account/Container services). Object quorum_size is defined
+ on a storage policy basis.
+
Number of successful backend requests needed for the proxy to consider
the client request successful.
"""
@@ -3139,6 +3148,26 @@ _rfc_extension_pattern = re.compile(
r'(?:\s*;\s*(' + _rfc_token + r")\s*(?:=\s*(" + _rfc_token +
r'|"(?:[^"\\]|\\.)*"))?)')
+_content_range_pattern = re.compile(r'^bytes (\d+)-(\d+)/(\d+)$')
+
+
+def parse_content_range(content_range):
+ """
+ Parse a content-range header into (first_byte, last_byte, total_size).
+
+ See RFC 7233 section 4.2 for details on the header format, but it's
+ basically "Content-Range: bytes ${start}-${end}/${total}".
+
+ :param content_range: Content-Range header value to parse,
+ e.g. "bytes 100-1249/49004"
+ :returns: 3-tuple (start, end, total)
+ :raises: ValueError if malformed
+ """
+ found = re.search(_content_range_pattern, content_range)
+ if not found:
+ raise ValueError("malformed Content-Range %r" % (content_range,))
+ return tuple(int(x) for x in found.groups())
+
def parse_content_type(content_type):
"""
@@ -3293,8 +3322,11 @@ def iter_multipart_mime_documents(wsgi_input, boundary, read_chunk_size=4096):
:raises: MimeInvalid if the document is malformed
"""
boundary = '--' + boundary
- if wsgi_input.readline(len(boundary + '\r\n')).strip() != boundary:
- raise swift.common.exceptions.MimeInvalid('invalid starting boundary')
+ blen = len(boundary) + 2 # \r\n
+ got = wsgi_input.readline(blen)
+ if got.strip() != boundary:
+ raise swift.common.exceptions.MimeInvalid(
+ 'invalid starting boundary: wanted %r, got %r', (boundary, got))
boundary = '\r\n' + boundary
input_buffer = ''
done = False