summaryrefslogtreecommitdiff
path: root/dns/rdata.py
diff options
context:
space:
mode:
authorBob Halley <halley@dnspython.org>2020-05-03 07:23:54 -0700
committerBob Halley <halley@dnspython.org>2020-05-03 07:23:54 -0700
commitec3b370e5135d10e9f6eecc3c548bca834874d81 (patch)
treee5b78181d52fe6ef2f547089ed495f0cfdca15ed /dns/rdata.py
parent45de6ec85b2666aabcf0e093f81775ba67eeb544 (diff)
downloaddnspython-ec3b370e5135d10e9f6eecc3c548bca834874d81.tar.gz
Add IDNA codec support to tokenizer and dns.rdata.from_text()
Diffstat (limited to 'dns/rdata.py')
-rw-r--r--dns/rdata.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/dns/rdata.py b/dns/rdata.py
index 6396d1b..dafd4c3 100644
--- a/dns/rdata.py
+++ b/dns/rdata.py
@@ -392,7 +392,7 @@ def get_rdata_class(rdclass, rdtype):
def from_text(rdclass, rdtype, tok, origin=None, relativize=True,
- relativize_to=None):
+ relativize_to=None, idna_codec=None):
"""Build an rdata object from text format.
This function attempts to dynamically load a class which
@@ -420,11 +420,18 @@ def from_text(rdclass, rdtype, tok, origin=None, relativize=True,
*relativize_to*, a ``dns.name.Name`` (or ``None``), the origin to use
when relativizing names. If not set, the *origin* value will be used.
+ *idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA
+ encoder/decoder to use if a tokenizer needs to be created. If
+ ``None``, the default IDNA 2003 encoder/decoder is used. If a
+ tokenizer is not created, then the codec associated with the tokenizer
+ is the one that is used.
+
Returns an instance of the chosen Rdata subclass.
+
"""
if isinstance(tok, str):
- tok = dns.tokenizer.Tokenizer(tok)
+ tok = dns.tokenizer.Tokenizer(tok, idna_codec=idna_codec)
cls = get_rdata_class(rdclass, rdtype)
if cls != GenericRdata:
# peek at first token