summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/default_config.cfg4
-rw-r--r--poezio/__main__.py4
-rw-r--r--poezio/config.py1
-rw-r--r--poezio/connection.py12
-rw-r--r--poezio/core/commands.py2
-rw-r--r--poezio/core/core.py10
-rw-r--r--poezio/core/handlers.py10
-rw-r--r--poezio/logger.py11
-rw-r--r--poezio/poezio.py17
-rw-r--r--poezio/windows/roster_win.py4
10 files changed, 51 insertions, 24 deletions
diff --git a/data/default_config.cfg b/data/default_config.cfg
index a71fa42c..3b8d17f0 100644
--- a/data/default_config.cfg
+++ b/data/default_config.cfg
@@ -22,6 +22,10 @@ password =
# manager like secret-tool on gnome, or anything you want
eval_password =
+# This identifies this client over time with the server, to let it optimise
+# offline storage and various other features.
+device_id =
+
# Path to a PEM certificate file to use for certificate authentication
# through SASL External. If set, keyfile MUST be provided as well in
# order to login.
diff --git a/poezio/__main__.py b/poezio/__main__.py
index 1f46f051..d6f60f24 100644
--- a/poezio/__main__.py
+++ b/poezio/__main__.py
@@ -1,7 +1,7 @@
def run():
- from poezio.poezio import main, test_curses, test_env
+ from poezio.poezio import main, test_curses, test_env, test_unicode
- if not test_curses() or not test_env():
+ if not test_curses() or not test_env() or not test_unicode():
import sys
sys.exit(1)
else:
diff --git a/poezio/config.py b/poezio/config.py
index e90cac8b..ed295c92 100644
--- a/poezio/config.py
+++ b/poezio/config.py
@@ -47,6 +47,7 @@ DEFAULT_CONFIG = {
'data_dir': '',
'default_nick': '',
'deterministic_nick_colors': True,
+ 'device_id': '',
'nick_color_aliases': True,
'display_activity_notifications': False,
'display_gaming_notifications': False,
diff --git a/poezio/connection.py b/poezio/connection.py
index 69259690..c97365f8 100644
--- a/poezio/connection.py
+++ b/poezio/connection.py
@@ -14,6 +14,8 @@ log = logging.getLogger(__name__)
import getpass
import subprocess
import sys
+import base64
+import random
import slixmpp
from slixmpp.xmlstream import ET
@@ -38,12 +40,19 @@ class Connection(slixmpp.ClientXMPP):
keyfile = config.get('keyfile')
certfile = config.get('certfile')
+ device_id = config.get('device_id')
+ if not device_id:
+ rng = random.SystemRandom()
+ device_id = base64.urlsafe_b64encode(
+ rng.getrandbits(24).to_bytes(3, 'little')).decode('ascii')
+ config.set_and_save('device_id', device_id)
+
if config.get('jid'):
# Field used to know if we are anonymous or not.
# many features will be handled differently
# depending on this setting
self.anon = False
- jid = '%s' % config.get('jid')
+ jid = config.get('jid')
password = config.get('password')
eval_password = config.get('eval_password')
if not password and not eval_password and not (keyfile
@@ -72,6 +81,7 @@ class Connection(slixmpp.ClientXMPP):
jid = config.get('server')
password = None
jid = safeJID(jid)
+ jid.resource = '%s-%s' % (jid.resource, device_id) if jid.resource else 'poezio-%s' % device_id
# TODO: use the system language
slixmpp.ClientXMPP.__init__(
self, jid, password, lang=config.get('lang'))
diff --git a/poezio/core/commands.py b/poezio/core/commands.py
index 8c7cbcd2..7d503fff 100644
--- a/poezio/core/commands.py
+++ b/poezio/core/commands.py
@@ -895,7 +895,7 @@ class CommandCore:
def iqfunc(iq):
"handler for an iq reply"
- self.core.information('%s' % iq, 'Iq')
+ self.core.information(str(iq), 'Iq')
self.core.xmpp.remove_handler('Iq %s' % iq_id)
self.core.xmpp.register_handler(
diff --git a/poezio/core/core.py b/poezio/core/core.py
index d7f8a018..e24335fb 100644
--- a/poezio/core/core.py
+++ b/poezio/core/core.py
@@ -810,7 +810,7 @@ class Core(object):
'Could not execute command (%s)',
repr(command),
exc_info=True)
- self.information('%s' % exc, 'Error')
+ self.information(str(exc), 'Error')
def do_command(self, key, raw):
"""
@@ -1179,7 +1179,7 @@ class Core(object):
def go_to_previous_tab(self):
"Go to the previous tab"
- self.command.win('%s' % (self.previous_tab_nb, ))
+ self.command.win(str(self.previous_tab_nb))
def go_to_important_room(self):
"""
@@ -1207,7 +1207,7 @@ class Core(object):
if (tab.nb < self.current_tab_nb
and tab_refs[state][-1].nb > self.current_tab_nb):
continue
- self.command.win('%s' % tab.nb)
+ self.command.win(str(tab.nb))
return
return
@@ -1216,7 +1216,7 @@ class Core(object):
for tab in self.tabs:
if tab.name == tab_name:
if (type_ and (isinstance(tab, type_))) or not type_:
- self.command.win('%s' % (tab.nb, ))
+ self.command.win(str(tab.nb))
return True
return False
@@ -1267,7 +1267,7 @@ class Core(object):
# if the room exists, focus it and return
for tab in self.get_tabs(tabs.PrivateTab):
if tab.name == complete_jid:
- self.command.win('%s' % tab.nb)
+ self.command.win(str(tab.nb))
return tab
# create the new tab
tab = self.get_tab_by_name(room_name, tabs.MucTab)
diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py
index 268c9733..d34534d0 100644
--- a/poezio/core/handlers.py
+++ b/poezio/core/handlers.py
@@ -1404,7 +1404,7 @@ class HandlerCore:
"""
When a data form is received
"""
- self.core.information('%s' % message)
+ self.core.information(str(message))
def on_attention(self, message):
"""
@@ -1430,11 +1430,11 @@ class HandlerCore:
"""
if self.core.xml_tab:
if PYGMENTS:
- xhtml_text = highlight('%s' % stanza, LEXER, FORMATTER)
+ xhtml_text = highlight(str(stanza), LEXER, FORMATTER)
poezio_colored = xhtml.xhtml_to_poezio_colors(
xhtml_text, force=True).rstrip('\x19o').strip()
else:
- poezio_colored = '%s' % stanza
+ poezio_colored = str(stanza)
self.core.add_message_to_text_buffer(
self.core.xml_buffer,
poezio_colored,
@@ -1459,11 +1459,11 @@ class HandlerCore:
"""
if self.core.xml_tab:
if PYGMENTS:
- xhtml_text = highlight('%s' % stanza, LEXER, FORMATTER)
+ xhtml_text = highlight(str(stanza), LEXER, FORMATTER)
poezio_colored = xhtml.xhtml_to_poezio_colors(
xhtml_text, force=True).rstrip('\x19o').strip()
else:
- poezio_colored = '%s' % stanza
+ poezio_colored = str(stanza)
self.core.add_message_to_text_buffer(
self.core.xml_buffer,
poezio_colored,
diff --git a/poezio/logger.py b/poezio/logger.py
index 1ebd5cf4..207af0c3 100644
--- a/poezio/logger.py
+++ b/poezio/logger.py
@@ -267,14 +267,9 @@ def build_log_message(nick, msg, date=None, typ=1):
return ''
msg = clean_text(msg)
- if date is None:
- str_time = common.get_utc_time().strftime('%Y%m%dT%H:%M:%SZ')
- else:
- str_time = common.get_utc_time(date).strftime('%Y%m%dT%H:%M:%SZ')
- if typ == 1:
- prefix = 'MR'
- else:
- prefix = 'MI'
+ time = common.get_utc_time() if date is None else common.get_utc_time(date)
+ str_time = time.strftime('%Y%m%dT%H:%M:%SZ')
+ prefix = 'MR' if typ == 1 else 'MI'
lines = msg.split('\n')
first_line = lines.pop(0)
nb_lines = str(len(lines)).zfill(3)
diff --git a/poezio/poezio.py b/poezio/poezio.py
index 841e706f..d74eca74 100644
--- a/poezio/poezio.py
+++ b/poezio/poezio.py
@@ -53,6 +53,23 @@ def test_env():
return True
+def test_unicode():
+ import poopt
+ try:
+ poopt.wcswidth('✔')
+ except UnicodeError:
+ print("""\
+ERROR: The current system is misconfigured for Unicode.
+
+Check your locale setup, especially the $LANG environment variable and \
+whether it matches a locale built on your system. Also check that it is a \
+.UTF-8 locale, and not using some legacy encoding.
+
+Poezio is unable to display characters properly, so it will now exit.""")
+ return False
+ return True
+
+
def main():
"""
Entry point.
diff --git a/poezio/windows/roster_win.py b/poezio/windows/roster_win.py
index 0906d1e9..36c41ae6 100644
--- a/poezio/windows/roster_win.py
+++ b/poezio/windows/roster_win.py
@@ -274,11 +274,11 @@ class RosterWin(Win):
contact.subscription, keep=show_roster_sub))
if not show_roster_jids and contact.name:
- display_name = '%s' % contact.name
+ display_name = contact.name
elif contact.name and contact.name != contact.bare_jid:
display_name = '%s (%s)' % (contact.name, contact.bare_jid)
else:
- display_name = '%s' % (contact.bare_jid, )
+ display_name = contact.bare_jid
display_name = self.truncate_name(display_name, added) + nb