summaryrefslogtreecommitdiff
path: root/openid
diff options
context:
space:
mode:
authorVlastimil Zíma <vlastimil.zima@nic.cz>2018-05-04 13:41:04 +0200
committerVlastimil Zíma <vlastimil.zima@nic.cz>2018-05-11 13:39:31 +0200
commit61e6d6a135600db480ed14ec8f6fbb8676668dc3 (patch)
tree4a4d911b184d7729bce93d2def41905caffe593d /openid
parentcbc2ed111c1cef8d704d96602d68a6701e5b98d6 (diff)
downloadopenid-61e6d6a135600db480ed14ec8f6fbb8676668dc3.tar.gz
Transform Extensions API to text strings
Diffstat (limited to 'openid')
-rw-r--r--openid/extensions/ax.py39
-rw-r--r--openid/extensions/draft/pape2.py21
-rw-r--r--openid/extensions/pape.py23
-rw-r--r--openid/extensions/sreg.py37
-rw-r--r--openid/sreg.py1
-rw-r--r--openid/test/test_ax.py4
-rw-r--r--openid/test/test_pape.py2
-rw-r--r--openid/test/test_pape_draft2.py2
-rw-r--r--openid/test/test_pape_draft5.py2
-rw-r--r--openid/test/test_sreg.py2
10 files changed, 85 insertions, 48 deletions
diff --git a/openid/extensions/ax.py b/openid/extensions/ax.py
index 39b85cd..6bbad7c 100644
--- a/openid/extensions/ax.py
+++ b/openid/extensions/ax.py
@@ -1,8 +1,15 @@
-# -*- test-case-name: openid.test.test_ax -*-
"""Implements the OpenID Attribute Exchange specification, version 1.0.
@since: 2.1.0
"""
+from __future__ import unicode_literals
+
+import six
+
+from openid import extension
+from openid.message import OPENID_NS, NamespaceMap
+from openid.oidutil import string_to_text
+from openid.server.trustroot import TrustRoot
__all__ = [
'AttrInfo',
@@ -12,10 +19,6 @@ __all__ = [
'StoreResponse',
]
-from openid import extension
-from openid.message import OPENID_NS, NamespaceMap
-from openid.server.trustroot import TrustRoot
-
# Use this as the 'count' value for an attribute in a FetchRequest to
# ask for as many values as the OP can provide.
UNLIMITED_VALUES = "unlimited"
@@ -107,7 +110,7 @@ class AttrInfo(object):
represents and how it is serialized. For example, one type URI
representing dates could represent a Unix timestamp in base 10
and another could represent a human-readable string.
- @type type_uri: str
+ @type type_uri: six.text_type
@ivar alias: The name that should be given to this alias in the
request. If it is not supplied, a generic name will be
@@ -115,7 +118,7 @@ class AttrInfo(object):
value 'tstamp', set its alias to that value. If two attributes
in the same message request to use the same alias, the request
will fail to be generated.
- @type alias: str or NoneType
+ @type alias: six.text_type or NoneType
"""
def __init__(self, type_uri, count=1, required=False, alias=None):
@@ -148,7 +151,7 @@ def toTypeURIs(namespace_map, alias_list_s):
@param alias_list_s: The string containing the comma-separated
list of aliases. May also be None for convenience.
- @type alias_list_s: str or NoneType
+ @type alias_list_s: Optional[six.text_type], six.binary_type is deprecated
@returns: The list of namespace URIs that corresponds to the
supplied list of aliases. If the string was zero-length or
@@ -160,6 +163,8 @@ def toTypeURIs(namespace_map, alias_list_s):
uris = []
if alias_list_s:
+ alias_list_s = string_to_text(alias_list_s,
+ "Binary values for alias_list_s are deprecated. Use text input instead.")
for alias in alias_list_s.split(','):
type_uri = namespace_map.getNamespaceURI(alias)
if type_uri is None:
@@ -178,7 +183,7 @@ class FetchRequest(AXMessage):
@ivar requested_attributes: The attributes that have been
requested thus far, indexed by the type URI.
- @type requested_attributes: {str:AttrInfo}
+ @type requested_attributes: Dict[six.text_type, AttrInfo]
@ivar update_url: A URL that will accept responses for this
attribute exchange request, even in the absence of the user
@@ -246,7 +251,7 @@ class FetchRequest(AXMessage):
if_available.append(alias)
if attribute.count != 1:
- ax_args['count.' + alias] = str(attribute.count)
+ ax_args['count.' + alias] = six.text_type(attribute.count)
ax_args['type.' + alias] = type_uri
@@ -264,7 +269,7 @@ class FetchRequest(AXMessage):
@returns: A list of the type URIs for attributes that have
been marked as required.
- @rtype: [str]
+ @rtype: List[six.text_type]
"""
required = []
for type_uri, attribute in self.requested_attributes.iteritems():
@@ -457,7 +462,7 @@ class AXKeyValueMessage(AXMessage):
alias = aliases.add(type_uri)
ax_args['type.' + alias] = type_uri
- ax_args['count.' + alias] = str(len(values))
+ ax_args['count.' + alias] = six.text_type(len(values))
for i, value in enumerate(values):
key = 'value.%s.%d' % (alias, i + 1)
@@ -498,7 +503,7 @@ class AXKeyValueMessage(AXMessage):
except KeyError:
value = ax_args['value.' + alias]
- if value == u'':
+ if value == '':
values = []
else:
values = [value]
@@ -517,8 +522,8 @@ class AXKeyValueMessage(AXMessage):
for this attribute, use the supplied default. If there is more
than one value for this attribute, this method will fail.
- @type type_uri: str
@param type_uri: The URI for the attribute
+ @type type_uri: six.text_type, six.binary_type is deprecated
@param default: The value to return if the attribute was not
sent in the fetch_response.
@@ -531,6 +536,7 @@ class AXKeyValueMessage(AXMessage):
parameter in the fetch_response message.
@raises KeyError: If the attribute was not sent in this response
"""
+ type_uri = string_to_text(type_uri, "Binary values for type_uri are deprecated. Use text input instead.")
values = self.data.get(type_uri)
if not values:
return default
@@ -593,9 +599,12 @@ class FetchResponse(AXKeyValueMessage):
request. But if you do not supply the request, you may set
the C{update_url} here.
- @type update_url: str
+ @type update_url: Optional[six.text_type], six.binary_type is deprecated
"""
AXKeyValueMessage.__init__(self)
+ if update_url is not None:
+ update_url = string_to_text(update_url,
+ "Binary values for update_url are deprecated. Use text input instead.")
self.update_url = update_url
self.request = request
diff --git a/openid/extensions/draft/pape2.py b/openid/extensions/draft/pape2.py
index a26ddfc..529f329 100644
--- a/openid/extensions/draft/pape2.py
+++ b/openid/extensions/draft/pape2.py
@@ -5,6 +5,14 @@ Extension 1.0
@since: 2.1.0
"""
+from __future__ import unicode_literals
+
+import re
+import warnings
+
+import six
+
+from openid.extension import Extension
__all__ = [
'Request',
@@ -15,11 +23,6 @@ __all__ = [
'AUTH_MULTI_FACTOR_PHYSICAL',
]
-import re
-import warnings
-
-from openid.extension import Extension
-
warnings.warn("Module 'openid.extensions.draft.pape2' is deprecated. Use 'openid.extensions.pape' instead.",
DeprecationWarning)
@@ -41,7 +44,7 @@ class Request(Extension):
@ivar preferred_auth_policies: The authentication policies that
the relying party prefers
- @type preferred_auth_policies: [str]
+ @type preferred_auth_policies: List[six.text_type]
@ivar max_auth_age: The maximum time, in seconds, that the relying
party wants to allow to have elapsed before the user must
@@ -84,7 +87,7 @@ class Request(Extension):
}
if self.max_auth_age is not None:
- ns_args['max_auth_age'] = str(self.max_auth_age)
+ ns_args['max_auth_age'] = six.text_type(self.max_auth_age)
return ns_args
@@ -147,7 +150,7 @@ class Request(Extension):
sequence, and may be empty if the provider does not prefer
any of the supported authentication types.
- @returntype: [str]
+ @returntype: List[six.text_type]
"""
return [i for i in supported_types if i in self.preferred_auth_policies]
@@ -268,7 +271,7 @@ class Response(Extension):
if self.nist_auth_level not in range(0, 5):
raise ValueError('nist_auth_level must be an integer between '
'zero and four, inclusive')
- ns_args['nist_auth_level'] = str(self.nist_auth_level)
+ ns_args['nist_auth_level'] = six.text_type(self.nist_auth_level)
if self.auth_time is not None:
if not TIME_VALIDATOR.match(self.auth_time):
diff --git a/openid/extensions/pape.py b/openid/extensions/pape.py
index 7065500..d69c4db 100644
--- a/openid/extensions/pape.py
+++ b/openid/extensions/pape.py
@@ -5,6 +5,14 @@ Extension 1.0, Draft 5
@since: 2.1.0
"""
+from __future__ import unicode_literals
+
+import re
+import warnings
+
+import six
+
+from openid.extension import Extension
__all__ = [
'Request',
@@ -17,11 +25,6 @@ __all__ = [
'LEVELS_JISA',
]
-import re
-import warnings
-
-from openid.extension import Extension
-
ns_uri = "http://specs.openid.net/extensions/pape/1.0"
AUTH_MULTI_FACTOR_PHYSICAL = \
@@ -98,7 +101,7 @@ class Request(PAPEExtension):
@ivar preferred_auth_policies: The authentication policies that
the relying party prefers
- @type preferred_auth_policies: [str]
+ @type preferred_auth_policies: List[six.text_type]
@ivar max_auth_age: The maximum time, in seconds, that the relying
party wants to allow to have elapsed before the user must
@@ -108,7 +111,7 @@ class Request(PAPEExtension):
@ivar preferred_auth_level_types: Ordered list of authentication
level namespace URIs
- @type preferred_auth_level_types: [str]
+ @type preferred_auth_level_types: List[six.text_type]
"""
ns_alias = 'pape'
@@ -158,7 +161,7 @@ class Request(PAPEExtension):
}
if self.max_auth_age is not None:
- ns_args['max_auth_age'] = str(self.max_auth_age)
+ ns_args['max_auth_age'] = six.text_type(self.max_auth_age)
if self.preferred_auth_level_types:
preferred_types = []
@@ -262,7 +265,7 @@ class Request(PAPEExtension):
sequence, and may be empty if the provider does not prefer
any of the supported authentication types.
- @returntype: [str]
+ @returntype: List[six.text_type]
"""
return [i for i in supported_types if i in self.preferred_auth_policies]
@@ -459,7 +462,7 @@ class Response(PAPEExtension):
for level_type, level in self.auth_levels.iteritems():
alias = self._getAlias(level_type)
ns_args['auth_level.ns.%s' % (alias,)] = level_type
- ns_args['auth_level.%s' % (alias,)] = str(level)
+ ns_args['auth_level.%s' % (alias,)] = six.text_type(level)
if self.auth_time is not None:
if not TIME_VALIDATOR.match(self.auth_time):
diff --git a/openid/extensions/sreg.py b/openid/extensions/sreg.py
index 4bdb262..7523e56 100644
--- a/openid/extensions/sreg.py
+++ b/openid/extensions/sreg.py
@@ -34,11 +34,15 @@ OpenID providers.
@var sreg_uri: The preferred URI to use for the simple registration
namespace and XRD Type value
"""
+from __future__ import unicode_literals
import logging
+import six
+
from openid.extension import Extension
from openid.message import NamespaceAliasRegistrationError, registerNamespaceAlias
+from openid.oidutil import string_to_text
__all__ = [
'SRegRequest',
@@ -138,7 +142,7 @@ def getSRegNS(message):
@returns: the sreg namespace URI for the supplied message. The
message may be modified to define a simple registration
namespace.
- @rtype: C{str}
+ @rtype: six.text_type
@raise ValueError: when using OpenID 1 if the message defines
the 'sreg' alias to be something other than a simple
@@ -169,14 +173,14 @@ class SRegRequest(Extension):
@ivar required: A list of the required fields in this simple
registration request
- @type required: [str]
+ @type required: List[six.text_type]
@ivar optional: A list of the optional fields in this simple
registration request
- @type optional: [str]
+ @type optional: List[six.text_type]
@ivar policy_url: The policy URL that was provided with the request
- @type policy_url: str or NoneType
+ @type policy_url: Optional[six.text_type]
@group Consumer: requestField, requestFields, getExtensionArgs, addToOpenIDRequest
@group Server: fromOpenIDRequest, parseExtensionArgs
@@ -246,7 +250,7 @@ class SRegRequest(Extension):
>>> request.parseExtensionArgs(args)
@param args: The unqualified simple registration arguments
- @type args: {str:str}
+ @type args: Dict[six.text_type, six.text_type], six.binary_type is deprecated
@param strict: Whether requests with fields that are not
defined in the simple registration specification should be
@@ -259,6 +263,7 @@ class SRegRequest(Extension):
required = (list_name == 'required')
items = args.get(list_name)
if items:
+ items = string_to_text(items, "Binary values for args are deprecated. Use text input instead.")
for field_name in items.split(','):
try:
self.requestField(field_name, required, strict)
@@ -266,13 +271,17 @@ class SRegRequest(Extension):
if strict:
raise
- self.policy_url = args.get('policy_url')
+ policy_url = args.get('policy_url')
+ if policy_url is not None:
+ policy_url = string_to_text(args.get('policy_url'),
+ "Binary values for args are deprecated. Use text input instead.")
+ self.policy_url = policy_url
def allRequestedFields(self):
"""A list of all of the simple registration fields that were
requested, whether they were required or optional.
- @rtype: [str]
+ @rtype: List[six.text_type]
"""
return self.required + self.optional
@@ -292,7 +301,7 @@ class SRegRequest(Extension):
"""Request the specified field from the OpenID user
@param field_name: the unqualified simple registration field name
- @type field_name: str
+ @type field_name: six.text_type, six.binary_type is deprecated
@param required: whether the given field should be presented
to the user as being a required to successfully complete
@@ -305,6 +314,7 @@ class SRegRequest(Extension):
registration field or strict is set and the field was
requested more than once
"""
+ field_name = string_to_text(field_name, "Binary values for field_name are deprecated. Use text input instead.")
checkFieldName(field_name)
if strict:
@@ -329,7 +339,7 @@ class SRegRequest(Extension):
"""Add the given list of fields to the request
@param field_names: The simple registration data fields to request
- @type field_names: [str]
+ @type field_names: List[six.text_type], six.binary_type is deprecated
@param required: Whether these values should be presented to
the user as required
@@ -341,11 +351,13 @@ class SRegRequest(Extension):
registration field or strict is set and a field was
requested more than once
"""
- if isinstance(field_names, basestring):
+ if isinstance(field_names, six.string_types):
raise TypeError('Fields should be passed as a list of '
'strings (not %r)' % (type(field_names),))
for field_name in field_names:
+ field_name = string_to_text(field_name,
+ "Binary values for field_names are deprecated. Use text input instead.")
self.requestField(field_name, required, strict=strict)
def getExtensionArgs(self):
@@ -356,7 +368,7 @@ class SRegRequest(Extension):
C{L{parseExtensionArgs}}. This method serializes the simple
registration request fields.
- @rtype: {str:str}
+ @rtype: Dict[six.text_type, six.text_type]
"""
args = {}
@@ -417,7 +429,7 @@ class SRegResponse(Extension):
registration field name to string (unicode) value. For
instance, the nickname should be stored under the key
'nickname'.
- @type data: {str:str}
+ @type data: Dict[six.text_type, six.text_type], six.binary_type is deprecated
@returns: a simple registration response object
@rtype: SRegResponse
@@ -427,6 +439,7 @@ class SRegResponse(Extension):
for field in request.allRequestedFields():
value = data.get(field)
if value is not None:
+ value = string_to_text(value, "Binary values for data are deprecated. Use text input instead.")
self.data[field] = value
return self
diff --git a/openid/sreg.py b/openid/sreg.py
index bceb53f..20b0d8a 100644
--- a/openid/sreg.py
+++ b/openid/sreg.py
@@ -1,4 +1,5 @@
"""moved to L{openid.extensions.sreg}"""
+from __future__ import unicode_literals
import warnings
diff --git a/openid/test/test_ax.py b/openid/test/test_ax.py
index 3221169..adff4d9 100644
--- a/openid/test/test_ax.py
+++ b/openid/test/test_ax.py
@@ -1,5 +1,5 @@
-"""Tests for the attribute exchange extension module
-"""
+"""Tests for the attribute exchange extension module."""
+from __future__ import unicode_literals
import unittest
diff --git a/openid/test/test_pape.py b/openid/test/test_pape.py
index 056fb89..d6f55cd 100644
--- a/openid/test/test_pape.py
+++ b/openid/test/test_pape.py
@@ -1,3 +1,5 @@
+from __future__ import unicode_literals
+
import unittest
import warnings
diff --git a/openid/test/test_pape_draft2.py b/openid/test/test_pape_draft2.py
index 67ebcc7..a1d3d87 100644
--- a/openid/test/test_pape_draft2.py
+++ b/openid/test/test_pape_draft2.py
@@ -1,3 +1,5 @@
+from __future__ import unicode_literals
+
import unittest
from openid.extensions.draft import pape2 as pape
diff --git a/openid/test/test_pape_draft5.py b/openid/test/test_pape_draft5.py
index 9585206..fdb783d 100644
--- a/openid/test/test_pape_draft5.py
+++ b/openid/test/test_pape_draft5.py
@@ -1,3 +1,5 @@
+from __future__ import unicode_literals
+
import unittest
from openid.extensions import pape
diff --git a/openid/test/test_sreg.py b/openid/test/test_sreg.py
index 80fd442..b56c5c6 100644
--- a/openid/test/test_sreg.py
+++ b/openid/test/test_sreg.py
@@ -1,3 +1,5 @@
+from __future__ import unicode_literals
+
import unittest
from openid.extensions import sreg