filtered_headers = headers
if 'Youtubedl-no-compression' in filtered_headers:
- filtered_headers = dict((k, v) for k, v in filtered_headers.items() if k.lower() != 'accept-encoding')
+ filtered_headers = filter_dict(filtered_headers, cndn=lambda k, _: k.lower() != 'accept-encoding')
del filtered_headers['Youtubedl-no-compression']
return filtered_headers
new_data = None
remove_headers.extend(['Content-Length', 'Content-Type'])
- # NB: don't use dict comprehension for python 2.6 compatibility
- new_headers = dict((k, v) for k, v in req.headers.items()
- if k.title() not in remove_headers)
+ new_headers = filter_dict(req.headers, cndn=lambda k, _: k.title() not in remove_headers)
return compat_urllib_request.Request(
newurl, headers=new_headers, origin_req_host=req.origin_req_host,
return v
+def filter_dict(dct, cndn=lambda _, v: v is not None):
+ # NB: don't use dict comprehension for python 2.6 compatibility
+ return dict((k, v) for k, v in dct.items() if cndn(k, v))
+
+
def merge_dicts(*dicts, **kwargs):
"""
Merge the `dict`s in `dicts` using the first valid value for each key.