Convert CLDR scripts to Python 3
The convertion is moslty done using 2to3 script with manual cleanup afterwards. Task-number: QTBUG-83488 Pick-to: 6.2 Change-Id: I4d33b04e7269c55a83ff2deb876a23a78a89f39d Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
973ca1fac6
commit
b02d17c5c0
@ -153,7 +153,7 @@ class CldrReader (object):
|
||||
|
||||
def __parseTags(self, locale):
|
||||
tags = self.__splitLocale(locale)
|
||||
language = tags.next()
|
||||
language = next(tags)
|
||||
script = territory = variant = ''
|
||||
try:
|
||||
script, territory, variant = tags
|
||||
@ -171,10 +171,10 @@ class CldrReader (object):
|
||||
single tag (i.e. contains no underscores). Always yields 1 or
|
||||
4 values, never 2 or 3."""
|
||||
tags = iter(name.split('_'))
|
||||
yield tags.next() # Language
|
||||
yield next(tags) # Language
|
||||
|
||||
try:
|
||||
tag = tags.next()
|
||||
tag = next(tags)
|
||||
except StopIteration:
|
||||
return
|
||||
|
||||
@ -182,7 +182,7 @@ class CldrReader (object):
|
||||
if len(tag) == 4 and tag[0].isupper() and tag[1:].islower():
|
||||
yield tag
|
||||
try:
|
||||
tag = tags.next()
|
||||
tag = next(tags)
|
||||
except StopIteration:
|
||||
tag = ''
|
||||
else:
|
||||
@ -192,7 +192,7 @@ class CldrReader (object):
|
||||
if tag and tag.isupper() or tag.isdigit():
|
||||
yield tag
|
||||
try:
|
||||
tag = tags.next()
|
||||
tag = next(tags)
|
||||
except StopIteration:
|
||||
tag = ''
|
||||
else:
|
||||
@ -726,7 +726,7 @@ enumdata.py (keeping the old name as an alias):
|
||||
except (KeyError, ValueError, TypeError):
|
||||
pass
|
||||
else:
|
||||
if key not in seen or not elt.attributes.has_key('alt'):
|
||||
if key not in seen or 'alt' not in elt.attributes:
|
||||
yield key, value
|
||||
seen.add(key)
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# coding=utf8
|
||||
#############################################################################
|
||||
##
|
||||
@ -100,10 +100,6 @@ def main(args, out, err):
|
||||
usage(name, err, 'Too many arguments - excess: ' + ' '.join(args))
|
||||
return 1
|
||||
|
||||
if emit.encoding != 'UTF-8' or (emit.encoding is None and sys.getdefaultencoding() != 'UTF-8'):
|
||||
reload(sys) # Weirdly, this gets a richer sys module than the plain import got us !
|
||||
sys.setdefaultencoding('UTF-8')
|
||||
|
||||
# TODO - command line options to tune choice of grumble and whitter:
|
||||
reader = CldrReader(root, err.write, err.write)
|
||||
writer = QLocaleXmlWriter(emit.write)
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
#############################################################################
|
||||
##
|
||||
## Copyright (C) 2020 The Qt Company Ltd.
|
||||
|
@ -60,7 +60,7 @@ def _convert_pattern(pattern):
|
||||
"v" : "t", "vv" : "t", "vvv" : "t", "vvvv" : "t", # timezone
|
||||
"V" : "t", "VV" : "t", "VVV" : "t", "VVVV" : "t" # timezone
|
||||
}
|
||||
if qt_patterns.has_key(pattern):
|
||||
if pattern in qt_patterns:
|
||||
return qt_patterns[pattern]
|
||||
for r,v in qt_regexps.items():
|
||||
pattern = re.sub(r, v, pattern)
|
||||
|
@ -124,7 +124,7 @@ class Node (object):
|
||||
one."""
|
||||
seq = self.findAllChildren(tag)
|
||||
try:
|
||||
node = seq.next()
|
||||
node = next(seq)
|
||||
except StopIteration:
|
||||
raise Error('No child found where one was expected', tag)
|
||||
for it in seq:
|
||||
@ -197,7 +197,7 @@ class Supplement (XmlScanner):
|
||||
for e in elts):
|
||||
if elt.attributes:
|
||||
yield (elt.nodeName,
|
||||
dict((k, v if isinstance(v, basestring) else v.nodeValue)
|
||||
dict((k, v if isinstance(v, str) else v.nodeValue)
|
||||
for k, v in elt.attributes.items()))
|
||||
|
||||
class LocaleScanner (object):
|
||||
@ -312,7 +312,7 @@ class LocaleScanner (object):
|
||||
except Error:
|
||||
money = self.find(xpath)
|
||||
money = self.__currencyFormats(money, plus, minus)
|
||||
yield 'currencyFormat', money.next()
|
||||
yield 'currencyFormat', next(money)
|
||||
neg = ''
|
||||
for it in money:
|
||||
assert not neg, 'There should be at most one more pattern'
|
||||
|
@ -40,8 +40,8 @@ Classes:
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
class Error (StandardError):
|
||||
__upinit = StandardError.__init__
|
||||
class Error (Exception):
|
||||
__upinit = Exception.__init__
|
||||
def __init__(self, msg, *args):
|
||||
self.__upinit(msg, *args)
|
||||
self.message = msg
|
||||
|
@ -36,14 +36,14 @@ Provides classes:
|
||||
Support:
|
||||
Spacer -- provides control over indentation of the output.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
from xml.sax.saxutils import escape
|
||||
|
||||
from localetools import Error
|
||||
|
||||
# Tools used by Locale:
|
||||
def camel(seq):
|
||||
yield seq.next()
|
||||
yield next(seq)
|
||||
for word in seq:
|
||||
yield word.capitalize()
|
||||
|
||||
@ -58,7 +58,7 @@ def startCount(c, text): # strspn
|
||||
"""First index in text where it doesn't have a character in c"""
|
||||
assert text and text[0] in c
|
||||
try:
|
||||
return (j for j, d in enumerate(text) if d not in c).next()
|
||||
return next((j for j, d in enumerate(text) if d not in c))
|
||||
except StopIteration:
|
||||
return len(text)
|
||||
|
||||
@ -166,7 +166,7 @@ class QLocaleXmlReader (object):
|
||||
|
||||
def languageIndices(self, locales):
|
||||
index = 0
|
||||
for key, value in self.languages.iteritems():
|
||||
for key, value in self.languages.items():
|
||||
i, count = 0, locales.count(key)
|
||||
if count > 0:
|
||||
i = index
|
||||
@ -360,9 +360,7 @@ class QLocaleXmlWriter (object):
|
||||
self.__openTag('locale')
|
||||
self.__writeLocale(Locale.C(calendars), calendars)
|
||||
self.__closeTag('locale')
|
||||
keys = locales.keys()
|
||||
keys.sort()
|
||||
for key in keys:
|
||||
for key in sorted(locales.keys()):
|
||||
self.__openTag('locale')
|
||||
self.__writeLocale(locales[key], calendars)
|
||||
self.__closeTag('locale')
|
||||
@ -403,7 +401,7 @@ class QLocaleXmlWriter (object):
|
||||
|
||||
def __enumTable(self, tag, table):
|
||||
self.__openTag(tag + 'List')
|
||||
for key, value in table.iteritems():
|
||||
for key, value in table.items():
|
||||
self.__openTag(tag)
|
||||
self.inTag('name', value[0])
|
||||
self.inTag('id', key)
|
||||
@ -545,7 +543,7 @@ class Locale (object):
|
||||
'_'.join((k, cal))
|
||||
for k in self.propsMonthDay('months')
|
||||
for cal in calendars):
|
||||
write(key, escape(get(key)).encode('utf-8'))
|
||||
write(key, escape(get(key)))
|
||||
|
||||
write('groupSizes', ';'.join(str(x) for x in get('groupSizes')))
|
||||
for key in ('currencyDigits', 'currencyRounding'):
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
#############################################################################
|
||||
##
|
||||
## Copyright (C) 2021 The Qt Company Ltd.
|
||||
@ -162,8 +162,7 @@ class LocaleDataWriter (LocaleSourceEditor):
|
||||
def keyLikely(entry):
|
||||
have = entry[1] # Numeric id triple
|
||||
return have[0] or huge, have[2] or huge, have[1] or huge # language, region, script
|
||||
likely = list(likely) # Turn generator into list so we can sort it
|
||||
likely.sort(key=keyLikely)
|
||||
likely = sorted(likely, key=keyLikely)
|
||||
|
||||
i = 0
|
||||
self.writer.write('static const QLocaleId likely_subtags[] = {\n')
|
||||
|
Loading…
Reference in New Issue
Block a user