summaryrefslogtreecommitdiffstats
path: root/avahi-python
diff options
context:
space:
mode:
Diffstat (limited to 'avahi-python')
-rw-r--r--avahi-python/Makefile.am4
-rwxr-xr-xavahi-python/avahi-bookmarks.in2
-rw-r--r--avahi-python/avahi-discover/Makefile.am15
-rw-r--r--avahi-python/avahi-discover/SimpleGladeApp.py341
-rwxr-xr-xavahi-python/avahi-discover/__init__.py2
-rwxr-xr-xavahi-python/avahi-discover/avahi-discover.in67
-rw-r--r--avahi-python/avahi/Makefile.am10
-rw-r--r--avahi-python/avahi/ServiceTypeDatabase.py.in73
-rw-r--r--avahi-python/avahi/__init__.py2
9 files changed, 109 insertions, 407 deletions
diff --git a/avahi-python/Makefile.am b/avahi-python/Makefile.am
index 4989b4b..7381a48 100644
--- a/avahi-python/Makefile.am
+++ b/avahi-python/Makefile.am
@@ -1,5 +1,3 @@
-# $Id$
-
# This file is part of avahi.
#
# avahi is free software; you can redistribute it and/or modify it
@@ -34,7 +32,7 @@ pythonscripts = \
avahi-bookmarks
avahi-bookmarks: avahi-bookmarks.in
- sed -e 's,@PYTHON\@,$(PYTHON),g' $< > $@
+ $(AM_V_GEN)sed -e 's,@PYTHON\@,$(PYTHON),g' $< > $@ && \
chmod +x $@
bin_SCRIPTS = $(pythonscripts)
diff --git a/avahi-python/avahi-bookmarks.in b/avahi-python/avahi-bookmarks.in
index 172abb3..dea7bef 100755
--- a/avahi-python/avahi-bookmarks.in
+++ b/avahi-python/avahi-bookmarks.in
@@ -1,7 +1,5 @@
#!@PYTHON@
# -*-python-*-
-# $Id$
-
# This file is part of avahi.
#
# avahi is free software; you can redistribute it and/or modify it
diff --git a/avahi-python/avahi-discover/Makefile.am b/avahi-python/avahi-discover/Makefile.am
index a44a071..454fd57 100644
--- a/avahi-python/avahi-discover/Makefile.am
+++ b/avahi-python/avahi-discover/Makefile.am
@@ -1,5 +1,3 @@
-# $Id$
-
# This file is part of avahi.
#
# avahi is free software; you can redistribute it and/or modify it
@@ -21,7 +19,6 @@ AM_CFLAGS=-I$(top_srcdir)
EXTRA_DIST = \
__init__.py \
- SimpleGladeApp.py \
avahi-discover.in \
avahi-discover.desktop.in.in
@@ -32,7 +29,7 @@ if HAVE_PYGTK
pythonscripts =
desktopdir = $(datadir)/applications
-desktop_DATA =
+desktop_DATA =
avahi_discoverdir = $(pythondir)/avahi_discover
avahi_discover_PYTHON =
@@ -42,7 +39,7 @@ pythonscripts += \
avahi-discover
desktop_DATA += avahi-discover.desktop
@INTLTOOL_DESKTOP_RULE@
-avahi_discover_PYTHON += __init__.py SimpleGladeApp.py
+avahi_discover_PYTHON += __init__.py
endif
if HAVE_DBM
@@ -50,17 +47,17 @@ pythonscripts += \
avahi-discover
desktop_DATA += avahi-discover.desktop
@INTLTOOL_DESKTOP_RULE@
-avahi_discover_PYTHON += __init__.py SimpleGladeApp.py
+avahi_discover_PYTHON += __init__.py
endif
avahi-discover.desktop.in: avahi-discover.desktop.in.in
- sed -e 's,@bindir\@,$(bindir),g' $< > $@
+ $(AM_V_GEN)sed -e 's,@bindir\@,$(bindir),g' $< > $@
avahi-discover: avahi-discover.in
- sed -e 's,@PYTHON\@,$(PYTHON),g' \
+ $(AM_V_GEN)sed -e 's,@PYTHON\@,$(PYTHON),g' \
-e 's,@GETTEXT_PACKAGE\@,"$(GETTEXT_PACKAGE)",g' \
-e 's,@LOCALEDIR\@,"$(datadir)/locale",g' \
- -e 's,@interfacesdir\@,$(interfacesdir),g' $< > $@
+ -e 's,@interfacesdir\@,$(interfacesdir),g' $< > $@ && \
chmod +x $@
bin_SCRIPTS = $(pythonscripts)
diff --git a/avahi-python/avahi-discover/SimpleGladeApp.py b/avahi-python/avahi-discover/SimpleGladeApp.py
deleted file mode 100644
index 90c598c..0000000
--- a/avahi-python/avahi-discover/SimpleGladeApp.py
+++ /dev/null
@@ -1,341 +0,0 @@
-"""
- SimpleGladeApp.py
- Module that provides an object oriented abstraction to pygtk and libglade.
- Copyright (C) 2004 Sandino Flores Moreno
-"""
-
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-# USA
-
-import os
-import sys
-import re
-
-import tokenize
-import gtk
-import gtk.glade
-import weakref
-import inspect
-
-__version__ = "1.0"
-__author__ = 'Sandino "tigrux" Flores-Moreno'
-
-def bindtextdomain(app_name, locale_dir=None):
- """
- Bind the domain represented by app_name to the locale directory locale_dir.
- It has the effect of loading translations, enabling applications for different
- languages.
-
- app_name:
- a domain to look for translations, tipically the name of an application.
-
- locale_dir:
- a directory with locales like locale_dir/lang_isocode/LC_MESSAGES/app_name.mo
- If omitted or None, then the current binding for app_name is used.
- """
- try:
- import locale
- import gettext
- locale.setlocale(locale.LC_ALL, "")
- gtk.glade.bindtextdomain(app_name, locale_dir)
- gettext.install(app_name, locale_dir, unicode=1)
- except (IOError,locale.Error), e:
- print "Warning", app_name, e
- __builtins__.__dict__["_"] = lambda x : x
-
-
-class SimpleGladeApp:
-
- def __init__(self, path, root=None, domain=None, **kwargs):
- """
- Load a glade file specified by glade_filename, using root as
- root widget and domain as the domain for translations.
-
- If it receives extra named arguments (argname=value), then they are used
- as attributes of the instance.
-
- path:
- path to a glade filename.
- If glade_filename cannot be found, then it will be searched in the
- same directory of the program (sys.argv[0])
-
- root:
- the name of the widget that is the root of the user interface,
- usually a window or dialog (a top level widget).
- If None or ommited, the full user interface is loaded.
-
- domain:
- A domain to use for loading translations.
- If None or ommited, no translation is loaded.
-
- **kwargs:
- a dictionary representing the named extra arguments.
- It is useful to set attributes of new instances, for example:
- glade_app = SimpleGladeApp("ui.glade", foo="some value", bar="another value")
- sets two attributes (foo and bar) to glade_app.
- """
- if os.path.isfile(path):
- self.glade_path = path
- else:
- glade_dir = os.path.dirname( sys.argv[0] )
- self.glade_path = os.path.join(glade_dir, path)
- for key, value in kwargs.items():
- try:
- setattr(self, key, weakref.proxy(value) )
- except TypeError:
- setattr(self, key, value)
- self.glade = None
- self.install_custom_handler(self.custom_handler)
- self.glade = self.create_glade(self.glade_path, root, domain)
- if root:
- self.main_widget = self.get_widget(root)
- else:
- self.main_widget = None
- self.normalize_names()
- self.add_callbacks(self)
- self.new()
-
- def __repr__(self):
- class_name = self.__class__.__name__
- if self.main_widget:
- root = gtk.Widget.get_name(self.main_widget)
- repr = '%s(path="%s", root="%s")' % (class_name, self.glade_path, root)
- else:
- repr = '%s(path="%s")' % (class_name, self.glade_path)
- return repr
-
- def new(self):
- """
- Method called when the user interface is loaded and ready to be used.
- At this moment, the widgets are loaded and can be refered as self.widget_name
- """
- pass
-
- def add_callbacks(self, callbacks_proxy):
- """
- It uses the methods of callbacks_proxy as callbacks.
- The callbacks are specified by using:
- Properties window -> Signals tab
- in glade-2 (or any other gui designer like gazpacho).
-
- Methods of classes inheriting from SimpleGladeApp are used as
- callbacks automatically.
-
- callbacks_proxy:
- an instance with methods as code of callbacks.
- It means it has methods like on_button1_clicked, on_entry1_activate, etc.
- """
- self.glade.signal_autoconnect(callbacks_proxy)
-
- def normalize_names(self):
- """
- It is internally used to normalize the name of the widgets.
- It means a widget named foo:vbox-dialog in glade
- is refered self.vbox_dialog in the code.
-
- It also sets a data "prefixes" with the list of
- prefixes a widget has for each widget.
- """
- for widget in self.get_widgets():
- widget_name = gtk.Widget.get_name(widget)
- prefixes_name_l = widget_name.split(":")
- prefixes = prefixes_name_l[ : -1]
- widget_api_name = prefixes_name_l[-1]
- widget_api_name = "_".join( re.findall(tokenize.Name, widget_api_name) )
- gtk.Widget.set_name(widget, widget_api_name)
- if hasattr(self, widget_api_name):
- raise AttributeError("instance %s already has an attribute %s" % (self,widget_api_name))
- else:
- setattr(self, widget_api_name, widget)
- if prefixes:
- gtk.Widget.set_data(widget, "prefixes", prefixes)
-
- def add_prefix_actions(self, prefix_actions_proxy):
- """
- By using a gui designer (glade-2, gazpacho, etc)
- widgets can have a prefix in theirs names
- like foo:entry1 or foo:label3
- It means entry1 and label3 has a prefix action named foo.
-
- Then, prefix_actions_proxy must have a method named prefix_foo which
- is called everytime a widget with prefix foo is found, using the found widget
- as argument.
-
- prefix_actions_proxy:
- An instance with methods as prefix actions.
- It means it has methods like prefix_foo, prefix_bar, etc.
- """
- prefix_s = "prefix_"
- prefix_pos = len(prefix_s)
-
- is_method = lambda t : callable( t[1] )
- is_prefix_action = lambda t : t[0].startswith(prefix_s)
- drop_prefix = lambda (k,w): (k[prefix_pos:],w)
-
- members_t = inspect.getmembers(prefix_actions_proxy)
- methods_t = filter(is_method, members_t)
- prefix_actions_t = filter(is_prefix_action, methods_t)
- prefix_actions_d = dict( map(drop_prefix, prefix_actions_t) )
-
- for widget in self.get_widgets():
- prefixes = gtk.Widget.get_data(widget, "prefixes")
- if prefixes:
- for prefix in prefixes:
- if prefix in prefix_actions_d:
- prefix_action = prefix_actions_d[prefix]
- prefix_action(widget)
-
- def custom_handler(self,
- glade, function_name, widget_name,
- str1, str2, int1, int2):
- """
- Generic handler for creating custom widgets, internally used to
- enable custom widgets (custom widgets of glade).
-
- The custom widgets have a creation function specified in design time.
- Those creation functions are always called with str1,str2,int1,int2 as
- arguments, that are values specified in design time.
-
- Methods of classes inheriting from SimpleGladeApp are used as
- creation functions automatically.
-
- If a custom widget has create_foo as creation function, then the
- method named create_foo is called with str1,str2,int1,int2 as arguments.
- """
- try:
- handler = getattr(self, function_name)
- return handler(str1, str2, int1, int2)
- except AttributeError:
- return None
-
- def gtk_widget_show(self, widget, *args):
- """
- Predefined callback.
- The widget is showed.
- Equivalent to widget.show()
- """
- widget.show()
-
- def gtk_widget_hide(self, widget, *args):
- """
- Predefined callback.
- The widget is hidden.
- Equivalent to widget.hide()
- """
- widget.hide()
-
- def gtk_widget_grab_focus(self, widget, *args):
- """
- Predefined callback.
- The widget grabs the focus.
- Equivalent to widget.grab_focus()
- """
- widget.grab_focus()
-
- def gtk_widget_destroy(self, widget, *args):
- """
- Predefined callback.
- The widget is destroyed.
- Equivalent to widget.destroy()
- """
- widget.destroy()
-
- def gtk_window_activate_default(self, window, *args):
- """
- Predefined callback.
- The default widget of the window is activated.
- Equivalent to window.activate_default()
- """
- widget.activate_default()
-
- def gtk_true(self, *args):
- """
- Predefined callback.
- Equivalent to return True in a callback.
- Useful for stopping propagation of signals.
- """
- return True
-
- def gtk_false(self, *args):
- """
- Predefined callback.
- Equivalent to return False in a callback.
- """
- return False
-
- def gtk_main_quit(self, *args):
- """
- Predefined callback.
- Equivalent to self.quit()
- """
- self.quit()
-
- def main(self):
- """
- Starts the main loop of processing events.
- The default implementation calls gtk.main()
-
- Useful for applications that needs a non gtk main loop.
- For example, applications based on gstreamer needs to override
- this method with gst.main()
-
- Do not directly call this method in your programs.
- Use the method run() instead.
- """
- gtk.main()
-
- def quit(self):
- """
- Quit processing events.
- The default implementation calls gtk.main_quit()
-
- Useful for applications that needs a non gtk main loop.
- For example, applications based on gstreamer needs to override
- this method with gst.main_quit()
- """
- gtk.main_quit()
-
- def run(self):
- """
- Starts the main loop of processing events checking for Control-C.
-
- The default implementation checks wheter a Control-C is pressed,
- then calls on_keyboard_interrupt().
-
- Use this method for starting programs.
- """
- try:
- self.main()
- except KeyboardInterrupt:
- self.on_keyboard_interrupt()
-
- def on_keyboard_interrupt(self):
- """
- This method is called by the default implementation of run()
- after a program is finished by pressing Control-C.
- """
- pass
-
- def install_custom_handler(self, custom_handler):
- gtk.glade.set_custom_handler(custom_handler)
-
- def create_glade(self, glade_path, root, domain):
- return gtk.glade.XML(self.glade_path, root, domain)
-
- def get_widget(self, widget_name):
- return self.glade.get_widget(widget_name)
-
- def get_widgets(self):
- return self.glade.get_widget_prefix("")
diff --git a/avahi-python/avahi-discover/__init__.py b/avahi-python/avahi-discover/__init__.py
index b2cd7d8..6f3ec7f 100755
--- a/avahi-python/avahi-discover/__init__.py
+++ b/avahi-python/avahi-discover/__init__.py
@@ -1,7 +1,5 @@
#!@PYTHON@
# -*-python-*-
-# $Id$
-
# This file is part of avahi.
#
# avahi is free software; you can redistribute it and/or modify it
diff --git a/avahi-python/avahi-discover/avahi-discover.in b/avahi-python/avahi-discover/avahi-discover.in
index 0558424..ac6b657 100755
--- a/avahi-python/avahi-discover/avahi-discover.in
+++ b/avahi-python/avahi-discover/avahi-discover.in
@@ -1,7 +1,5 @@
#!@PYTHON@
# -*-python-*-
-# $Id$
-
# This file is part of avahi.
#
# avahi is free software; you can redistribute it and/or modify it
@@ -23,13 +21,13 @@ import os, sys
try:
import avahi, gettext, gtk, gobject, dbus, avahi.ServiceTypeDatabase
- from avahi_discover.SimpleGladeApp import SimpleGladeApp
- gtk.glade.bindtextdomain(@GETTEXT_PACKAGE@, @LOCALEDIR@)
- gtk.glade.textdomain(@GETTEXT_PACKAGE@)
_ = gettext.gettext
except ImportError, e:
print "Sorry, to use this tool you need to install Avahi, pygtk and python-dbus.\n Error: %s" % e
sys.exit(1)
+except Exception, e:
+ print "Failed to initialize: %s" % e
+ sys.exit(1)
## !!NOTE!! ##
@@ -52,15 +50,20 @@ def error_msg(msg):
d.run()
d.destroy()
-glade_dir = "@interfacesdir@"
+ui_dir = "@interfacesdir@"
service_type_db = avahi.ServiceTypeDatabase.ServiceTypeDatabase()
-class Main_window(SimpleGladeApp):
- def __init__(self, path="avahi-discover.glade", root="main_window", domain=None, **kwargs):
- path = os.path.join(glade_dir, path)
+class Main_window:
+ def __init__(self, path="avahi-discover.ui", root="main_window", domain=None, **kwargs):
+ path = os.path.join(ui_dir, path)
gtk.window_set_default_icon_name("network-wired")
- SimpleGladeApp.__init__(self, path, root, domain, **kwargs)
+ self.ui = gtk.Builder()
+ self.ui.add_from_file(path)
+ self.ui.connect_signals(self)
+ self.tree_view = self.ui.get_object("tree_view")
+ self.info_label = self.ui.get_object("info_label")
+ self.new()
def on_tree_view_cursor_changed(self, widget, *args):
(model, iter) = widget.get_selection().get_selected()
@@ -79,7 +82,7 @@ class Main_window(SimpleGladeApp):
if protocol == avahi.PROTO_INET6:
return "IPv6"
return "n/a"
-
+
def siocgifname(self, interface):
if interface <= 0:
return "n/a"
@@ -91,14 +94,14 @@ class Main_window(SimpleGladeApp):
return "Wide Area"
else:
return str(self.siocgifname(interface)) + " " + str(self.protoname(protocol))
-
+
def service_resolved(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags):
print "Service data for service '%s' of type '%s' in domain '%s' on %i.%i:" % (name, stype, domain, interface, protocol)
print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, str(avahi.txt_array_to_string_array(txt)))
self.update_label(interface, protocol, name, stype, domain, host, aprotocol, address, port, avahi.txt_array_to_string_array(txt))
-
+
def print_error(self, err):
error_label = "<b>Error:</b> %s" % (err)
self.info_label.set_markup(error_label)
@@ -111,13 +114,13 @@ class Main_window(SimpleGladeApp):
return service_type_db[stype]
except KeyError:
return stype
-
+
def new_service(self, interface, protocol, name, stype, domain, flags):
print "Found service '%s' of type '%s' in domain '%s' on %i.%i." % (name, stype, domain, interface, protocol)
if self.zc_ifaces.has_key((interface,protocol)) == False:
ifn = self.get_interface_name(interface, protocol)
-
+
self.zc_ifaces[(interface,protocol)] = self.insert_row(self.treemodel, None, ifn, None,interface,protocol,None,domain)
if self.zc_domains.has_key((interface,protocol,domain)) == False:
self.zc_domains[(interface,protocol,domain)] = self.insert_row(self.treemodel, self.zc_ifaces[(interface,protocol)], domain,None,interface,protocol,None,domain)
@@ -151,16 +154,16 @@ class Main_window(SimpleGladeApp):
parent = self.treemodel.iter_parent(treeiter)
self.treemodel.remove(treeiter)
del self.zc_ifaces[(interface,protocol)]
-
+
def new_service_type(self, interface, protocol, stype, domain, flags):
global service_browsers
- # Are we already browsing this domain for this type?
+ # Are we already browsing this domain for this type?
if service_browsers.has_key((interface, protocol, stype, domain)):
return
-
+
print "Browsing for services of type '%s' in domain '%s' on %i.%i ..." % (stype, domain, interface, protocol)
-
+
b = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceBrowserNew(interface, protocol, stype, domain, dbus.UInt32(0))), avahi.DBUS_INTERFACE_SERVICE_BROWSER)
b.connect_to_signal('ItemNew', self.new_service)
b.connect_to_signal('ItemRemove', self.remove_service)
@@ -183,7 +186,7 @@ class Main_window(SimpleGladeApp):
print e
error_msg("You should check that the avahi daemon is running.\n\nError : %s" % e)
sys.exit(0)
-
+
b.connect_to_signal('ItemNew', self.new_service_type)
service_type_browsers[(interface, protocol, domain)] = b
@@ -209,7 +212,7 @@ class Main_window(SimpleGladeApp):
if len(tmp[0]) > 0:
res[tmp[0]] = tmp[1]
return res
-
+
def update_label(self,interface, protocol, name, stype, domain, host, aprotocol, address, port, txt):
if len(txt) != 0:
@@ -230,7 +233,6 @@ class Main_window(SimpleGladeApp):
return myiter
def new(self):
- print "A new main_window has been created"
self.treemodel=gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
self.tree_view.set_model(self.treemodel)
@@ -249,14 +251,18 @@ class Main_window(SimpleGladeApp):
self.zc_domains = {}
self.zc_types = {}
self.services_browsed = {}
-
- self.bus = dbus.SystemBus()
- self.server = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)
+
+ try:
+ self.bus = dbus.SystemBus()
+ self.server = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)
+ except Exception, e:
+ print "Failed to connect to Avahi Server (Is it running?): %s" % e
+ sys.exit(1)
if self.domain is None:
# Explicitly browse .local
self.browse_domain(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "local")
-
+
# Browse for other browsable domains
db = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.DomainBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "", avahi.DOMAIN_BROWSER_BROWSE, dbus.UInt32(0))), avahi.DBUS_INTERFACE_DOMAIN_BROWSER)
db.connect_to_signal('ItemNew', self.new_domain)
@@ -264,13 +270,12 @@ class Main_window(SimpleGladeApp):
# Just browse the domain the user wants us to browse
self.browse_domain(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, domain)
-
+ def gtk_main_quit(self, *args):
+ gtk.main_quit()
+
def main():
main_window = Main_window()
+ gtk.main()
- main_window.run()
-
if __name__ == "__main__":
main()
-
-
diff --git a/avahi-python/avahi/Makefile.am b/avahi-python/avahi/Makefile.am
index c0c9c34..907c5eb 100644
--- a/avahi-python/avahi/Makefile.am
+++ b/avahi-python/avahi/Makefile.am
@@ -1,5 +1,3 @@
-# $Id$
-
# This file is part of avahi.
#
# avahi is free software; you can redistribute it and/or modify it
@@ -28,12 +26,12 @@ if HAVE_GDBM
nodist_avahi_SCRIPTS = ServiceTypeDatabase.py
ServiceTypeDatabase.py: ServiceTypeDatabase.py.in
- sed -e 's,@PYTHON\@,$(PYTHON),g' \
+ $(AM_V_GEN)sed -e 's,@PYTHON\@,$(PYTHON),g' \
-e 's,@DBM\@,gdbm,g' \
-e 's,@FIRST_KEY\@,key = self.db.firstkey(),g' \
-e 's,@CHECK_KEY\@,while key is not None:,g' \
-e 's,@NEXT_KEY\@,key = self.db.nextkey(key),g' \
- -e 's,@pkglibdir\@,$(pkglibdir),g' $< > $@
+ -e 's,@pkglibdir\@,$(pkglibdir),g' $< > $@ && \
chmod +x $@
endif
@@ -41,12 +39,12 @@ if HAVE_DBM
nodist_avahi_SCRIPTS = ServiceTypeDatabase.py
ServiceTypeDatabase.py: ServiceTypeDatabase.py.in
- sed -e 's,@PYTHON\@,$(PYTHON),g' \
+ $(AM_V_GEN)sed -e 's,@PYTHON\@,$(PYTHON),g' \
-e 's,@DBM\@,dbm,g' \
-e 's,@FIRST_KEY\@,keys = self.db.keys(),g' \
-e 's,@CHECK_KEY\@,for key in keys:,g' \
-e 's,@NEXT_KEY\@,,g' \
- -e 's,@pkglibdir\@,$(pkglibdir),g' $< > $@
+ -e 's,@pkglibdir\@,$(pkglibdir),g' $< > $@ && \
chmod +x $@
endif
diff --git a/avahi-python/avahi/ServiceTypeDatabase.py.in b/avahi-python/avahi/ServiceTypeDatabase.py.in
index d134510..8ad8d5e 100644
--- a/avahi-python/avahi/ServiceTypeDatabase.py.in
+++ b/avahi-python/avahi/ServiceTypeDatabase.py.in
@@ -1,7 +1,5 @@
#!@PYTHON@
# -*-python-*-
-# $Id$
-
# This file is part of avahi.
#
# avahi is free software; you can redistribute it and/or modify it
@@ -26,6 +24,7 @@ import re
locale.setlocale(locale.LC_ALL, '')
class ServiceTypeDatabase:
+ """ServiceTypeDatabase maps service types to descriptions"""
def __init__(self, filename = "@pkglibdir@/service-types.db"):
@@ -68,14 +67,7 @@ class ServiceTypeDatabase:
def items(self):
- items = []
- @FIRST_KEY@
- @CHECK_KEY@
- if re.search('_[a-zA-Z0-9-]+\._[a-zA-Z0-9-]+', key) and not re.search('_[a-zA-Z0-9-]+\._[a-zA-Z0-9-]+\[.*\]', key):
- localized_service_name = self[key]
- items.append((key, localized_service_name))
- @NEXT_KEY@
- return items
+ return list(self.iteritems())
def has_key(self, key):
@@ -96,6 +88,52 @@ class ServiceTypeDatabase:
return False
+ def __iter__(self):
+
+ @FIRST_KEY@
+ @CHECK_KEY@
+
+ if re.search('_[a-zA-Z0-9-]+\._[a-zA-Z0-9-]+', key) and not re.search('_[a-zA-Z0-9-]+\._[a-zA-Z0-9-]+\[.*\]', key):
+ yield key
+
+ @NEXT_KEY@
+
+ def __len__(self):
+
+ count = 0
+ for _ in self:
+
+ count+=1
+
+ self.__len__ = lambda : count
+ return len(self)
+
+ def get(self, key, default=None):
+
+ if key in self:
+ return self[key]
+ else:
+ return default
+
+ def iteritems(self):
+
+ return ((key, self[key]) for key in self)
+
+ def iterkeys(self):
+
+ return self.__iter__()
+
+ def itervalues(self):
+
+ return (self[key] for key in self)
+
+ def keys(self):
+
+ return list(self)
+
+ def values(self):
+
+ return list(self.itervalues())
if __name__ == "__main__":
@@ -107,4 +145,17 @@ if __name__ == "__main__":
print b["_webdav._tcp"]
print b["_webdavs._tcp"]
- print b["gurki._tcp"]
+ print b.get("gurki._tcp")
+ print len(b)
+
+ for key, _ in zip(b, xrange(3)):
+
+ print key
+
+ for key, _ in zip(b.iteritems(), xrange(3)):
+
+ print key
+
+ for key, _ in zip(b.itervalues(), xrange(3)):
+
+ print key
diff --git a/avahi-python/avahi/__init__.py b/avahi-python/avahi/__init__.py
index 81e2754..7b45029 100644
--- a/avahi-python/avahi/__init__.py
+++ b/avahi-python/avahi/__init__.py
@@ -1,5 +1,3 @@
-# $Id$
-
# This file is part of avahi.
#
# avahi is free software; you can redistribute it and/or modify it