mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Reformat code with automated tools
Apply standardized code style
This commit is contained in:
@@ -6,10 +6,8 @@ from tests.utils import ClientWithCsrfChecks
|
||||
|
||||
HAS_CRYPTOGRAPHY = True
|
||||
try:
|
||||
from cryptography.hazmat.primitives.asymmetric import rsa
|
||||
from cryptography.hazmat.primitives import serialization
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
from cryptography.hazmat.primitives.asymmetric import padding
|
||||
from cryptography.hazmat.primitives import hashes, serialization
|
||||
from cryptography.hazmat.primitives.asymmetric import padding, rsa
|
||||
except ImportError:
|
||||
HAS_CRYPTOGRAPHY = False
|
||||
|
||||
@@ -24,14 +22,14 @@ def make_key():
|
||||
|
||||
|
||||
def derive_public_webhook_key(private_key):
|
||||
"""Derive public """
|
||||
"""Derive public"""
|
||||
public_key = private_key.public_key()
|
||||
public_bytes = public_key.public_bytes(
|
||||
encoding=serialization.Encoding.PEM,
|
||||
format=serialization.PublicFormat.SubjectPublicKeyInfo
|
||||
format=serialization.PublicFormat.SubjectPublicKeyInfo,
|
||||
)
|
||||
public_bytes = b'\n'.join(public_bytes.splitlines()[1:-1])
|
||||
return public_bytes.decode('utf-8')
|
||||
public_bytes = b"\n".join(public_bytes.splitlines()[1:-1])
|
||||
return public_bytes.decode("utf-8")
|
||||
|
||||
|
||||
def sign(private_key, message):
|
||||
@@ -47,11 +45,11 @@ class _ClientWithPostalSignature(ClientWithCsrfChecks):
|
||||
self.private_key = private_key
|
||||
|
||||
def post(self, *args, **kwargs):
|
||||
signature = b64encode(sign(self.private_key, kwargs['data'].encode('utf-8')))
|
||||
kwargs.setdefault('HTTP_X_POSTAL_SIGNATURE', signature)
|
||||
signature = b64encode(sign(self.private_key, kwargs["data"].encode("utf-8")))
|
||||
kwargs.setdefault("HTTP_X_POSTAL_SIGNATURE", signature)
|
||||
|
||||
webhook_key = derive_public_webhook_key(self.private_key)
|
||||
with override_settings(ANYMAIL={'POSTAL_WEBHOOK_KEY': webhook_key}):
|
||||
with override_settings(ANYMAIL={"POSTAL_WEBHOOK_KEY": webhook_key}):
|
||||
return super().post(*args, **kwargs)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user