summaryrefslogtreecommitdiff
path: root/openid/extensions
diff options
context:
space:
mode:
authorVlastimil Zíma <vlastimil.zima@nic.cz>2017-11-24 15:07:29 +0100
committerVlastimil Zíma <vlastimil.zima@nic.cz>2017-11-29 08:38:30 +0100
commit8f0ff0d27771514d16a415b8ac76d18ea0809f38 (patch)
tree06b56cd9666f85aec459e9264e4c724f86c70f0d /openid/extensions
parentf58d7cee3e9f4bff9854dc10ffcd105fb3bc6619 (diff)
downloadopenid-8f0ff0d27771514d16a415b8ac76d18ea0809f38.tar.gz
Pepify and add flake8
Diffstat (limited to 'openid/extensions')
-rw-r--r--openid/extensions/ax.py40
-rw-r--r--openid/extensions/draft/pape2.py15
-rw-r--r--openid/extensions/draft/pape5.py16
-rw-r--r--openid/extensions/sreg.py37
4 files changed, 52 insertions, 56 deletions
diff --git a/openid/extensions/ax.py b/openid/extensions/ax.py
index 6b21812..c8fac3f 100644
--- a/openid/extensions/ax.py
+++ b/openid/extensions/ax.py
@@ -5,12 +5,12 @@
"""
__all__ = [
- 'AttributeRequest',
+ 'AttrInfo',
'FetchRequest',
'FetchResponse',
'StoreRequest',
'StoreResponse',
- ]
+]
from openid import extension
from openid.message import OPENID_NS, NamespaceMap
@@ -24,6 +24,7 @@ UNLIMITED_VALUES = "unlimited"
# completeness.
MINIMUM_SUPPORTED_ALIAS_LENGTH = 32
+
def checkAlias(alias):
"""
Check an alias for invalid characters; raise AXError if any are
@@ -60,11 +61,6 @@ class AXMessage(extension.Extension):
be overridden in subclasses.
"""
- # This class is abstract, so it's OK that it doesn't override the
- # abstract method in Extension:
- #
- #pylint:disable-msg=W0223
-
ns_alias = 'ax'
mode = None
ns_uri = 'http://openid.net/srv/ax/1.0'
@@ -90,7 +86,7 @@ class AXMessage(extension.Extension):
basic information that must be in every attribute exchange
message.
"""
- return {'mode':self.mode}
+ return {'mode': self.mode}
class AttrInfo(object):
@@ -122,11 +118,6 @@ class AttrInfo(object):
@type alias: str or NoneType
"""
- # It's OK that this class doesn't have public methods (it's just a
- # holder for a bunch of attributes):
- #
- #pylint:disable-msg=R0903
-
def __init__(self, type_uri, count=1, required=False, alias=None):
self.required = required
self.count = count
@@ -146,6 +137,7 @@ class AttrInfo(object):
"""
return self.count == UNLIMITED_VALUES
+
def toTypeURIs(namespace_map, alias_list_s):
"""Given a namespace mapping and a string containing a
comma-separated list of namespace aliases, return a list of type
@@ -304,7 +296,7 @@ class FetchRequest(AXMessage):
self = cls()
try:
self.parseExtensionArgs(ax_args)
- except NotAXMessage, err:
+ except NotAXMessage:
return None
if self.update_url:
@@ -413,11 +405,6 @@ class AXKeyValueMessage(AXMessage):
fetch_response and store_request.
"""
- # This class is abstract, so it's OK that it doesn't override the
- # abstract method in Extension:
- #
- #pylint:disable-msg=W0223
-
def __init__(self):
AXMessage.__init__(self)
self.data = {}
@@ -652,8 +639,7 @@ class FetchResponse(AXKeyValueMessage):
values = []
zero_value_types.append(attr_info)
- if (attr_info.count != UNLIMITED_VALUES) and \
- (attr_info.count < len(values)):
+ if (attr_info.count != UNLIMITED_VALUES) and (attr_info.count < len(values)):
raise AXError(
'More than the number of requested values were '
'specified for %r' % (attr_info.type_uri,))
@@ -671,8 +657,7 @@ class FetchResponse(AXKeyValueMessage):
kv_args['type.' + alias] = attr_info.type_uri
kv_args['count.' + alias] = '0'
- update_url = ((self.request and self.request.update_url)
- or self.update_url)
+ update_url = ((self.request and self.request.update_url) or self.update_url)
if update_url:
ax_args['update_url'] = update_url
@@ -709,7 +694,7 @@ class FetchResponse(AXKeyValueMessage):
try:
self.parseExtensionArgs(ax_args)
- except NotAXMessage, err:
+ except NotAXMessage:
return None
else:
return self
@@ -762,7 +747,7 @@ class StoreRequest(AXKeyValueMessage):
self = cls()
try:
self.parseExtensionArgs(ax_args)
- except NotAXMessage, err:
+ except NotAXMessage:
return None
return self
@@ -782,8 +767,7 @@ class StoreResponse(AXMessage):
AXMessage.__init__(self)
if succeeded and error_message is not None:
- raise AXError('An error message may only be included in a '
- 'failing fetch response')
+ raise AXError('An error message may only be included in a failing fetch response')
if succeeded:
self.mode = self.SUCCESS_MODE
else:
@@ -826,7 +810,7 @@ class StoreResponse(AXMessage):
try:
self.parseExtensionArgs(ax_args)
- except NotAXMessage, err:
+ except NotAXMessage:
return None
else:
return self
diff --git a/openid/extensions/draft/pape2.py b/openid/extensions/draft/pape2.py
index b800ce2..f9b84c8 100644
--- a/openid/extensions/draft/pape2.py
+++ b/openid/extensions/draft/pape2.py
@@ -13,7 +13,7 @@ __all__ = [
'AUTH_PHISHING_RESISTANT',
'AUTH_MULTI_FACTOR',
'AUTH_MULTI_FACTOR_PHYSICAL',
- ]
+]
import re
@@ -30,6 +30,7 @@ AUTH_PHISHING_RESISTANT = \
TIME_VALIDATOR = re.compile('^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ$')
+
class Request(Extension):
"""A Provider Authentication Policy request, sent from a relying
party to a provider
@@ -75,8 +76,8 @@ class Request(Extension):
"""@see: C{L{Extension.getExtensionArgs}}
"""
ns_args = {
- 'preferred_auth_policies':' '.join(self.preferred_auth_policies)
- }
+ 'preferred_auth_policies': ' '.join(self.preferred_auth_policies)
+ }
if self.max_auth_age is not None:
ns_args['max_auth_age'] = str(self.max_auth_age)
@@ -148,6 +149,7 @@ class Request(Extension):
return filter(self.preferred_auth_policies.__contains__,
supported_types)
+
Request.ns_uri = ns_uri
@@ -254,12 +256,12 @@ class Response(Extension):
"""
if len(self.auth_policies) == 0:
ns_args = {
- 'auth_policies':'none',
+ 'auth_policies': 'none',
}
else:
ns_args = {
- 'auth_policies':' '.join(self.auth_policies),
- }
+ 'auth_policies': ' '.join(self.auth_policies),
+ }
if self.nist_auth_level is not None:
if self.nist_auth_level not in range(0, 5):
@@ -275,4 +277,5 @@ class Response(Extension):
return ns_args
+
Response.ns_uri = ns_uri
diff --git a/openid/extensions/draft/pape5.py b/openid/extensions/draft/pape5.py
index e146873..6d0b1dd 100644
--- a/openid/extensions/draft/pape5.py
+++ b/openid/extensions/draft/pape5.py
@@ -15,7 +15,7 @@ __all__ = [
'AUTH_MULTI_FACTOR_PHYSICAL',
'LEVELS_NIST',
'LEVELS_JISA',
- ]
+]
import re
import warnings
@@ -38,11 +38,12 @@ TIME_VALIDATOR = re.compile('^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ$')
LEVELS_NIST = 'http://csrc.nist.gov/publications/nistpubs/800-63/SP800-63V1_0_2.pdf'
LEVELS_JISA = 'http://www.jisa.or.jp/spec/auth_level.html'
+
class PAPEExtension(Extension):
_default_auth_level_aliases = {
'nist': LEVELS_NIST,
'jisa': LEVELS_JISA,
- }
+ }
def __init__(self):
self.auth_level_aliases = self._default_auth_level_aliases.copy()
@@ -90,6 +91,7 @@ class PAPEExtension(Extension):
raise KeyError(auth_level_uri)
+
class Request(PAPEExtension):
"""A Provider Authentication Policy request, sent from a relying
party to a provider
@@ -152,8 +154,8 @@ class Request(PAPEExtension):
"""@see: C{L{Extension.getExtensionArgs}}
"""
ns_args = {
- 'preferred_auth_policies':' '.join(self.preferred_auth_policies),
- }
+ 'preferred_auth_policies': ' '.join(self.preferred_auth_policies),
+ }
if self.max_auth_age is not None:
ns_args['max_auth_age'] = str(self.max_auth_age)
@@ -266,6 +268,7 @@ class Request(PAPEExtension):
return filter(self.preferred_auth_policies.__contains__,
supported_types)
+
Request.ns_uri = ns_uri
@@ -455,8 +458,8 @@ class Response(PAPEExtension):
}
else:
ns_args = {
- 'auth_policies':' '.join(self.auth_policies),
- }
+ 'auth_policies': ' '.join(self.auth_policies),
+ }
for level_type, level in self.auth_levels.iteritems():
alias = self._getAlias(level_type)
@@ -471,4 +474,5 @@ class Response(PAPEExtension):
return ns_args
+
Response.ns_uri = ns_uri
diff --git a/openid/extensions/sreg.py b/openid/extensions/sreg.py
index e147cf1..786aeea 100644
--- a/openid/extensions/sreg.py
+++ b/openid/extensions/sreg.py
@@ -48,22 +48,23 @@ __all__ = [
'ns_uri_1_0',
'ns_uri_1_1',
'supportsSReg',
- ]
+]
_LOGGER = logging.getLogger(__name__)
# The data fields that are listed in the sreg spec
data_fields = {
- 'fullname':'Full Name',
- 'nickname':'Nickname',
- 'dob':'Date of Birth',
- 'email':'E-mail Address',
- 'gender':'Gender',
- 'postcode':'Postal Code',
- 'country':'Country',
- 'language':'Language',
- 'timezone':'Time Zone',
- }
+ 'fullname': 'Full Name',
+ 'nickname': 'Nickname',
+ 'dob': 'Date of Birth',
+ 'email': 'E-mail Address',
+ 'gender': 'Gender',
+ 'postcode': 'Postal Code',
+ 'country': 'Country',
+ 'language': 'Language',
+ 'timezone': 'Time Zone',
+}
+
def checkFieldName(field_name):
"""Check to see that the given value is a valid simple
@@ -76,6 +77,7 @@ def checkFieldName(field_name):
raise ValueError('%r is not a defined simple registration field' %
(field_name,))
+
# URI used in the wild for Yadis documents advertising simple
# registration support
ns_uri_1_0 = 'http://openid.net/sreg/1.0'
@@ -90,9 +92,10 @@ ns_uri = ns_uri_1_1
try:
registerNamespaceAlias(ns_uri_1_1, 'sreg')
-except NamespaceAliasRegistrationError, e:
+except NamespaceAliasRegistrationError as e:
_LOGGER.exception('registerNamespaceAlias(%r, %r) failed: %s', ns_uri_1_1, 'sreg', e)
+
def supportsSReg(endpoint):
"""Does the given endpoint advertise support for simple
registration?
@@ -106,6 +109,7 @@ def supportsSReg(endpoint):
return (endpoint.usesExtension(ns_uri_1_1) or
endpoint.usesExtension(ns_uri_1_0))
+
class SRegNamespaceError(ValueError):
"""The simple registration namespace was not found and could not
be created using the expected name (there's another extension
@@ -120,6 +124,7 @@ class SRegNamespaceError(ValueError):
the message that is being processed.
"""
+
def getSRegNS(message):
"""Extract the simple registration namespace URI from the given
OpenID message. Handles OpenID 1 and 2, as well as both sreg
@@ -151,14 +156,13 @@ def getSRegNS(message):
sreg_ns_uri = ns_uri_1_1
try:
message.namespaces.addAlias(ns_uri_1_1, 'sreg')
- except KeyError, why:
+ except KeyError as why:
# An alias for the string 'sreg' already exists, but it's
# defined for something other than simple registration
raise SRegNamespaceError(why[0])
- # we know that sreg_ns_uri defined, because it's defined in the
- # else clause of the loop as well, so disable the warning
- return sreg_ns_uri #pylint:disable-msg=W0631
+ return sreg_ns_uri
+
class SRegRequest(Extension):
"""An object to hold the state of a simple registration request.
@@ -368,6 +372,7 @@ class SRegRequest(Extension):
return args
+
class SRegResponse(Extension):
"""Represents the data returned in a simple registration response
inside of an OpenID C{id_res} response. This object will be