+ mainloop = gobject.MainLoop()
+ gobject.timeout_add(timeout, mainloop.quit)
+
+ try:
+ mainloop.run()
+ except KeyboardInterrupt:
+ pass
+
+ print 'Content-type: text/html\n\n' + cgi.render_html()
+
+else:
+ try:
+ from twisted.internet import glib2reactor
+ glib2reactor.install()
+ from twisted.internet import reactor
+ from twisted.web import server, resource
+ except ImportError:
+ print "Sorry, to use this tool as a server you need to install twisted and twisted.web.\n"
+ sys.exit(1)
+
+ class AvahiBookmarksServer(AvahiBookmarks, resource.Resource):
+ isLeaf = True
+
+ def __init__(self, use_host_names):
+ resource.Resource.__init__(self)
+ AvahiBookmarks.__init__(self, use_host_names)
+
+ def render_GET(self, request):
+ return self.render_html()
+
+ site = server.Site(AvahiBookmarksServer(use_host_names))
+ reactor.listenTCP(port, site, interface=address)
+
+ print "Now point your web browser to http://%s:%u/!" % (address, port)
+
+ try:
+ reactor.run()
+ except KeyboardInterrupt:
+ pass