diff --git a/avahi-python/avahi-bookmarks.in b/avahi-python/avahi-bookmarks.in
index dea7bef..f920c14 100755
--- a/avahi-python/avahi-bookmarks.in
+++ b/avahi-python/avahi-bookmarks.in
@@ -17,12 +17,20 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA.
+from __future__ import print_function
+
import sys, getopt, os
try:
- import avahi, gobject, dbus
+ import avahi, dbus
+except ImportError:
+ print("Sorry, to use this tool you need to install Avahi and python-dbus.")
+ sys.exit(1)
+
+try:
+ from gi.repository import GObject
except ImportError:
- print "Sorry, to use this tool you need to install Avahi and python-dbus."
+ print("Sorry, to use this tool you need to install GObject Introspection.")
sys.exit(1)
try:
@@ -95,7 +103,7 @@ class AvahiBookmarks:
else:
t += '
'
- for k, v in self.services.iteritems():
+ for k, v in self.services.items():
if v[3] == 80:
port = ''
@@ -138,16 +146,16 @@ class AvahiBookmarks:
def usage(retval = 0):
- print "%s [options]\n" % sys.argv[0]
- print " -h --help Show this help"
- print " -c --cgi Run as a CGI instead of as a server (default to server"
- print " unless environment variable GATEWAY_INTERFACE is set)"
- print " -t --timeout MS Specify the max time for CGI browsing (default %u)" % timeout
- print " -p --port PORT Specify the port to use (default %u)" % port
- print " -a --address ADDRESS Specify the address to bind to (default %s)" % address
- print " -H --host-names Show links with real hostnames"
- print " -A --addresses Show links with numeric IP addresses"
- print " -d --domain DOMAIN Specify the domain to browse"
+ print("%s [options]\n" % sys.argv[0])
+ print(" -h --help Show this help")
+ print(" -c --cgi Run as a CGI instead of as a server (default to server")
+ print(" unless environment variable GATEWAY_INTERFACE is set)")
+ print(" -t --timeout MS Specify the max time for CGI browsing (default %u)" % timeout)
+ print(" -p --port PORT Specify the port to use (default %u)" % port)
+ print(" -a --address ADDRESS Specify the address to bind to (default %s)" % address)
+ print(" -H --host-names Show links with real hostnames")
+ print(" -A --addresses Show links with numeric IP addresses")
+ print(" -d --domain DOMAIN Specify the domain to browse")
sys.exit(retval)
try:
@@ -181,30 +189,30 @@ for o, a in opts:
domain = a
if use_CGI is None:
- use_CGI = os.environ.has_key("GATEWAY_INTERFACE")
+ use_CGI = "GATEWAY_INTERFACE" in os.environ
if use_CGI:
cgi = AvahiBookmarks(use_host_names)
- mainloop = gobject.MainLoop()
- gobject.timeout_add(timeout, mainloop.quit)
+ 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()
+ print('Content-type: text/html\n\n' + cgi.render_html())
else:
try:
- from twisted.internet import glib2reactor
- glib2reactor.install()
+ from twisted.internet import gireactor
+ gireactor.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)
+ 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
@@ -214,12 +222,15 @@ else:
AvahiBookmarks.__init__(self, use_host_names)
def render_GET(self, request):
- return self.render_html()
+ if sys.version_info[0] > 2:
+ return bytes(self.render_html(),'utf-8')
+ else:
+ 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)
+ print("Now point your web browser to http://%s:%u/!" % (address, port))
try:
reactor.run()