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>
This commit is contained in:
parent
904f1d3b13
commit
82f8afe6ba
@ -21,6 +21,10 @@ See individual classes for further detail.
|
|||||||
from localetools import Error
|
from localetools import Error
|
||||||
from dateconverter import convert_date
|
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):
|
class Node (object):
|
||||||
"""Wrapper for an arbitrary DOM node.
|
"""Wrapper for an arbitrary DOM node.
|
||||||
|
|
||||||
@ -50,6 +54,9 @@ class Node (object):
|
|||||||
else:
|
else:
|
||||||
self.draft = max(draft, self.draftScore(attr))
|
self.draft = max(draft, self.draftScore(attr))
|
||||||
|
|
||||||
|
def attributes(self):
|
||||||
|
return _attrsFromDom(self.dom)
|
||||||
|
|
||||||
def findAllChildren(self, tag, wanted = None, allDull = False):
|
def findAllChildren(self, tag, wanted = None, allDull = False):
|
||||||
"""All children that do have the given tag and attributes.
|
"""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
|
if not any(a in e.dom.attributes
|
||||||
for a in exclude)):
|
for a in exclude)):
|
||||||
if elt.attributes:
|
if elt.attributes:
|
||||||
yield (elt.nodeName,
|
yield elt.nodeName, _attrsFromDom(elt)
|
||||||
dict((k, v if isinstance(v, str) else v.nodeValue)
|
|
||||||
for k, v in elt.attributes.items()))
|
|
||||||
|
|
||||||
class LocaleScanner (object):
|
class LocaleScanner (object):
|
||||||
def __init__(self, name, nodes, root):
|
def __init__(self, name, nodes, root):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user