diff options
-rw-r--r-- | gemato/cli.py | 5 | ||||
-rw-r--r-- | gemato/openpgp.py | 11 |
2 files changed, 11 insertions, 5 deletions
diff --git a/gemato/cli.py b/gemato/cli.py index 021057d..3b5786e 100644 --- a/gemato/cli.py +++ b/gemato/cli.py @@ -89,6 +89,8 @@ class BaseOpenPGPMixin(object): subp.add_argument('-K', '--openpgp-key', help='Use only the OpenPGP key(s) from a specific file') + subp.add_argument('--proxy', + help='Use HTTP proxy') def parse_args(self, args, argp): super(BaseOpenPGPMixin, self).parse_args(args, argp) @@ -99,7 +101,8 @@ class BaseOpenPGPMixin(object): env_class = gemato.openpgp.OpenPGPEnvironment else: env_class = gemato.openpgp.OpenPGPSystemEnvironment - self.openpgp_env = env_class(debug=args.debug) + self.openpgp_env = env_class(debug=args.debug, + proxy=args.proxy) if args.openpgp_key is not None: with io.open(args.openpgp_key, 'rb') as f: diff --git a/gemato/openpgp.py b/gemato/openpgp.py index c854d1a..2efef8d 100644 --- a/gemato/openpgp.py +++ b/gemato/openpgp.py @@ -40,7 +40,7 @@ class OpenPGPSystemEnvironment(object): __slots__ = ['debug'] - def __init__(self, debug=False): + def __init__(self, debug=False, proxy=None): self.debug = debug def __enter__(self): @@ -183,10 +183,11 @@ class OpenPGPEnvironment(OpenPGPSystemEnvironment): or use as a context manager (via 'with'). """ - __slots__ = ['_home'] + __slots__ = ['_home', 'proxy'] - def __init__(self, debug=False): + def __init__(self, debug=False, proxy=None): super(OpenPGPEnvironment, self).__init__(debug=debug) + self.proxy = proxy self._home = tempfile.mkdtemp(prefix='gemato.') with open(os.path.join(self._home, 'dirmngr.conf'), 'w') as f: @@ -221,7 +222,7 @@ debug-level guru self.close() def clone(self): - return OpenPGPEnvironment(debug=self.debug) + return OpenPGPEnvironment(debug=self.debug, proxy=self.proxy) @staticmethod def _rmtree_error_handler(func, path, exc_info): @@ -385,5 +386,7 @@ debug-level guru def _spawn_gpg(self, options, stdin=''): env_override = {'GNUPGHOME': self.home} + if self.proxy is not None: + env_override['http_proxy'] = self.proxy return (super(OpenPGPEnvironment, self) ._spawn_gpg(options, stdin, env_override)) |