5
class EpiphanyFormatBookmarksParser(xml.sax.ContentHandler):
6
def __init__(self, index):
7
xml.sax.ContentHandler.__init__(self)
12
self.bookmarks = set()
16
def startElement(self, name, attrs):
23
def endElement(self, name):
25
self.title = self.chars
28
self.href = self.chars
29
elif name == "ephy:smartlink":
30
self.href = self.chars
32
# We don't want bookmarks that are themselves queries
33
# such as "Search for %s"
34
if (not self.href.startswith("javascript:")) and (self.href.find("%s") == -1):
35
self.bookmarks.add((self.title, self.href))
38
def characters(self, chars):
39
self.chars = self.chars + chars
42
def endDocument(self):
43
self.bookmarks = list(self.bookmarks)
44
# sort by titles (element 0 of the title,href tuple)
45
self.bookmarks.sort(lambda x, y: cmp(x[0].lower(), y[0].lower()))
46
for b in self.bookmarks:
47
self.index.add(b[0], b)
50
def add_to_index(index):
51
bookmarks_file_name = os.path.expanduser("~/.gnome2/epiphany/bookmarks.rdf")
52
if os.path.exists(bookmarks_file_name):
53
parser = xml.sax.make_parser()
54
parser.setContentHandler(EpiphanyFormatBookmarksParser(index))
55
parser.parse(bookmarks_file_name)