3 from xml
.sax
import make_parser
4 from xml
.sax
.handler
import ContentHandler
5 from ephyhistory
import History
, HistoryPageNode
9 class HistoryHandler(ContentHandler
):
14 self
.history
= History()
16 def startElement(self
, name
, attrs
):
22 elif name
== 'property':
23 self
.propId
= int(attrs
.get('id'))
26 def endElement(self
, name
):
30 self
.createVisit(self
.props
)
31 elif name
== 'property':
34 def characters(self
, ch
):
36 self
.props
[self
.propId
] = self
.props
.get(self
.propId
, '') + ch
38 def createVisit(self
, props
):
39 # refer to enum in ephy-history.h for propId -> property mapping
41 # XXX: add a function to the API for specifying
42 # visit count and visit date when adding a page
44 url
= props
.get(3, None)
46 self
.history
.add_page(url
, redirect
=False, toplevel
=False, ref_url
='')
47 title
= props
.get(2, None)
49 self
.history
.set_page_title(url
, title
.encode('utf-8'))
50 favicon
= props
.get(9, None)
52 self
.history
.set_icon(url
, favicon
)
54 if __name__
== '__main__':
56 xmlfile
= os
.path
.expanduser('~/.gnome2/epiphany/ephy-history.xml')
59 parser
= make_parser()
61 parser
.setContentHandler(hh
)