Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions storages/backends/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@
# NOTE: these are defined as functions so both can be tested
def _use_cryptography_signer():
# https://cryptography.io as an RSA backend
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives.serialization import load_pem_private_key
from cryptography.hazmat.backends import default_backend # noqa: PLC0415
from cryptography.hazmat.primitives import hashes # noqa: PLC0415
from cryptography.hazmat.primitives.asymmetric import padding # noqa: PLC0415
from cryptography.hazmat.primitives.serialization import ( # noqa: PLC0415
load_pem_private_key,
)

def _cloud_front_signer_from_pem(key_id, pem):
if isinstance(pem, str):
Expand All @@ -64,7 +66,7 @@ def _cloud_front_signer_from_pem(key_id, pem):

def _use_rsa_signer():
# https://stuvel.eu/rsa as an RSA backend
import rsa
import rsa # noqa: PLC0415

def _cloud_front_signer_from_pem(key_id, pem):
if isinstance(pem, str):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ def test_with_string_file(self):
# bytes when encoding with utf-8 vs windows-1252 vs utf-16

def test_with_string_file_specified_encoding(self):
content = "\u2122\u20AC\u2030"
content = "\u2122\u20ac\u2030"
file = io.StringIO(content)
file_wrapped = utils.ReadBytesWrapper(file, encoding="utf-16")

# test read() returns specified encoding
self.assertEqual(file_wrapped.read(), content.encode("utf-16"))

def test_with_string_file_detect_encoding(self):
content = "\u2122\u20AC\u2030"
content = "\u2122\u20ac\u2030"
with open(
file=os.path.join(
os.path.dirname(__file__), "test_files", "windows-1252-encoded.txt"
Expand All @@ -214,7 +214,7 @@ def test_with_string_file_detect_encoding(self):
self.assertEqual(file_wrapped.read(), content.encode("windows-1252"))

def test_with_string_file_fallback_encoding(self):
content = "\u2122\u20AC\u2030"
content = "\u2122\u20ac\u2030"
file = io.StringIO(content)
file_wrapped = utils.ReadBytesWrapper(file)

Expand Down