Added comments to _fix_ns to clarify the cleaning procedure.

This commit is contained in:
Lance Stout 2010-08-26 18:40:58 -04:00
parent 37ff17b0cb
commit ca6ce26b0d

View file

@ -765,17 +765,24 @@ class ElementBase(object):
False, which returns a flat string path. False, which returns a flat string path.
""" """
fixed = [] fixed = []
# Split the XPath into a series of blocks, where a block
# is started by an element with a namespace.
ns_blocks = xpath.split('{') ns_blocks = xpath.split('{')
for ns_block in ns_blocks: for ns_block in ns_blocks:
if '}' in ns_block: if '}' in ns_block:
# Apply the found namespace to following elements
# that do not have namespaces.
namespace = ns_block.split('}')[0] namespace = ns_block.split('}')[0]
elements = ns_block.split('}')[1].split('/') elements = ns_block.split('}')[1].split('/')
else: else:
# Apply the stanza's namespace to the following
# elements since no namespace was provided.
namespace = self.namespace namespace = self.namespace
elements = ns_block.split('/') elements = ns_block.split('/')
for element in elements: for element in elements:
if element: if element:
# Skip empty entry artifacts from splitting.
fixed.append('{%s}%s' % (namespace, fixed.append('{%s}%s' % (namespace,
element)) element))
if split: if split: