[telepathy-butterfly/master] Fixed some encoding issues in log messages and handles name
Louis-Francis Ratté-Boulianne
louis-francis.ratte-boulianne at collabora.co.uk
Wed Aug 12 10:15:31 PDT 2009
Now use __unicode__ instead of __repr__ in log messages
Handles name is now in unicode (instead of utf-8)
---
butterfly/aliasing.py | 2 +-
butterfly/channel/group.py | 39 +++++++++++++++++++++------------------
butterfly/channel/text.py | 10 +++++-----
butterfly/connection.py | 4 ++--
butterfly/handle.py | 6 +++---
butterfly/presence.py | 10 +++++++---
6 files changed, 39 insertions(+), 32 deletions(-)
diff --git a/butterfly/aliasing.py b/butterfly/aliasing.py
index 879ce4d..cd0656b 100644
--- a/butterfly/aliasing.py
+++ b/butterfly/aliasing.py
@@ -142,6 +142,6 @@ class ButterflyAliasing(
alias = contact.display_name
alias = unicode(alias, 'utf-8')
- logger.info("Contact %r alias changed to '%s'" % (handle, alias))
+ logger.info("Contact %s alias changed to '%s'" % (unicode(handle), alias))
self.AliasesChanged([(handle, alias)])
diff --git a/butterfly/channel/group.py b/butterfly/channel/group.py
index 1a898c2..569c1c1 100644
--- a/butterfly/channel/group.py
+++ b/butterfly/channel/group.py
@@ -47,7 +47,8 @@ class ButterflyGroupChannel(ButterflyListChannel,
@async
def create_group():
if self._handle.group is None:
- connection.msn_client.address_book.add_group(self._handle.name)
+ name = self._handle.name.encode("utf-8")
+ connection.msn_client.address_book.add_group(name)
create_group()
def AddMembers(self, contacts, message):
@@ -56,8 +57,8 @@ class ButterflyGroupChannel(ButterflyListChannel,
for contact_handle_id in contacts:
contact_handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT,
contact_handle_id)
- logger.info("Adding contact %r to pending group %r" %
- (contact_handle, self._handle))
+ logger.info("Adding contact %s to pending group %s" %
+ (unicode(contact_handle), unicode(self._handle)))
if contact_handle_id in self.__pending_remove:
self.__pending_remove.remove(contact_handle_id)
else:
@@ -67,8 +68,8 @@ class ButterflyGroupChannel(ButterflyListChannel,
for contact_handle_id in contacts:
contact_handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT,
contact_handle_id)
- logger.info("Adding contact %r to group %r" %
- (contact_handle, self._handle))
+ logger.info("Adding contact %s to group %s" %
+ (unicode(contact_handle), unicode(self._handle)))
contact = contact_handle.contact
group = self._handle.group
if contact is not None and contact.is_member(papyon.Membership.FORWARD):
@@ -82,8 +83,8 @@ class ButterflyGroupChannel(ButterflyListChannel,
for contact_handle_id in contacts:
contact_handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT,
contact_handle_id)
- logger.info("Adding contact %r to pending group %r" %
- (contact_handle, self._handle))
+ logger.info("Adding contact %s to pending group %s" %
+ (unicode(contact_handle), unicode(self._handle)))
if contact_handle_id in self.__pending_add:
self.__pending_add.remove(contact_handle_id)
else:
@@ -93,8 +94,8 @@ class ButterflyGroupChannel(ButterflyListChannel,
for contact_handle_id in contacts:
contact_handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT,
contact_handle_id)
- logger.info("Removing contact %r from pending group %r" %
- (contact_handle, self._handle))
+ logger.info("Removing contact %s from pending group %s" %
+ (unicode(contact_handle), unicode(self._handle)))
contact = contact_handle.contact
group = self._handle.group
if contact is not None and contact.is_member(papyon.Membership.FORWARD):
@@ -111,24 +112,25 @@ class ButterflyGroupChannel(ButterflyListChannel,
def _filter_contact(self, contact):
if contact.is_member(papyon.Membership.FORWARD):
for group in contact.groups:
- if group.name == self._handle.name:
+ if group.name.decode("utf-8") == self._handle.name:
return (True, False, False)
return (False, False, False)
def on_addressbook_group_added(self, group):
- if group.name == self._handle.name:
+ if group.name.decode("utf-8") == self._handle.name:
self.AddMembers(self.__pending_add, None)
self.__pending_add = []
self.RemoveMembers(self.__pending_remove, None)
self.__pending_remove = []
def on_addressbook_group_deleted(self, group):
- if group.name == self._handle.name:
+ if group.name.decode("utf-8") == self._handle.name:
self.Closed()
self._conn.remove_channel(self)
def on_addressbook_group_contact_added(self, group, contact):
- if group.name == self._handle.name:
+ group_name = group.name.decode("utf-8")
+ if group_name == self._handle.name:
handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
contact.account, contact.network_id)
@@ -138,11 +140,12 @@ class ButterflyGroupChannel(ButterflyListChannel,
self.MembersChanged('', added, (), (), (), 0,
telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
- logger.debug("Contact %s added to group %s" % (handle.name,
- group.name))
+ logger.debug("Contact %s added to group %s" %
+ (handle.name, group_name))
def on_addressbook_group_contact_deleted(self, group, contact):
- if group.name == self._handle.name:
+ group_name = group.name.decode("utf-8")
+ if group_name == self._handle.name:
handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
contact.account, contact.network_id)
@@ -152,6 +155,6 @@ class ButterflyGroupChannel(ButterflyListChannel,
self.MembersChanged('', (), removed, (), (), 0,
telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
- logger.debug("Contact %s removed from group %s" % (handle.name,
- group.name))
+ logger.debug("Contact %s removed from group %s" %
+ (handle.name, group_name))
diff --git a/butterfly/channel/text.py b/butterfly/channel/text.py
index c42b6be..81624ed 100644
--- a/butterfly/channel/text.py
+++ b/butterfly/channel/text.py
@@ -82,7 +82,7 @@ class ButterflyTextChannel(
def on_conversation_user_joined(self, contact):
handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
contact.account, contact.network_id)
- logger.info("User %r joined" % handle)
+ logger.info("User %s joined" % unicode(handle))
self.MembersChanged('', [handle], [], [], [],
handle, telepathy.CHANNEL_GROUP_CHANGE_REASON_INVITED)
@@ -90,7 +90,7 @@ class ButterflyTextChannel(
def on_conversation_user_left(self, contact):
handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
contact.account, contact.network_id)
- logger.info("User %r left" % handle)
+ logger.info("User %s left" % unicode(handle))
if len(self._members) == 1:
self.ChatStateChanged(handle, telepathy.CHANNEL_CHAT_STATE_GONE)
else:
@@ -101,7 +101,7 @@ class ButterflyTextChannel(
def on_conversation_user_typing(self, contact):
handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
contact.account, contact.network_id)
- logger.info("User %r is typing" % handle)
+ logger.info("User %s is typing" % unicode(handle))
self.ChatStateChanged(handle, telepathy.CHANNEL_CHAT_STATE_COMPOSING)
# papyon.event.ConversationEventInterface
@@ -112,7 +112,7 @@ class ButterflyTextChannel(
sender.account, sender.network_id)
type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
message = message.content
- logger.info("User %r sent a message" % handle)
+ logger.info("User %s sent a message" % unicode(handle))
self.Received(id, timestamp, handle, type, 0, message)
self._recv_id += 1
@@ -124,7 +124,7 @@ class ButterflyTextChannel(
sender.account, sender.network_id)
type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_ACTION
text = unicode("sends you a nudge", "utf-8")
- logger.info("User %r sent a nudge" % handle)
+ logger.info("User %s sent a nudge" % unicode(handle))
self.Received(id, timestamp, handle, type, 0, text)
self._recv_id += 1
diff --git a/butterfly/connection.py b/butterfly/connection.py
index 4bd644e..a0e6402 100644
--- a/butterfly/connection.py
+++ b/butterfly/connection.py
@@ -139,7 +139,6 @@ class ButterflyConnection(telepathy.server.Connection,
handles = []
for name in names:
- name = name.encode('utf-8')
if handle_type == telepathy.HANDLE_TYPE_CONTACT:
name = name.rsplit('#', 1)
contact_name = name[0]
@@ -227,7 +226,8 @@ class ButterflyConnection(telepathy.server.Connection,
#self._channel_manager.channel_for_props(props, signal=True)
for group in self.msn_client.address_book.groups:
- handle = ButterflyHandleFactory(self, 'group', group.name)
+ handle = ButterflyHandleFactory(self, 'group',
+ group.name.decode("utf-8"))
props = self._generate_props(
telepathy.CHANNEL_TYPE_CONTACT_LIST, handle, False)
self._channel_manager.channel_for_props(props, signal=True)
diff --git a/butterfly/handle.py b/butterfly/handle.py
index 360769c..e72a23e 100644
--- a/butterfly/handle.py
+++ b/butterfly/handle.py
@@ -42,7 +42,7 @@ class ButterflyHandleMeta(type):
obj, newly_created = cls.__new__(cls, connection, *args)
if newly_created:
obj.__init__(connection, connection.get_handle_id(), *args)
- logger.info("New Handle %r" % obj)
+ logger.info("New Handle %s" % unicode(obj))
return obj
@@ -62,7 +62,7 @@ class ButterflyHandle(telepathy.server.Handle):
telepathy.server.Handle.__init__(self, id, handle_type, name)
self._conn = weakref.proxy(connection)
- def __repr__(self):
+ def __unicode__(self):
type_mapping = {telepathy.HANDLE_TYPE_CONTACT : 'Contact',
telepathy.HANDLE_TYPE_ROOM : 'Room',
telepathy.HANDLE_TYPE_LIST : 'List',
@@ -127,7 +127,7 @@ class ButterflyGroupHandle(ButterflyHandle):
def group(self):
for group in self._conn.msn_client.address_book.groups:
# Microsoft seems to like case insensitive stuff
- if group.name.lower() == self.name.lower():
+ if group.name.decode("utf-8").lower() == self.name.lower():
return group
return None
diff --git a/butterfly/presence.py b/butterfly/presence.py
index 9a6cdc0..d072d2a 100644
--- a/butterfly/presence.py
+++ b/butterfly/presence.py
@@ -147,11 +147,13 @@ class ButterflyPresence(telepathy.server.ConnectionInterfacePresence,
self.Disconnect()
presence = ButterflyPresenceMapping.to_papyon[status]
- message = arguments.get('message', u'').encode("utf-8")
+ message = arguments.get('message', u'')
logger.info("Setting Presence to '%s'" % presence)
logger.info("Setting Personal message to '%s'" % message)
+ message.encode("utf-8")
+
if self._status != telepathy.CONNECTION_STATUS_CONNECTED:
self._initial_presence = presence
self._initial_personal_message = message
@@ -196,11 +198,12 @@ class ButterflyPresence(telepathy.server.ConnectionInterfacePresence,
presence = ButterflyPresenceMapping.to_papyon[status]
except KeyError:
raise telepathy.errors.InvalidArgument
- message = message.encode("utf-8")
logger.info("Setting Presence to '%s'" % presence)
logger.info("Setting Personal message to '%s'" % message)
+ message = message.encode("utf-8")
+
if self._status != telepathy.CONNECTION_STATUS_CONNECTED:
self._initial_presence = presence
self._initial_personal_message = message
@@ -266,7 +269,8 @@ class ButterflyPresence(telepathy.server.ConnectionInterfacePresence,
def on_contact_presence_changed(self, contact):
handle = ButterflyHandleFactory(self, 'contact',
contact.account, contact.network_id)
- logger.info("Contact %r presence changed to '%s'" % (handle, contact.presence))
+ logger.info("Contact %s presence changed to '%s'" % (unicode(handle),
+ contact.presence))
self._presence_changed(handle, contact.presence, contact.personal_message)
# papyon.event.ContactEventInterface
--
1.5.6.5
More information about the telepathy-commits
mailing list