[Sugar-devel] [PATCH v2 Get Books] Drop libxml2 SL #3419
Manuel Kaufmann
humitos at gmail.com
Wed Jul 25 10:24:06 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 | 33 +++++++++------------------------
2 files changed, 9 insertions(+), 25 deletions(-)
diff --git a/GetIABooksActivity.py b/GetIABooksActivity.py
index f7943c9..3fb36b7 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..06423c6 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,20 @@ 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()
-
- def close(self):
- if self._xmldoc is not None:
- self._xmldoc.freeDoc()
+ self._cache = None
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()
+ _xmldoc = ElementTree.parse(_ISO_639_XML_PATH)
+ _eroot = _xmldoc.getroot()
+
+ for child in _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