Skip to content

Commit

Permalink
Fix/python310 (abhishek-ram#42)
Browse files Browse the repository at this point in the history
* Update pylama pylint black

* Adding Python 3.9 and 3.10.

* Update dist for python 3.10 support
  • Loading branch information
chadgates authored Jan 10, 2022
1 parent a82381a commit 7a41284
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 64 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9, "3.10"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -24,7 +24,7 @@ jobs:
pip install -e ".[tests]"
- name: Run Tests
run: |
pytest --cov=pyas2lib --cov-config .coveragerc --black --pylava
pytest --cov=pyas2lib --cov-config .coveragerc --black --pylama
- name: Generate CodeCov Report
run: |
pip install codecov
Expand Down
6 changes: 3 additions & 3 deletions pyas2lib/as2.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,20 @@ def load_key(key_str: bytes, key_pass: str):
except ValueError as e:
# If it fails due to invalid password raise error here
if e.args[0] == "Password provided is invalid":
raise AS2Exception("Password not valid for Private Key.")
raise AS2Exception("Password not valid for Private Key.") from e

# if not try to parse as a pem file
key, cert = None, None
for kc in split_pem(key_str):
try:
cert = asymmetric.load_certificate(kc)
except (ValueError, TypeError):
except (ValueError, TypeError) as e:
try:
key = asymmetric.load_private_key(kc, key_pass)
except OSError:
raise AS2Exception(
"Invalid Private Key or password is not correct."
)
) from e

if not key or not cert:
raise AS2Exception("Invalid Private key file or Public key not included.")
Expand Down
18 changes: 11 additions & 7 deletions pyas2lib/cms.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def decompress_message(compressed_data):
raise DecompressionError("Compressed data not found in ASN.1 ")

except Exception as e:
raise DecompressionError("Decompression failed with cause: {}".format(e))
raise DecompressionError("Decompression failed with cause: {}".format(e)) from e


def encrypt_message(data_to_encrypt, enc_alg, encryption_cert):
Expand Down Expand Up @@ -204,10 +204,10 @@ def decrypt_message(encrypted_data, decryption_key):
):
try:
key = asymmetric.rsa_pkcs1v15_decrypt(decryption_key[0], encrypted_key)
except Exception:
except Exception as e:
raise DecryptionError(
"Failed to decrypt the payload: Could not extract decryption key."
)
) from e

alg = cms_content["content"]["encrypted_content_info"][
"content_encryption_algorithm"
Expand Down Expand Up @@ -235,7 +235,9 @@ def decrypt_message(encrypted_data, decryption_key):
else:
raise AS2Exception("Unsupported Encryption Algorithm")
except Exception as e:
raise DecryptionError("Failed to decrypt the payload: {}".format(e))
raise DecryptionError(
"Failed to decrypt the payload: {}".format(e)
) from e
else:
raise AS2Exception("Unsupported Encryption Algorithm")
else:
Expand Down Expand Up @@ -276,7 +278,7 @@ def sign_message(
message_digest = digest_func.digest()

class SmimeCapability(core.Sequence):
""""Define the possible list of Smime Capability."""
"""Define the possible list of Smime Capability."""

_fields = [
("0", core.Any, {"optional": True}),
Expand All @@ -287,7 +289,7 @@ class SmimeCapability(core.Sequence):
]

class SmimeCapabilities(core.Sequence):
""""Define the Smime Capabilities supported by pyas2."""
"""Define the Smime Capabilities supported by pyas2."""

_fields = [
("0", SmimeCapability),
Expand Down Expand Up @@ -515,7 +517,9 @@ def verify_message(data_to_verify, signature, verify_cert):
else:
raise AS2Exception("Unsupported Signature Algorithm")
except Exception as e:
raise IntegrityError("Failed to verify message signature: {}".format(e))
raise IntegrityError(
"Failed to verify message signature: {}".format(e)
) from e
else:
raise IntegrityError("Signed data not found in ASN.1 ")

Expand Down
2 changes: 1 addition & 1 deletion pyas2lib/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AS2Exception(Exception):
disposition_modifier = ""

def __init__(self, message, disposition_modifier=None):
super(AS2Exception, self).__init__(message)
super().__init__(message)
if disposition_modifier:
self.disposition_modifier = disposition_modifier

Expand Down
10 changes: 5 additions & 5 deletions pyas2lib/tests/livetest_with_mecas2.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def setUp(self):
self.out_message = None

def test_compressed_message(self):
""" Send Unencrypted Unsigned Compressed Message to Mendelson AS2"""
"""Send Unencrypted Unsigned Compressed Message to Mendelson AS2"""

self.partner.compress = True
self.out_message = as2.Message(self.org, self.partner)
Expand All @@ -53,7 +53,7 @@ def test_compressed_message(self):
self.assertEqual(status, "processed")

def test_encrypted_message(self):
""" Send Encrypted Unsigned Uncompressed Message to Mendelson AS2"""
"""Send Encrypted Unsigned Uncompressed Message to Mendelson AS2"""

self.partner.encrypt = True
self.out_message = as2.Message(self.org, self.partner)
Expand All @@ -77,7 +77,7 @@ def test_encrypted_message(self):
self.assertEqual(status, "processed")

def test_signed_message(self):
""" Send Unencrypted Signed Uncompressed Message to Mendelson AS2"""
"""Send Unencrypted Signed Uncompressed Message to Mendelson AS2"""

self.partner.sign = True
self.out_message = as2.Message(self.org, self.partner)
Expand All @@ -101,7 +101,7 @@ def test_signed_message(self):
self.assertEqual(status, "processed")

def test_encrypted_signed_message(self):
""" Send Encrypted Signed Uncompressed Message to Mendelson AS2"""
"""Send Encrypted Signed Uncompressed Message to Mendelson AS2"""

self.partner.sign = True
self.partner.encrypt = True
Expand All @@ -126,7 +126,7 @@ def test_encrypted_signed_message(self):
self.assertEqual(status, "processed")

def test_encrypted_signed_compressed_message(self):
""" Send Encrypted Signed Compressed Message to Mendelson AS2"""
"""Send Encrypted Signed Compressed Message to Mendelson AS2"""

self.partner.sign = True
self.partner.encrypt = True
Expand Down
10 changes: 5 additions & 5 deletions pyas2lib/tests/livetest_with_oldpyas2.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def setUp(self):
self.out_message = None

def test_compressed_message(self):
""" Send Unencrypted Unsigned Compressed Message to Mendelson AS2"""
"""Send Unencrypted Unsigned Compressed Message to Mendelson AS2"""

self.partner.compress = True
self.out_message = as2.Message(self.org, self.partner)
Expand All @@ -53,7 +53,7 @@ def test_compressed_message(self):
self.assertEqual(status, "processed")

def test_encrypted_message(self):
""" Send Encrypted Unsigned Uncompressed Message to Mendelson AS2"""
"""Send Encrypted Unsigned Uncompressed Message to Mendelson AS2"""

self.partner.encrypt = True
self.out_message = as2.Message(self.org, self.partner)
Expand All @@ -77,7 +77,7 @@ def test_encrypted_message(self):
self.assertEqual(status, "processed")

def test_signed_message(self):
""" Send Unencrypted Signed Uncompressed Message to Mendelson AS2"""
"""Send Unencrypted Signed Uncompressed Message to Mendelson AS2"""

self.partner.sign = True
self.out_message = as2.Message(self.org, self.partner)
Expand All @@ -101,7 +101,7 @@ def test_signed_message(self):
self.assertEqual(status, "processed")

def test_encrypted_signed_message(self):
""" Send Encrypted Signed Uncompressed Message to Mendelson AS2"""
"""Send Encrypted Signed Uncompressed Message to Mendelson AS2"""

self.partner.sign = True
self.partner.encrypt = True
Expand All @@ -126,7 +126,7 @@ def test_encrypted_signed_message(self):
self.assertEqual(status, "processed")

def test_encrypted_signed_compressed_message(self):
""" Send Encrypted Signed Compressed Message to Mendelson AS2"""
"""Send Encrypted Signed Compressed Message to Mendelson AS2"""

self.partner.sign = True
self.partner.encrypt = True
Expand Down
22 changes: 11 additions & 11 deletions pyas2lib/tests/test_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setUp(self):
)

def test_binary_message(self):
""" Test Encrypted Signed Binary Message """
"""Test Encrypted Signed Binary Message"""

# Build an As2 message to be transmitted to partner
self.partner.sign = True
Expand Down Expand Up @@ -60,7 +60,7 @@ def test_binary_message(self):
self.assertEqual(out_message.mic, in_message.mic)

def test_partner_not_found(self):
""" Test case where partner and organization is not found """
"""Test case where partner and organization is not found"""

# Build an As2 message to be transmitted to partner
self.partner.sign = True
Expand Down Expand Up @@ -106,7 +106,7 @@ def test_partner_not_found(self):
self.assertEqual(detailed_status, "unknown-trading-partner")

def test_duplicate_message(self):
""" Test case where a duplicate message is sent to the partner """
"""Test case where a duplicate message is sent to the partner"""

# Build an As2 message to be transmitted to partner
self.partner.sign = True
Expand Down Expand Up @@ -135,7 +135,7 @@ def test_duplicate_message(self):
self.assertEqual(detailed_status, "duplicate-document")

def test_failed_decompression(self):
""" Test case where message decompression has failed """
"""Test case where message decompression has failed"""

# Build an As2 message to be transmitted to partner
self.partner.compress = True
Expand All @@ -162,7 +162,7 @@ def test_failed_decompression(self):
self.assertEqual(detailed_status, "decompression-failed")

def test_insufficient_security(self):
""" Test case where message security is not as per the configuration """
"""Test case where message security is not as per the configuration"""

# Build an As2 message to be transmitted to partner
self.partner.mdn_mode = as2.SYNCHRONOUS_MDN
Expand Down Expand Up @@ -198,7 +198,7 @@ def test_insufficient_security(self):
self.assertEqual(exc.disposition_modifier, "insufficient-message-security")

def test_failed_decryption(self):
""" Test case where message decryption has failed """
"""Test case where message decryption has failed"""

# Build an As2 message to be transmitted to partner
self.partner.encrypt = True
Expand Down Expand Up @@ -228,7 +228,7 @@ def test_failed_decryption(self):
self.assertEqual(detailed_status, "decryption-failed")

def test_failed_signature(self):
""" Test case where signature verification has failed """
"""Test case where signature verification has failed"""

# Build an As2 message to be transmitted to partner
self.partner.sign = True
Expand Down Expand Up @@ -258,7 +258,7 @@ def test_failed_signature(self):
self.assertEqual(detailed_status, "authentication-failed")

def test_verify_certificate(self):
""" Test case where we have try to load an expired cert """
"""Test case where we have try to load an expired cert"""

# First test with a certificate with invalid root
cert_path = os.path.join(TEST_DIR, "verify_cert_test1.pem")
Expand Down Expand Up @@ -298,7 +298,7 @@ def test_verify_certificate(self):
self.fail("Failed to load chain certificate: %s" % e)

def test_load_private_key(self):
""" Test case where we have try to load keys in different formats """
"""Test case where we have try to load keys in different formats"""

# First test with a pkcs12 key file
cert_path = os.path.join(TEST_DIR, "cert_test.p12")
Expand Down Expand Up @@ -547,7 +547,7 @@ def setUp(self):

@pytest.mark.skip(reason="no way of currently testing this")
def test_process_message(self):
""" Test processing message received from Sterling Integrator"""
"""Test processing message received from Sterling Integrator"""
with open(os.path.join(TEST_DIR, "sb2bi_signed_cmp.msg"), "rb") as msg:
as2message = as2.Message()
status, exception, as2mdn = as2message.parse(
Expand All @@ -559,7 +559,7 @@ def test_process_message(self):
self.assertEqual(status, "processed")

def test_process_mdn(self):
""" Test processing mdn received from Sterling Integrator"""
"""Test processing mdn received from Sterling Integrator"""
msg = as2.Message(sender=self.org, receiver=self.partner)
msg.message_id = (
"151694007918.24690.7052273208458909245@ip-172-31-14-209.ec2.internal"
Expand Down
14 changes: 7 additions & 7 deletions pyas2lib/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def setUp(self):
)

def test_plain_message(self):
""" Test Unencrypted Unsigned Uncompressed Message """
"""Test Unencrypted Unsigned Uncompressed Message"""

# Build an As2 message to be transmitted to partner
out_message = as2.Message(self.org, self.partner)
Expand All @@ -40,7 +40,7 @@ def test_plain_message(self):
self.assertEqual(self.test_data, in_message.content)

def test_compressed_message(self):
""" Test Unencrypted Unsigned Compressed Message """
"""Test Unencrypted Unsigned Compressed Message"""

# Build an As2 message to be transmitted to partner
self.partner.compress = True
Expand All @@ -62,7 +62,7 @@ def test_compressed_message(self):
self.assertEqual(self.test_data.splitlines(), in_message.content.splitlines())

def test_encrypted_message(self):
""" Test Encrypted Unsigned Uncompressed Message """
"""Test Encrypted Unsigned Uncompressed Message"""

# Build an As2 message to be transmitted to partner
self.partner.encrypt = True
Expand All @@ -84,7 +84,7 @@ def test_encrypted_message(self):
self.assertEqual(self.test_data.splitlines(), in_message.content.splitlines())

def test_signed_message(self):
""" Test Unencrypted Signed Uncompressed Message """
"""Test Unencrypted Signed Uncompressed Message"""

# Build an As2 message to be transmitted to partner
self.partner.sign = True
Expand All @@ -107,7 +107,7 @@ def test_signed_message(self):
self.assertEqual(out_message.mic, in_message.mic)

def test_encrypted_signed_message(self):
""" Test Encrypted Signed Uncompressed Message """
"""Test Encrypted Signed Uncompressed Message"""

# Build an As2 message to be transmitted to partner
self.partner.sign = True
Expand All @@ -132,7 +132,7 @@ def test_encrypted_signed_message(self):
self.assertEqual(self.test_data.splitlines(), in_message.content.splitlines())

def test_encrypted_signed_message_dos(self):
""" Test Encrypted Signed Uncompressed Message with DOS line endings. """
"""Test Encrypted Signed Uncompressed Message with DOS line endings."""

# Build an As2 message to be transmitted to partner
self.partner.sign = True
Expand All @@ -157,7 +157,7 @@ def test_encrypted_signed_message_dos(self):
self.assertEqual(self.test_data_dos, in_message.content)

def test_encrypted_signed_compressed_message(self):
""" Test Encrypted Signed Compressed Message """
"""Test Encrypted Signed Compressed Message"""

# Build an As2 message to be transmitted to partner
self.partner.sign = True
Expand Down
4 changes: 2 additions & 2 deletions pyas2lib/tests/test_mdn.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setUp(self):
self.out_message = None

def test_unsigned_mdn(self):
""" Test unsigned MDN generation and parsing """
"""Test unsigned MDN generation and parsing"""

# Build an As2 message to be transmitted to partner
self.partner.sign = True
Expand Down Expand Up @@ -49,7 +49,7 @@ def test_unsigned_mdn(self):
self.assertEqual(status, "processed")

def test_signed_mdn(self):
""" Test signed MDN generation and parsing """
"""Test signed MDN generation and parsing"""

# Build an As2 message to be transmitted to partner
self.partner.sign = True
Expand Down
Loading

0 comments on commit 7a41284

Please sign in to comment.