summaryrefslogtreecommitdiff
path: root/openid
diff options
context:
space:
mode:
authorVlastimil Zíma <vlastimil.zima@nic.cz>2018-02-02 18:53:45 +0100
committerVlastimil Zíma <vlastimil.zima@nic.cz>2018-02-02 18:53:45 +0100
commit4697b9f5cf47d5f89e542f2f6ff1624e940a4401 (patch)
tree1b81dbc9f257927475a6531acaa2ef7d42145b25 /openid
parentec98cbd31f7a0670e672b404351c363df7dab0d8 (diff)
downloadopenid-4697b9f5cf47d5f89e542f2f6ff1624e940a4401.tar.gz
Use common decorators as such
Diffstat (limited to 'openid')
-rw-r--r--openid/association.py6
-rw-r--r--openid/consumer/consumer.py6
-rw-r--r--openid/consumer/discover.py15
-rw-r--r--openid/dh.py3
-rw-r--r--openid/extensions/ax.py12
-rw-r--r--openid/extensions/draft/pape2.py6
-rw-r--r--openid/extensions/draft/pape5.py14
-rw-r--r--openid/extensions/sreg.py9
-rw-r--r--openid/message.py9
-rw-r--r--openid/server/server.py20
-rw-r--r--openid/server/trustroot.py9
-rw-r--r--openid/yadis/filters.py3
12 files changed, 38 insertions, 74 deletions
diff --git a/openid/association.py b/openid/association.py
index 8a52b78..920bd63 100644
--- a/openid/association.py
+++ b/openid/association.py
@@ -259,6 +259,7 @@ class Association(object):
'HMAC-SHA256': cryptutil.hmacSha256,
}
+ @classmethod
def fromExpiresIn(cls, expires_in, handle, secret, assoc_type):
"""
This is an alternate constructor used by the OpenID consumer
@@ -297,8 +298,6 @@ class Association(object):
lifetime = expires_in
return cls(handle, secret, issued, lifetime, assoc_type)
- fromExpiresIn = classmethod(fromExpiresIn)
-
def __init__(self, handle, secret, issued, lifetime, assoc_type):
"""
This is the standard constructor for creating an association.
@@ -421,6 +420,7 @@ class Association(object):
return kvform.seqToKV(pairs, strict=True)
+ @classmethod
def deserialize(cls, assoc_s):
"""
Parse an association as stored by serialize().
@@ -453,8 +453,6 @@ class Association(object):
secret = oidutil.fromBase64(secret)
return cls(handle, secret, issued, lifetime, assoc_type)
- deserialize = classmethod(deserialize)
-
def sign(self, pairs):
"""
Generate a signature for a sequence of (key, value) pairs
diff --git a/openid/consumer/consumer.py b/openid/consumer/consumer.py
index a228938..a836c90 100644
--- a/openid/consumer/consumer.py
+++ b/openid/consumer/consumer.py
@@ -539,6 +539,7 @@ class ServerError(Exception):
self.error_code = error_code
self.message = message
+ @classmethod
def fromMessage(cls, message):
"""Generate a ServerError instance, extracting the error text
and the error code from the message."""
@@ -547,8 +548,6 @@ class ServerError(Exception):
error_code = message.getArg(OPENID_NS, 'error_code')
return cls(error_text, error_code, message)
- fromMessage = classmethod(fromMessage)
-
class GenericConsumer(object):
"""This is the implementation of the common logic for OpenID
@@ -832,6 +831,7 @@ class GenericConsumer(object):
if message.hasKey(OPENID_NS, field) and field not in signed_list:
raise ProtocolError('"%s" not signed' % (field,))
+ @staticmethod
def _verifyReturnToArgs(query):
"""Verify that the arguments in the return_to URL are present in this
response.
@@ -864,8 +864,6 @@ class GenericConsumer(object):
if pair not in parsed_args:
raise ProtocolError("Parameter %s not in return_to URL" % (pair[0],))
- _verifyReturnToArgs = staticmethod(_verifyReturnToArgs)
-
def _verifyDiscoveryResults(self, resp_msg, endpoint=None):
"""
Extract the information from an OpenID assertion message and
diff --git a/openid/consumer/discover.py b/openid/consumer/discover.py
index f847c63..b9bc30e 100644
--- a/openid/consumer/discover.py
+++ b/openid/consumer/discover.py
@@ -119,6 +119,7 @@ class OpenIDServiceEndpoint(object):
else:
return self.local_id or self.canonicalID
+ @classmethod
def fromBasicServiceEndpoint(cls, endpoint):
"""Create a new instance of this class from the endpoint
object passed in.
@@ -140,8 +141,7 @@ class OpenIDServiceEndpoint(object):
return openid_endpoint
- fromBasicServiceEndpoint = classmethod(fromBasicServiceEndpoint)
-
+ @classmethod
def fromHTML(cls, uri, html):
"""Parse the given document as HTML looking for an OpenID <link
rel=...>
@@ -172,8 +172,7 @@ class OpenIDServiceEndpoint(object):
return services
- fromHTML = classmethod(fromHTML)
-
+ @classmethod
def fromXRDS(cls, uri, xrds):
"""Parse the given document as XRDS looking for OpenID services.
@@ -185,8 +184,7 @@ class OpenIDServiceEndpoint(object):
"""
return extractServices(uri, xrds, cls)
- fromXRDS = classmethod(fromXRDS)
-
+ @classmethod
def fromDiscoveryResult(cls, discoveryResult):
"""Create endpoints from a DiscoveryResult.
@@ -205,8 +203,7 @@ class OpenIDServiceEndpoint(object):
return method(discoveryResult.normalized_uri,
discoveryResult.response_text)
- fromDiscoveryResult = classmethod(fromDiscoveryResult)
-
+ @classmethod
def fromOPEndpointURL(cls, op_endpoint_url):
"""Construct an OP-Identifier OpenIDServiceEndpoint object for
a given OP Endpoint URL
@@ -219,8 +216,6 @@ class OpenIDServiceEndpoint(object):
service.type_uris = [OPENID_IDP_2_0_TYPE]
return service
- fromOPEndpointURL = classmethod(fromOPEndpointURL)
-
def __str__(self):
return ("<%s.%s "
"server_url=%r "
diff --git a/openid/dh.py b/openid/dh.py
index b0400b9..5b7a440 100644
--- a/openid/dh.py
+++ b/openid/dh.py
@@ -21,11 +21,10 @@ class DiffieHellman(object):
DEFAULT_GEN = 2
+ @classmethod
def fromDefaults(cls):
return cls(cls.DEFAULT_MOD, cls.DEFAULT_GEN)
- fromDefaults = classmethod(fromDefaults)
-
def __init__(self, modulus, generator):
self.modulus = long(modulus)
self.generator = long(generator)
diff --git a/openid/extensions/ax.py b/openid/extensions/ax.py
index c8fac3f..b48d19c 100644
--- a/openid/extensions/ax.py
+++ b/openid/extensions/ax.py
@@ -273,6 +273,7 @@ class FetchRequest(AXMessage):
return required
+ @classmethod
def fromOpenIDRequest(cls, openid_request):
"""Extract a FetchRequest from an OpenID message
@@ -316,8 +317,6 @@ class FetchRequest(AXMessage):
return self
- fromOpenIDRequest = classmethod(fromOpenIDRequest)
-
def parseExtensionArgs(self, ax_args):
"""Given attribute exchange arguments, populate this FetchRequest.
@@ -671,6 +670,7 @@ class FetchResponse(AXKeyValueMessage):
super(FetchResponse, self).parseExtensionArgs(ax_args)
self.update_url = ax_args.get('update_url')
+ @classmethod
def fromSuccessResponse(cls, success_response, signed=True):
"""Construct a FetchResponse object from an OpenID library
SuccessResponse object.
@@ -699,8 +699,6 @@ class FetchResponse(AXKeyValueMessage):
else:
return self
- fromSuccessResponse = classmethod(fromSuccessResponse)
-
class StoreRequest(AXKeyValueMessage):
"""A store request attribute exchange message representation
@@ -724,6 +722,7 @@ class StoreRequest(AXKeyValueMessage):
ax_args.update(kv_args)
return ax_args
+ @classmethod
def fromOpenIDRequest(cls, openid_request):
"""Extract a StoreRequest from an OpenID message
@@ -752,8 +751,6 @@ class StoreRequest(AXKeyValueMessage):
return self
- fromOpenIDRequest = classmethod(fromOpenIDRequest)
-
class StoreResponse(AXMessage):
"""An indication that the store request was processed along with
@@ -787,6 +784,7 @@ class StoreResponse(AXMessage):
return ax_args
+ @classmethod
def fromSuccessResponse(cls, success_response, signed=True):
"""Construct a StoreResponse object from an OpenID library
SuccessResponse object.
@@ -814,5 +812,3 @@ class StoreResponse(AXMessage):
return None
else:
return self
-
- fromSuccessResponse = classmethod(fromSuccessResponse)
diff --git a/openid/extensions/draft/pape2.py b/openid/extensions/draft/pape2.py
index f9b84c8..954c5c0 100644
--- a/openid/extensions/draft/pape2.py
+++ b/openid/extensions/draft/pape2.py
@@ -84,6 +84,7 @@ class Request(Extension):
return ns_args
+ @classmethod
def fromOpenIDRequest(cls, request):
"""Instantiate a Request object from the arguments in a
C{checkid_*} OpenID message
@@ -97,8 +98,6 @@ class Request(Extension):
self.parseExtensionArgs(args)
return self
- fromOpenIDRequest = classmethod(fromOpenIDRequest)
-
def parseExtensionArgs(self, args):
"""Set the state of this request to be that expressed in these
PAPE arguments
@@ -184,6 +183,7 @@ class Response(Extension):
if policy_uri not in self.auth_policies:
self.auth_policies.append(policy_uri)
+ @classmethod
def fromSuccessResponse(cls, success_response):
"""Create a C{L{Response}} object from a successful OpenID
library response
@@ -249,8 +249,6 @@ class Response(Extension):
elif strict:
raise ValueError("auth_time must be in RFC3339 format")
- fromSuccessResponse = classmethod(fromSuccessResponse)
-
def getExtensionArgs(self):
"""@see: C{L{Extension.getExtensionArgs}}
"""
diff --git a/openid/extensions/draft/pape5.py b/openid/extensions/draft/pape5.py
index 6d0b1dd..e7568dd 100644
--- a/openid/extensions/draft/pape5.py
+++ b/openid/extensions/draft/pape5.py
@@ -172,6 +172,7 @@ class Request(PAPEExtension):
return ns_args
+ @classmethod
def fromOpenIDRequest(cls, request):
"""Instantiate a Request object from the arguments in a
C{checkid_*} OpenID message
@@ -186,8 +187,6 @@ class Request(PAPEExtension):
self.parseExtensionArgs(args, is_openid1)
return self
- fromOpenIDRequest = classmethod(fromOpenIDRequest)
-
def parseExtensionArgs(self, args, is_openid1, strict=False):
"""Set the state of this request to be that expressed in these
PAPE arguments
@@ -325,16 +324,14 @@ class Response(PAPEExtension):
"""
return self.auth_levels[level_uri]
- def _getNISTAuthLevel(self):
+ @property
+ def nist_auth_level(self):
+ """Backward-compatibility accessor for the NIST auth level."""
try:
return int(self.getAuthLevel(LEVELS_NIST))
except KeyError:
return None
- nist_auth_level = property(
- _getNISTAuthLevel,
- doc="Backward-compatibility accessor for the NIST auth level")
-
def addPolicyURI(self, policy_uri):
"""Add a authentication policy to this response
@@ -352,6 +349,7 @@ class Response(PAPEExtension):
if policy_uri not in self.auth_policies:
self.auth_policies.append(policy_uri)
+ @classmethod
def fromSuccessResponse(cls, success_response):
"""Create a C{L{Response}} object from a successful OpenID
library response
@@ -447,8 +445,6 @@ class Response(PAPEExtension):
elif strict:
raise ValueError("auth_time must be in RFC3339 format")
- fromSuccessResponse = classmethod(fromSuccessResponse)
-
def getExtensionArgs(self):
"""@see: C{L{Extension.getExtensionArgs}}
"""
diff --git a/openid/extensions/sreg.py b/openid/extensions/sreg.py
index 786aeea..4bdb262 100644
--- a/openid/extensions/sreg.py
+++ b/openid/extensions/sreg.py
@@ -203,6 +203,7 @@ class SRegRequest(Extension):
# overridden for testing.
_getSRegNS = staticmethod(getSRegNS)
+ @classmethod
def fromOpenIDRequest(cls, request):
"""Create a simple registration request that contains the
fields that were requested in the OpenID request with the
@@ -226,8 +227,6 @@ class SRegRequest(Extension):
return self
- fromOpenIDRequest = classmethod(fromOpenIDRequest)
-
def parseExtensionArgs(self, args, strict=False):
"""Parse the unqualified simple registration request
parameters and add them to this object.
@@ -404,6 +403,7 @@ class SRegResponse(Extension):
self.ns_uri = sreg_ns_uri
+ @classmethod
def extractResponse(cls, request, data):
"""Take a C{L{SRegRequest}} and a dictionary of simple
registration values and create a C{L{SRegResponse}}
@@ -430,12 +430,11 @@ class SRegResponse(Extension):
self.data[field] = value
return self
- extractResponse = classmethod(extractResponse)
-
# Assign getSRegArgs to a static method so that it can be
# overridden for testing
_getSRegNS = staticmethod(getSRegNS)
+ @classmethod
def fromSuccessResponse(cls, success_response, signed_only=True):
"""Create a C{L{SRegResponse}} object from a successful OpenID
library response
@@ -469,8 +468,6 @@ class SRegResponse(Extension):
return self
- fromSuccessResponse = classmethod(fromSuccessResponse)
-
def getExtensionArgs(self):
"""Get the fields to put in the simple registration namespace
when adding them to an id_res message.
diff --git a/openid/message.py b/openid/message.py
index 9c487d6..c7d5323 100644
--- a/openid/message.py
+++ b/openid/message.py
@@ -150,6 +150,7 @@ class Message(object):
implicit = openid_namespace in OPENID1_NAMESPACES
self.setOpenIDNamespace(openid_namespace, implicit)
+ @classmethod
def fromPostArgs(cls, args):
"""Construct a Message containing a set of POST arguments.
@@ -177,8 +178,7 @@ class Message(object):
return self
- fromPostArgs = classmethod(fromPostArgs)
-
+ @classmethod
def fromOpenIDArgs(cls, openid_args):
"""Construct a Message from a parsed KVForm message.
@@ -189,8 +189,6 @@ class Message(object):
self._fromOpenIDArgs(openid_args)
return self
- fromOpenIDArgs = classmethod(fromOpenIDArgs)
-
def _fromOpenIDArgs(self, openid_args):
ns_args = []
@@ -260,12 +258,11 @@ class Message(object):
def isOpenID2(self):
return self.getOpenIDNamespace() == OPENID2_NS
+ @classmethod
def fromKVForm(cls, kvform_string):
"""Create a Message from a KVForm string"""
return cls.fromOpenIDArgs(kvform.kvToDict(kvform_string))
- fromKVForm = classmethod(fromKVForm)
-
def copy(self):
return copy.deepcopy(self)
diff --git a/openid/server/server.py b/openid/server/server.py
index 436b8ad..8d45bc8 100644
--- a/openid/server/server.py
+++ b/openid/server/server.py
@@ -191,6 +191,7 @@ class CheckAuthRequest(OpenIDRequest):
self.invalidate_handle = invalidate_handle
self.namespace = OPENID2_NS
+ @classmethod
def fromMessage(klass, message, op_endpoint=UNUSED):
"""Construct me from an OpenID Message.
@@ -223,8 +224,6 @@ class CheckAuthRequest(OpenIDRequest):
return self
- fromMessage = classmethod(fromMessage)
-
def answer(self, signatory):
"""Respond to this request.
@@ -280,11 +279,10 @@ class PlainTextServerSession(object):
session_type = 'no-encryption'
allowed_assoc_types = ['HMAC-SHA1', 'HMAC-SHA256']
+ @classmethod
def fromMessage(cls, unused_request):
return cls()
- fromMessage = classmethod(fromMessage)
-
def answer(self, secret):
return {'mac_key': oidutil.toBase64(secret)}
@@ -316,6 +314,7 @@ class DiffieHellmanSHA1ServerSession(object):
self.dh = dh
self.consumer_pubkey = consumer_pubkey
+ @classmethod
def fromMessage(cls, message):
"""
@param message: The associate request message
@@ -357,8 +356,6 @@ class DiffieHellmanSHA1ServerSession(object):
return cls(dh, consumer_pubkey)
- fromMessage = classmethod(fromMessage)
-
def answer(self, secret):
mac_key = self.dh.xorSecret(self.consumer_pubkey,
secret,
@@ -411,6 +408,7 @@ class AssociateRequest(OpenIDRequest):
self.assoc_type = assoc_type
self.namespace = OPENID2_NS
+ @classmethod
def fromMessage(klass, message, op_endpoint=UNUSED):
"""Construct me from an OpenID Message.
@@ -462,8 +460,6 @@ class AssociateRequest(OpenIDRequest):
self.namespace = message.getOpenIDNamespace()
return self
- fromMessage = classmethod(fromMessage)
-
def answer(self, assoc):
"""Respond to this request with an X{association}.
@@ -578,14 +574,14 @@ class CheckIDRequest(OpenIDRequest):
raise UntrustedReturnURL(None, self.return_to, self.trust_root)
self.message = None
- def _getNamespace(self):
+ @property
+ def namespace(self):
warnings.warn('The "namespace" attribute of CheckIDRequest objects '
'is deprecated. Use "message.getOpenIDNamespace()" '
'instead', DeprecationWarning, stacklevel=2)
return self.message.getOpenIDNamespace()
- namespace = property(_getNamespace)
-
+ @classmethod
def fromMessage(klass, message, op_endpoint):
"""Construct me from an OpenID message.
@@ -678,8 +674,6 @@ class CheckIDRequest(OpenIDRequest):
return self
- fromMessage = classmethod(fromMessage)
-
def idSelect(self):
"""Is the identifier to be selected by the IDP?
diff --git a/openid/server/trustroot.py b/openid/server/trustroot.py
index ec771b9..a71ed71 100644
--- a/openid/server/trustroot.py
+++ b/openid/server/trustroot.py
@@ -246,6 +246,7 @@ class TrustRoot(object):
return True
+ @classmethod
def parse(cls, trust_root):
"""
This method creates a C{L{TrustRoot}} instance from the given
@@ -298,8 +299,7 @@ class TrustRoot(object):
return tr
- parse = classmethod(parse)
-
+ @classmethod
def checkSanity(cls, trust_root_string):
"""str -> bool
@@ -311,16 +311,13 @@ class TrustRoot(object):
else:
return trust_root.isSane()
- checkSanity = classmethod(checkSanity)
-
+ @classmethod
def checkURL(cls, trust_root, url):
"""quick func for validating a url against a trust root. See the
TrustRoot class if you need more control."""
tr = cls.parse(trust_root)
return tr is not None and tr.validateURL(url)
- checkURL = classmethod(checkURL)
-
def buildDiscoveryURL(self):
"""Return a discovery URL for this realm.
diff --git a/openid/yadis/filters.py b/openid/yadis/filters.py
index 1a9d3e7..0d87ad0 100644
--- a/openid/yadis/filters.py
+++ b/openid/yadis/filters.py
@@ -48,6 +48,7 @@ class BasicServiceEndpoint(object):
"""
return [uri for uri in type_uris if uri in self.type_uris]
+ @staticmethod
def fromBasicServiceEndpoint(endpoint):
"""Trivial transform from a basic endpoint to itself. This
method exists to allow BasicServiceEndpoint to be used as a
@@ -60,8 +61,6 @@ class BasicServiceEndpoint(object):
"""
return endpoint
- fromBasicServiceEndpoint = staticmethod(fromBasicServiceEndpoint)
-
class IFilter(object):
"""Interface for Yadis filter objects. Other filter-like things