[Sugar-devel] [PATCH Get Books] Drop libxml2 SL #3419

Manuel Kaufmann humitos at gmail.com
Mon Jul 2 09:48:59 EDT 2012


This module dependency is replaced by ElementTree from the Python's
Standard Library

Signed-off-by: Manuel Kaufmann <humitos at gmail.com>
---
 GetIABooksActivity.py |    1 -
 languagenames.py      |   30 ++++++++----------------------
 2 files changed, 8 insertions(+), 23 deletions(-)

diff --git a/GetIABooksActivity.py b/GetIABooksActivity.py
index 8d20e70..a6a559d 100644
--- a/GetIABooksActivity.py
+++ b/GetIABooksActivity.py
@@ -595,7 +595,6 @@ class GetIABooksActivity(activity.Activity):
             self.bt_catalogs.set_active(True)
 
     def can_close(self):
-        self._lang_code_handler.close()
         if self.queryresults is not None:
             self.queryresults.cancel()
             self.queryresults = None
diff --git a/languagenames.py b/languagenames.py
index 644af8f..3b1da4c 100644
--- a/languagenames.py
+++ b/languagenames.py
@@ -16,7 +16,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-import libxml2
+from xml.etree import ElementTree
 import logging
 
 _ISO_639_XML_PATH = '/usr/share/xml/iso-codes/iso_639.xml'
@@ -33,35 +33,21 @@ def singleton(object, instantiated=[]):
 class LanguageNames(object):
     def __init__(self):
         singleton(self)
-        try:
-            self._xmldoc = libxml2.parseFile(_ISO_639_XML_PATH)
-            self._cache = None
-        except libxml2.parserError:
-            self._xmldoc = None
-            return
-
-        self._eroot = self._xmldoc.getRootElement()
+        self._xmldoc = ElementTree.parse(_ISO_639_XML_PATH)
+        self._cache = None
 
-    def close(self):
-        if self._xmldoc is not None:
-            self._xmldoc.freeDoc()
+        self._eroot = self._xmldoc.getroot()
 
     def get_full_language_name(self, code):
         if self._cache == None:
             self._cache = {}
-            for child in self._eroot.children:
-                if child.properties is not None:
-                    lang_code = None
-                    lang_name = None
-                    for property in child.properties:
-                        if property.get_name() == 'name':
-                            lang_name = property.get_content()
-                        elif property.get_name() == 'iso_639_1_code':
-                            lang_code = property.get_content()
+            for child in self._eroot.getchildren():
+                if child.attrib is not None:
+                    lang_name = child.attrib.get('name', None)
+                    lang_code = child.attrib.get('iso_639_1_code', None)
 
                     if lang_code is not None and lang_name is not None:
                         self._cache[lang_code] = lang_name
-            self._xmldoc.freeDoc()
             self._xmldoc = None
 
         return self._cache[code]
-- 
1.7.10.4



More information about the Sugar-devel mailing list