Skip to content

Commit

Permalink
Merge pull request #98 from Batterii/pullrequest_85
Browse files Browse the repository at this point in the history
Pullrequest 85 + test coverage
  • Loading branch information
tseaver committed Mar 29, 2013
2 parents c2fc58d + 1270039 commit 6661e97
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 12 additions & 2 deletions tests/test_response.py
Expand Up @@ -941,7 +941,6 @@ def test_encode_content_gzip_notyet_gzipped():
eq_(res.content_length, 23)
eq_(res.app_iter, [
b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff',
b'',
b'K\xcb\xcf\x07\x00',
b'!es\x8c\x03\x00\x00\x00'
])
Expand All @@ -954,11 +953,22 @@ def test_encode_content_gzip_notyet_gzipped_lazy():
eq_(res.content_length, None)
eq_(list(res.app_iter), [
b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff',
b'',
b'K\xcb\xcf\x07\x00',
b'!es\x8c\x03\x00\x00\x00'
])

def test_encode_content_gzip_buffer_coverage():
"""this test is to provide 100% coverage of
response.Response.encode_content was necessary in order to get
pull request https://github.com/Pylons/webob/pull/85 into upstream
"""
res = Response()
DATA = b"abcdefghijklmnopqrstuvwxyz0123456789" * 1000000
res.app_iter = io.BytesIO(DATA)
res.encode_content('gzip')
result = list(res.app_iter)
assert len("".join(result)) < len(DATA)

def test_decode_content_identity():
res = Response()
res.content_encoding = 'identity'
Expand Down
14 changes: 12 additions & 2 deletions webob/response.py
Expand Up @@ -1277,8 +1277,18 @@ def gzip_app_iter(app_iter):
for item in app_iter:
size += len(item)
crc = zlib.crc32(item, crc) & 0xffffffff
yield compress.compress(item)
yield compress.flush()

# The compress function may return zero length bytes if the input is
# small enough; it buffers the input for the next iteration or for a
# flush.
result = compress.compress(item)
if result:
yield result

# Similarly, flush may also not yield a value.
result = compress.flush()
if result:
yield result
yield struct.pack("<2L", crc, size & 0xffffffff)

def _error_unicode_in_app_iter(app_iter, body):
Expand Down

0 comments on commit 6661e97

Please sign in to comment.