From 241ff426eb69cd30fa45cdc91a66b0f5e7688623 Mon Sep 17 00:00:00 2001
From: Konstantin Ritt <ritt.ks@gmail.com>
Date: Fri, 20 Mar 2015 20:37:02 +0400
Subject: [PATCH] [locale database utility] Minor code deduplication

Change-Id: Ib6917940dfc410148d88e539cad2cdf7331a940d
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
---
 util/local_database/xpathlite.py | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/util/local_database/xpathlite.py b/util/local_database/xpathlite.py
index ecf1dad4445..39402058c62 100644
--- a/util/local_database/xpathlite.py
+++ b/util/local_database/xpathlite.py
@@ -36,8 +36,6 @@ import sys
 import os
 import xml.dom.minidom
 
-doc_cache = {}
-
 class DraftResolution:
     # See http://www.unicode.org/cldr/process.html for description
     unconfirmed = 'unconfirmed'
@@ -56,6 +54,12 @@ class Error:
     def __str__(self):
         return self.msg
 
+doc_cache = {}
+def parseDoc(file):
+    if not doc_cache.has_key(file):
+        doc_cache[file] = xml.dom.minidom.parse(file)
+    return doc_cache[file]
+
 def findChild(parent, tag_name, arg_name=None, arg_value=None, draft=None):
     for node in parent.childNodes:
         if node.nodeType != node.ELEMENT_NODE:
@@ -80,12 +84,7 @@ def findChild(parent, tag_name, arg_name=None, arg_value=None, draft=None):
     return False
 
 def findTagsInFile(file, path):
-    doc = False
-    if doc_cache.has_key(file):
-        doc = doc_cache[file]
-    else:
-        doc = xml.dom.minidom.parse(file)
-        doc_cache[file] = doc
+    doc = parseDoc(file)
 
     elt = doc.documentElement
     tag_spec_list = path.split("/")
@@ -122,12 +121,7 @@ def findTagsInFile(file, path):
     return ret
 
 def _findEntryInFile(file, path, draft=None, attribute=None):
-    doc = False
-    if doc_cache.has_key(file):
-        doc = doc_cache[file]
-    else:
-        doc = xml.dom.minidom.parse(file)
-        doc_cache[file] = doc
+    doc = parseDoc(file)
 
     elt = doc.documentElement
     tag_spec_list = path.split("/")
@@ -177,12 +171,7 @@ def _findEntryInFile(file, path, draft=None, attribute=None):
     return (None, None)
 
 def findAlias(file):
-    doc = False
-    if doc_cache.has_key(file):
-        doc = doc_cache[file]
-    else:
-        doc = xml.dom.minidom.parse(file)
-        doc_cache[file] = doc
+    doc = parseDoc(file)
 
     alias_elt = findChild(doc.documentElement, "alias")
     if not alias_elt:
-- 
GitLab