PEP8 white space and long line fixes

This commit is contained in:
Sascha Silbe
2009-08-25 21:12:40 +02:00
parent ecdaf6b795
commit c9e63eb8ea
50 changed files with 574 additions and 291 deletions
+18 -16
View File
@@ -26,8 +26,10 @@ import dbus
import gobject
import telepathy
_logger = logging.getLogger('sugar.presence.activity')
class Activity(gobject.GObject):
"""UI interface for an Activity in the presence service
@@ -43,23 +45,23 @@ class Activity(gobject.GObject):
"""
__gsignals__ = {
'buddy-joined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'buddy-left': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'new-channel': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'joined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT])),
([gobject.TYPE_PYOBJECT])),
'buddy-left': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'new-channel': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'joined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT])),
}
__gproperties__ = {
'id' : (str, None, None, None, gobject.PARAM_READABLE),
'name' : (str, None, None, None, gobject.PARAM_READWRITE),
'tags' : (str, None, None, None, gobject.PARAM_READWRITE),
'color' : (str, None, None, None, gobject.PARAM_READWRITE),
'type' : (str, None, None, None, gobject.PARAM_READABLE),
'private' : (bool, None, None, True, gobject.PARAM_READWRITE),
'joined' : (bool, None, None, False, gobject.PARAM_READABLE),
'id': (str, None, None, None, gobject.PARAM_READABLE),
'name': (str, None, None, None, gobject.PARAM_READWRITE),
'tags': (str, None, None, None, gobject.PARAM_READWRITE),
'color': (str, None, None, None, gobject.PARAM_READWRITE),
'type': (str, None, None, None, gobject.PARAM_READABLE),
'private': (bool, None, None, True, gobject.PARAM_READWRITE),
'joined': (bool, None, None, False, gobject.PARAM_READABLE),
}
_PRESENCE_SERVICE = "org.laptop.Sugar.Presence"
@@ -175,10 +177,10 @@ class Activity(gobject.GObject):
elif pspec.name == "private":
return self._private
# FIXME: need an asynchronous API to set these properties, particularly
# 'private'
def do_set_property(self, pspec, val):
"""Set a particular property in our property dictionary"""
# FIXME: need an asynchronous API to set these properties,
# particularly 'private'
if pspec.name == "name":
self._activity.SetProperties({'name': val})
self._name = val
+14 -13
View File
@@ -24,6 +24,7 @@ import gobject
import gtk
import dbus
class Buddy(gobject.GObject):
"""UI interface for a Buddy in the presence service
@@ -40,26 +41,26 @@ class Buddy(gobject.GObject):
'icon': (XXX pixel data for an icon?)
See __gproperties__
"""
__gsignals__ = {
'icon-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([])),
'icon-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
'joined-activity': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
([gobject.TYPE_PYOBJECT])),
'left-activity': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
([gobject.TYPE_PYOBJECT])),
'property-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
([gobject.TYPE_PYOBJECT])),
}
__gproperties__ = {
'key' : (str, None, None, None, gobject.PARAM_READABLE),
'icon' : (str, None, None, None, gobject.PARAM_READABLE),
'nick' : (str, None, None, None, gobject.PARAM_READABLE),
'color' : (str, None, None, None, gobject.PARAM_READABLE),
'current-activity' : (object, None, None, gobject.PARAM_READABLE),
'owner' : (bool, None, None, False, gobject.PARAM_READABLE),
'ip4-address' : (str, None, None, None, gobject.PARAM_READABLE),
'tags' : (str, None, None, None, gobject.PARAM_READABLE),
'key': (str, None, None, None, gobject.PARAM_READABLE),
'icon': (str, None, None, None, gobject.PARAM_READABLE),
'nick': (str, None, None, None, gobject.PARAM_READABLE),
'color': (str, None, None, None, gobject.PARAM_READABLE),
'current-activity': (object, None, None, gobject.PARAM_READABLE),
'owner': (bool, None, None, False, gobject.PARAM_READABLE),
'ip4-address': (str, None, None, None, gobject.PARAM_READABLE),
'tags': (str, None, None, None, gobject.PARAM_READABLE),
}
_PRESENCE_SERVICE = "org.laptop.Sugar.Presence"
+58 -67
View File
@@ -63,13 +63,12 @@ class PresenceService(gobject.GObject):
([gobject.TYPE_PYOBJECT])),
'activity-shared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT,
gobject.TYPE_PYOBJECT]))
gobject.TYPE_PYOBJECT])),
}
_PS_BUDDY_OP = DBUS_PATH + "/Buddies/"
_PS_ACTIVITY_OP = DBUS_PATH + "/Activities/"
def __init__(self, allow_offline_iface=True):
"""Initialise the service and attempt to connect to events
"""
@@ -98,6 +97,7 @@ class PresenceService(gobject.GObject):
self._get_ps()
_ps_ = None
def _get_ps(self):
"""Retrieve dbus interface to PresenceService
@@ -123,17 +123,16 @@ class PresenceService(gobject.GObject):
self._bus.get_object(DBUS_SERVICE,
DBUS_PATH,
follow_name_owner_changes=True),
DBUS_INTERFACE
)
DBUS_INTERFACE)
except dbus.exceptions.DBusException, err:
_logger.error(
"""Failure retrieving %r interface from
the D-BUS service %r %r: %s""",
DBUS_INTERFACE, DBUS_SERVICE, DBUS_PATH, err
)
DBUS_INTERFACE, DBUS_SERVICE, DBUS_PATH, err)
if self._allow_offline_iface:
return _OfflineInterface()
raise RuntimeError("Failed to connect to the presence service.")
raise RuntimeError('Failed to connect to the presence '
'service.')
else:
self._ps_ = ps
ps.connect_to_signal('BuddyAppeared',
@@ -150,11 +149,9 @@ class PresenceService(gobject.GObject):
self._private_invitation_cb)
return self._ps_
_ps = property(
_get_ps, None, None,
_ps = property(_get_ps, None, None,
"""DBUS interface to the PresenceService
(services/presence/presenceservice)"""
)
(services/presence/presenceservice)""")
def _new_object(self, object_path):
"""Turn new object path into (cached) Buddy/Activity instance
@@ -207,7 +204,8 @@ class PresenceService(gobject.GObject):
return False
def _buddy_appeared_cb(self, op):
"""Callback for dbus event (forwards to method to emit GObject event)"""
"""Callback for dbus event (forwards to method to emit GObject
event)"""
gobject.idle_add(self._emit_buddy_appeared_signal, op)
def _emit_buddy_disappeared_signal(self, object_path):
@@ -218,9 +216,9 @@ class PresenceService(gobject.GObject):
obj = self._objcache[object_path]
self.emit('buddy-disappeared', obj)
# We cannot maintain the object in the cache because that would keep
# a lot of objects from being collected. That includes UI objects
# due to signals using strong references.
# We cannot maintain the object in the cache because that would
# keep a lot of objects from being collected. That includes UI
# objects due to signals using strong references.
# If we want to cache some despite the memory usage increase,
# we could use a LRU cache limited to some value.
del self._objcache[object_path]
@@ -229,7 +227,8 @@ class PresenceService(gobject.GObject):
return False
def _buddy_disappeared_cb(self, object_path):
"""Callback for dbus event (forwards to method to emit GObject event)"""
"""Callback for dbus event (forwards to method to emit GObject
event)"""
gobject.idle_add(self._emit_buddy_disappeared_signal, object_path)
def _emit_activity_invitation_signal(self, activity_path, buddy_path,
@@ -240,7 +239,8 @@ class PresenceService(gobject.GObject):
return False
def _activity_invitation_cb(self, activity_path, buddy_path, message):
"""Callback for dbus event (forwards to method to emit GObject event)"""
"""Callback for dbus event (forwards to method to emit GObject
event)"""
gobject.idle_add(self._emit_activity_invitation_signal, activity_path,
buddy_path, message)
@@ -252,7 +252,8 @@ class PresenceService(gobject.GObject):
return False
def _private_invitation_cb(self, bus_name, connection, channel, chan_type):
"""Callback for dbus event (forwards to method to emit GObject event)"""
"""Callback for dbus event (forwards to method to emit GObject
event)"""
gobject.idle_add(self._emit_private_invitation_signal, bus_name,
connection, channel, chan_type)
@@ -262,7 +263,8 @@ class PresenceService(gobject.GObject):
return False
def _activity_appeared_cb(self, object_path):
"""Callback for dbus event (forwards to method to emit GObject event)"""
"""Callback for dbus event (forwards to method to emit GObject
event)"""
gobject.idle_add(self._emit_activity_appeared_signal, object_path)
def _emit_activity_disappeared_signal(self, object_path):
@@ -271,7 +273,8 @@ class PresenceService(gobject.GObject):
return False
def _activity_disappeared_cb(self, object_path):
"""Callback for dbus event (forwards to method to emit GObject event)"""
"""Callback for dbus event (forwards to method to emit GObject
event)"""
gobject.idle_add(self._emit_activity_disappeared_signal, object_path)
def get(self, object_path):
@@ -288,11 +291,9 @@ class PresenceService(gobject.GObject):
"""
try:
resp = self._ps.GetActivities()
except dbus.exceptions.DBusException, err:
_logger.warn(
"""Unable to retrieve activity list from presence service: %s"""
% err
)
except dbus.exceptions.DBusException:
_logger.exception('Unable to retrieve activity list from '
'presence service')
return []
else:
acts = []
@@ -311,10 +312,8 @@ class PresenceService(gobject.GObject):
if error_handler:
error_handler(e)
else:
_logger.warn(
"""Unable to retrieve activity-list from presence service: %s"""
% e
)
_logger.warn('Unable to retrieve activity-list from presence '
'service: %s', e)
def get_activities_async(self, reply_handler=None, error_handler=None):
"""Retrieve set of all activities from service asyncronously
@@ -331,7 +330,6 @@ class PresenceService(gobject.GObject):
error_handler=lambda e: \
self._get_activities_error_cb(error_handler, e))
def get_activity(self, activity_id, warn_if_none=True):
"""Retrieve single Activity object for the given unique id
@@ -357,11 +355,9 @@ class PresenceService(gobject.GObject):
"""
try:
resp = self._ps.GetBuddies()
except dbus.exceptions.DBusException, err:
_logger.warn(
"""Unable to retrieve buddy-list from presence service: %s"""
% err
)
except dbus.exceptions.DBusException:
_logger.exception('Unable to retrieve buddy-list from presence '
'service')
return []
else:
buddies = []
@@ -380,10 +376,8 @@ class PresenceService(gobject.GObject):
if error_handler:
error_handler(e)
else:
_logger.warn(
"""Unable to retrieve buddy-list from presence service: %s"""
% e
)
_logger.warn('Unable to retrieve buddy-list from presence '
'service: %s', e)
def get_buddies_async(self, reply_handler=None, error_handler=None):
"""Retrieve set of all buddies from service asyncronously
@@ -411,12 +405,9 @@ class PresenceService(gobject.GObject):
"""
try:
buddy_op = self._ps.GetBuddyByPublicKey(dbus.ByteArray(key))
except dbus.exceptions.DBusException, err:
_logger.warn(
"""Unable to retrieve buddy handle
for %r from presence service: %s"""
% key, err
)
except dbus.exceptions.DBusException:
_logger.exception('Unable to retrieve buddy handle for %r from '
'presence service', key)
return None
return self._new_object(buddy_op)
@@ -450,12 +441,9 @@ class PresenceService(gobject.GObject):
"""Retrieves the laptop "owner" Buddy object."""
try:
owner_op = self._ps.GetOwner()
except dbus.exceptions.DBusException, err:
_logger.warn(
"""Unable to retrieve local user/owner
from presence service: %s"""
% err
)
except dbus.exceptions.DBusException:
_logger.exception('Unable to retrieve local user/owner from '
'presence service')
raise RuntimeError("Could not get owner object.")
return self._new_object(owner_op)
@@ -526,7 +514,8 @@ class PresenceService(gobject.GObject):
return bus_name, object_path
class _OfflineInterface( object ):
class _OfflineInterface(object):
"""Offline-presence-service interface
Used to mimic the behaviour of a real PresenceService sufficiently
@@ -535,33 +524,33 @@ class _OfflineInterface( object ):
XXX we could likely return a "MockOwner" object reasonably
easily, but would it be worth it?
"""
def raiseException( self, *args, **named ):
def raiseException(self, *args, **named):
"""Raise dbus.exceptions.DBusException"""
raise dbus.exceptions.DBusException(
"""PresenceService Interface not available"""
)
raise dbus.exceptions.DBusException('PresenceService Interface not '
'available')
GetActivities = raiseException
GetActivityById = raiseException
GetBuddies = raiseException
GetBuddyByPublicKey = raiseException
GetOwner = raiseException
GetPreferredConnection = raiseException
def ShareActivity(
self, actid, atype, name, properties,
reply_handler, error_handler,
):
def ShareActivity(self, actid, atype, name, properties, reply_handler,
error_handler):
"""Pretend to share and fail..."""
exc = IOError(
"""Unable to share activity as PresenceService
is not currenly available"""
)
return error_handler( exc )
exc = IOError('Unable to share activity as PresenceService is not '
'currently available')
return error_handler(exc)
class _MockPresenceService(gobject.GObject):
"""Test fixture allowing testing of items that use PresenceService
See PresenceService for usage and purpose
"""
__gsignals__ = {
'buddy-appeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
@@ -575,7 +564,7 @@ class _MockPresenceService(gobject.GObject):
'activity-appeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'activity-disappeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT]))
([gobject.TYPE_PYOBJECT])),
}
def __init__(self):
@@ -599,11 +588,13 @@ class _MockPresenceService(gobject.GObject):
def share_activity(self, activity, properties=None):
return None
_ps = None
def get_instance(allow_offline_iface=False):
"""Retrieve this process' view of the PresenceService"""
global _ps
if not _ps:
_ps = PresenceService(allow_offline_iface)
return _ps
+5 -5
View File
@@ -20,7 +20,7 @@
STABLE.
"""
__all__ = ('TubeConnection',)
__all__ = ('TubeConnection', )
__docformat__ = 'reStructuredText'
@@ -34,10 +34,10 @@ logger = logging.getLogger('telepathy.tubeconn')
class TubeConnection(Connection):
# pylint: disable-msg=W0212
# Confused by __new__
def __new__(cls, conn, tubes_iface, tube_id, address=None,
group_iface=None, mainloop=None):
# pylint: disable-msg=W0212
# Confused by __new__
if address is None:
address = tubes_iface.GetDBusTubeAddress(tube_id)
self = super(TubeConnection, cls).__new__(cls, address,
@@ -58,9 +58,9 @@ class TubeConnection(Connection):
return self
# pylint: disable-msg=W0201
# Confused by __new__
def _on_get_self_handle_reply(self, handle):
# pylint: disable-msg=W0201
# Confused by __new__
self.self_handle = handle
match = self._tubes_iface.connect_to_signal('DBusNamesChanged',
self._on_dbus_names_changed)