From 1f5d1048344b3e68b5fb294371f269c398c8f69a Mon Sep 17 00:00:00 2001 From: mathieui Date: Wed, 9 Nov 2011 22:00:38 +0100 Subject: -get -set +@property +@property.setter --- src/contact.py | 81 +++++++++++++++++++++++++++++++++------------------------- src/core.py | 34 ++++++++++++------------ src/roster.py | 2 +- src/tabs.py | 40 ++++++++++++++--------------- src/windows.py | 40 ++++++++++++++--------------- 5 files changed, 104 insertions(+), 93 deletions(-) (limited to 'src') diff --git a/src/contact.py b/src/contact.py index 99c24a32..1874ff59 100644 --- a/src/contact.py +++ b/src/contact.py @@ -26,30 +26,37 @@ class Resource(object): self._presence = 'unavailable' self._priority = 0 - def get_jid(self): + @property + def jid(self): return self._jid def __repr__(self): return '%s' % self._jid - def set_priority(self, priority): - assert isinstance(priority, int) - self._priority = priority - - def get_priority(self): + @property + def priority(self): return self._priority - def set_presence(self, pres): - self._presence = pres + @priority.setter + def priority(self, value): + assert isinstance(value, int) + self._priority = value - def get_presence(self): + @property + def presence(self): return self._presence - def get_status(self): + @presence.setter + def presence(self, value): + self._presence = value + + @property + def status(self): return self._status - def set_status(self, s): - self._status = s + @status.setter + def status(self, value): + self._status = value class Contact(object): """ @@ -66,16 +73,14 @@ class Contact(object): self._ask = None self._groups = [] # a list of groups the contact is in - def get_groups(self): - """ - Return the groups the contact is in - """ + @property + def groups(self): + """Groups the contact is in""" return self._groups - def get_bare_jid(self): - """ - Just get the bare_jid or the contact - """ + @property + def bare_jid(self): + """The bare_jid or the contact""" return self._jid def get_highest_priority_resource(self): @@ -84,7 +89,7 @@ class Contact(object): """ ret = None for resource in self._resources: - if not ret or ret.get_priority() < resource.get_priority(): + if not ret or ret.priority < resource.priority: ret = resource return ret @@ -94,7 +99,7 @@ class Contact(object): (the first, or any subsequent one) """ def f(o): - return o.get_priority() + return o.priority self._resources.append(resource) self._resources = sorted(self._resources, key=f, reverse=True) @@ -109,7 +114,7 @@ class Contact(object): Like 'remove_resource' but just by knowing the full jid """ for resource in self._resources: - if resource.get_jid().full == fulljid: + if resource.jid == fulljid: self._resources.remove(resource) return assert False @@ -119,7 +124,7 @@ class Contact(object): Return the resource with the given fulljid """ for resource in self._resources: - if resource.get_jid().full == fulljid: + if resource.jid.full == fulljid: return resource return None @@ -129,24 +134,30 @@ class Contact(object): """ self._folded = not self._folded - def set_name(self, name): - self._display_name = name - - def get_name(self): + @property + def name(self): return self._display_name - def set_ask(self, ask): - self._ask = ask + @name.setter + def name(self, value): + self._display_name = value - def get_ask(self): + @property + def ask(self): return self._ask - def set_subscription(self, sub): - self._subscription = sub + @ask.setter + def ask(self, value): + self._ask = value - def get_subscription(self): + @property + def subscription(self): return self._subscription + @subscription.setter + def subscription(self, value): + self._subscription = value + def get_nb_resources(self): """ Get the number of connected resources @@ -157,7 +168,7 @@ class Contact(object): """ Return all resources, sorted by priority """ - compare_resources = lambda x: x.get_priority() + compare_resources = lambda x: x.priority return sorted(self._resources, key=compare_resources) def __repr__(self): diff --git a/src/core.py b/src/core.py index b352f627..9109cff6 100644 --- a/src/core.py +++ b/src/core.py @@ -372,13 +372,13 @@ class Core(object): return # If a resource got offline, display the message in the conversation with this # precise resource. - self.add_information_message_to_conversation_tab(jid.full, '\x195}%s is \x191}offline' % (resource.get_jid().full)) + self.add_information_message_to_conversation_tab(jid.full, '\x195}%s is \x191}offline' % (resource.jid.full)) contact.remove_resource(resource) # Display the message in the conversation with the bare JID only if that was # the only resource online (i.e. now the contact is completely disconnected) if not contact.get_highest_priority_resource(): # No resource left: that was the last one self.add_information_message_to_conversation_tab(jid.bare, '\x195}%s is \x191}offline' % (jid.bare)) - self.information('\x193}%s \x195}is \x191}offline' % (resource.get_jid().bare), "Roster") + self.information('\x193}%s \x195}is \x191}offline' % (resource.jid.bare), "Roster") if isinstance(self.current_tab(), tabs.RosterInfoTab): self.refresh_window() @@ -395,18 +395,18 @@ class Core(object): status = presence['type'] status_message = presence['status'] priority = presence.getPriority() or 0 - resource.set_status(status_message) - resource.set_presence(status) - resource.set_priority(priority) + resource.status = status_message + resource.presence = status + resource.priority = priority self.add_information_message_to_conversation_tab(jid.full, '\x195}%s is \x194}online' % (jid.full)) if not contact.get_highest_priority_resource(): # No connected resource yet: the user's just connecting if time.time() - self.connection_time > 12: # We do not display messages if we recently logged in if status_message: - self.information("\x193}%s \x195}is \x194}online\x195} (\x19o%s\x195})" % (resource.get_jid().bare, status_message), "Roster") + self.information("\x193}%s \x195}is \x194}online\x195} (\x19o%s\x195})" % (resource.jid.bare, status_message), "Roster") else: - self.information("\x193}%s \x195}is \x194}online\x195}" % resource.get_jid().bare, "Roster") + self.information("\x193}%s \x195}is \x194}online\x195}" % resource.jid.bare, "Roster") self.add_information_message_to_conversation_tab(jid.bare, '\x195}%s is \x194}online' % (jid.bare)) contact.add_resource(resource) if isinstance(self.current_tab(), tabs.RosterInfoTab): @@ -655,9 +655,9 @@ class Core(object): status = presence['type'] status_message = presence['status'] priority = presence.getPriority() or 0 - resource.set_presence(status) - resource.set_priority(priority) - resource.set_status(status_message) + resource.presence = status + resource.priority = priority + resource.status = status_message if isinstance(self.current_tab(), tabs.RosterInfoTab): self.refresh_window() @@ -673,19 +673,19 @@ class Core(object): contact = Contact(jid) roster.add_contact(contact, jid) if 'ask' in item.attrib: - contact.set_ask(item.attrib['ask']) + contact.ask = item.attrib['ask'] else: - contact.set_ask(None) + contact.ask = None if 'name' in item.attrib: - contact.set_name(item.attrib['name']) + contact.name = item.attrib['name'] else: - contact.set_name(None) + contact.name = None if item.attrib['subscription']: - contact.set_subscription(item.attrib['subscription']) + contact.subscription = item.attrib['subscription'] groups = item.findall('{jabber:iq:roster}group') roster.edit_groups_of_contact(contact, [group.text for group in groups]) if item.attrib['subscription'] == 'remove': - roster.remove_contact(contact.get_bare_jid()) + roster.remove_contact(contact.bare_jid) if isinstance(self.current_tab(), tabs.RosterInfoTab): self.refresh_window() @@ -700,7 +700,7 @@ class Core(object): contact = Contact(jid) roster.add_contact(contact, jid) roster.edit_groups_of_contact(contact, []) - contact.set_ask('asked') + contact.ask = 'asked' self.get_tab_by_number(0).state = 'highlight' self.information('%s wants to subscribe to your presence'%jid, 'Roster') if isinstance(self.current_tab(), tabs.RosterInfoTab): diff --git a/src/roster.py b/src/roster.py index df84d4d8..5f214bb0 100644 --- a/src/roster.py +++ b/src/roster.py @@ -234,7 +234,7 @@ class RosterGroup(object): def compare_contact(a): if not a.get_highest_priority_resource(): return 0 - show = a.get_highest_priority_resource().get_presence() + show = a.get_highest_priority_resource() if show not in PRESENCE_PRIORITY: return 5 return PRESENCE_PRIORITY[show] diff --git a/src/tabs.py b/src/tabs.py index 0e9f345a..6ba94c50 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -1487,10 +1487,10 @@ class RosterInfoTab(Tab): self.core.information(_('No such JID in roster'), 'Error') return - groups = set(contact.get_groups()) - subscription = contact.get_subscription() + groups = set(contact.groups) + subscription = contact.subscription if self.core.xmpp.update_roster(jid, name=name, groups=groups, subscription=subscription): - contact.set_name(name) + contact.name = name def command_groupadd(self, args): """ @@ -1507,7 +1507,7 @@ class RosterInfoTab(Tab): self.core.information(_('No such JID in roster'), 'Error') return - new_groups = set(contact.get_groups()) + new_groups = set(contact.groups) if group in new_groups: self.core.information(_('JID already in group'), 'Error') return @@ -1518,8 +1518,8 @@ class RosterInfoTab(Tab): except KeyError: pass - name = contact.get_name() - subscription = contact.get_subscription() + name = contact.name + subscription = contact.subscription if self.core.xmpp.update_roster(jid, name=name, groups=new_groups, subscription=subscription): roster.edit_groups_of_contact(contact, new_groups) @@ -1538,7 +1538,7 @@ class RosterInfoTab(Tab): self.core.information(_('No such JID in roster'), 'Error') return - new_groups = set(contact.get_groups()) + new_groups = set(contact.groups) try: new_groups.remove('none') except KeyError: @@ -1548,8 +1548,8 @@ class RosterInfoTab(Tab): return new_groups.remove(group) - name = contact.get_name() - subscription = contact.get_subscription() + name = contact.name + subscription = contact.subscription if self.core.xmpp.update_roster(jid, name=name, groups=new_groups, subscription=subscription): roster.edit_groups_of_contact(contact, new_groups) @@ -1624,7 +1624,7 @@ class RosterInfoTab(Tab): """ From with any JID presence in the roster """ - jids = [contact.get_bare_jid() for contact in roster.get_contacts()] + jids = [contact.bare_jid for contact in roster.get_contacts()] return the_input.auto_completion(jids, '') def completion_name(self, the_input): @@ -1634,7 +1634,7 @@ class RosterInfoTab(Tab): n += 1 if n == 2: - jids = [contact.get_bare_jid() for contact in roster.get_contacts()] + jids = [contact.bare_jid for contact in roster.get_contacts()] return the_input.auto_completion(jids, '') return False @@ -1645,7 +1645,7 @@ class RosterInfoTab(Tab): n += 1 if n == 2: - jids = [contact.get_bare_jid() for contact in roster.get_contacts()] + jids = [contact.bare_jid for contact in roster.get_contacts()] return the_input.auto_completion(jids, '') elif n == 3: groups = [group.name for group in roster.get_groups() if group.name != 'none'] @@ -1660,13 +1660,13 @@ class RosterInfoTab(Tab): n += 1 if n == 2: - jids = [contact.get_bare_jid() for contact in roster.get_contacts()] + jids = [contact.bare_jid for contact in roster.get_contacts()] return the_input.auto_completion(jids, '') elif n == 3: contact = roster.get_contact_by_jid(args[1]) if not contact: return False - groups = list(contact.get_groups()) + groups = list(contact.groups) try: groups.remove('none') except ValueError: @@ -1679,8 +1679,8 @@ class RosterInfoTab(Tab): Complete the first argument from the list of the contact with ask=='subscribe' """ - jids = [contact.get_bare_jid() for contact in roster.get_contacts()\ - if contact.get_ask() == 'asked'] + jids = [contact.bare_jid for contact in roster.get_contacts()\ + if contact.ask == 'asked'] return the_input.auto_completion(jids, '') def command_accept(self, args): @@ -1915,7 +1915,7 @@ class ConversationTab(ChatTab): else: resource = contact.get_highest_priority_resource() if resource: - self._text_buffer.add_message("\x195}Status: %s\x193}" %resource.get_status(), None, None, None, None, None) + self._text_buffer.add_message("\x195}Status: %s\x193}" %resource.status, None, None, None, None, None) self.refresh() self.core.doupdate() @@ -2219,7 +2219,7 @@ def jid_and_name_match(contact, txt): """ if not txt: return True - if txt in JID(contact.get_bare_jid()).user: + if txt in JID(contact.bare_jid).user: return True return False @@ -2230,9 +2230,9 @@ def jid_and_name_match_slow(contact, txt): """ if not txt: return True # Everything matches when search is empty - user = JID(contact.get_bare_jid()).user + user = JID(contact.bare_jid).user if diffmatch(txt, user): return True - if contact.get_name() and diffmatch(txt, contact.get_name()): + if contact.name and diffmatch(txt, contact.name): return True return False diff --git a/src/windows.py b/src/windows.py index 2253b871..ed5dfca2 100644 --- a/src/windows.py +++ b/src/windows.py @@ -415,7 +415,7 @@ class ConversationInfoWin(InfoWin): if not resource: presence = "unavailable" else: - presence = resource.get_presence() + presence = resource.presence color = RosterWin.color_show[presence]() self.addstr('[', to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) self.addstr(" ", to_curses_attr(color)) @@ -428,7 +428,7 @@ class ConversationInfoWin(InfoWin): if not contact: self.addstr("(contact not in roster)", to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) return - display_name = contact.get_name() or contact.get_bare_jid() + display_name = contact.name or contact.bare_jid self.addstr('%s '%(display_name), to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) def write_contact_jid(self, jid): @@ -468,7 +468,7 @@ class ConversationStatusMessageWin(InfoWin): self._refresh() def write_status_message(self, resource): - self.addstr(resource.get_status(), to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) + self.addstr(resource.status, to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) class MucInfoWin(InfoWin): """ @@ -1471,14 +1471,14 @@ class RosterWin(Win): presence = 'unavailable' nb = '' else: - presence = resource.get_presence() + presence = resource.presence nb = ' (%s)' % (contact.get_nb_resources(),) color = RosterWin.color_show[presence]() - if contact.get_name(): - display_name = '%s (%s)%s' % (contact.get_name(), - contact.get_bare_jid(), nb,) + if contact.name: + display_name = '%s (%s)%s' % (contact.name, + contact.bare_jid, nb,) else: - display_name = '%s%s' % (contact.get_bare_jid(), nb,) + display_name = '%s%s' % (contact.bare_jid, nb,) self.addstr(y, 0, ' ') self.addstr(" ", to_curses_attr(color)) if resource: @@ -1488,7 +1488,7 @@ class RosterWin(Win): self.addstr(display_name, to_curses_attr(get_theme().COLOR_SELECTED_ROW)) else: self.addstr(display_name) - if contact.get_ask() == 'asked': + if contact.ask == 'asked': self.addstr('?', to_curses_attr(get_theme().COLOR_HIGHLIGHT_NICK)) self.finish_line() @@ -1496,12 +1496,12 @@ class RosterWin(Win): """ Draw a specific resource line """ - color = RosterWin.color_show[resource.get_presence()]() + color = RosterWin.color_show[resource.presence]() self.addstr(y, 4, " ", to_curses_attr(color)) if colored: - self.addstr(y, 6, resource.get_jid().full, to_curses_attr(get_theme().COLOR_SELECTED_ROW)) + self.addstr(y, 6, resource.jid.full, to_curses_attr(get_theme().COLOR_SELECTED_ROW)) else: - self.addstr(y, 6, resource.get_jid().full) + self.addstr(y, 6, resource.jid.full) self.finish_line() def get_selected_row(self): @@ -1517,22 +1517,22 @@ class ContactInfoWin(Win): """ resource = contact.get_highest_priority_resource() if contact: - jid = contact.get_bare_jid() + jid = contact.bare_jid else: - jid = jid or resource.get_jid().full + jid = jid or resource.jid.full if resource: - presence = resource.get_presence() + presence = resource.presence else: presence = 'unavailable' self.addstr(0, 0, '%s (%s)'%(jid, presence,), to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) self.finish_line(get_theme().COLOR_INFORMATION_BAR) - self.addstr(1, 0, 'Subscription: %s' % (contact.get_subscription(),)) - if contact.get_ask(): + self.addstr(1, 0, 'Subscription: %s' % (contact.subscription,)) + if contact.ask: self.addstr(' ') - if contact.get_ask() == 'asked': - self.addstr('Ask: %s' % (contact.get_ask(),), to_curses_attr(get_theme().COLOR_HIGHLIGHT_NICK)) + if contact.ask == 'asked': + self.addstr('Ask: %s' % (contact.ask,), to_curses_attr(get_theme().COLOR_HIGHLIGHT_NICK)) else: - self.addstr('Ask: %s' % (contact.get_ask(),)) + self.addstr('Ask: %s' % (contact.ask,)) self.finish_line() -- cgit v1.2.3