summaryrefslogtreecommitdiff
path: root/sleekxmpp/thirdparty/suelta/saslprep.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-07-31 21:33:19 -0700
committerLance Stout <lancestout@gmail.com>2012-07-31 21:33:19 -0700
commit06a9d9fc3075df8e07960716c25d1eca2eb47f05 (patch)
tree94adfe3467fb50e3710548d6c97f1a6b36ed57a8 /sleekxmpp/thirdparty/suelta/saslprep.py
parent44ce01a70b7926a1e1f4af6692be3bdc671f7318 (diff)
parent1383ca19b50ae7463a1f310f007ed120f811b574 (diff)
downloadslixmpp-06a9d9fc3075df8e07960716c25d1eca2eb47f05.tar.gz
slixmpp-06a9d9fc3075df8e07960716c25d1eca2eb47f05.tar.bz2
slixmpp-06a9d9fc3075df8e07960716c25d1eca2eb47f05.tar.xz
slixmpp-06a9d9fc3075df8e07960716c25d1eca2eb47f05.zip
Merge branch 'master' into develop
Conflicts: sleekxmpp/thirdparty/__init__.py
Diffstat (limited to 'sleekxmpp/thirdparty/suelta/saslprep.py')
-rw-r--r--sleekxmpp/thirdparty/suelta/saslprep.py81
1 files changed, 0 insertions, 81 deletions
diff --git a/sleekxmpp/thirdparty/suelta/saslprep.py b/sleekxmpp/thirdparty/suelta/saslprep.py
deleted file mode 100644
index 0e72fcb1..00000000
--- a/sleekxmpp/thirdparty/suelta/saslprep.py
+++ /dev/null
@@ -1,81 +0,0 @@
-from __future__ import unicode_literals
-
-import sys
-import stringprep
-import unicodedata
-
-
-from sleekxmpp.thirdparty.suelta.exceptions import SASLPrepFailure
-
-
-def saslprep(text, strict=True):
- """
- Return a processed version of the given string, using the SASLPrep
- profile of stringprep.
-
- :param text: The string to process, in UTF-8.
- :param strict: If ``True``, prevent the use of unassigned code points.
- """
-
- if sys.version_info < (3, 0):
- if type(text) == str:
- text = text.decode('utf-8')
-
- # Mapping:
- #
- # - non-ASCII space characters [StringPrep, C.1.2] that can be
- # mapped to SPACE (U+0020), and
- #
- # - the 'commonly mapped to nothing' characters [StringPrep, B.1]
- # that can be mapped to nothing.
- buffer = ''
- for char in text:
- if stringprep.in_table_c12(char):
- buffer += ' '
- elif not stringprep.in_table_b1(char):
- buffer += char
-
- # Normalization using form KC
- text = unicodedata.normalize('NFKC', buffer)
-
- # Check for bidirectional string
- buffer = ''
- first_is_randal = False
- if text:
- first_is_randal = stringprep.in_table_d1(text[0])
- if first_is_randal and not stringprep.in_table_d1(text[-1]):
- raise SASLPrepFailure('Section 6.3 [end]')
-
- # Check for prohibited characters
- for x in range(len(text)):
- if strict and stringprep.in_table_a1(text[x]):
- raise SASLPrepFailure('Unassigned Codepoint')
- if stringprep.in_table_c12(text[x]):
- raise SASLPrepFailure('In table C.1.2')
- if stringprep.in_table_c21(text[x]):
- raise SASLPrepFailure('In table C.2.1')
- if stringprep.in_table_c22(text[x]):
- raise SASLPrepFailure('In table C.2.2')
- if stringprep.in_table_c3(text[x]):
- raise SASLPrepFailure('In table C.3')
- if stringprep.in_table_c4(text[x]):
- raise SASLPrepFailure('In table C.4')
- if stringprep.in_table_c5(text[x]):
- raise SASLPrepFailure('In table C.5')
- if stringprep.in_table_c6(text[x]):
- raise SASLPrepFailure('In table C.6')
- if stringprep.in_table_c7(text[x]):
- raise SASLPrepFailure('In table C.7')
- if stringprep.in_table_c8(text[x]):
- raise SASLPrepFailure('In table C.8')
- if stringprep.in_table_c9(text[x]):
- raise SASLPrepFailure('In table C.9')
- if x:
- if first_is_randal and stringprep.in_table_d2(text[x]):
- raise SASLPrepFailure('Section 6.2')
- if not first_is_randal and \
- x != len(text) - 1 and \
- stringprep.in_table_d1(text[x]):
- raise SASLPrepFailure('Section 6.3')
-
- return text