From 9ab40444b66d59b8a6f623db2ad3125058a2fba5 Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Tue, 7 Jul 2015 08:15:33 +0000 Subject: [PATCH] More Python data model fixes for acme. --- acme/jose/jwa.py | 7 ++++++- acme/jose/jwa_test.py | 5 +++++ acme/messages.py | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/acme/jose/jwa.py b/acme/jose/jwa.py index c3d79ff20..f081aa169 100644 --- a/acme/jose/jwa.py +++ b/acme/jose/jwa.py @@ -35,7 +35,12 @@ class JWASignature(JWA): self.name = name def __eq__(self, other): - return isinstance(other, JWASignature) and self.name == other.name + if not isinstance(other, JWASignature): + return NotImplemented + return self.name == other.name + + def __ne__(self, other): + return not self == other @classmethod def register(cls, signature_cls): diff --git a/acme/jose/jwa_test.py b/acme/jose/jwa_test.py index c8347ff69..91b864cf5 100644 --- a/acme/jose/jwa_test.py +++ b/acme/jose/jwa_test.py @@ -44,8 +44,13 @@ class JWASignatureTest(unittest.TestCase): def test_eq(self): self.assertEqual(self.Sig1, self.Sig1) + + def test_ne(self): self.assertNotEqual(self.Sig1, self.Sig2) + def test_ne_other_type(self): + self.assertNotEqual(self.Sig1, 5) + def test_repr(self): self.assertEqual('Sig1', repr(self.Sig1)) self.assertEqual('Sig2', repr(self.Sig2)) diff --git a/acme/messages.py b/acme/messages.py index 35c325e4e..c224e9bde 100644 --- a/acme/messages.py +++ b/acme/messages.py @@ -84,7 +84,7 @@ class _Constant(jose.JSONDeSerializable): return isinstance(other, type(self)) and other.name == self.name def __ne__(self, other): - return not self.__eq__(other) + return not self == other class Status(_Constant):