X-Git-Url: https://git.mdrn.pl/django-cas-provider.git/blobdiff_plain/087a24803f4e6749a5c32a88c62fcb922290635d..c93d6d97601a8a01e3230c543113613309c81cb2:/cas_provider/attribute_formatters.py?ds=inline diff --git a/cas_provider/attribute_formatters.py b/cas_provider/attribute_formatters.py index 3f3ab3c..b06cd84 100644 --- a/cas_provider/attribute_formatters.py +++ b/cas_provider/attribute_formatters.py @@ -1,16 +1,23 @@ from lxml import etree +import collections CAS_URI = 'http://www.yale.edu/tp/cas' 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, list): + 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) element.text = e @@ -22,8 +29,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(): - if isinstance(value, list): + 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) element.text = e @@ -31,10 +38,11 @@ def ruby_cas(auth_success, attrs): element = etree.SubElement(auth_success, CAS + name) element.text = value + 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): + 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) else: