Skip to content

Commit

Permalink
Cast attributes to strings when writing XML
Browse files Browse the repository at this point in the history
  • Loading branch information
goodmami committed Jan 29, 2021
1 parent 0f4780a commit ae30999
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed

* `wn.lmf` specifies `utf-8` when opening files ([#95])
* `wn.lmf.dump()` casts attribute values to strings


## [v0.5.0]
Expand Down
8 changes: 6 additions & 2 deletions wn/lmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,9 @@ def _dump_lexicon(lexicon: Lexicon, out: TextIO, version: str) -> None:
attrib['citation'] = lexicon.citation
attrib.update(_meta_dict(lexicon.meta))
attrdelim = '\n' + (' ' * 11)
attrs = attrdelim.join(f'{attr}={quoteattr(val)}' for attr, val in attrib.items())
attrs = attrdelim.join(
f'{attr}={quoteattr(str(val))}' for attr, val in attrib.items()
)
print(f' <Lexicon {attrs}>', file=out)

for entry in lexicon.lexical_entries:
Expand Down Expand Up @@ -918,7 +920,9 @@ def _indent(elem: ET.Element, level: int) -> None:

def _meta_dict(m: Optional[Metadata]) -> Dict:
if m:
d = {f'dc:{key}': val for key, val in zip(m._fields, m) if val is not None}
d = {f'dc:{key}': str(val)
for key, val in zip(m._fields, m)
if val is not None}
else:
d = {}
return d

0 comments on commit ae30999

Please sign in to comment.