Skip to content
Permalink
Browse files
Coerce BaseBuddyModel.props.key to str
In Group View when a friend is made a traceback occurs.

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/jarabe/view/buddymenu.py", line 205, in _make_friend_cb
    friends.get_model().makefriend(self._buddy)
  File "/usr/lib/python3/dist-packages/jarabe/model/friends.py", line 130, in make_friend
    self.save()
  File "/usr/lib/python3/dist-packages,jarabe/model/friends.py", line 160, in save
    cp.add_section(section)
  File "/usr/lib/python3.8/configparser.py", line 1207, in add_section
    self._validate_value_types(section=section)
  File "/usr/lib/python3.8/configparser.py", line 1180, in _validate_value_types
    raise TypeError("section names must be strings")
TypeError: section names must be strings

In Group View when a friend is removed a traceback occurs.

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/jarabe/desktop/groupbox.py", line 67, in _friend_removed_cb
    icon = self._friend[key]
KeyError: "b'AAAA0...'"

Regression introduced aa18879; a
BaseBuddyModel.props.key is coerced to bytes before being sent to
Telepathy.

Telepathy API for connection interface buddy info key uses a
dbus.ByteArray.

A dbus.ByteArray is now a subclass of bytes, where in Python 2 it is a
subclass of str.

https://dbus.freedesktop.org/doc/dbus-python/PY3PORT.html

When the buddy key is set from bytes, convert to str in utf-8 encoding.

When the buddy key is sent to Telepathy, convert to bytes.

Signed-off-by: James Cameron <quozl@laptop.org>
  • Loading branch information
quozl committed Aug 24, 2020
1 parent 118fe73 commit 5810104
Showing 1 changed file with 5 additions and 3 deletions.
@@ -57,6 +57,9 @@ def get_key(self):
return self._key

def set_key(self, key):
if isinstance(key, bytes):
key = key.decode('utf-8')

self._key = key

key = GObject.Property(type=object, getter=get_key, setter=set_key)
@@ -160,9 +163,8 @@ def _sync_properties_on_connection(self, connection):
if CONNECTION_INTERFACE_BUDDY_INFO in connection:
properties = {}
if self.props.key is not None:
if isinstance(self.props.key, str):
self.props.key = self.props.key.encode()
properties['key'] = dbus.ByteArray(self.props.key)
properties['key'] = dbus.ByteArray(
self.props.key.encode('utf-8'))
if self.props.color is not None:
properties['color'] = self.props.color.to_string()

0 comments on commit 5810104

Please sign in to comment.