|
|
74a2db8 |
From 795d14a968a23ea50f8f96b6a888f69fd60c7f96 Mon Sep 17 00:00:00 2001
|
|
|
74a2db8 |
From: Michal Schmidt <mschmidt@redhat.com>
|
|
|
74a2db8 |
Date: Fri, 4 Jan 2019 17:59:15 +0100
|
|
|
74a2db8 |
Subject: [PATCH 2/3] Revert "Dont test if precis_i18n is available"
|
|
|
74a2db8 |
|
|
|
74a2db8 |
This reverts commit 08bde952b9e5fd1a77ff94196d2d6830c0ae4a18.
|
|
|
74a2db8 |
|
|
|
74a2db8 |
Until python-precis-i18n is available in Fedora, let's make
|
|
|
74a2db8 |
its use optional again in Gajim.
|
|
|
74a2db8 |
---
|
|
|
74a2db8 |
gajim/common/helpers.py | 26 +++++++++++++++++++++-----
|
|
|
74a2db8 |
1 file changed, 21 insertions(+), 5 deletions(-)
|
|
|
74a2db8 |
|
|
|
74a2db8 |
diff --git a/gajim/common/helpers.py b/gajim/common/helpers.py
|
|
|
74a2db8 |
index ba3baf72c0..2138ebf5b9 100644
|
|
|
74a2db8 |
--- a/gajim/common/helpers.py
|
|
|
74a2db8 |
+++ b/gajim/common/helpers.py
|
|
|
74a2db8 |
@@ -48,8 +48,6 @@ from encodings.punycode import punycode_encode
|
|
|
74a2db8 |
from string import Template
|
|
|
74a2db8 |
|
|
|
74a2db8 |
import nbxmpp
|
|
|
74a2db8 |
-from nbxmpp.stringprepare import nameprep
|
|
|
74a2db8 |
-import precis_i18n.codec # pylint: disable=unused-import
|
|
|
74a2db8 |
|
|
|
74a2db8 |
from gajim.common import caps_cache
|
|
|
74a2db8 |
from gajim.common import configpaths
|
|
|
74a2db8 |
@@ -57,6 +55,12 @@ from gajim.common.i18n import Q_
|
|
|
74a2db8 |
from gajim.common.i18n import _
|
|
|
74a2db8 |
from gajim.common.i18n import ngettext
|
|
|
74a2db8 |
|
|
|
74a2db8 |
+try:
|
|
|
74a2db8 |
+ import precis_i18n.codec # pylint: disable=unused-import
|
|
|
74a2db8 |
+ HAS_PRECIS_I18N = True
|
|
|
74a2db8 |
+except ImportError:
|
|
|
74a2db8 |
+ HAS_PRECIS_I18N = False
|
|
|
74a2db8 |
+
|
|
|
74a2db8 |
log = logging.getLogger('gajim.c.helpers')
|
|
|
74a2db8 |
|
|
|
74a2db8 |
special_groups = (_('Transports'), _('Not in Roster'), _('Observers'), _('Groupchats'))
|
|
|
74a2db8 |
@@ -154,7 +158,10 @@ def parse_resource(resource):
|
|
|
74a2db8 |
"""
|
|
|
74a2db8 |
if resource:
|
|
|
74a2db8 |
try:
|
|
|
74a2db8 |
- return resource.encode('OpaqueString').decode('utf-8')
|
|
|
74a2db8 |
+ if HAS_PRECIS_I18N:
|
|
|
74a2db8 |
+ return resource.encode('OpaqueString').decode('utf-8')
|
|
|
74a2db8 |
+ from nbxmpp.stringprepare import resourceprep
|
|
|
74a2db8 |
+ return resourceprep.prepare(resource)
|
|
|
74a2db8 |
except UnicodeError:
|
|
|
74a2db8 |
raise InvalidFormat('Invalid character in resource.')
|
|
|
74a2db8 |
|
|
|
74a2db8 |
@@ -188,6 +195,7 @@ def prep(user, server, resource):
|
|
|
74a2db8 |
if not server or len(server.encode('utf-8')) > 1023:
|
|
|
74a2db8 |
raise InvalidFormat(_('Server must be between 1 and 1023 bytes'))
|
|
|
74a2db8 |
try:
|
|
|
74a2db8 |
+ from nbxmpp.stringprepare import nameprep
|
|
|
74a2db8 |
server = nameprep.prepare(server)
|
|
|
74a2db8 |
except UnicodeError:
|
|
|
74a2db8 |
raise InvalidFormat(_('Invalid character in hostname.'))
|
|
|
74a2db8 |
@@ -198,7 +206,11 @@ def prep(user, server, resource):
|
|
|
74a2db8 |
if not user or len(user.encode('utf-8')) > 1023:
|
|
|
74a2db8 |
raise InvalidFormat(_('Username must be between 1 and 1023 bytes'))
|
|
|
74a2db8 |
try:
|
|
|
74a2db8 |
- user = user.encode('UsernameCaseMapped').decode('utf-8')
|
|
|
74a2db8 |
+ if HAS_PRECIS_I18N:
|
|
|
74a2db8 |
+ user = user.encode('UsernameCaseMapped').decode('utf-8')
|
|
|
74a2db8 |
+ else:
|
|
|
74a2db8 |
+ from nbxmpp.stringprepare import nodeprep
|
|
|
74a2db8 |
+ user = nodeprep.prepare(user)
|
|
|
74a2db8 |
except UnicodeError:
|
|
|
74a2db8 |
raise InvalidFormat(_('Invalid character in username.'))
|
|
|
74a2db8 |
else:
|
|
|
74a2db8 |
@@ -208,7 +220,11 @@ def prep(user, server, resource):
|
|
|
74a2db8 |
if not resource or len(resource.encode('utf-8')) > 1023:
|
|
|
74a2db8 |
raise InvalidFormat(_('Resource must be between 1 and 1023 bytes'))
|
|
|
74a2db8 |
try:
|
|
|
74a2db8 |
- resource = resource.encode('OpaqueString').decode('utf-8')
|
|
|
74a2db8 |
+ if HAS_PRECIS_I18N:
|
|
|
74a2db8 |
+ resource = resource.encode('OpaqueString').decode('utf-8')
|
|
|
74a2db8 |
+ else:
|
|
|
74a2db8 |
+ from nbxmpp.stringprepare import resourceprep
|
|
|
74a2db8 |
+ resource = resourceprep.prepare(resource)
|
|
|
74a2db8 |
except UnicodeError:
|
|
|
74a2db8 |
raise InvalidFormat(_('Invalid character in resource.'))
|
|
|
74a2db8 |
else:
|
|
|
74a2db8 |
--
|
|
|
74a2db8 |
2.20.1
|
|
|
74a2db8 |
|