Skip to content
Myr

Reduce overall memory usage of Requests module by removing cgi module dependency in utils.py. Instead wrote a nested function to parse header and return content type and params.

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

authored by dbairaktaris1 · committed by dbairaktaris1 · parent 24092b1 · Browse files · 1 file+16 added−2 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+16 added−2 removed

  • other:+16 added−2 removed

1 file+16 added−2 removed

modified:requests/utils.py+16 added-2 removed
6 unmodified lines
7This module provides utility functions that are used within Requests8that are also useful for external consumption.9"""1011import cgi11import codecs12import collections13import contextlib14import io
436 unmodified lines
451452 :param headers: dictionary to extract encoding from.453 :rtype: str454 """455 def parse_header(content_type):456 #Inner function to parse header457 content_type_and_params_delimiter = ';'458459 #append delimiter on end to ensure atleast two elements when split by ';'460 content_type += content_type_and_params_delimiter461462 tokens = content_type.split(content_type_and_params_delimiter)463 content_type_index = 0464 params_index = 1465466 content_type = tokens[content_type_index]467 params = tokens[params_index]468 params_dict = dict(param.split('=') for param in params.split())469 return content_type,params_dict470471 content_type = headers.get('content-type')472473 if not content_type:474 return None475462 content_type, params = cgi.parse_header(content_type)476 content_type, params = parse_header(content_type)477478 if 'charset' in params:479 return params['charset'].strip("'\"")480
482 unmodified lines