diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2024-01-19 15:59:33 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2024-01-29 15:14:43 +0100 |
commit | 82f8afe6bab42b7b70f571825d23cbb9270b9071 (patch) | |
tree | 1e664acb1ba57fab2d16d1669fdfef0f070bd644 /util | |
parent | 904f1d3b13f5893ea63781b44857ee5cef48883d (diff) |
Package DOM attributes for Node objects
The Supplement type did the needed mapping (using nodeValue when the
value wasn't a string) and it turns out to be useful to do the same
for the DOM object packaged by a Node, too. Pull out into a helper
function, use dict-comprehension and expose as a method of Node.
Change-Id: Ice6737a54a33372b45cf42152e3fdbf5f2da7ba4
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'util')
-rw-r--r-- | util/locale_database/ldml.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/util/locale_database/ldml.py b/util/locale_database/ldml.py index 2a029ce98b..d259bedba1 100644 --- a/util/locale_database/ldml.py +++ b/util/locale_database/ldml.py @@ -21,6 +21,10 @@ See individual classes for further detail. from localetools import Error from dateconverter import convert_date +def _attrsFromDom(dom): + return { k: (v if isinstance(v, str) else v.nodeValue) + for k, v in dom.attributes.items() } + class Node (object): """Wrapper for an arbitrary DOM node. @@ -50,6 +54,9 @@ class Node (object): else: self.draft = max(draft, self.draftScore(attr)) + def attributes(self): + return _attrsFromDom(self.dom) + def findAllChildren(self, tag, wanted = None, allDull = False): """All children that do have the given tag and attributes. @@ -184,9 +191,7 @@ class Supplement (XmlScanner): if not any(a in e.dom.attributes for a in exclude)): if elt.attributes: - yield (elt.nodeName, - dict((k, v if isinstance(v, str) else v.nodeValue) - for k, v in elt.attributes.items())) + yield elt.nodeName, _attrsFromDom(elt) class LocaleScanner (object): def __init__(self, name, nodes, root): |