a04828d9cca5c34cade0ec5cb97f41877c8328fc
[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
35 def name_value(auth_success, attrs):
36     etree.SubElement(auth_success, CAS + 'attribute', name=u'attraStyle', value=u'Name-Value')
37     for name, value in attrs.items():
38         if isinstance(value, list):
39             for e in value:
40                 etree.SubElement(auth_success, CAS + 'attribute', name=name, value=e)
41         else:
42             etree.SubElement(auth_success, CAS + 'attribute', name=name, value=value)