Commit 08bde952 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Dont test if precis_i18n is available

Its listed as dependency
parent 584c9ff6
...@@ -47,6 +47,8 @@ ...@@ -47,6 +47,8 @@
from string import Template from string import Template
import nbxmpp import nbxmpp
from nbxmpp.stringprepare import nameprep
import precis_i18n.codec # pylint: disable=unused-import
from gajim.common import caps_cache from gajim.common import caps_cache
from gajim.common import configpaths from gajim.common import configpaths
...@@ -55,12 +57,6 @@ ...@@ -55,12 +57,6 @@
from gajim.common.i18n import ngettext from gajim.common.i18n import ngettext
from gajim.common.caps_cache import muc_caps_cache from gajim.common.caps_cache import muc_caps_cache
try:
import precis_i18n.codec # pylint: disable=unused-import
HAS_PRECIS_I18N = True
except ImportError:
HAS_PRECIS_I18N = False
log = logging.getLogger('gajim.c.helpers') log = logging.getLogger('gajim.c.helpers')
special_groups = (_('Transports'), _('Not in Roster'), _('Observers'), _('Groupchats')) special_groups = (_('Transports'), _('Not in Roster'), _('Observers'), _('Groupchats'))
...@@ -158,10 +154,7 @@ def parse_resource(resource): ...@@ -158,10 +154,7 @@ def parse_resource(resource):
""" """
if resource: if resource:
try: try:
if HAS_PRECIS_I18N: return resource.encode('Nickname').decode('utf-8')
return resource.encode('Nickname').decode('utf-8')
from nbxmpp.stringprepare import resourceprep
return resourceprep.prepare(resource)
except UnicodeError: except UnicodeError:
raise InvalidFormat('Invalid character in resource.') raise InvalidFormat('Invalid character in resource.')
...@@ -195,7 +188,6 @@ def prep(user, server, resource): ...@@ -195,7 +188,6 @@ def prep(user, server, resource):
if not server or len(server.encode('utf-8')) > 1023: if not server or len(server.encode('utf-8')) > 1023:
raise InvalidFormat(_('Server must be between 1 and 1023 bytes')) raise InvalidFormat(_('Server must be between 1 and 1023 bytes'))
try: try:
from nbxmpp.stringprepare import nameprep
server = nameprep.prepare(server) server = nameprep.prepare(server)
except UnicodeError: except UnicodeError:
raise InvalidFormat(_('Invalid character in hostname.')) raise InvalidFormat(_('Invalid character in hostname.'))
...@@ -206,11 +198,7 @@ def prep(user, server, resource): ...@@ -206,11 +198,7 @@ def prep(user, server, resource):
if not user or len(user.encode('utf-8')) > 1023: if not user or len(user.encode('utf-8')) > 1023:
raise InvalidFormat(_('Username must be between 1 and 1023 bytes')) raise InvalidFormat(_('Username must be between 1 and 1023 bytes'))
try: try:
if HAS_PRECIS_I18N: user = user.encode('UsernameCaseMapped').decode('utf-8')
user = user.encode('UsernameCaseMapped').decode('utf-8')
else:
from nbxmpp.stringprepare import nodeprep
user = nodeprep.prepare(user)
except UnicodeError: except UnicodeError:
raise InvalidFormat(_('Invalid character in username.')) raise InvalidFormat(_('Invalid character in username.'))
else: else:
...@@ -220,11 +208,7 @@ def prep(user, server, resource): ...@@ -220,11 +208,7 @@ def prep(user, server, resource):
if not resource or len(resource.encode('utf-8')) > 1023: if not resource or len(resource.encode('utf-8')) > 1023:
raise InvalidFormat(_('Resource must be between 1 and 1023 bytes')) raise InvalidFormat(_('Resource must be between 1 and 1023 bytes'))
try: try:
if HAS_PRECIS_I18N: resource = resource.encode('OpaqueString').decode('utf-8')
resource = resource.encode('OpaqueString').decode('utf-8')
else:
from nbxmpp.stringprepare import resourceprep
resource = resourceprep.prepare(resource)
except UnicodeError: except UnicodeError:
raise InvalidFormat(_('Invalid character in resource.')) raise InvalidFormat(_('Invalid character in resource.'))
else: else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment