Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Feb 24, 2023
1 parent 8be4979 commit 179fbf7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
5 changes: 1 addition & 4 deletions owslib/catalogue/csw2.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ def getrecords2(self, constraints=[], sortby=None, typenames='csw:Record', esn='
if sortby is not None and isinstance(sortby, fes.SortBy):
node1.append(sortby.toXML())

print("NODE0", etree.tostring(node0, pretty_print=1))
self.request = node0

self._invoke()
Expand Down Expand Up @@ -678,9 +677,7 @@ def _invoke(self):
self.request = cleanup_namespaces(self.request)
# Add any namespaces used in the "typeNames" attribute of the
# csw:Query element to the query's xml namespaces.
print("TOM", etree.tostring(self.request, pretty_print=1))
print("TOM", namespaces)
for query in self.request.findall(util.nspath_eval('//csw:Query', namespaces)):
for query in self.request.findall(util.nspath_eval('csw:Query', namespaces)):
ns = query.get("typeNames", None)
if ns is not None:
# Pull out "gmd" from something like "gmd:MD_Metadata" from the list
Expand Down
19 changes: 18 additions & 1 deletion owslib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ def nspath_eval(xpath, namespaces):

def cleanup_namespaces(element):
""" Remove unused namespaces from an element """
return etree.cleanup_namespaces(element)
etree.cleanup_namespaces(element)
return element


def add_namespaces(root, ns_keys):
Expand All @@ -288,6 +289,22 @@ def add_namespaces(root, ns_keys):

ns_keys = [(x, namespaces.get_namespace(x)) for x in ns_keys]

# lxml does not support setting xmlns attributes
# Update the elements nsmap with new namespaces
new_map = root.nsmap
for key, link in ns_keys:
if link is not None:
new_map[key] = link
# Recreate the root element with updated nsmap
new_root = etree.Element(root.tag, nsmap=new_map)
# Carry over attributes
for a, v in list(root.items()):
new_root.set(a, v)
# Carry over children
for child in root:
new_root.append(deepcopy(child))
return new_root

# We can just add more namespaces when not using lxml.
# We can't re-add an existing namespaces. Get a list of current
# namespaces in use
Expand Down

0 comments on commit 179fbf7

Please sign in to comment.