FS#56934 - [python-dbus] python3.x does not ship dict.has_key()
Attached to Project:
Arch Linux
Opened by Martin Kühne (mar77i) - Wednesday, 03 January 2018, 10:57 GMT
Last edited by freswa (frederik) - Saturday, 26 September 2020, 20:22 GMT
Opened by Martin Kühne (mar77i) - Wednesday, 03 January 2018, 10:57 GMT
Last edited by freswa (frederik) - Saturday, 26 September 2020, 20:22 GMT
|
Details
Description:
avahi-discover breaks with an exception from python-dbus, because somehow the python-dbus connection.py uses the python2 dict.has_key(), which is no longer available. Additional info: * package version(s) - extra/python-dbus 1.2.4-2 - extra/avahi 0.7-2 Steps to reproduce: $ avahi-discover Browsing domain 'local' on -1.-1 ... ERROR:dbus.connection:Exception in handler for D-Bus signal: Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/dbus/connection.py", line 230, in maybe_handle_message self._handler(*args, **kwargs) File "/bin/avahi-discover", line 212, in new_domain if self.zc_ifaces.has_key((interface,protocol)) == False: AttributeError: 'dict' object has no attribute 'has_key' |
This task depends upon
Closed by freswa (frederik)
Saturday, 26 September 2020, 20:22 GMT
Reason for closing: Fixed
Additional comments about closing: avahi 0.8+6+g751be80-1 please see comments for details.
Saturday, 26 September 2020, 20:22 GMT
Reason for closing: Fixed
Additional comments about closing: avahi 0.8+6+g751be80-1 please see comments for details.
#!/usr/bin/python3
# -*-python-*-
# This file is part of avahi.
This seems like a bug in avahi to me not python-dbus avahi-discover specifies python3
https://github.com/lathiat/avahi/blob/6242e5f0fe001b7de2ccaa9431db279b2ee76b83/avahi-python/avahi-discover/avahi-discover.py#L270
self.zc_ifaces = {} would be a python3 dictionary
https://github.com/lathiat/avahi/blob/6242e5f0fe001b7de2ccaa9431db279b2ee76b83/avahi-python/avahi-discover/avahi-discover.py#L212
if self.zc_ifaces.has_key((interface,protocol)) == False:
https://docs.python.org/3.0/whatsnew/3.0.html#builtins Removed. dict.has_key() – use the in operator instead.
so using the removed builtin has_key fails
1) change the first line of /usr/bin/avahi-discover from #!/usr/bin/python3 to #!/usr/bin/python2 and ensure the package python2-dbus is installed
2) sudo 2to3 -nw /usr/bin/avahi-discover
to reset the file to its original state `pacman -S avahi`
Using 2to3 works great here too:
# 2to3 -nw /usr/bin/avahi-discover
RefactoringTool: Skipping optional fixer: buffer
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Refactored /usr/bin/avahi-discover
--- /usr/bin/avahi-discover (original)
+++ /usr/bin/avahi-discover (refactored)
@@ -17,7 +17,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA.
-from __future__ import print_function
+
import os, sys
@@ -209,10 +209,10 @@
self.new_service_type(interface, protocol, self.stype, domain)
def new_domain(self,interface, protocol, domain, flags):
- if self.zc_ifaces.has_key((interface,protocol)) == False:
+ if ((interface,protocol) in self.zc_ifaces) == 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:
+ if ((interface,protocol,domain) in self.zc_domains) == False:
self.zc_domains[(interface,protocol,domain)] = self.insert_row(self.treemodel, self.zc_ifaces[(interface,protocol)], domain,None,interface,protocol,None,domain)
if domain != "local":
self.browse_domain(interface, protocol, domain)
@@ -233,7 +233,7 @@
if len(txt) != 0:
txts = ""
txtd = self.pair_to_dict(txt)
- for k,v in txtd.items():
+ for k,v in list(txtd.items()):
txts+="<b>" + _("TXT") + " <i>%s</i></b> = %s\n" % (k,v)
else:
txts = "<b>" + _("TXT Data:") + "</b> <i>" + _("empty") + "</i>"
RefactoringTool: Files that were modified:
RefactoringTool: /usr/bin/avahi-discover
FS#55740could be closed after changing the twisted dependencyalthough avahi-bookmarks would still be broken as https://github.com/lathiat/avahi/blob/6242e5f0fe001b7de2ccaa9431db279b2ee76b83/avahi-python/avahi-bookmarks.in#L151
indents with a tab instead of spaces required to match the existing indentation
Needless to say that all of this should go upstream one way or another.
The patch for avahi-bookmarks turned out to be much more expansive than expected so keeping that using python2 is probably safer for now just fix optional dependencies python2-dbus and python2-gobject2
The patch for avahi-bookmarks in addition to general 2 to 3 compatibility fixes switches legacy GObject which is python2 only for gobject introspection which has bindings for both 2 and 3,
twisted.web's resource.Resource render_GET method requires a string to be returned under python2 but bytes under python3, accommodate this by checking python version so in theory the code
should still be python2 compatible.
avahi-bookmarks.patch (4.5 KiB)
[1] https://github.com/archlinux/svntogit-packages/commit/4a27138e2940c78bc52a20373d97ddad40a74ac5
[2] https://github.com/lathiat/avahi/commit/6bb345e84919870a98a052424383aff39db461f0