Replace BeautifulSoup with ElementTree
- removes dependency on BeautifulSoup 3,
- avoids BeautifulSoup 4 which is not available on Fedora 18,
- ElementTree already used elsewhere in activity and toolkit,
- test case; open an EPUB file and use the edit toolbar find entry.
Reported-by: György Balló <ballogyor@gmail.com>
James Cameron
6 years ago
20 | 20 | import widgets |
21 | 21 | import math |
22 | 22 | import os.path |
23 | import BeautifulSoup | |
23 | import xml.etree.ElementTree as etree | |
24 | 24 | |
25 | 25 | import threading |
26 | 26 | |
61 | 61 | return False |
62 | 62 | |
63 | 63 | def _searchfile(self, fileobj): |
64 | soup = BeautifulSoup.BeautifulSoup(fileobj) | |
65 | body = soup.find('body') | |
66 | tags = body.findChildren(True) | |
67 | for tag in tags: | |
68 | if tag.string is not None: | |
69 | if tag.string.lower().find(self.obj._text.lower()) > -1: | |
64 | tree = etree.parse(fileobj) | |
65 | root = tree.getroot() | |
66 | ||
67 | body = None | |
68 | for child in root: | |
69 | if child.tag.endswith('body'): | |
70 | body = child | |
71 | ||
72 | if body is None: | |
73 | return False | |
74 | ||
75 | for child in body.iter(): | |
76 | if child.text is not None: | |
77 | if child.text.lower().find(self.obj._text.lower()) > -1: | |
70 | 78 | return True |
71 | 79 | |
72 | 80 | return False |