Ticket #3419: 0001-Drop-libxml2-SL-3419.patch

File 0001-Drop-libxml2-SL-3419.patch, 3.0 KB (added by humitos, 12 years ago)
  • GetIABooksActivity.py

    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): 
    595595            self.bt_catalogs.set_active(True)
    596596
    597597    def can_close(self):
    598         self._lang_code_handler.close()
    599598        if self.queryresults is not None:
    600599            self.queryresults.cancel()
    601600            self.queryresults = None
  • languagenames.py

    diff --git a/languagenames.py b/languagenames.py
    index 644af8f..3b1da4c 100644
    a b  
    1616# along with this program; if not, write to the Free Software
    1717# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1818
    19 import libxml2
     19from xml.etree import ElementTree
    2020import logging
    2121
    2222_ISO_639_XML_PATH = '/usr/share/xml/iso-codes/iso_639.xml'
    def singleton(object, instantiated=[]): 
    3333class LanguageNames(object):
    3434    def __init__(self):
    3535        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
    4438
    45     def close(self):
    46         if self._xmldoc is not None:
    47             self._xmldoc.freeDoc()
     39        self._eroot = self._xmldoc.getroot()
    4840
    4941    def get_full_language_name(self, code):
    5042        if self._cache == None:
    5143            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)
    6148
    6249                    if lang_code is not None and lang_name is not None:
    6350                        self._cache[lang_code] = lang_name
    64             self._xmldoc.freeDoc()
    6551            self._xmldoc = None
    6652
    6753        return self._cache[code]