diff --git a/wstools/c14n.py b/wstools/c14n.py index de13914..f88160d 100644 --- a/wstools/c14n.py +++ b/wstools/c14n.py @@ -55,13 +55,10 @@ except: class XMLNS: BASE = "http://www.w3.org/2000/xmlns/" XML = "http://www.w3.org/XML/1998/namespace" -try: - import cStringIO - StringIO = cStringIO -except ImportError: - import StringIO -_attrs = lambda E: (E.attributes and E.attributes.values()) or [] +import io + +_attrs = lambda E: (E.attributes and list(E.attributes.values())) or [] _children = lambda E: E.childNodes or [] _IN_XML_NS = lambda n: n.name.startswith("xmlns") _inclusive = lambda n: n.unsuppressedPrefixes is None @@ -69,7 +66,7 @@ _inclusive = lambda n: n.unsuppressedPrefixes is None # Does a document/PI has lesser/greater document order than the # first element? -_LesserElement, _Element, _GreaterElement = range(3) +_LesserElement, _Element, _GreaterElement = list(range(3)) def _sorter(n1, n2): @@ -191,7 +188,7 @@ class _implementation: canonicalization.''' # Collect the initial list of xml:foo attributes. - xmlattrs = filter(_IN_XML_NS, _attrs(node)) + xmlattrs = list(filter(_IN_XML_NS, _attrs(node))) # Walk up and get all xml:XXX attributes we inherit. inherited, parent = [], node.parentNode @@ -367,7 +364,7 @@ class _implementation: # Create list of NS attributes to render. ns_to_render = [] - for n, v in ns_local.items(): + for n, v in list(ns_local.items()): # If default namespace is XMLNS.BASE or empty, # and if an ancestor was the same @@ -384,7 +381,7 @@ class _implementation: # If not previously rendered # and it's inclusive or utilized - if (n, v) not in ns_rendered.items(): + if (n, v) not in list(ns_rendered.items()): if inclusive or _utilized(n, node, other_attrs, self.unsuppressedPrefixes): ns_to_render.append((n, v)) elif not inclusive: @@ -400,9 +397,9 @@ class _implementation: # Else, add all local and ancestor xml attributes # Sort and render the attributes. if not inclusive or _in_subset(self.subset, node.parentNode): # 0426 - other_attrs.extend(xml_attrs_local.values()) + other_attrs.extend(list(xml_attrs_local.values())) else: - other_attrs.extend(xml_attrs.values()) + other_attrs.extend(list(xml_attrs.values())) other_attrs.sort(_sorter) for a in other_attrs: self._do_attr(a.nodeName, a.value) @@ -435,8 +432,8 @@ def Canonicalize(node, output=None, **kw): prefixes that should be inherited. ''' if output: - apply(_implementation, (node, output.write), kw) + _implementation(*(node, output.write), **kw) else: s = StringIO.StringIO() - apply(_implementation, (node, s.write), kw) + _implementation(*(node, s.write), **kw) return s.getvalue()