Skip to content

Commit ec9d640

Browse files
committed
prettify XML string output by registering default namespace prefixes
as @spaceone already proposed here: #326
1 parent 58138e0 commit ec9d640

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/saml2/__init__.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,28 @@
4646
root_logger = logging.getLogger(__name__)
4747
root_logger.level = logging.NOTSET
4848

49+
4950
NAMESPACE = 'urn:oasis:names:tc:SAML:2.0:assertion'
5051
# TEMPLATE = '{urn:oasis:names:tc:SAML:2.0:assertion}%s'
5152
# XSI_NAMESPACE = 'http://www.w3.org/2001/XMLSchema-instance'
5253

54+
# spaceone's https://github.com/IdentityPython/pysaml2/pull/326
55+
SAMLP_NAMESPACE = 'urn:oasis:names:tc:SAML:2.0:protocol'
56+
XSI_NAMESPACE = 'http://www.w3.org/2001/XMLSchema-instance'
57+
XS_NAMESPACE = 'http://www.w3.org/2001/XMLSchema'
58+
DS_NAMESPACE = 'http://www.w3.org/2000/09/xmldsig#'
59+
MD_NAMESPACE = "urn:oasis:names:tc:SAML:2.0:metadata"
60+
MDUI_NAMESPACE = "urn:oasis:names:tc:SAML:metadata:ui"
61+
DEFAULT_NS_PREFIXES = {'saml': NAMESPACE, 'samlp': SAMLP_NAMESPACE,
62+
'ds': DS_NAMESPACE, 'xsi': XSI_NAMESPACE,
63+
'xs': XS_NAMESPACE,
64+
'mdui': MDUI_NAMESPACE,
65+
'md': MD_NAMESPACE,
66+
# 'alg': TODO: algsupport.DIGEST_METHODS|SIGNING_METHODS shoulb be moved before mapping them here
67+
# TODO: <ns1:EntityAttributes>
68+
}
69+
70+
5371
NAMEID_FORMAT_EMAILADDRESS = (
5472
"urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress")
5573

@@ -687,7 +705,7 @@ def to_string_force_namespace(self, nspair):
687705

688706
return ElementTree.tostring(elem, encoding="UTF-8")
689707

690-
def to_string(self, nspair=None):
708+
def to_string(self, nspair=DEFAULT_NS_PREFIXES):
691709
"""Converts the Saml object to a string containing XML.
692710
693711
:param nspair: A dictionary of prefixes and uris to use when

0 commit comments

Comments
 (0)