Skip to content

Commit 9e64ad5

Browse files
committed
Improve naming
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent b7c2cd4 commit 9e64ad5

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

src/saml2/saml.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -218,67 +218,71 @@ def _wrong_type_value(xs_type, value):
218218
type(None): '',
219219
}
220220

221+
# entries of xs-types each declaring:
222+
# - a corresponding python type
223+
# - a function to turn a string into that type
224+
# - a function to turn that type into a text-value
221225
xs_types_map = {
222226
'xs:string': {
223227
'type': _str,
224-
'typed_constructor': _str,
225-
'text_constructor': _str,
228+
'to_type': _str,
229+
'to_text': _str,
226230
},
227231
'xs:integer': {
228232
'type': int,
229-
'typed_constructor': int,
230-
'text_constructor': _str,
233+
'to_type': int,
234+
'to_text': _str,
231235
},
232236
'xs:short': {
233237
'type': int,
234-
'typed_constructor': int,
235-
'text_constructor': _str,
238+
'to_type': int,
239+
'to_text': _str,
236240
},
237241
'xs:int': {
238242
'type': int,
239-
'typed_constructor': int,
240-
'text_constructor': _str,
243+
'to_type': int,
244+
'to_text': _str,
241245
},
242246
'xs:long': {
243247
'type': int,
244-
'typed_constructor': int,
245-
'text_constructor': _str,
248+
'to_type': int,
249+
'to_text': _str,
246250
},
247251
'xs:float': {
248252
'type': float,
249-
'typed_constructor': float,
250-
'text_constructor': _str,
253+
'to_type': float,
254+
'to_text': _str,
251255
},
252256
'xs:double': {
253257
'type': float,
254-
'typed_constructor': float,
255-
'text_constructor': _str,
258+
'to_type': float,
259+
'to_text': _str,
256260
},
257261
'xs:boolean': {
258262
'type': bool,
259-
'typed_constructor': lambda x: {
263+
'to_type': lambda x: {
260264
'true': True,
261265
'false': False,
262266
}[_str(x).lower()],
263-
'text_constructor': lambda x: _str(x).lower(),
267+
'to_text': lambda x: _str(x).lower(),
264268
},
265269
'xs:base64Binary': {
266270
'type': _str,
267-
'typed_constructor': _str,
268-
'text_constructor': lambda x:
271+
'to_type': _str,
272+
'to_text': lambda x:
269273
_b64_encode_fn(x.encode())
270274
if base64encode
271275
else x,
272276
},
273277
'xs:anyType': {
274278
'type': type(value),
275-
'typed_constructor': lambda x: x,
276-
'text_constructor': lambda x: x,
279+
'to_type': lambda x: x,
280+
'to_text': lambda x: x,
277281
},
278282
'': {
279283
'type': type(None),
280-
'typed_constructor': lambda x: None,
281-
'text_constructor': lambda x: '',
284+
'to_type': lambda x: None,
285+
'to_text': lambda x: '',
282286
},
283287
}
284288

@@ -289,13 +293,13 @@ def _wrong_type_value(xs_type, value):
289293
or xs_type_from_type.get(type(value), type(None))
290294
xs_type_map = xs_types_map.get(xs_type, {})
291295
valid_type = xs_type_map.get('type', type(None))
292-
to_typed = xs_type_map.get('typed_constructor', str)
293-
to_text = xs_type_map.get('text_constructor', str)
296+
to_type = xs_type_map.get('to_type', str)
297+
to_text = xs_type_map.get('to_text', str)
294298

295299
# cast to correct type before type-checking
296300
if type(value) is _str and valid_type is not _str:
297301
try:
298-
value = to_typed(value)
302+
value = to_type(value)
299303
except (TypeError, ValueError, KeyError) as e:
300304
# the cast failed
301305
_wrong_type_value(xs_type=xs_type, value=value)

0 commit comments

Comments
 (0)