Port from Python 2 to six

Signed-off-by: James Cameron <quozl@laptop.org>
This commit is contained in:
Pro-Panda
2018-03-01 17:28:56 +05:30
committed by James Cameron
parent 6345da8e07
commit aa8a5e70c4
74 changed files with 623 additions and 700 deletions
+15 -9
View File
@@ -21,6 +21,7 @@
STABLE.
"""
import six
import logging
from functools import partial
@@ -124,6 +125,11 @@ class Activity(GObject.GObject):
def _start_tracking_properties(self):
bus = dbus.SessionBus()
arg_dict = dict(reply_handler=self.__got_properties_cb,
error_handler=self.__error_handler_cb)
if six.PY2:
arg_dict = arg_dict.update(utf8_strings=True)
self._get_properties_call = bus.call_async(
self.telepathy_conn.requested_bus_name,
self.telepathy_conn.object_path,
@@ -131,9 +137,7 @@ class Activity(GObject.GObject):
'GetProperties',
'u',
(self.room_handle,),
reply_handler=self.__got_properties_cb,
error_handler=self.__error_handler_cb,
utf8_strings=True)
arg_dict)
# As only one Activity instance is needed per activity process,
# we can afford listening to ActivityPropertiesChanged like this.
@@ -144,7 +148,7 @@ class Activity(GObject.GObject):
def __activity_properties_changed_cb(self, room_handle, properties):
_logger.debug('%r: Activity properties changed to %r' % (self,
properties))
properties))
self._update_properties(properties)
def __got_properties_cb(self, properties):
@@ -239,7 +243,7 @@ class Activity(GObject.GObject):
returns list of presence Buddy objects that we can successfully
create from the buddy object paths that PS has for this activity.
"""
return self._joined_buddies.values()
return list(self._joined_buddies.values())
def get_buddy_by_handle(self, handle):
"""Retrieve the Buddy object given a telepathy handle.
@@ -300,8 +304,9 @@ class Activity(GObject.GObject):
channel.connect_to_signal('Closed', self.__text_channel_closed_cb)
def __get_all_members_cb(self, members, local_pending, remote_pending):
_logger.debug('__get_all_members_cb %r %r' % (members,
self._text_channel_group_flags))
_logger.debug(
'__get_all_members_cb %r %r' %
(members, self._text_channel_group_flags))
if self._channel_self_handle in members:
members.remove(self._channel_self_handle)
@@ -631,8 +636,9 @@ class _JoinCommand(_BaseCommand):
self._add_self_to_channel()
def __text_channel_group_flags_changed_cb(self, added, removed):
_logger.debug('__text_channel_group_flags_changed_cb %r %r' % (added,
removed))
_logger.debug(
'__text_channel_group_flags_changed_cb %r %r' %
(added, removed))
self.text_channel_group_flags |= added
self.text_channel_group_flags &= ~removed
+9 -7
View File
@@ -22,7 +22,7 @@ STABLE.
"""
import logging
import six
from gi.repository import GObject
import dbus
from telepathy.interfaces import CONNECTION, \
@@ -103,7 +103,7 @@ class BaseBuddy(GObject.GObject):
def get_current_activity(self):
if self._current_activity is None:
return None
for activity in self._activities.values():
for activity in list(self._activities.values()):
if activity.props.id == self._current_activity:
return activity
return None
@@ -164,6 +164,12 @@ class Buddy(BaseBuddy):
dbus_interface=CONNECTION)
self.contact_handle = handles[0]
arg_dict = dict(reply_handler=self.__got_properties_cb,
error_handler=self.__error_handler_cb,
byte_arrays = True)
if six.PY2:
arg_dict = arg_dict.update(utf8_strings=True)
self._get_properties_call = bus.call_async(
connection_name,
connection.object_path,
@@ -171,10 +177,7 @@ class Buddy(BaseBuddy):
'GetProperties',
'u',
(self.contact_handle,),
reply_handler=self.__got_properties_cb,
error_handler=self.__error_handler_cb,
utf8_strings=True,
byte_arrays=True)
arg_dict)
self._get_attributes_call = bus.call_async(
connection_name,
@@ -245,4 +248,3 @@ class Owner(BaseBuddy):
self.props.nick = get_nick_name()
self.props.color = get_color().to_string()
+4 -2
View File
@@ -92,7 +92,8 @@ class ConnectionManager(object):
def get_preferred_connection(self):
best_connection = None, None
for account_path, connection in self._connections_per_account.items():
for account_path, connection in list(
self._connections_per_account.items()):
if 'salut' in account_path and connection.connected:
best_connection = account_path, connection.connection
elif 'gabble' in account_path and connection.connected:
@@ -107,7 +108,8 @@ class ConnectionManager(object):
return self._connections_per_account
def get_account_for_connection(self, connection_path):
for account_path, connection in self._connections_per_account.items():
for account_path, connection in list(
self._connections_per_account.items()):
if connection.connection.object_path == connection_path:
return account_path
return None
+4 -3
View File
@@ -78,7 +78,8 @@ class PresenceService(GObject.GObject):
connection_manager = get_connection_manager()
connections_per_account = \
connection_manager.get_connections_per_account()
for account_path, connection in connections_per_account.items():
for account_path, connection in list(
connections_per_account.items()):
if not connection.connected:
continue
logging.debug('Calling GetActivity on %s' % account_path)
@@ -86,13 +87,13 @@ class PresenceService(GObject.GObject):
room_handle = connection.connection.GetActivity(
activity_id,
dbus_interface=CONN_INTERFACE_ACTIVITY_PROPERTIES)
except dbus.exceptions.DBusException, e:
except dbus.exceptions.DBusException as e:
name = 'org.freedesktop.Telepathy.Error.NotAvailable'
if e.get_dbus_name() == name:
logging.debug("There's no shared activity with the id "
"%s" % activity_id)
elif e.get_dbus_name() == \
'org.freedesktop.DBus.Error.UnknownMethod':
'org.freedesktop.DBus.Error.UnknownMethod':
logging.warning(
'Telepathy Account %r does not support '
'Sugar collaboration', account_path)
+5 -2
View File
@@ -24,6 +24,7 @@ __all__ = ('TubeConnection', )
__docformat__ = 'reStructuredText'
import six
import logging
from dbus.connection import Connection
@@ -77,7 +78,9 @@ class TubeConnection(Connection):
def close(self):
self._dbus_names_changed_match.remove()
self._on_dbus_names_changed(self.tube_id, (), self.participants.keys())
self._on_dbus_names_changed(
self.tube_id, (), list(
self.participants.keys()))
super(TubeConnection, self).close()
def _on_get_dbus_names_reply(self, names):
@@ -111,6 +114,6 @@ class TubeConnection(Connection):
# GetDBusNames already returned: fake a participant add event
# immediately
added = []
for k, v in self.participants.iteritems():
for k, v in six.iteritems(self.participants):
added.append((k, v))
callback(added, [])