Skip to content

Commit

Permalink
prettify XML string output by registering default namespace prefixes
Browse files Browse the repository at this point in the history
as @spaceone already proposed here: #326
  • Loading branch information
peppelinux committed Jul 19, 2019
1 parent 58138e0 commit ec9d640
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/saml2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,28 @@
root_logger = logging.getLogger(__name__)
root_logger.level = logging.NOTSET


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

# spaceone's https://github.com/IdentityPython/pysaml2/pull/326
SAMLP_NAMESPACE = 'urn:oasis:names:tc:SAML:2.0:protocol'
XSI_NAMESPACE = 'http://www.w3.org/2001/XMLSchema-instance'
XS_NAMESPACE = 'http://www.w3.org/2001/XMLSchema'
DS_NAMESPACE = 'http://www.w3.org/2000/09/xmldsig#'
MD_NAMESPACE = "urn:oasis:names:tc:SAML:2.0:metadata"
MDUI_NAMESPACE = "urn:oasis:names:tc:SAML:metadata:ui"
DEFAULT_NS_PREFIXES = {'saml': NAMESPACE, 'samlp': SAMLP_NAMESPACE,
'ds': DS_NAMESPACE, 'xsi': XSI_NAMESPACE,
'xs': XS_NAMESPACE,
'mdui': MDUI_NAMESPACE,
'md': MD_NAMESPACE,
# 'alg': TODO: algsupport.DIGEST_METHODS|SIGNING_METHODS shoulb be moved before mapping them here
# TODO: <ns1:EntityAttributes>
}


NAMEID_FORMAT_EMAILADDRESS = (
"urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress")

Expand Down Expand Up @@ -687,7 +705,7 @@ def to_string_force_namespace(self, nspair):

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

def to_string(self, nspair=None):
def to_string(self, nspair=DEFAULT_NS_PREFIXES):
"""Converts the Saml object to a string containing XML.
:param nspair: A dictionary of prefixes and uris to use when
Expand Down

0 comments on commit ec9d640

Please # to comment.