forked from castlabs/django-cas-provider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattribute_formatters.py
41 lines (35 loc) · 1.44 KB
/
attribute_formatters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from lxml import etree
CAS_URI = 'http://www.yale.edu/tp/cas'
NSMAP = {'cas': CAS_URI}
CAS = '{%s}' % CAS_URI
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 e in value:
element = etree.SubElement(attributes, CAS + name)
element.text = e
else:
element = etree.SubElement(attributes, CAS + name)
element.text = value
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 e in value:
element = etree.SubElement(auth_success, CAS + name)
element.text = e
else:
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 e in value:
etree.SubElement(auth_success, CAS + 'attribute', name=name, value=e)
else:
etree.SubElement(auth_success, CAS + 'attribute', name=name, value=value)