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):
|
def __parseTags(self, locale):
|
||||||
tags = self.__splitLocale(locale)
|
tags = self.__splitLocale(locale)
|
||||||
language = tags.next()
|
language = next(tags)
|
||||||
script = territory = variant = ''
|
script = territory = variant = ''
|
||||||
try:
|
try:
|
||||||
script, territory, variant = tags
|
script, territory, variant = tags
|
||||||
@ -171,10 +171,10 @@ class CldrReader (object):
|
|||||||
single tag (i.e. contains no underscores). Always yields 1 or
|
single tag (i.e. contains no underscores). Always yields 1 or
|
||||||
4 values, never 2 or 3."""
|
4 values, never 2 or 3."""
|
||||||
tags = iter(name.split('_'))
|
tags = iter(name.split('_'))
|
||||||
yield tags.next() # Language
|
yield next(tags) # Language
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tag = tags.next()
|
tag = next(tags)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -182,7 +182,7 @@ class CldrReader (object):
|
|||||||
if len(tag) == 4 and tag[0].isupper() and tag[1:].islower():
|
if len(tag) == 4 and tag[0].isupper() and tag[1:].islower():
|
||||||
yield tag
|
yield tag
|
||||||
try:
|
try:
|
||||||
tag = tags.next()
|
tag = next(tags)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
tag = ''
|
tag = ''
|
||||||
else:
|
else:
|
||||||
@ -192,7 +192,7 @@ class CldrReader (object):
|
|||||||
if tag and tag.isupper() or tag.isdigit():
|
if tag and tag.isupper() or tag.isdigit():
|
||||||
yield tag
|
yield tag
|
||||||
try:
|
try:
|
||||||
tag = tags.next()
|
tag = next(tags)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
tag = ''
|
tag = ''
|
||||||
else:
|
else:
|
||||||
@ -726,7 +726,7 @@ enumdata.py (keeping the old name as an alias):
|
|||||||
except (KeyError, ValueError, TypeError):
|
except (KeyError, ValueError, TypeError):
|
||||||
pass
|
pass
|
||||||
else:
|
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
|
yield key, value
|
||||||
seen.add(key)
|
seen.add(key)
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python3
|
||||||
# coding=utf8
|
# coding=utf8
|
||||||
#############################################################################
|
#############################################################################
|
||||||
##
|
##
|
||||||
@ -100,10 +100,6 @@ def main(args, out, err):
|
|||||||
usage(name, err, 'Too many arguments - excess: ' + ' '.join(args))
|
usage(name, err, 'Too many arguments - excess: ' + ' '.join(args))
|
||||||
return 1
|
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:
|
# TODO - command line options to tune choice of grumble and whitter:
|
||||||
reader = CldrReader(root, err.write, err.write)
|
reader = CldrReader(root, err.write, err.write)
|
||||||
writer = QLocaleXmlWriter(emit.write)
|
writer = QLocaleXmlWriter(emit.write)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python3
|
||||||
#############################################################################
|
#############################################################################
|
||||||
##
|
##
|
||||||
## Copyright (C) 2020 The Qt Company Ltd.
|
## 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
|
||||||
"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]
|
return qt_patterns[pattern]
|
||||||
for r,v in qt_regexps.items():
|
for r,v in qt_regexps.items():
|
||||||
pattern = re.sub(r, v, pattern)
|
pattern = re.sub(r, v, pattern)
|
||||||
|
@ -124,7 +124,7 @@ class Node (object):
|
|||||||
one."""
|
one."""
|
||||||
seq = self.findAllChildren(tag)
|
seq = self.findAllChildren(tag)
|
||||||
try:
|
try:
|
||||||
node = seq.next()
|
node = next(seq)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
raise Error('No child found where one was expected', tag)
|
raise Error('No child found where one was expected', tag)
|
||||||
for it in seq:
|
for it in seq:
|
||||||
@ -197,7 +197,7 @@ class Supplement (XmlScanner):
|
|||||||
for e in elts):
|
for e in elts):
|
||||||
if elt.attributes:
|
if elt.attributes:
|
||||||
yield (elt.nodeName,
|
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()))
|
for k, v in elt.attributes.items()))
|
||||||
|
|
||||||
class LocaleScanner (object):
|
class LocaleScanner (object):
|
||||||
@ -312,7 +312,7 @@ class LocaleScanner (object):
|
|||||||
except Error:
|
except Error:
|
||||||
money = self.find(xpath)
|
money = self.find(xpath)
|
||||||
money = self.__currencyFormats(money, plus, minus)
|
money = self.__currencyFormats(money, plus, minus)
|
||||||
yield 'currencyFormat', money.next()
|
yield 'currencyFormat', next(money)
|
||||||
neg = ''
|
neg = ''
|
||||||
for it in money:
|
for it in money:
|
||||||
assert not neg, 'There should be at most one more pattern'
|
assert not neg, 'There should be at most one more pattern'
|
||||||
|
@ -40,8 +40,8 @@ Classes:
|
|||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
class Error (StandardError):
|
class Error (Exception):
|
||||||
__upinit = StandardError.__init__
|
__upinit = Exception.__init__
|
||||||
def __init__(self, msg, *args):
|
def __init__(self, msg, *args):
|
||||||
self.__upinit(msg, *args)
|
self.__upinit(msg, *args)
|
||||||
self.message = msg
|
self.message = msg
|
||||||
|
@ -36,14 +36,14 @@ Provides classes:
|
|||||||
Support:
|
Support:
|
||||||
Spacer -- provides control over indentation of the output.
|
Spacer -- provides control over indentation of the output.
|
||||||
"""
|
"""
|
||||||
from __future__ import print_function
|
|
||||||
from xml.sax.saxutils import escape
|
from xml.sax.saxutils import escape
|
||||||
|
|
||||||
from localetools import Error
|
from localetools import Error
|
||||||
|
|
||||||
# Tools used by Locale:
|
# Tools used by Locale:
|
||||||
def camel(seq):
|
def camel(seq):
|
||||||
yield seq.next()
|
yield next(seq)
|
||||||
for word in seq:
|
for word in seq:
|
||||||
yield word.capitalize()
|
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"""
|
"""First index in text where it doesn't have a character in c"""
|
||||||
assert text and text[0] in c
|
assert text and text[0] in c
|
||||||
try:
|
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:
|
except StopIteration:
|
||||||
return len(text)
|
return len(text)
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ class QLocaleXmlReader (object):
|
|||||||
|
|
||||||
def languageIndices(self, locales):
|
def languageIndices(self, locales):
|
||||||
index = 0
|
index = 0
|
||||||
for key, value in self.languages.iteritems():
|
for key, value in self.languages.items():
|
||||||
i, count = 0, locales.count(key)
|
i, count = 0, locales.count(key)
|
||||||
if count > 0:
|
if count > 0:
|
||||||
i = index
|
i = index
|
||||||
@ -360,9 +360,7 @@ class QLocaleXmlWriter (object):
|
|||||||
self.__openTag('locale')
|
self.__openTag('locale')
|
||||||
self.__writeLocale(Locale.C(calendars), calendars)
|
self.__writeLocale(Locale.C(calendars), calendars)
|
||||||
self.__closeTag('locale')
|
self.__closeTag('locale')
|
||||||
keys = locales.keys()
|
for key in sorted(locales.keys()):
|
||||||
keys.sort()
|
|
||||||
for key in keys:
|
|
||||||
self.__openTag('locale')
|
self.__openTag('locale')
|
||||||
self.__writeLocale(locales[key], calendars)
|
self.__writeLocale(locales[key], calendars)
|
||||||
self.__closeTag('locale')
|
self.__closeTag('locale')
|
||||||
@ -403,7 +401,7 @@ class QLocaleXmlWriter (object):
|
|||||||
|
|
||||||
def __enumTable(self, tag, table):
|
def __enumTable(self, tag, table):
|
||||||
self.__openTag(tag + 'List')
|
self.__openTag(tag + 'List')
|
||||||
for key, value in table.iteritems():
|
for key, value in table.items():
|
||||||
self.__openTag(tag)
|
self.__openTag(tag)
|
||||||
self.inTag('name', value[0])
|
self.inTag('name', value[0])
|
||||||
self.inTag('id', key)
|
self.inTag('id', key)
|
||||||
@ -545,7 +543,7 @@ class Locale (object):
|
|||||||
'_'.join((k, cal))
|
'_'.join((k, cal))
|
||||||
for k in self.propsMonthDay('months')
|
for k in self.propsMonthDay('months')
|
||||||
for cal in calendars):
|
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')))
|
write('groupSizes', ';'.join(str(x) for x in get('groupSizes')))
|
||||||
for key in ('currencyDigits', 'currencyRounding'):
|
for key in ('currencyDigits', 'currencyRounding'):
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python3
|
||||||
#############################################################################
|
#############################################################################
|
||||||
##
|
##
|
||||||
## Copyright (C) 2021 The Qt Company Ltd.
|
## Copyright (C) 2021 The Qt Company Ltd.
|
||||||
@ -162,8 +162,7 @@ class LocaleDataWriter (LocaleSourceEditor):
|
|||||||
def keyLikely(entry):
|
def keyLikely(entry):
|
||||||
have = entry[1] # Numeric id triple
|
have = entry[1] # Numeric id triple
|
||||||
return have[0] or huge, have[2] or huge, have[1] or huge # language, region, script
|
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 = sorted(likely, key=keyLikely)
|
||||||
likely.sort(key=keyLikely)
|
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
self.writer.write('static const QLocaleId likely_subtags[] = {\n')
|
self.writer.write('static const QLocaleId likely_subtags[] = {\n')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user