From 7f5fd130c52f2d58011ddeb520e245cfb3b5fd14 Mon Sep 17 00:00:00 2001 From: Jakub Roztocil Date: Thu, 28 Dec 2017 18:15:17 +0100 Subject: [PATCH] Start using dict comprehensions --- httpie/__init__.py | 6 +++--- httpie/client.py | 2 +- httpie/input.py | 6 +++--- httpie/plugins/manager.py | 3 +-- httpie/sessions.py | 6 +++--- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/httpie/__init__.py b/httpie/__init__.py index abed9a91..0725cc15 100644 --- a/httpie/__init__.py +++ b/httpie/__init__.py @@ -25,8 +25,8 @@ class ExitStatus: ERROR_HTTP_5XX = 5 -EXIT_STATUS_LABELS = dict( - (value, key) +EXIT_STATUS_LABELS = { + value: key for key, value in ExitStatus.__dict__.items() if key.isupper() -) +} diff --git a/httpie/client.py b/httpie/client.py index 0c7566aa..1ffc6fbd 100644 --- a/httpie/client.py +++ b/httpie/client.py @@ -166,7 +166,7 @@ def get_requests_kwargs(args, base_headers=None): 'cert': cert, 'timeout': args.timeout, 'auth': args.auth, - 'proxies': dict((p.key, p.value) for p in args.proxy), + 'proxies': {p.key: p.value for p in args.proxy}, 'files': args.files, 'allow_redirects': args.follow, 'params': args.params, diff --git a/httpie/input.py b/httpie/input.py index 978b4b44..affb73fe 100644 --- a/httpie/input.py +++ b/httpie/input.py @@ -112,11 +112,11 @@ SSL_VERSION_ARG_MAPPING = { 'tls1.1': 'PROTOCOL_TLSv1_1', 'tls1.2': 'PROTOCOL_TLSv1_2', } -SSL_VERSION_ARG_MAPPING = dict( - (cli_arg, getattr(ssl, ssl_constant)) +SSL_VERSION_ARG_MAPPING = { + cli_arg: getattr(ssl, ssl_constant) for cli_arg, ssl_constant in SSL_VERSION_ARG_MAPPING.items() if hasattr(ssl, ssl_constant) -) +} class HTTPieArgumentParser(ArgumentParser): diff --git a/httpie/plugins/manager.py b/httpie/plugins/manager.py index f7a2a063..c6390f26 100644 --- a/httpie/plugins/manager.py +++ b/httpie/plugins/manager.py @@ -39,8 +39,7 @@ class PluginManager(object): return [plugin for plugin in self if issubclass(plugin, AuthPlugin)] def get_auth_plugin_mapping(self): - return dict((plugin.auth_type, plugin) - for plugin in self.get_auth_plugins()) + return {plugin.auth_type: plugin for plugin in self.get_auth_plugins()} def get_auth_plugin(self, auth_type): return self.get_auth_plugin_mapping()[auth_type] diff --git a/httpie/sessions.py b/httpie/sessions.py index ff3969be..ba162e14 100644 --- a/httpie/sessions.py +++ b/httpie/sessions.py @@ -136,10 +136,10 @@ class Session(BaseConfigDict): stored_attrs = ['value', 'path', 'secure', 'expires'] self['cookies'] = {} for cookie in jar: - self['cookies'][cookie.name] = dict( - (attname, getattr(cookie, attname)) + self['cookies'][cookie.name] = { + attname: getattr(cookie, attname) for attname in stored_attrs - ) + } @property def auth(self):