diff --git a/util/locale_database/cldr.py b/util/locale_database/cldr.py index 91b46d6a016..78ed7a70a08 100644 --- a/util/locale_database/cldr.py +++ b/util/locale_database/cldr.py @@ -708,7 +708,8 @@ enumdata.py (keeping the old name as an alias): def __parentLocale(self, cache = {}): # see http://www.unicode.org/reports/tr35/#Parent_Locales if not cache: - for tag, attrs in self.__supplementalData.find('parentLocales'): + for tag, attrs in self.__supplementalData.find('parentLocales', + ('component',)): parent = attrs.get('parent', '') for child in attrs['locales'].split(): cache[child] = parent diff --git a/util/locale_database/ldml.py b/util/locale_database/ldml.py index f292235fb44..f0a8be520e3 100644 --- a/util/locale_database/ldml.py +++ b/util/locale_database/ldml.py @@ -166,10 +166,23 @@ class XmlScanner (object): return elts class Supplement (XmlScanner): - def find(self, xpath): + def find(self, xpath, exclude=()): + """Finds nodes by matching a specified xpath. + + If exclude is passed, it should be a sequence of attribute names (its + default is empty). Any matches to the given xpath that also have any + attribute in this sequence will be excluded. + + For each childless node matching the xpath, or child of a node matching + the xpath, this yields a twople (name, attrs) where name is the + nodeName and attrs is a dict mapping the node's attribute's names to + their values. For attribute values that are not simple strings, the + nodeValue of the attribute node is used.""" elts = self.findNodes(xpath) - for elt in _iterateEach(e.dom.childNodes if e.dom.childNodes else (e.dom,) - for e in elts): + for elt in _iterateEach(e.dom.childNodes or (e.dom,) + for e in elts + 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)