summaryrefslogtreecommitdiff
path: root/slixmpp/stringprep.pyx
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2015-08-23 17:14:53 +0200
committermathieui <mathieui@mathieui.net>2015-08-23 17:14:53 +0200
commit804b23d390fe5733f4f2cbd1b588fbc9b7c42e21 (patch)
treede208053ef66ad1650f650e888b836d49915603e /slixmpp/stringprep.pyx
parent6e61adf3dba6945423bb4b8812c8ed0107274f50 (diff)
parent04eaf52b1d919e06f2a3c60ab63d625bc5d0797f (diff)
downloadslixmpp-804b23d390fe5733f4f2cbd1b588fbc9b7c42e21.tar.gz
slixmpp-804b23d390fe5733f4f2cbd1b588fbc9b7c42e21.tar.bz2
slixmpp-804b23d390fe5733f4f2cbd1b588fbc9b7c42e21.tar.xz
slixmpp-804b23d390fe5733f4f2cbd1b588fbc9b7c42e21.zip
Merge branch 'socks5' of http://git.linkmauve.fr/slixmpp
Diffstat (limited to 'slixmpp/stringprep.pyx')
-rw-r--r--slixmpp/stringprep.pyx20
1 files changed, 19 insertions, 1 deletions
diff --git a/slixmpp/stringprep.pyx b/slixmpp/stringprep.pyx
index e17c62c3..e751c8ea 100644
--- a/slixmpp/stringprep.pyx
+++ b/slixmpp/stringprep.pyx
@@ -19,7 +19,8 @@ from libc.stdlib cimport free
# Those are Cython declarations for the C function we’ll be using.
cdef extern from "stringprep.h" nogil:
- int stringprep_profile(const char* in_, char** out, const char* profile, int flags)
+ int stringprep_profile(const char* in_, char** out, const char* profile,
+ int flags)
cdef extern from "idna.h" nogil:
int idna_to_ascii_8z(const char* in_, char** out, int flags)
@@ -40,16 +41,19 @@ cdef str _stringprep(str in_, const char* profile):
free(out)
return unicode_out
+
def nodeprep(str node):
"""The nodeprep profile of stringprep used to validate the local, or
username, portion of a JID."""
return _stringprep(node, 'Nodeprep')
+
def resourceprep(str resource):
"""The resourceprep profile of stringprep, which is used to validate the
resource portion of a JID."""
return _stringprep(resource, 'Resourceprep')
+
def idna(str domain):
"""The idna conversion functions, which are used to validate the domain
portion of a JID."""
@@ -69,3 +73,17 @@ def idna(str domain):
unicode_domain = utf8_domain.decode('utf-8')
free(utf8_domain)
return unicode_domain
+
+
+def punycode(str domain):
+ """Converts a domain name to its punycode representation."""
+
+ cdef char* ascii_domain
+ cdef bytes bytes_domain
+
+ ret = idna_to_ascii_8z(domain.encode('utf-8'), &ascii_domain, 0)
+ if ret != 0:
+ raise StringprepError(ret)
+ bytes_domain = ascii_domain
+ free(ascii_domain)
+ return bytes_domain