summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2011-06-04 20:15:18 +0200
committermathieui <mathieui@mathieui.net>2011-06-04 20:15:18 +0200
commite27c6d74ada2dbe81c41b991a26028a4d9436ee4 (patch)
treea7216ec578c92bea59316a95c35b4d647421c2af /src
parentfc3f6d936dd821e66ac96e9797bc7868f8d4b4db (diff)
downloadpoezio-e27c6d74ada2dbe81c41b991a26028a4d9436ee4.tar.gz
poezio-e27c6d74ada2dbe81c41b991a26028a4d9436ee4.tar.bz2
poezio-e27c6d74ada2dbe81c41b991a26028a4d9436ee4.tar.xz
poezio-e27c6d74ada2dbe81c41b991a26028a4d9436ee4.zip
fix the display of the action 'emptying the status', and some few minor changes
Diffstat (limited to 'src')
-rw-r--r--src/config.py6
-rw-r--r--src/contact.py2
-rw-r--r--src/multiuserchat.py8
-rw-r--r--src/room.py6
-rw-r--r--src/tabs.py33
-rw-r--r--src/xhtml.py7
6 files changed, 38 insertions, 24 deletions
diff --git a/src/config.py b/src/config.py
index 4776e7d3..af6e05e6 100644
--- a/src/config.py
+++ b/src/config.py
@@ -134,15 +134,15 @@ class Config(RawConfigParser):
# and copy the default config in it
CONFIG_HOME = environ.get("XDG_CONFIG_HOME")
if not CONFIG_HOME:
- CONFIG_HOME = environ.get('HOME')+'/.config'
-CONFIG_PATH = CONFIG_HOME + '/poezio/'
+ CONFIG_HOME = path.join(environ.get('HOME'), '/.config')
+CONFIG_PATH = path.join(CONFIG_HOME, 'poezio')
try:
makedirs(CONFIG_PATH)
except OSError:
pass
if not path.isfile(CONFIG_PATH+'poezio.cfg'):
- copy2(path.join(path.dirname(__file__), '../data/default_config.cfg'), CONFIG_PATH+'poezio.cfg')
+ copy2(path.join(path.dirname(__file__), '../data/default_config.cfg'), path.join(CONFIG_PATH, 'poezio.cfg'))
parser = OptionParser()
parser.add_option("-f", "--file", dest="filename", default=CONFIG_PATH+'poezio.cfg',
diff --git a/src/contact.py b/src/contact.py
index 804a7068..ee0e1e80 100644
--- a/src/contact.py
+++ b/src/contact.py
@@ -166,5 +166,5 @@ class Contact(object):
def __repr__(self):
ret = '<Contact: %s' % self._jid
for resource in self._resources:
- ret += '\n\t\t%s'%resource
+ ret += '\n\t\t%s' % resource
return ret + ' />\n'
diff --git a/src/multiuserchat.py b/src/multiuserchat.py
index 87443e07..dd936039 100644
--- a/src/multiuserchat.py
+++ b/src/multiuserchat.py
@@ -25,6 +25,8 @@ from xml.etree import cElementTree as ET
import logging
log = logging.getLogger(__name__)
+NS_MUC_ADMIN = 'http://jabber.org/protocol/muc#admin'
+
def send_private_message(xmpp, jid, line):
"""
Send a private message
@@ -77,10 +79,10 @@ def eject_user(xmpp, jid, nick, reason):
(try to) Eject an user from the room
"""
iq = xmpp.makeIqSet()
- query = ET.Element('{http://jabber.org/protocol/muc#admin}query')
- item = ET.Element('{http://jabber.org/protocol/muc#admin}item', {'nick':nick, 'role':'none'})
+ query = ET.Element('{%s}query' % NS_MUC_ADMIN)
+ item = ET.Element('{%s}item' % NS_MUC_ADMIN, {'nick':nick, 'role':'none'})
if reason:
- reason_el = ET.Element('{http://jabber.org/protocol/muc#admin}reason')
+ reason_el = ET.Element('{%s}reason' % NS_MUC_ADMIN)
reason_el.text = reason
item.append(reason_el)
query.append(item)
diff --git a/src/room.py b/src/room.py
index a5a05845..45ebddbd 100644
--- a/src/room.py
+++ b/src/room.py
@@ -46,6 +46,9 @@ class Room(TextBuffer):
self.joined = False
def get_single_line_topic(self):
+ """
+ Return the topic as a single-line string (for the window header)
+ """
return self.topic.replace('\n', '|')
def log_message(self, txt, time, nickname):
@@ -77,6 +80,9 @@ class Room(TextBuffer):
return color
def get_user_by_name(self, nick):
+ """
+ Gets the user associated with the given nick, or None if not found
+ """
for user in self.users:
if user.nick == nick:
return user
diff --git a/src/tabs.py b/src/tabs.py
index 12bf08be..4ea3c280 100644
--- a/src/tabs.py
+++ b/src/tabs.py
@@ -63,6 +63,8 @@ SHOW_NAME = {
'': _('available')
}
+NS_MUC_USER = 'http://jabber.org/protocol/muc#user'
+
class Tab(object):
number = 0
tab_core = None
@@ -119,8 +121,8 @@ class Tab(object):
return command[2](the_input)
else:
# complete the command's name
- words = ['/%s'%(name) for name in self.core.commands] +\
- ['/%s'% (name) for name in self.commands]
+ words = ['/%s'% (name) for name in self.core.commands] +\
+ ['/%s' % (name) for name in self.commands]
the_input.auto_completion(words, '')
return True
return False
@@ -767,12 +769,10 @@ class MucTab(ChatTab):
def handle_presence(self, presence):
from_nick = presence['from'].resource
from_room = presence['from'].bare
- code = presence.find('{jabber:client}status')
- status_codes = set([s.attrib['code'] for s in presence.findall('{http://jabber.org/protocol/muc#user}x/{http://jabber.org/protocol/muc#user}status')])
+ status_codes = set([s.attrib['code'] for s in presence.findall('{%s}x/{%s}status' % (NS_MUC_USER, NS_MUC_USER))])
# Check if it's not an error presence.
if presence['type'] == 'error':
return self.core.room_error(presence, from_room)
- msg = None
affiliation = presence['muc']['affiliation']
show = presence['show']
status = presence['status']
@@ -834,7 +834,7 @@ class MucTab(ChatTab):
room.add_message('\x194%(spec)s \x193%(nick)s \x195(\x194%(jid)s\x195) joined the room' % {'spec':theme.CHAR_JOIN, 'nick':from_nick, 'jid':jid.full})
def on_user_nick_change(self, room, presence, user, from_nick, from_room):
- new_nick = presence.find('{http://jabber.org/protocol/muc#user}x/{http://jabber.org/protocol/muc#user}item').attrib['nick']
+ new_nick = presence.find('{%s}x/{%s}item' % (NS_MUC_USER, NS_MUC_USER)).attrib['nick']
if user.nick == room.own_nick:
room.own_nick = new_nick
# also change our nick in all private discussion of this room
@@ -851,8 +851,8 @@ class MucTab(ChatTab):
When someone is banned from a muc
"""
room.users.remove(user)
- by = presence.find('{http://jabber.org/protocol/muc#user}x/{http://jabber.org/protocol/muc#user}item/{http://jabber.org/protocol/muc#user}actor')
- reason = presence.find('{http://jabber.org/protocol/muc#user}x/{http://jabber.org/protocol/muc#user}item/{http://jabber.org/protocol/muc#user}reason')
+ by = presence.find('{%s}x/{%s}item/{%s}actor' % (NS_MUC_USER, NS_MUC_USER, NS_MUC_USER))
+ reason = presence.find('{%s}x/{%s}item/{%s}reason' % (NS_MUC_USER, NS_MUC_USER, NS_MUC_USER))
by = by.attrib['jid'] if by is not None else None
if from_nick == room.own_nick: # we are banned
room.disconnect()
@@ -874,8 +874,8 @@ class MucTab(ChatTab):
When someone is kicked from a muc
"""
room.users.remove(user)
- by = presence.find('{http://jabber.org/protocol/muc#user}x/{http://jabber.org/protocol/muc#user}item/{http://jabber.org/protocol/muc#user}actor')
- reason = presence.find('{http://jabber.org/protocol/muc#user}x/{http://jabber.org/protocol/muc#user}item/{http://jabber.org/protocol/muc#user}reason')
+ by = presence.find('{%s}x/{%s}item/{%s}actor' % (NS_MUC_USER, NS_MUC_USER, NS_MUC_USER))
+ reason = presence.find('{%s}x/{%s}item/{%s}reason' % (NS_MUC_USER, NS_MUC_USER, NS_MUC_USER))
by = by.attrib['jid'] if by is not None else None
if from_nick == room.own_nick: # we are kicked
room.disconnect()
@@ -931,9 +931,14 @@ class MucTab(ChatTab):
if show != user.show and show in SHOW_NAME:
msg += _('show: %s, ') % SHOW_NAME[show]
display_message = True
- if status and status != user.status:
- msg += _('status: %s, ') % status
+ if status != user.status:
+ # if the user sets his status to nothing
+ if not status:
+ msg += _('show: %s, ') % SHOW_NAME[show]
+ else:
+ msg += _('status: %s, ') % status
display_message = True
+
if not display_message:
return
msg = msg[:-2] # remove the last ", "
@@ -1571,7 +1576,7 @@ class MucListTab(Tab):
self.name = server
self.upper_message = windows.Topic()
self.upper_message.set_message('Chatroom list on server %s (Loading)' % self.name)
- columns = ('node-part','name', 'users')
+ columns = ('node-part', 'name', 'users')
self.list_header = windows.ColumnHeaderWin(columns)
self.listview = windows.ListWin(columns)
self.tab_win = windows.GlobalInfoBar()
@@ -1764,6 +1769,7 @@ def diffmatch(search, string):
def jid_and_name_match(contact, txt):
"""
+ Match jid with text precisely
"""
if not txt:
return True
@@ -1776,7 +1782,6 @@ def jid_and_name_match_slow(contact, txt):
A function used to know if a contact in the roster should
be shown in the roster
"""
- ratio = 0.7
if not txt:
return True # Everything matches when search is empty
user = JID(contact.get_bare_jid()).user
diff --git a/src/xhtml.py b/src/xhtml.py
index d755229f..16972b65 100644
--- a/src/xhtml.py
+++ b/src/xhtml.py
@@ -28,11 +28,12 @@ import subprocess
from sleekxmpp.xmlstream import ET
from xml.etree.ElementTree import ElementTree
from sys import version_info
-from string import digits
from config import config
import logging
+digits = '0123456789' # never trust the modules
+
log = logging.getLogger(__name__)
shell_colors_re = re.compile(r'(\[(?:\d+;)*(?:\d+m))')
@@ -73,9 +74,9 @@ def convert_links_to_plaintext(text):
if child.tag == '{http://www.w3.org/1999/xhtml}a':
if child.attrib['href'] != child.text:
if child.text is None and 'title' in child.attrib:
- link_text = '\n%s (%s)'%(child.attrib['href'], child.attrib['title'])
+ link_text = '\n%s (%s)' % (child.attrib['href'], child.attrib['title'])
else:
- link_text = '\n%s (%s)'%(child.attrib['href'], child.text)
+ link_text = '\n%s (%s)' % (child.attrib['href'], child.text)
else:
link_text = child.text
if previous_child is not None: