-# Copyright (C) 2006, 2007, 2009-2011 Nominum, Inc.
+# Copyright (C) 2006-2017 Nominum, Inc.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose with or without fee is hereby granted,
import dns.exception
import dns.rdata
import dns.tokenizer
-from dns._compat import binary_type
+from dns._compat import binary_type, string_types
class TXTBase(dns.rdata.Rdata):
"""Base class for rdata that is like a TXT record
- @ivar strings: the text strings
- @type strings: list of string
+ @ivar strings: the strings
+ @type strings: list of binary
@see: RFC 1035"""
__slots__ = ['strings']
def __init__(self, rdclass, rdtype, strings):
super(TXTBase, self).__init__(rdclass, rdtype)
- if isinstance(strings, str):
+ if isinstance(strings, binary_type) or \
+ isinstance(strings, string_types):
strings = [strings]
- self.strings = strings[:]
+ self.strings = []
+ for string in strings:
+ if isinstance(string, string_types):
+ string = string.encode()
+ self.strings.append(string)
def to_text(self, origin=None, relativize=True, **kw):
txt = ''
-# Copyright (C) 2006, 2007, 2009-2011 Nominum, Inc.
+# Copyright (C) 2006-2017 Nominum, Inc.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose with or without fee is hereby granted,
import dns.rdata
import dns.rdataclass
import dns.rdatatype
+import dns.rdtypes.ANY.TXT
import dns.ttl
class BugsTestCase(unittest.TestCase):
text6 = binascii.hexlify(out6).decode('ascii')
self.failUnless(text6 == '0002018f000000000000000000000000000010')
+ def test_TXT_conversions(self):
+ t1 = dns.rdtypes.ANY.TXT.TXT(dns.rdataclass.IN, dns.rdatatype.TXT,
+ [b'foo'])
+ t2 = dns.rdtypes.ANY.TXT.TXT(dns.rdataclass.IN, dns.rdatatype.TXT,
+ b'foo')
+ t3 = dns.rdtypes.ANY.TXT.TXT(dns.rdataclass.IN, dns.rdatatype.TXT,
+ 'foo')
+ t4 = dns.rdtypes.ANY.TXT.TXT(dns.rdataclass.IN, dns.rdatatype.TXT,
+ ['foo'])
+ self.failUnless(t1 == t2)
+ self.failUnless(t1 == t2)
+ self.failUnless(t1 == t4)
+
if __name__ == '__main__':
unittest.main()