Skip to content
Myr

utils.py

This file

Path

tests/utils.py

17 lines · 366 bytes · Python

Last changed by

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

History of this file

Take it

The walk stopped after 200 commits: lines older than 1096835 point at it.

Appropriately handle urllib3's InvalidHeader exception (#5914)Nate Prewittbefore adoption1096835

lines 1–17why, one step back
1import contextlib
2import os345@contextlib.contextmanager6def override_environ(**kwargs):7 save_env = dict(os.environ)8 for key, value in kwargs.items():9 if value is None:10 del os.environ[key]11 else:12 os.environ[key] = value13 try:14 yield15 finally:16 os.environ.clear()17 os.environ.update(save_env)