Skip to content
Myr

hooks now comply hook interface

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Luca De Vitis · committed by Luca De Vitis · parent 660e090 · Browse files · 1 file+4 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+4 added−3 removed

  • other:+4 added−3 removed

1 file+4 added−3 removed

modified:requests/hooks/response.py+4 added-3 removed
9 unmodified lines
1011#: Dictionary of content decoders.12decoders = {13 # No decoding applied.14 'identity': lambda r: r,14 'identity': lambda r: r.content,15 # Decode Response file object compressed with deflate.16 'deflate': lambda r: zlib.decompress(r.content),17 # Decode Response file object compressed with gzip.18 'gzip': lambda r: zlib.decompress(r.content, 16+zlib.MAX_WBITS),
13 unmodified lines
32def unicode_response(r):33 """Encode response file object in unicode."""34 content_type, params = parse_header(r.headers.get('content-type'))35 charset = params.get('charset', '').strip("'\"")36 r.content = unicode(r.content, charset) if charset else unicode(r.content)36 r._content = unicode(r.content, charset) if charset else unicode(r.content)37 return r3839def decode_response(r):40 """Decode compressed response content using Contetn-Encoding header."""41 encoding = r.headers.get('content-encoding')42 return decoders.get(encoding)(r)42 r._content = decoders.get(encoding)(r)43 return r44