Use SASLPrepFailure as the exception name instead of UnicodeError.
This commit is contained in:
parent
8a23f28dfa
commit
f5beac2afa
@ -10,6 +10,7 @@ import logging
|
|||||||
|
|
||||||
from sleekxmpp.thirdparty import suelta
|
from sleekxmpp.thirdparty import suelta
|
||||||
from sleekxmpp.thirdparty.suelta.exceptions import SASLCancelled, SASLError
|
from sleekxmpp.thirdparty.suelta.exceptions import SASLCancelled, SASLError
|
||||||
|
from sleekxmpp.thirdparty.suelta.exceptions import SASLPrepFailure
|
||||||
|
|
||||||
from sleekxmpp.stanza import StreamFeatures
|
from sleekxmpp.stanza import StreamFeatures
|
||||||
from sleekxmpp.xmlstream import RestartStream, register_stanza_plugin
|
from sleekxmpp.xmlstream import RestartStream, register_stanza_plugin
|
||||||
@ -129,7 +130,7 @@ class FeatureMechanisms(BasePlugin):
|
|||||||
except SASLError:
|
except SASLError:
|
||||||
self.attempted_mechs.add(self.mech.name)
|
self.attempted_mechs.add(self.mech.name)
|
||||||
self._send_auth()
|
self._send_auth()
|
||||||
except UnicodeError as e:
|
except SASLPrepFailure:
|
||||||
log.exception("A credential value did not pass SASLprep.")
|
log.exception("A credential value did not pass SASLprep.")
|
||||||
self.xmpp.disconnect()
|
self.xmpp.disconnect()
|
||||||
else:
|
else:
|
||||||
|
4
sleekxmpp/thirdparty/suelta/exceptions.py
vendored
4
sleekxmpp/thirdparty/suelta/exceptions.py
vendored
@ -29,3 +29,7 @@ class SASLCancelled(SASLError):
|
|||||||
:type sasl: `suelta.SASL`
|
:type sasl: `suelta.SASL`
|
||||||
"""
|
"""
|
||||||
super(SASLCancelled, self).__init__(sasl, "User cancelled", mech)
|
super(SASLCancelled, self).__init__(sasl, "User cancelled", mech)
|
||||||
|
|
||||||
|
|
||||||
|
class SASLPrepFailure(UnicodeError):
|
||||||
|
pass
|
||||||
|
31
sleekxmpp/thirdparty/suelta/saslprep.py
vendored
31
sleekxmpp/thirdparty/suelta/saslprep.py
vendored
@ -5,6 +5,9 @@ import stringprep
|
|||||||
import unicodedata
|
import unicodedata
|
||||||
|
|
||||||
|
|
||||||
|
from sleekxmpp.thirdparty.suelta.exceptions import SASLPrepFailure
|
||||||
|
|
||||||
|
|
||||||
def saslprep(text, strict=True):
|
def saslprep(text, strict=True):
|
||||||
"""
|
"""
|
||||||
Return a processed version of the given string, using the SASLPrep
|
Return a processed version of the given string, using the SASLPrep
|
||||||
@ -41,38 +44,38 @@ def saslprep(text, strict=True):
|
|||||||
if text:
|
if text:
|
||||||
first_is_randal = stringprep.in_table_d1(text[0])
|
first_is_randal = stringprep.in_table_d1(text[0])
|
||||||
if first_is_randal and not stringprep.in_table_d1(text[-1]):
|
if first_is_randal and not stringprep.in_table_d1(text[-1]):
|
||||||
raise UnicodeError('Section 6.3 [end]')
|
raise SASLPrepFailure('Section 6.3 [end]')
|
||||||
|
|
||||||
# Check for prohibited characters
|
# Check for prohibited characters
|
||||||
for x in range(len(text)):
|
for x in range(len(text)):
|
||||||
if strict and stringprep.in_table_a1(text[x]):
|
if strict and stringprep.in_table_a1(text[x]):
|
||||||
raise UnicodeError('Unassigned Codepoint')
|
raise SASLPrepFailure('Unassigned Codepoint')
|
||||||
if stringprep.in_table_c12(text[x]):
|
if stringprep.in_table_c12(text[x]):
|
||||||
raise UnicodeError('In table C.1.2')
|
raise SASLPrepFailure('In table C.1.2')
|
||||||
if stringprep.in_table_c21(text[x]):
|
if stringprep.in_table_c21(text[x]):
|
||||||
raise UnicodeError('In table C.2.1')
|
raise SASLPrepFailure('In table C.2.1')
|
||||||
if stringprep.in_table_c22(text[x]):
|
if stringprep.in_table_c22(text[x]):
|
||||||
raise UnicodeError('In table C.2.2')
|
raise SASLPrepFailure('In table C.2.2')
|
||||||
if stringprep.in_table_c3(text[x]):
|
if stringprep.in_table_c3(text[x]):
|
||||||
raise UnicodeError('In table C.3')
|
raise SASLPrepFailure('In table C.3')
|
||||||
if stringprep.in_table_c4(text[x]):
|
if stringprep.in_table_c4(text[x]):
|
||||||
raise UnicodeError('In table C.4')
|
raise SASLPrepFailure('In table C.4')
|
||||||
if stringprep.in_table_c5(text[x]):
|
if stringprep.in_table_c5(text[x]):
|
||||||
raise UnicodeError('In table C.5')
|
raise SASLPrepFailure('In table C.5')
|
||||||
if stringprep.in_table_c6(text[x]):
|
if stringprep.in_table_c6(text[x]):
|
||||||
raise UnicodeError('In table C.6')
|
raise SASLPrepFailure('In table C.6')
|
||||||
if stringprep.in_table_c7(text[x]):
|
if stringprep.in_table_c7(text[x]):
|
||||||
raise UnicodeError('In table C.7')
|
raise SASLPrepFailure('In table C.7')
|
||||||
if stringprep.in_table_c8(text[x]):
|
if stringprep.in_table_c8(text[x]):
|
||||||
raise UnicodeError('In table C.8')
|
raise SASLPrepFailure('In table C.8')
|
||||||
if stringprep.in_table_c9(text[x]):
|
if stringprep.in_table_c9(text[x]):
|
||||||
raise UnicodeError('In table C.9')
|
raise SASLPrepFailure('In table C.9')
|
||||||
if x:
|
if x:
|
||||||
if first_is_randal and stringprep.in_table_d2(text[x]):
|
if first_is_randal and stringprep.in_table_d2(text[x]):
|
||||||
raise UnicodeError('Section 6.2')
|
raise SASLPrepFailure('Section 6.2')
|
||||||
if not first_is_randal and \
|
if not first_is_randal and \
|
||||||
x != len(text) - 1 and \
|
x != len(text) - 1 and \
|
||||||
stringprep.in_table_d1(text[x]):
|
stringprep.in_table_d1(text[x]):
|
||||||
raise UnicodeError('Section 6.3')
|
raise SASLPrepFailure('Section 6.3')
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
Loading…
Reference in New Issue
Block a user