Skip to content

Commit

Permalink
Move LocaleScanner's INHERIT check from find upstream to __find
Browse files Browse the repository at this point in the history
When digesting CLDR v44.1's github form, some data (e.g. pt_BR's
language endonym) were None that had perfectly sensible values in the
zip-file form.  Letting __find() yield INHERIT entries lead to find()
sometimes returning None, where __find() should have tried harder or
raised an Error.

This further amends commit bcdd51c
(after commit 0f770b0 isolated its
magic value).

Pick-to: 6.5
Task-number: QTBUG-115158
Change-Id: I1af92a687cd50b8fd026c25f068c804a3516ef95
Reviewed-by: Mate Barany <mate.barany@qt.io>
(cherry picked from commit 43cb413)
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
  • Loading branch information
ediosyncratic committed Apr 19, 2024
1 parent a7338bd commit 249b8ff
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions util/locale_database/ldml.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ def find(self, xpath, default = None, draft = None):
for elt in self.__find(xpath):
try:
if draft is None or elt.draft <= draft:
value = elt.dom.firstChild.nodeValue
if value != INHERIT:
return value
return elt.dom.firstChild.nodeValue
except (AttributeError, KeyError):
pass
except Error as e:
Expand Down Expand Up @@ -420,6 +418,7 @@ def __find(self, xpath):
break

else: # Found matching elements
elts = tuple(self.__skipInheritors(elts))
if elts:
foundNone = False
# Possibly filter elts to prefer the least drafty ?
Expand Down Expand Up @@ -448,6 +447,7 @@ def __find(self, xpath):
raise Error(f'All lack child {selector} for {sought} in {self.name}')

else: # Found matching elements
roots = tuple(self.__skipInheritors(roots))
if roots:
foundNone = False
for elt in roots:
Expand All @@ -459,6 +459,15 @@ def __find(self, xpath):
sought += f' (for {xpath})'
raise Error(f'No {sought} in {self.name}')

@staticmethod
def __skipInheritors(elts):
for elt in elts:
try:
if elt.dom.firstChild.nodeValue != INHERIT:
yield elt
except (AttributeError, KeyError):
yield elt

def __currencyDisplayName(self, stem):
try:
return self.find(stem + 'displayName')
Expand Down

0 comments on commit 249b8ff

Please sign in to comment.