aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/Twisted/py3/twisted/internet/_idna.py
diff options
context:
space:
mode:
authorshmel1k <shmel1k@ydb.tech>2023-11-26 18:16:14 +0300
committershmel1k <shmel1k@ydb.tech>2023-11-26 18:43:30 +0300
commitb8cf9e88f4c5c64d9406af533d8948deb050d695 (patch)
tree218eb61fb3c3b96ec08b4d8cdfef383104a87d63 /contrib/python/Twisted/py3/twisted/internet/_idna.py
parent523f645a83a0ec97a0332dbc3863bb354c92a328 (diff)
downloadydb-b8cf9e88f4c5c64d9406af533d8948deb050d695.tar.gz
add kikimr_configure
Diffstat (limited to 'contrib/python/Twisted/py3/twisted/internet/_idna.py')
-rw-r--r--contrib/python/Twisted/py3/twisted/internet/_idna.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/contrib/python/Twisted/py3/twisted/internet/_idna.py b/contrib/python/Twisted/py3/twisted/internet/_idna.py
new file mode 100644
index 0000000000..852d8a6be8
--- /dev/null
+++ b/contrib/python/Twisted/py3/twisted/internet/_idna.py
@@ -0,0 +1,51 @@
+# -*- test-case-name: twisted.test.test_sslverify -*-
+# Copyright (c) Twisted Matrix Laboratories.
+# See LICENSE for details.
+
+"""
+Shared interface to IDNA encoding and decoding, using the C{idna} PyPI package
+if available, otherwise the stdlib implementation.
+"""
+
+
+def _idnaBytes(text: str) -> bytes:
+ """
+ Convert some text typed by a human into some ASCII bytes.
+
+ This is provided to allow us to use the U{partially-broken IDNA
+ implementation in the standard library <http://bugs.python.org/issue17305>}
+ if the more-correct U{idna <https://pypi.python.org/pypi/idna>} package is
+ not available; C{service_identity} is somewhat stricter about this.
+
+ @param text: A domain name, hopefully.
+ @type text: L{unicode}
+
+ @return: The domain name's IDNA representation, encoded as bytes.
+ @rtype: L{bytes}
+ """
+ try:
+ import idna
+ except ImportError:
+ return text.encode("idna")
+ else:
+ return idna.encode(text)
+
+
+def _idnaText(octets: bytes) -> str:
+ """
+ Convert some IDNA-encoded octets into some human-readable text.
+
+ Currently only used by the tests.
+
+ @param octets: Some bytes representing a hostname.
+ @type octets: L{bytes}
+
+ @return: A human-readable domain name.
+ @rtype: L{unicode}
+ """
+ try:
+ import idna
+ except ImportError:
+ return octets.decode("idna")
+ else:
+ return idna.decode(octets)