Can't have ForeignKey from PGT to ST, if ST is deleted immediately.
[django-cas-provider.git] / cas_provider / attribute_formatters.py
index d61af0f..b06cd84 100644 (file)
@@ -6,12 +6,18 @@ NSMAP = {'cas': CAS_URI}
 CAS = '{%s}' % 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'
 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):
+    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
             for e in value:
                 element = etree.SubElement(attributes, CAS + name)
                 element.text = e
@@ -23,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'
 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
             for e in value:
                 element = etree.SubElement(auth_success, CAS + name)
                 element.text = e
@@ -35,8 +41,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')
 
 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:
             for e in value:
                 etree.SubElement(auth_success, CAS + 'attribute', name=name, value=e)
         else: