changeset bd7fe1131cb6 in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=bd7fe1131cb6
description: Use implicit delegation with __getattr__ instead of explicit
delegation via method calls
diffstat:
src/common/contacts.py | 68 ++++++----------------------------
1 files changed, 12 insertions(+), 56 deletions(-)
diffs (95 lines):
diff -r 8c0028113c7b -r bd7fe1131cb6 src/common/contacts.py
--- a/src/common/contacts.py Tue Nov 10 19:05:47 2009 +0100
+++ b/src/common/contacts.py Tue Nov 10 19:26:17 2009 +0100
@@ -411,36 +411,6 @@
nbr_total += 1
return nbr_online, nbr_total
- def define_metacontacts(self, account, tags_list):
- return self._metacontact_manager.define_metacontacts(account,
tags_list)
-
- def get_metacontacts_tags(self, account):
- return self._metacontact_manager.get_metacontacts_tags(account)
-
- def add_metacontact(self, brother_account, brother_jid, account, jid,
order=None):
- return
self._metacontact_manager.add_metacontact(brother_account, brother_jid,
account, jid, order)
-
- def remove_metacontact(self, account, jid):
- return self._metacontact_manager.remove_metacontact(account,
jid)
-
- def has_brother(self, account, jid, accounts):
- return self._metacontact_manager.has_brother(account, jid,
accounts)
-
- def is_big_brother(self, account, jid, accounts):
- return self._metacontact_manager.is_big_brother(account, jid,
accounts)
-
- def get_metacontacts_jids(self, tag, accounts):
- return self._metacontact_manager.get_metacontacts_jids(tag,
accounts)
-
- def get_metacontacts_family(self, account, jid):
- return
self._metacontact_manager.get_metacontacts_family(account, jid)
-
- def get_metacontacts_family_from_tag(self, account, tag):
- return
self._metacontact_manager.get_metacontacts_family_from_tag(account, tag)
-
- def get_metacontacts_big_brother(self, family):
- return
self._metacontact_manager.get_metacontacts_big_brother(family)
-
def is_pm_from_jid(self, account, jid):
'''Returns True if the given jid is a private message jid'''
if jid in self._contacts[account]:
@@ -452,34 +422,20 @@
if isinstance(contact, Contact):
return False
return True
-
+
def get_jid_list(self, account):
return self._contacts[account].keys()
- def create_gc_contact(self, room_jid, account, name='', show='',
status='',
- role='', affiliation='', jid='', resource=''):
- return self._gc_contacts.create_gc_contact(room_jid, account,
name, show, status, role, affiliation, jid, resource)
-
- def add_gc_contact(self, account, gc_contact):
- return self._gc_contacts.add_gc_contact(account, gc_contact)
-
- def remove_gc_contact(self, account, gc_contact):
- return self._gc_contacts.remove_gc_contact(account, gc_contact)
-
- def remove_room(self, account, room_jid):
- return self._gc_contacts.remove_room(account, room_jid)
-
- def get_gc_list(self, account):
- return self._gc_contacts.get_gc_list(account)
-
- def get_nick_list(self, account, room_jid):
- return self._gc_contacts.get_nick_list(account, room_jid)
-
- def get_gc_contact(self, account, room_jid, nick):
- return self._gc_contacts.get_gc_contact(account, room_jid, nick)
-
- def get_nb_role_total_gc_contacts(self, account, room_jid, role):
- return self._gc_contacts.get_nb_role_total_gc_contacts(account,
room_jid, role)
+
+ def __getattr__(self, attr_name):
+ # Only called if self has no attr_name
+ if hasattr(self._gc_contacts, attr_name):
+ return getattr(self._gc_contacts, attr_name)
+ elif hasattr(self._metacontact_manager, attr_name):
+ return getattr(self._metacontact_manager, attr_name)
+ else:
+ raise AttributeError(attr_name)
+
class GC_Contacts():
@@ -508,7 +464,7 @@
# No such account before ?
if account not in self._gc_contacts:
- self._contacts[account] = {gc_contact.room_jid :
{gc_contact.name: \
+ self._gc_contacts[account] = {gc_contact.room_jid :
{gc_contact.name: \
gc_contact}}
return
# No such room_jid before ?
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits