Replace three functions with one simpler function
load{Language,Script,Country}Map() were all structurally very similar, so replace them with a single loadMap() that takes a second argument to say *which* map to load. At the same time, use a dict comprehension to simplify constructing the result. Change-Id: Ie43a71156010277200543a8937056efd35251955 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
e93af7dafd
commit
6a4875f0d1
@ -88,38 +88,12 @@ def eltText(elt):
|
|||||||
child = child.nextSibling
|
child = child.nextSibling
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def loadLanguageMap(doc):
|
def loadMap(doc, category):
|
||||||
result = {}
|
return dict((int(eltText(firstChildElt(element, 'id'))),
|
||||||
|
(eltText(firstChildElt(element, 'name')),
|
||||||
for language_elt in eachEltInGroup(doc.documentElement, "languageList", "language"):
|
eltText(firstChildElt(element, 'code'))))
|
||||||
language_id = int(eltText(firstChildElt(language_elt, "id")))
|
for element in eachEltInGroup(doc.documentElement,
|
||||||
language_name = eltText(firstChildElt(language_elt, "name"))
|
category + 'List', category))
|
||||||
language_code = eltText(firstChildElt(language_elt, "code"))
|
|
||||||
result[language_id] = (language_name, language_code)
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def loadScriptMap(doc):
|
|
||||||
result = {}
|
|
||||||
|
|
||||||
for script_elt in eachEltInGroup(doc.documentElement, "scriptList", "script"):
|
|
||||||
script_id = int(eltText(firstChildElt(script_elt, "id")))
|
|
||||||
script_name = eltText(firstChildElt(script_elt, "name"))
|
|
||||||
script_code = eltText(firstChildElt(script_elt, "code"))
|
|
||||||
result[script_id] = (script_name, script_code)
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def loadCountryMap(doc):
|
|
||||||
result = {}
|
|
||||||
|
|
||||||
for country_elt in eachEltInGroup(doc.documentElement, "countryList", "country"):
|
|
||||||
country_id = int(eltText(firstChildElt(country_elt, "id")))
|
|
||||||
country_name = eltText(firstChildElt(country_elt, "name"))
|
|
||||||
country_code = eltText(firstChildElt(country_elt, "code"))
|
|
||||||
result[country_id] = (country_name, country_code)
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def loadLikelySubtagsMap(doc):
|
def loadLikelySubtagsMap(doc):
|
||||||
result = {}
|
result = {}
|
||||||
@ -391,9 +365,9 @@ def main():
|
|||||||
data_temp_file.write(GENERATED_BLOCK_START)
|
data_temp_file.write(GENERATED_BLOCK_START)
|
||||||
|
|
||||||
doc = xml.dom.minidom.parse(localexml)
|
doc = xml.dom.minidom.parse(localexml)
|
||||||
language_map = loadLanguageMap(doc)
|
language_map = loadMap(doc, 'language')
|
||||||
script_map = loadScriptMap(doc)
|
script_map = loadMap(doc, 'script')
|
||||||
country_map = loadCountryMap(doc)
|
country_map = loadMap(doc, 'country')
|
||||||
likely_subtags_map = loadLikelySubtagsMap(doc)
|
likely_subtags_map = loadLikelySubtagsMap(doc)
|
||||||
default_map = {}
|
default_map = {}
|
||||||
for key in likely_subtags_map.keys():
|
for key in likely_subtags_map.keys():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user