corrected formatting
[django-cas-provider.git] / cas_provider / attribute_formatters.py
1 from lxml import etree
2
3 CAS_URI = 'http://www.yale.edu/tp/cas'
4 NSMAP = {'cas': CAS_URI}
5 CAS = '{%s}' % CAS_URI
6
7
8 def jasig(auth_success, attrs):
9     attributes = etree.SubElement(auth_success, CAS + 'attributes')
10     style = etree.SubElement(attributes, CAS + 'attraStyle')
11     style.text = u'Jasig'
12     for name, value in attrs.items():
13         if isinstance(value, list):
14             for e in value:
15                 element = etree.SubElement(attributes, CAS + name)
16                 element.text = e
17         else:
18             element = etree.SubElement(attributes, CAS + name)
19             element.text = value
20
21
22 def ruby_cas(auth_success, attrs):
23     style = etree.SubElement(auth_success, CAS + 'attraStyle')
24     style.text = u'RubyCAS'
25     for name, value in attrs.items():
26         if isinstance(value, list):
27             for e in value:
28                 element = etree.SubElement(auth_success, CAS + name)
29                 element.text = e
30         else:
31             element = etree.SubElement(auth_success, CAS + name)
32             element.text = value
33
34 def name_value(auth_success, attrs):
35     etree.SubElement(auth_success, CAS + 'attribute', name=u'attraStyle', value=u'Name-Value')
36     for name, value in attrs.items():
37         if isinstance(value, list):
38             for e in value:
39                 etree.SubElement(auth_success, CAS + 'attribute', name=name, value=e)
40         else:
41             etree.SubElement(auth_success, CAS + 'attribute', name=name, value=value)