Dont test if precis_i18n is available

Its listed as dependency
This commit is contained in:
Philipp Hörist 2018-11-10 19:16:17 +01:00
parent 584c9ff695
commit 08bde952b9
1 changed files with 5 additions and 21 deletions

View File

@ -47,6 +47,8 @@ from encodings.punycode import punycode_encode
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 @@ from gajim.common.i18n import _
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):
""" """
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):
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):
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):
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: