Skip to content
Myr

Forgot to add the hooks sub-package

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 d12eac8 · Browse files · 4 files+64 added−0 removed
This commit

State

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

Diff stats

4 files+64 added−0 removed

  • other:+64 added−0 removed

4 files+64 added−0 removed

added:requests/hooks/args.py+7 added
1"""2request.hooks.args3~~~~~~~~~~~~~~~~~~45This module provide a collection of args hooks.6"""7
added:requests/hooks/post_request.py+7 added
1"""2request.hooks.post_request3~~~~~~~~~~~~~~~~~~~~~~~~~~45This module provide a collection of post_request hooks.6"""7
added:requests/hooks/pre_request.py+7 added
1"""2request.hooks.pre_request3~~~~~~~~~~~~~~~~~~~~~~~~~45This module provide a collection of pre_request hooks.6"""7
added:requests/hooks/response.py+43 added
1"""2request.hooks.response3~~~~~~~~~~~~~~~~~~~~~~45This module provide a collection of response hooks.6"""7from functools import wraps8import zlib9from cgi import parse_header1011#: Dictionary of content decoders.12decoders = {13 # No decoding applied.14 'identity': lambda r: r,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),19}2021# Decode Response file object compressed with compress.22decoders['compress'] = decoders['deflate']2324try:25 import bz226except ImportError:27 pass28else:29 # Decode Response file object compressed with bz2.30 decoders['bzip2'] = lambda r: bz2.decompress(r.content)3132def 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)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)43