From dd5051998416d19f0ccc45b207c00494ae85ae19 Mon Sep 17 00:00:00 2001 From: martynp <12006448+martynp@users.noreply.github.com> Date: Tue, 14 Mar 2023 09:51:07 +0000 Subject: [PATCH] Fix linting errors --- httpie_hmac/__init__.py | 2 +- httpie_hmac/httpie_hmac.py | 32 +++++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/httpie_hmac/__init__.py b/httpie_hmac/__init__.py index 355abe3..8038f1b 100644 --- a/httpie_hmac/__init__.py +++ b/httpie_hmac/__init__.py @@ -1 +1 @@ -from .httpie_hmac import HmacPlugin, HmacAuth, HmacGenerate \ No newline at end of file +from .httpie_hmac import HmacPlugin, HmacAuth, HmacGenerate # noqa: F401 diff --git a/httpie_hmac/httpie_hmac.py b/httpie_hmac/httpie_hmac.py index e647cdf..e2fa94e 100644 --- a/httpie_hmac/httpie_hmac.py +++ b/httpie_hmac/httpie_hmac.py @@ -19,12 +19,26 @@ class HmacGenerate: - def generate(access_key, secret_key, method, content_type, content_md5, http_date, path, r): + def generate(access_key, + secret_key, + method, + content_type, + content_md5, + http_date, + path, + r): pass class Simple(HmacGenerate): - def generate(access_key, secret_key, method, content_type, content_md5, http_date, path, r): + def generate(access_key, + secret_key, + method, + content_type, + content_md5, + http_date, + path, + r): string_to_sign = '\n'.join( [method, content_md5, content_type, http_date, path]).encode() @@ -32,7 +46,7 @@ def generate(access_key, secret_key, method, content_type, content_md5, http_dat hashlib.sha256).digest() signature = base64.b64encode(digest).rstrip().decode('utf-8') - if access_key == None or access_key == '': + if access_key is None or access_key == '': r.headers['Authorization'] = f"HMAC {signature}" elif secret_key == '': raise ValueError('HMAC secret key cannot be empty.') @@ -65,7 +79,8 @@ def __init__(self, access_key, secret_key, format): loader.exec_module(mod) if issubclass(mod.HmacAuthCustom, HmacGenerate) is False: raise TypeError( - "Custom generator must inherit httpie_hmac.HmacGenerate") + "Custom generator must inherit " + "httpie_hmac.HmacGenerate") self.formatter = mod.HmacAuthCustom else: self.formatter = generators[format] @@ -108,7 +123,14 @@ def __call__(self, r): path = url.path # Call the formatter to add the required headers and return r - return self.formatter.generate(self.access_key, self.secret_key_bytes, method, content_type, content_md5, http_date, path, r) + return self.formatter.generate(self.access_key, + self.secret_key_bytes, + method, + content_type, + content_md5, + http_date, + path, + r) class HmacPlugin(AuthPlugin):