Skip to content

Commit

Permalink
Move nested '_process_content_range' helper out to module scope.
Browse files Browse the repository at this point in the history
Addresses:
#1209 (comment)
  • Loading branch information
tseaver committed Nov 18, 2015
1 parent f66f1b8 commit 7e94700
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions gcloud/streaming/http_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ def body(self, value):
self.loggable_body = '<media body>'


def _process_content_range(content_range):
"""Convert a 'Content-Range' header into a length for the response.
Helper for :meth:`Response.length`.
:type content_range: string
:param content_range: the header value being parsed.
:rtype: integer
:returns: the length of the response chunk.
"""
_, _, range_spec = content_range.partition(' ')
byte_range, _, _ = range_spec.partition('/')
start, _, end = byte_range.partition('-')
return int(end) - int(start) + 1


# Note: currently the order of fields here is important, since we want
# to be able to pass in the result from httplib2.request.
class Response(collections.namedtuple(
Expand All @@ -160,12 +177,6 @@ def length(self):
Returns:
Response length (as int or long)
"""
def _process_content_range(content_range):
_, _, range_spec = content_range.partition(' ')
byte_range, _, _ = range_spec.partition('/')
start, _, end = byte_range.partition('-')
return int(end) - int(start) + 1

if 'content-encoding' in self.info and 'content-range' in self.info:
# httplib2 rewrites content-length in the case of a compressed
# transfer; we can't trust the content-length header in that
Expand Down

0 comments on commit 7e94700

Please sign in to comment.