"""
s = StringIO()
- s.write(u'id %d\n' % self.id)
- s.write(u'opcode %s\n' %
+ s.write('id %d\n' % self.id)
+ s.write('opcode %s\n' %
dns.opcode.to_text(dns.opcode.from_flags(self.flags)))
rc = dns.rcode.from_flags(self.flags, self.ednsflags)
- s.write(u'rcode %s\n' % dns.rcode.to_text(rc))
- s.write(u'flags %s\n' % dns.flags.to_text(self.flags))
+ s.write('rcode %s\n' % dns.rcode.to_text(rc))
+ s.write('flags %s\n' % dns.flags.to_text(self.flags))
if self.edns >= 0:
- s.write(u'edns %s\n' % self.edns)
+ s.write('edns %s\n' % self.edns)
if self.ednsflags != 0:
- s.write(u'eflags %s\n' %
+ s.write('eflags %s\n' %
dns.flags.edns_to_text(self.ednsflags))
- s.write(u'payload %d\n' % self.payload)
+ s.write('payload %d\n' % self.payload)
for opt in self.options:
- s.write(u'option %s\n' % opt.to_text())
+ s.write('option %s\n' % opt.to_text())
is_update = dns.opcode.is_update(self.flags)
if is_update:
- s.write(u';ZONE\n')
+ s.write(';ZONE\n')
else:
- s.write(u';QUESTION\n')
+ s.write(';QUESTION\n')
for rrset in self.question:
s.write(rrset.to_text(origin, relativize, **kw))
- s.write(u'\n')
+ s.write('\n')
if is_update:
- s.write(u';PREREQ\n')
+ s.write(';PREREQ\n')
else:
- s.write(u';ANSWER\n')
+ s.write(';ANSWER\n')
for rrset in self.answer:
s.write(rrset.to_text(origin, relativize, **kw))
- s.write(u'\n')
+ s.write('\n')
if is_update:
- s.write(u';UPDATE\n')
+ s.write(';UPDATE\n')
else:
- s.write(u';AUTHORITY\n')
+ s.write(';AUTHORITY\n')
for rrset in self.authority:
s.write(rrset.to_text(origin, relativize, **kw))
- s.write(u'\n')
- s.write(u';ADDITIONAL\n')
+ s.write('\n')
+ s.write(';ADDITIONAL\n')
for rrset in self.additional:
s.write(rrset.to_text(origin, relativize, **kw))
- s.write(u'\n')
+ s.write('\n')
#
# We strip off the final \n so the caller can print the result without
# doing weird things to get around eccentricities in Python print
for rds in self.rdatasets:
if len(rds) > 0:
s.write(rds.to_text(name, **kw))
- s.write(u'\n')
+ s.write('\n')
return s.getvalue()[:-1]
def __repr__(self):
# some dynamic updates, so we don't need to print out the TTL
# (which is meaningless anyway).
#
- s.write(u'{}{}{} {}\n'.format(ntext, pad,
- dns.rdataclass.to_text(rdclass),
- dns.rdatatype.to_text(self.rdtype)))
+ s.write('{}{}{} {}\n'.format(ntext, pad,
+ dns.rdataclass.to_text(rdclass),
+ dns.rdatatype.to_text(self.rdtype)))
else:
for rd in self:
- s.write(u'%s%s%d %s %s %s\n' %
+ s.write('%s%s%d %s %s %s\n' %
(ntext, pad, self.ttl, dns.rdataclass.to_text(rdclass),
dns.rdatatype.to_text(self.rdtype),
rd.to_text(origin=origin, relativize=relativize,
def to_text(self, origin=None, relativize=True, **kw):
hit = binascii.hexlify(self.hit).decode()
key = base64.b64encode(self.key).replace(b'\n', b'').decode()
- text = u''
+ text = ''
servers = []
for server in self.servers:
servers.append(server.choose_relativity(origin, relativize))
if len(servers) > 0:
- text += (u' ' + u' '.join((x.to_unicode() for x in servers)))
- return u'%u %s %s%s' % (self.algorithm, hit, key, text)
+ text += (' ' + ' '.join((x.to_unicode() for x in servers)))
+ return '%u %s %s%s' % (self.algorithm, hit, key, text)
@classmethod
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
salt = '-'
else:
salt = binascii.hexlify(self.salt).decode()
- text = u''
+ text = ''
for (window, bitmap) in self.windows:
bits = []
for (i, byte) in enumerate(bitmap):
if byte & (0x80 >> j):
bits.append(dns.rdatatype.to_text(window * 256 +
i * 8 + j))
- text += (u' ' + u' '.join(bits))
- return u'%u %u %u %s %s%s' % (self.algorithm, self.flags,
- self.iterations, salt, next, text)
+ text += (' ' + ' '.join(bits))
+ return '%u %u %u %s %s%s' % (self.algorithm, self.flags,
+ self.iterations, salt, next, text)
@classmethod
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
flags = tok.get_uint8()
iterations = tok.get_uint16()
salt = tok.get_string()
- if salt == u'-':
+ if salt == '-':
salt = b''
else:
salt = binascii.unhexlify(salt.encode('ascii'))
if nl is None:
nl_b = os.linesep.encode(file_enc) # binary mode, '\n' is not enough
- nl = u'\n'
+ nl = '\n'
elif isinstance(nl, str):
nl_b = nl.encode(file_enc)
else:
for i in range(start, stop + 1, step):
# +1 because bind is inclusive and python is exclusive
- if lsign == u'+':
+ if lsign == '+':
lindex = i + int(loffset)
- elif lsign == u'-':
+ elif lsign == '-':
lindex = i - int(loffset)
- if rsign == u'-':
+ if rsign == '-':
rindex = i - int(roffset)
- elif rsign == u'+':
+ elif rsign == '+':
rindex = i + int(roffset)
lzfindex = str(lindex).zfill(int(lwidth))
rzfindex = str(rindex).zfill(int(rwidth))
- name = lhs.replace(u'$%s' % (lmod), lzfindex)
- rdata = rhs.replace(u'$%s' % (rmod), rzfindex)
+ name = lhs.replace('$%s' % (lmod), lzfindex)
+ rdata = rhs.replace('$%s' % (rmod), rzfindex)
self.last_name = dns.name.from_text(name, self.current_origin)
name = self.last_name
elif token.is_comment():
self.tok.get_eol()
continue
- elif token.value[0] == u'$':
+ elif token.value[0] == '$':
c = token.value.upper()
- if c == u'$TTL':
+ if c == '$TTL':
token = self.tok.get()
if not token.is_identifier():
raise dns.exception.SyntaxError("bad $TTL")
self.default_ttl = dns.ttl.from_text(token.value)
self.default_ttl_known = True
self.tok.get_eol()
- elif c == u'$ORIGIN':
+ elif c == '$ORIGIN':
self.current_origin = self.tok.get_name()
self.tok.get_eol()
if self.zone.origin is None:
self.zone.origin = self.current_origin
- elif c == u'$INCLUDE' and self.allow_include:
+ elif c == '$INCLUDE' and self.allow_include:
token = self.tok.get()
filename = token.value
token = self.tok.get()
self.tok = dns.tokenizer.Tokenizer(self.current_file,
filename)
self.current_origin = new_origin
- elif c == u'$GENERATE':
+ elif c == '$GENERATE':
self._generate_line()
else:
raise dns.exception.SyntaxError(
def test_CAA_from_wire(self):
rdata = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CAA,
- u'0 issue "ca.example.net"')
+ '0 issue "ca.example.net"')
f = BytesIO()
rdata.to_wire(f)
wire = f.getvalue()
self.failUnlessRaises(dns.name.NoParent, bad)
def testFromUnicode1(self):
- n = dns.name.from_text(u'foo.bar')
+ n = dns.name.from_text('foo.bar')
self.assertEqual(n.labels, (b'foo', b'bar', b''))
def testFromUnicode2(self):
- n = dns.name.from_text(u'foo\u1234bar.bar')
+ n = dns.name.from_text('foo\u1234bar.bar')
self.assertEqual(n.labels, (b'xn--foobar-r5z', b'bar', b''))
def testFromUnicodeAlternateDot1(self):
- n = dns.name.from_text(u'foo\u3002bar')
+ n = dns.name.from_text('foo\u3002bar')
self.assertEqual(n.labels, (b'foo', b'bar', b''))
def testFromUnicodeAlternateDot2(self):
- n = dns.name.from_text(u'foo\uff0ebar')
+ n = dns.name.from_text('foo\uff0ebar')
self.assertEqual(n.labels, (b'foo', b'bar', b''))
def testFromUnicodeAlternateDot3(self):
- n = dns.name.from_text(u'foo\uff61bar')
+ n = dns.name.from_text('foo\uff61bar')
self.assertEqual(n.labels, (b'foo', b'bar', b''))
def testFromUnicodeIDNA2003Explicit(self):
- t = u'Königsgäßchen'
+ t = 'Königsgäßchen'
e = dns.name.from_unicode(t, idna_codec=dns.name.IDNA_2003)
self.assertEqual(str(e), 'xn--knigsgsschen-lcb0w.')
def testFromUnicodeIDNA2003Default(self):
- t = u'Königsgäßchen'
+ t = 'Königsgäßchen'
e = dns.name.from_unicode(t)
self.assertEqual(str(e), 'xn--knigsgsschen-lcb0w.')
def testFromUnicodeIDNA2008(self):
if dns.name.have_idna_2008:
- t = u'Königsgäßchen'
+ t = 'Königsgäßchen'
def bad():
codec = dns.name.IDNA_2008_Strict
return dns.name.from_unicode(t, idna_codec=codec)
def testFromUnicodeIDNA2008Mixed(self):
# the IDN rules for names are very restrictive, disallowing
- # practical names like u'_sip._tcp.Königsgäßchen'. Dnspython
+ # practical names like '_sip._tcp.Königsgäßchen'. Dnspython
# has a "practical" mode which permits labels which are purely
# ASCII to go straight through, and thus not invalid useful
# things in the real world.
if dns.name.have_idna_2008:
- t = u'_sip._tcp.Königsgäßchen'
+ t = '_sip._tcp.Königsgäßchen'
def bad1():
codec = dns.name.IDNA_2008_Strict
return dns.name.from_unicode(t, idna_codec=codec)
self.assertEqual(str(e), '_sip._tcp.xn--knigsgchen-b4a3dun.')
def testToUnicode1(self):
- n = dns.name.from_text(u'foo.bar')
+ n = dns.name.from_text('foo.bar')
s = n.to_unicode()
- self.assertEqual(s, u'foo.bar.')
+ self.assertEqual(s, 'foo.bar.')
def testToUnicode2(self):
- n = dns.name.from_text(u'foo\u1234bar.bar')
+ n = dns.name.from_text('foo\u1234bar.bar')
s = n.to_unicode()
- self.assertEqual(s, u'foo\u1234bar.bar.')
+ self.assertEqual(s, 'foo\u1234bar.bar.')
def testToUnicode3(self):
n = dns.name.from_text('foo.bar')
s = n.to_unicode()
- self.assertEqual(s, u'foo.bar.')
+ self.assertEqual(s, 'foo.bar.')
def testToUnicode4(self):
if dns.name.have_idna_2008:
- n = dns.name.from_text(u'ドメイン.テスト',
+ n = dns.name.from_text('ドメイン.テスト',
idna_codec=dns.name.IDNA_2008)
s = n.to_unicode()
self.assertEqual(str(n), 'xn--eckwd4c7c.xn--zckzah.')
- self.assertEqual(s, u'ドメイン.テスト.')
+ self.assertEqual(s, 'ドメイン.テスト.')
def testDefaultDecodeIsJustPunycode(self):
# groß.com. in IDNA2008 form, pre-encoded.
n = dns.name.from_text('xn--gro-7ka.com')
# output using default codec which just decodes the punycode and
# doesn't test for IDNA2003 or IDNA2008.
- self.assertEqual(n.to_unicode(), u'groß.com.')
+ self.assertEqual(n.to_unicode(), 'groß.com.')
def testStrictINDA2003Decode(self):
# groß.com. in IDNA2008 form, pre-encoded.
token = tok.get()
self.failUnless(token == Token(dns.tokenizer.IDENTIFIER, 'foo'))
- def testUnicode(self):
- tok = dns.tokenizer.Tokenizer(u'foo')
- token = tok.get()
- self.failUnless(token == Token(dns.tokenizer.IDENTIFIER, 'foo'))
-
def testQuotedString1(self):
tok = dns.tokenizer.Tokenizer(r'"foo"')
token = tok.get()
names.sort()
for n in names:
f.write(z[n].to_text(n))
- f.write(u'\n')
+ f.write('\n')
self.assertEqual(f.getvalue(), example_text_output)
def testTorture1(self): # type: () -> None