cldr.py: Avoid raising StopIteration from generators
The behavior of StopIteration in generators was changed in Python 3 (see https://www.python.org/dev/peps/pep-0479/). Not raising that exception makes it easier to port the code to Python 3. Task-number: QTBUG-83488 Pick-to: 6.2 Change-Id: Iac6e3f6f1e1e8ef3a1a0d89b19d2ac2d186434f5 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
451733bd57
commit
d804d21e8f
@ -172,7 +172,11 @@ class CldrReader (object):
|
||||
4 values, never 2 or 3."""
|
||||
tags = iter(name.split('_'))
|
||||
yield tags.next() # Language
|
||||
tag = tags.next() # may raise StopIteration
|
||||
|
||||
try:
|
||||
tag = tags.next()
|
||||
except StopIteration:
|
||||
return
|
||||
|
||||
# Script is always four letters, always capitalised:
|
||||
if len(tag) == 4 and tag[0].isupper() and tag[1:].islower():
|
||||
@ -201,10 +205,11 @@ class CldrReader (object):
|
||||
else:
|
||||
yield ''
|
||||
|
||||
# If nothing is left, StopIteration will avoid the warning:
|
||||
if not tag:
|
||||
tag = tags.next()
|
||||
self.grumble('Ignoring unparsed cruft {} in {}\n'.format('_'.join(tag + tuple(tags)), name))
|
||||
rest = [tag] if tag else []
|
||||
rest.extend(tags)
|
||||
|
||||
if rest:
|
||||
self.grumble('Ignoring unparsed cruft {} in {}\n'.format('_'.join(rest), name))
|
||||
|
||||
def __getLocaleData(self, scan, calendars, language, script, territory, variant):
|
||||
ids, names = zip(*self.root.codesToIdName(language, script, territory, variant))
|
||||
|
Loading…
Reference in New Issue
Block a user