X-Git-Url: https://git.mdrn.pl/django-cas-provider.git/blobdiff_plain/3b6a516384b03ed3b2bc71f09209d4274d3e6748..f3c49c09dc7b2a7ccee36b897b9056a9622e0c02:/cas_provider/attribute_formatters.py?ds=sidebyside diff --git a/cas_provider/attribute_formatters.py b/cas_provider/attribute_formatters.py index 55eb4dd..8574962 100644 --- a/cas_provider/attribute_formatters.py +++ b/cas_provider/attribute_formatters.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from lxml import etree import collections @@ -6,11 +8,17 @@ 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(): + style.text = 'Jasig' + for name, value in sorted(attrs.items()): if isinstance(value, collections.Iterable) and not isinstance(value, basestring): for e in value: element = etree.SubElement(attributes, CAS + name) @@ -22,8 +30,8 @@ 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(): + style.text = 'RubyCAS' + for name, value in sorted(attrs.items()): if isinstance(value, collections.Iterable) and not isinstance(value, basestring): for e in value: element = etree.SubElement(auth_success, CAS + name) @@ -34,8 +42,8 @@ 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(): + etree.SubElement(auth_success, CAS + 'attribute', name='attraStyle', value='Name-Value') + for name, value in sorted(attrs.items()): if isinstance(value, collections.Iterable) and not isinstance(value, basestring): for e in value: etree.SubElement(auth_success, CAS + 'attribute', name=name, value=e)