Pylint, mypy and oldest tests fix.

This commit is contained in:
Adrien Ferrand 2019-12-28 23:16:30 +01:00
parent 5a1709c85f
commit 855efe5cbb
3 changed files with 19 additions and 18 deletions

View file

@ -4,12 +4,8 @@ The JWS implementation in josepy only implements the base JOSE standard. In
order to support the new header fields defined in ACME, this module defines some
ACME-specific classes that layer on top of josepy.
"""
import json
import josepy as jose
from acme.challenges import ChallengeResponse
class Header(jose.Header):
"""ACME-specific JOSE Header. Implements nonce, kid, and url.

View file

@ -1,16 +1,11 @@
from josepy import JSONObjectWithFields
from acme.magic_typing import TYPE_CHECKING # pylint: disable=unused-import, no-name-in-module
if TYPE_CHECKING:
_Base = JSONObjectWithFields
else:
_Base = object
"""Useful mixins for Challenge and Resource objects"""
class VersionedLEACMEMixin(object):
"""This mixin allows to store the current ACME version as a property"""
@property
def le_auto_version(self):
"""Define the version of ACME protocol to use"""
return getattr(self, '_le_auto_version', 1)
@le_auto_version.setter
@ -22,16 +17,21 @@ class VersionedLEACMEMixin(object):
def __setattr__(self, key, value):
if key == 'le_auto_version':
# Needed to allow @property to operate properly. See comment above.
# Required for @property to operate properly. See comment above.
object.__setattr__(self, key, value)
else:
super(VersionedLEACMEMixin, self).__setattr__(key, value)
class ResourceMixin(VersionedLEACMEMixin, _Base):
class ResourceMixin(VersionedLEACMEMixin):
"""
This mixin allows to generate a RFC8555 compliant JWS payload
by removing the `resource` field if needed (eg. ACME v2 protocol).
"""
def to_partial_json(self):
"""See josepy.JSONDeserializable.to_partial_json()"""
if hasattr(super(ResourceMixin, self), 'to_partial_json'):
jobj = super(ResourceMixin, self).to_partial_json()
jobj = super(ResourceMixin, self).to_partial_json() # type: ignore
if self.le_auto_version == 2:
jobj.pop('resource', None)
return jobj
@ -39,10 +39,15 @@ class ResourceMixin(VersionedLEACMEMixin, _Base):
raise AttributeError('This class does not implement method to_partial_json().')
class TypeMixin(VersionedLEACMEMixin, _Base):
class TypeMixin(VersionedLEACMEMixin):
"""
This mixin allows to generate a RFC8555 compliant JWS payload
by removing the `type` field if needed (eg. ACME v2 protocol).
"""
def to_partial_json(self):
"""See josepy.JSONDeserializable.to_partial_json()"""
if hasattr(super(TypeMixin, self), 'to_partial_json'):
jobj = super(TypeMixin, self).to_partial_json()
jobj = super(TypeMixin, self).to_partial_json() # type: ignore
if self.le_auto_version == 2:
jobj.pop('type', None)
return jobj

View file

@ -1,3 +1,3 @@
# Remember to update setup.py to match the package versions below.
acme[dev]==1.0.0
-e acme[dev]
-e certbot[dev]