summaryrefslogtreecommitdiff
path: root/sleekxmpp/util
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-07-27 10:45:52 -0700
committerLance Stout <lancestout@gmail.com>2012-07-27 10:45:52 -0700
commitc2189b4ecd6b022ed9900a6f411bd7e9d57c47ce (patch)
tree88b7dabe06edbbfeb45403c06628230c18301458 /sleekxmpp/util
parentc9b2cf60431f415584c1d12a7855e0d2ac148ec4 (diff)
parente3fab66dfb27abdd8aa28a8d15367a490d4b42dd (diff)
downloadslixmpp-c2189b4ecd6b022ed9900a6f411bd7e9d57c47ce.tar.gz
slixmpp-c2189b4ecd6b022ed9900a6f411bd7e9d57c47ce.tar.bz2
slixmpp-c2189b4ecd6b022ed9900a6f411bd7e9d57c47ce.tar.xz
slixmpp-c2189b4ecd6b022ed9900a6f411bd7e9d57c47ce.zip
Merge branch 'master' into develop
Diffstat (limited to 'sleekxmpp/util')
-rw-r--r--sleekxmpp/util/stringprep_profiles.py41
1 files changed, 40 insertions, 1 deletions
diff --git a/sleekxmpp/util/stringprep_profiles.py b/sleekxmpp/util/stringprep_profiles.py
index 6844c9ac..08278d6c 100644
--- a/sleekxmpp/util/stringprep_profiles.py
+++ b/sleekxmpp/util/stringprep_profiles.py
@@ -1,3 +1,19 @@
+# -*- coding: utf-8 -*-
+"""
+ sleekxmpp.util.stringprep_profiles
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ This module makes it easier to define profiles of stringprep,
+ such as nodeprep and resourceprep for JID validation, and
+ SASLprep for SASL.
+
+ Part of SleekXMPP: The Sleek XMPP Library
+
+ :copyright: (c) 2012 Nathanael C. Fritz, Lance J.T. Stout
+ :license: MIT, see LICENSE for more details
+"""
+
+
from __future__ import unicode_literals
import sys
@@ -10,6 +26,7 @@ class StringPrepError(UnicodeError):
def to_unicode(data):
+ """Ensure that a given string is Unicode, regardless of Python version."""
if sys.version_info < (3, 0):
return unicode(data)
else:
@@ -17,10 +34,12 @@ def to_unicode(data):
def b1_mapping(char):
- return '' if stringprep.in_table_c12(char) else None
+ """Map characters that are commonly mapped to nothing."""
+ return '' if stringprep.in_table_b1(char) else None
def c12_mapping(char):
+ """Map non-ASCII whitespace to spaces."""
return ' ' if stringprep.in_table_c12(char) else None
@@ -102,6 +121,26 @@ def check_bidi(data):
def create(nfkc=True, bidi=True, mappings=None,
prohibited=None, unassigned=None):
+ """Create a profile of stringprep.
+
+ :param bool nfkc:
+ If `True`, perform NFKC Unicode normalization. Defaults to `True`.
+ :param bool bidi:
+ If `True`, perform bidirectional text checks. Defaults to `True`.
+ :param list mappings:
+ Optional list of functions for mapping characters to
+ suitable replacements.
+ :param list prohibited:
+ Optional list of functions which check for the presence of
+ prohibited characters.
+ :param list unassigned:
+ Optional list of functions for detecting the use of unassigned
+ code points.
+
+ :raises: StringPrepError
+ :return: Unicode string of the resulting text passing the
+ profile's requirements.
+ """
def profile(data, query=False):
try:
data = to_unicode(data)