Skip to content

Commit

Permalink
Add XMLFormat.ns_prefix() convenience method
Browse files Browse the repository at this point in the history
  • Loading branch information
khaeru committed Jul 31, 2023
1 parent c3c94ee commit 8918f8f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sdmx/format/xml/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ def __eq__(self, other):
def __hash__(self):
return hash(self.base_ns)

@lru_cache()
def ns_prefix(self, url) -> str:
"""Return the namespace prefix from :attr:`.NS` given its full `url`."""
for prefix, _url in self.NS.items():
if url == _url:
return prefix
raise ValueError(url)

@lru_cache()
def qname(self, ns_or_name, name=None) -> QName:
"""Return a fully-qualified tag `name` in namespace `ns`."""
Expand Down

0 comments on commit 8918f8f

Please sign in to comment.