From 830fa4858d3e2f4a923658d7f87425962823e82b Mon Sep 17 00:00:00 2001
From: Manuel Kaufmann <humitos@gmail.com>
Date: Mon, 2 Jul 2012 10:46:47 -0300
Subject: [PATCH Get Books] Drop libxml2 SL #3419
This module dependency is replaced by ElementTree from the Python's
Standard Library
Signed-off-by: Manuel Kaufmann <humitos@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
|
b
|
class GetIABooksActivity(activity.Activity): |
595 | 595 | self.bt_catalogs.set_active(True) |
596 | 596 | |
597 | 597 | def can_close(self): |
598 | | self._lang_code_handler.close() |
599 | 598 | if self.queryresults is not None: |
600 | 599 | self.queryresults.cancel() |
601 | 600 | self.queryresults = None |
diff --git a/languagenames.py b/languagenames.py
index 644af8f..3b1da4c 100644
a
|
b
|
|
16 | 16 | # along with this program; if not, write to the Free Software |
17 | 17 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
18 | 18 | |
19 | | import libxml2 |
| 19 | from xml.etree import ElementTree |
20 | 20 | import logging |
21 | 21 | |
22 | 22 | _ISO_639_XML_PATH = '/usr/share/xml/iso-codes/iso_639.xml' |
… |
… |
def singleton(object, instantiated=[]): |
33 | 33 | class LanguageNames(object): |
34 | 34 | def __init__(self): |
35 | 35 | singleton(self) |
36 | | try: |
37 | | self._xmldoc = libxml2.parseFile(_ISO_639_XML_PATH) |
38 | | self._cache = None |
39 | | except libxml2.parserError: |
40 | | self._xmldoc = None |
41 | | return |
42 | | |
43 | | self._eroot = self._xmldoc.getRootElement() |
| 36 | self._xmldoc = ElementTree.parse(_ISO_639_XML_PATH) |
| 37 | self._cache = None |
44 | 38 | |
45 | | def close(self): |
46 | | if self._xmldoc is not None: |
47 | | self._xmldoc.freeDoc() |
| 39 | self._eroot = self._xmldoc.getroot() |
48 | 40 | |
49 | 41 | def get_full_language_name(self, code): |
50 | 42 | if self._cache == None: |
51 | 43 | self._cache = {} |
52 | | for child in self._eroot.children: |
53 | | if child.properties is not None: |
54 | | lang_code = None |
55 | | lang_name = None |
56 | | for property in child.properties: |
57 | | if property.get_name() == 'name': |
58 | | lang_name = property.get_content() |
59 | | elif property.get_name() == 'iso_639_1_code': |
60 | | lang_code = property.get_content() |
| 44 | for child in self._eroot.getchildren(): |
| 45 | if child.attrib is not None: |
| 46 | lang_name = child.attrib.get('name', None) |
| 47 | lang_code = child.attrib.get('iso_639_1_code', None) |
61 | 48 | |
62 | 49 | if lang_code is not None and lang_name is not None: |
63 | 50 | self._cache[lang_code] = lang_name |
64 | | self._xmldoc.freeDoc() |
65 | 51 | self._xmldoc = None |
66 | 52 | |
67 | 53 | return self._cache[code] |