summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorIevgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>2021-07-05 17:45:26 +0200
committerIevgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>2021-07-15 17:06:53 +0200
commitb02d17c5c0f01a6c24cacaea2a3a41bfcc37490f (patch)
tree17f5694bb410a1bd3d70a31b5eb3720e49ad7e29 /util
parent973ca1fac680d8c593645058fae3fe7c84a7fa16 (diff)
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>
Diffstat (limited to 'util')
-rw-r--r--util/locale_database/cldr.py12
-rwxr-xr-xutil/locale_database/cldr2qlocalexml.py6
-rwxr-xr-xutil/locale_database/cldr2qtimezone.py2
-rw-r--r--util/locale_database/dateconverter.py2
-rw-r--r--util/locale_database/ldml.py6
-rw-r--r--util/locale_database/localetools.py4
-rw-r--r--util/locale_database/qlocalexml.py16
-rwxr-xr-xutil/locale_database/qlocalexml2cpp.py5
8 files changed, 23 insertions, 30 deletions
diff --git a/util/locale_database/cldr.py b/util/locale_database/cldr.py
index a65c649106..e3cbf2d2b6 100644
--- a/util/locale_database/cldr.py
+++ b/util/locale_database/cldr.py
@@ -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)
diff --git a/util/locale_database/cldr2qlocalexml.py b/util/locale_database/cldr2qlocalexml.py
index 4e66d6f236..fc876a2c50 100755
--- a/util/locale_database/cldr2qlocalexml.py
+++ b/util/locale_database/cldr2qlocalexml.py
@@ -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)
diff --git a/util/locale_database/cldr2qtimezone.py b/util/locale_database/cldr2qtimezone.py
index 1e783b6add..cfe6736b06 100755
--- a/util/locale_database/cldr2qtimezone.py
+++ b/util/locale_database/cldr2qtimezone.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
#############################################################################
##
## Copyright (C) 2020 The Qt Company Ltd.
diff --git a/util/locale_database/dateconverter.py b/util/locale_database/dateconverter.py
index 333f184f3c..b8caabc37f 100644
--- a/util/locale_database/dateconverter.py
+++ b/util/locale_database/dateconverter.py
@@ -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)
diff --git a/util/locale_database/ldml.py b/util/locale_database/ldml.py
index ef40be47af..77a64fdef4 100644
--- a/util/locale_database/ldml.py
+++ b/util/locale_database/ldml.py
@@ -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'
diff --git a/util/locale_database/localetools.py b/util/locale_database/localetools.py
index 29153366b3..82691666aa 100644
--- a/util/locale_database/localetools.py
+++ b/util/locale_database/localetools.py
@@ -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
diff --git a/util/locale_database/qlocalexml.py b/util/locale_database/qlocalexml.py
index 630794735f..7358e674f8 100644
--- a/util/locale_database/qlocalexml.py
+++ b/util/locale_database/qlocalexml.py
@@ -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'):
diff --git a/util/locale_database/qlocalexml2cpp.py b/util/locale_database/qlocalexml2cpp.py
index 182cac8ab1..e510a49259 100755
--- a/util/locale_database/qlocalexml2cpp.py
+++ b/util/locale_database/qlocalexml2cpp.py
@@ -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')