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
|
||||
return result
|
||||
|
||||
def loadLanguageMap(doc):
|
||||
result = {}
|
||||
|
||||
for language_elt in eachEltInGroup(doc.documentElement, "languageList", "language"):
|
||||
language_id = int(eltText(firstChildElt(language_elt, "id")))
|
||||
language_name = eltText(firstChildElt(language_elt, "name"))
|
||||
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 loadMap(doc, category):
|
||||
return dict((int(eltText(firstChildElt(element, 'id'))),
|
||||
(eltText(firstChildElt(element, 'name')),
|
||||
eltText(firstChildElt(element, 'code'))))
|
||||
for element in eachEltInGroup(doc.documentElement,
|
||||
category + 'List', category))
|
||||
|
||||
def loadLikelySubtagsMap(doc):
|
||||
result = {}
|
||||
@ -391,9 +365,9 @@ def main():
|
||||
data_temp_file.write(GENERATED_BLOCK_START)
|
||||
|
||||
doc = xml.dom.minidom.parse(localexml)
|
||||
language_map = loadLanguageMap(doc)
|
||||
script_map = loadScriptMap(doc)
|
||||
country_map = loadCountryMap(doc)
|
||||
language_map = loadMap(doc, 'language')
|
||||
script_map = loadMap(doc, 'script')
|
||||
country_map = loadMap(doc, 'country')
|
||||
likely_subtags_map = loadLikelySubtagsMap(doc)
|
||||
default_map = {}
|
||||
for key in likely_subtags_map.keys():
|
||||
|
Loading…
Reference in New Issue
Block a user