Skip to content

Commit 1b5dcfb

Browse files
committed
prettify XML string output by registering default namespace prefixes
1 parent 9c04dc7 commit 1b5dcfb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/saml2/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@
4242

4343
NAMESPACE = 'urn:oasis:names:tc:SAML:2.0:assertion'
4444
# TEMPLATE = '{urn:oasis:names:tc:SAML:2.0:assertion}%s'
45-
# XSI_NAMESPACE = 'http://www.w3.org/2001/XMLSchema-instance'
45+
SAMLP_NAMESPACE = 'urn:oasis:names:tc:SAML:2.0:protocol'
46+
XSI_NAMESPACE = 'http://www.w3.org/2001/XMLSchema-instance'
47+
XS_NAMESPACE = 'http://www.w3.org/2001/XMLSchema'
48+
DS_NAMESPACE = 'http://www.w3.org/2000/09/xmldsig#'
49+
DEFAULT_NS_PREFIXES = {'saml': NAMESPACE, 'samlp': SAMLP_NAMESPACE, 'ds': DS_NAMESPACE, 'xsi': XSI_NAMESPACE, 'xs': XS_NAMESPACE}
4650

4751
NAMEID_FORMAT_EMAILADDRESS = (
4852
"urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress")
@@ -680,7 +684,7 @@ def to_string_force_namespace(self, nspair):
680684

681685
return ElementTree.tostring(elem, encoding="UTF-8")
682686

683-
def to_string(self, nspair=None):
687+
def to_string(self, nspair=DEFAULT_NS_PREFIXES):
684688
"""Converts the Saml object to a string containing XML.
685689
686690
:param nspair: A dictionary of prefixes and uris to use when

0 commit comments

Comments
 (0)