Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use named list for regex substitution of namespace prefixes #708

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions se/easy_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,13 @@ def _replace_shorthand_namespaces(self, value:str) -> str:
shorthand namespaces.

Example:
epub:type -> {http://www.idpf.org/2007/ops}:type
epub:type -> {http://www.idpf.org/2007/ops}type
"""

output = value

if self.namespaces:
for name, identifier in self.namespaces.items():
output = regex.sub(fr"^{name}:", f"{{{identifier}}}", output)
value = regex.sub(r"^(\L<ns>):", lambda m: f"{{{self.namespaces[m[1]]}}}", value, ns=self.namespaces.keys())

return output
return value

def to_tag_string(self) -> str:
"""
Expand Down
Loading