ahvn.utils.basic.request_utils module¶
Network and request helper utilities (proxies, contexts).
- class ahvn.utils.basic.request_utils.NetworkProxy(http_proxy=None, https_proxy=None, no_proxy=None, **kwargs)[source]¶
Bases:
objectA robust context manager for temporarily setting proxy environment variables.
This implementation properly handles: - Both uppercase and lowercase proxy environment variables - Proper restoration of original values (including deletion when they didn’t exist) - Empty string handling (removes proxy variables instead of setting to empty) - NO_PROXY support for bypassing proxy for specific hosts
- PROXY_VARS = ['HTTP_PROXY', 'http_proxy', 'HTTPS_PROXY', 'https_proxy', 'NO_PROXY', 'no_proxy']¶
- __init__(http_proxy=None, https_proxy=None, no_proxy=None, **kwargs)[source]¶
Initialize the NetworkProxy with optional proxy settings.
- Parameters:
http_proxy (Optional[str]) – The HTTP proxy URL. If empty empty string, HTTP proxy will be disabled. If None, the existing setting will be preserved.
https_proxy (Optional[str]) – The HTTPS proxy URL. If empty empty string, HTTPS proxy will be disabled. If None, the existing setting will be preserved.
no_proxy (Optional[str]) – Comma-separated list of hosts to bypass proxy for. If empty empty string, no_proxy will be disabled. If None, the existing setting will be preserved.
**kwargs – Additional keyword arguments for future extensions.
- ahvn.utils.basic.request_utils.google_download(file_id, path, http_proxy=None, https_proxy=None, *args, **kwargs)[source]¶
Download a file from Google Drive using its file ID. The file must be publicly accessible.
- Parameters:
file_id (str) – The Google Drive file ID.
path (str) – The local path to save the downloaded file.
http_proxy (Optional[str]) – HTTP proxy URL. If empty string, disables HTTP proxy.
https_proxy (Optional[str]) – HTTPS proxy URL. If empty string, disables HTTPS proxy.
*args – Additional positional arguments to pass to gdown.download.
**kwargs – Additional keyword arguments to pass to gdown.download.
- Returns:
The path to the downloaded file, or None if download failed.
- Return type: