summaryrefslogtreecommitdiff
path: root/src/saml2/saml.py
diff options
context:
space:
mode:
authorIvan Kanakarakis <ivan.kanak@gmail.com>2018-09-06 14:27:47 +0300
committerIvan Kanakarakis <ivan.kanak@gmail.com>2018-09-06 14:27:47 +0300
commit9e64ad559b6fd6864458be6f6bd27536cd79e6b9 (patch)
tree19a76f0bea18f7dd665125bee8f8ca82edbfbb9f /src/saml2/saml.py
parentb7c2cd4ca05442042c3122dccf0677dcfed0cf6e (diff)
downloadpysaml2-9e64ad559b6fd6864458be6f6bd27536cd79e6b9.tar.gz
Improve naming
Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
Diffstat (limited to 'src/saml2/saml.py')
-rw-r--r--src/saml2/saml.py54
1 files changed, 29 insertions, 25 deletions
diff --git a/src/saml2/saml.py b/src/saml2/saml.py
index 56cc6088..d3312c16 100644
--- a/src/saml2/saml.py
+++ b/src/saml2/saml.py
@@ -218,67 +218,71 @@ class AttributeValueBase(SamlBase):
type(None): '',
}
+ # entries of xs-types each declaring:
+ # - a corresponding python type
+ # - a function to turn a string into that type
+ # - a function to turn that type into a text-value
xs_types_map = {
'xs:string': {
'type': _str,
- 'typed_constructor': _str,
- 'text_constructor': _str,
+ 'to_type': _str,
+ 'to_text': _str,
},
'xs:integer': {
'type': int,
- 'typed_constructor': int,
- 'text_constructor': _str,
+ 'to_type': int,
+ 'to_text': _str,
},
'xs:short': {
'type': int,
- 'typed_constructor': int,
- 'text_constructor': _str,
+ 'to_type': int,
+ 'to_text': _str,
},
'xs:int': {
'type': int,
- 'typed_constructor': int,
- 'text_constructor': _str,
+ 'to_type': int,
+ 'to_text': _str,
},
'xs:long': {
'type': int,
- 'typed_constructor': int,
- 'text_constructor': _str,
+ 'to_type': int,
+ 'to_text': _str,
},
'xs:float': {
'type': float,
- 'typed_constructor': float,
- 'text_constructor': _str,
+ 'to_type': float,
+ 'to_text': _str,
},
'xs:double': {
'type': float,
- 'typed_constructor': float,
- 'text_constructor': _str,
+ 'to_type': float,
+ 'to_text': _str,
},
'xs:boolean': {
'type': bool,
- 'typed_constructor': lambda x: {
+ 'to_type': lambda x: {
'true': True,
'false': False,
}[_str(x).lower()],
- 'text_constructor': lambda x: _str(x).lower(),
+ 'to_text': lambda x: _str(x).lower(),
},
'xs:base64Binary': {
'type': _str,
- 'typed_constructor': _str,
- 'text_constructor': lambda x:
+ 'to_type': _str,
+ 'to_text': lambda x:
_b64_encode_fn(x.encode())
if base64encode
else x,
},
'xs:anyType': {
'type': type(value),
- 'typed_constructor': lambda x: x,
- 'text_constructor': lambda x: x,
+ 'to_type': lambda x: x,
+ 'to_text': lambda x: x,
},
'': {
'type': type(None),
- 'typed_constructor': lambda x: None,
- 'text_constructor': lambda x: '',
+ 'to_type': lambda x: None,
+ 'to_text': lambda x: '',
},
}
@@ -289,13 +293,13 @@ class AttributeValueBase(SamlBase):
or xs_type_from_type.get(type(value), type(None))
xs_type_map = xs_types_map.get(xs_type, {})
valid_type = xs_type_map.get('type', type(None))
- to_typed = xs_type_map.get('typed_constructor', str)
- to_text = xs_type_map.get('text_constructor', str)
+ to_type = xs_type_map.get('to_type', str)
+ to_text = xs_type_map.get('to_text', str)
# cast to correct type before type-checking
if type(value) is _str and valid_type is not _str:
try:
- value = to_typed(value)
+ value = to_type(value)
except (TypeError, ValueError, KeyError) as e:
# the cast failed
_wrong_type_value(xs_type=xs_type, value=value)