| 20 | def no_proxy(func): |
| 21 | """Decorator to disable proxy but then restore after the function call.""" |
| 22 | def wrapper(*args, **kwargs): |
| 23 | # http_proxy, https_proxy, HTTP_PROXY, HTTPS_PROXY, all_proxy |
| 24 | http_proxy = os.environ.get('http_proxy') |
| 25 | https_proxy = os.environ.get('https_proxy') |
| 26 | HTTP_PROXY = os.environ.get('HTTP_PROXY') |
| 27 | HTTPS_PROXY = os.environ.get('HTTPS_PROXY') |
| 28 | all_proxy = os.environ.get('all_proxy') |
| 29 | os.environ['http_proxy'] = '' |
| 30 | os.environ['https_proxy'] = '' |
| 31 | os.environ['HTTP_PROXY'] = '' |
| 32 | os.environ['HTTPS_PROXY'] = '' |
| 33 | os.environ['all_proxy'] = '' |
| 34 | try: |
| 35 | return func(*args, **kwargs) |
| 36 | finally: |
| 37 | os.environ['http_proxy'] = http_proxy |
| 38 | os.environ['https_proxy'] = https_proxy |
| 39 | os.environ['HTTP_PROXY'] = HTTP_PROXY |
| 40 | os.environ['HTTPS_PROXY'] = HTTPS_PROXY |
| 41 | os.environ['all_proxy'] = all_proxy |
| 42 | if NO_PROXY: |
| 43 | return wrapper |
| 44 | else: |