X-Git-Url: https://git.mdrn.pl/django-cas-provider.git/blobdiff_plain/59b906fd2d60bd4a8712c23796a3ccfecbf5c5ad..refs/heads/master:/cas_provider/attribute_formatters.py?ds=inline diff --git a/cas_provider/attribute_formatters.py b/cas_provider/attribute_formatters.py index d61af0f..405f2c1 100644 --- a/cas_provider/attribute_formatters.py +++ b/cas_provider/attribute_formatters.py @@ -6,12 +6,18 @@ NSMAP = {'cas': CAS_URI} CAS = '{%s}' % CAS_URI +try: + basestring +except NameError: + basestring = (str, bytes) + + def jasig(auth_success, attrs): attributes = etree.SubElement(auth_success, CAS + 'attributes') style = etree.SubElement(attributes, CAS + 'attraStyle') - style.text = u'Jasig' - for name, value in attrs.items(): - if isinstance(value, collections.Iterable): + style.text = 'Jasig' + for name, value in sorted(attrs.items()): + if isinstance(value, collections.abc.Iterable) and not isinstance(value, basestring): for e in value: element = etree.SubElement(attributes, CAS + name) element.text = e @@ -22,9 +28,9 @@ def jasig(auth_success, attrs): def ruby_cas(auth_success, attrs): style = etree.SubElement(auth_success, CAS + 'attraStyle') - style.text = u'RubyCAS' - for name, value in attrs.items(): - if isinstance(value, list): + style.text = 'RubyCAS' + for name, value in sorted(attrs.items()): + if isinstance(value, collections.abc.Iterable) and not isinstance(value, basestring): for e in value: element = etree.SubElement(auth_success, CAS + name) element.text = e @@ -34,9 +40,9 @@ def ruby_cas(auth_success, attrs): def name_value(auth_success, attrs): - etree.SubElement(auth_success, CAS + 'attribute', name=u'attraStyle', value=u'Name-Value') - for name, value in attrs.items(): - if isinstance(value, list): + etree.SubElement(auth_success, CAS + 'attribute', name='attraStyle', value='Name-Value') + for name, value in sorted(attrs.items()): + if isinstance(value, collections.abc.Iterable) and not isinstance(value, basestring): for e in value: etree.SubElement(auth_success, CAS + 'attribute', name=name, value=e) else: