From: Bob Halley Date: Tue, 8 Jan 2019 15:03:46 +0000 (-0800) Subject: remove the rest of the unicode string prefixes X-Git-Tag: v2.0.0rc1~375 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fabbd12061ff428ba7660433345033665b6ebdde;p=thirdparty%2Fdnspython.git remove the rest of the unicode string prefixes --- diff --git a/dns/message.py b/dns/message.py index c91484a5..e720a4e7 100644 --- a/dns/message.py +++ b/dns/message.py @@ -133,46 +133,46 @@ class Message(object): """ 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 diff --git a/dns/node.py b/dns/node.py index 8a7f19f5..36e5ffa8 100644 --- a/dns/node.py +++ b/dns/node.py @@ -49,7 +49,7 @@ class Node(object): 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): diff --git a/dns/rdataset.py b/dns/rdataset.py index 7f4339c0..df08c944 100644 --- a/dns/rdataset.py +++ b/dns/rdataset.py @@ -205,12 +205,12 @@ class Rdataset(dns.set.Set): # 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, diff --git a/dns/rdtypes/ANY/HIP.py b/dns/rdtypes/ANY/HIP.py index 7c876b2d..81e13c27 100644 --- a/dns/rdtypes/ANY/HIP.py +++ b/dns/rdtypes/ANY/HIP.py @@ -50,13 +50,13 @@ class HIP(dns.rdata.Rdata): 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): diff --git a/dns/rdtypes/ANY/NSEC3.py b/dns/rdtypes/ANY/NSEC3.py index e33cc7c3..95e02eb8 100644 --- a/dns/rdtypes/ANY/NSEC3.py +++ b/dns/rdtypes/ANY/NSEC3.py @@ -75,7 +75,7 @@ class NSEC3(dns.rdata.Rdata): salt = '-' else: salt = binascii.hexlify(self.salt).decode() - text = u'' + text = '' for (window, bitmap) in self.windows: bits = [] for (i, byte) in enumerate(bitmap): @@ -83,9 +83,9 @@ class NSEC3(dns.rdata.Rdata): 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): @@ -93,7 +93,7 @@ class NSEC3(dns.rdata.Rdata): 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')) diff --git a/dns/zone.py b/dns/zone.py index 3da8208b..9f552ad0 100644 --- a/dns/zone.py +++ b/dns/zone.py @@ -506,7 +506,7 @@ class Zone(object): 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: @@ -839,21 +839,21 @@ class _MasterReader(object): 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 @@ -918,21 +918,21 @@ class _MasterReader(object): 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() @@ -958,7 +958,7 @@ class _MasterReader(object): 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( diff --git a/tests/test_bugs.py b/tests/test_bugs.py index b3b47eb3..45906663 100644 --- a/tests/test_bugs.py +++ b/tests/test_bugs.py @@ -60,7 +60,7 @@ class BugsTestCase(unittest.TestCase): 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() diff --git a/tests/test_name.py b/tests/test_name.py index 54b0f31f..da576d90 100644 --- a/tests/test_name.py +++ b/tests/test_name.py @@ -650,38 +650,38 @@ class NameTestCase(unittest.TestCase): 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) @@ -694,12 +694,12 @@ class NameTestCase(unittest.TestCase): 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) @@ -717,34 +717,34 @@ class NameTestCase(unittest.TestCase): 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. diff --git a/tests/test_tokenizer.py b/tests/test_tokenizer.py index 8a6636c7..fc7e0e20 100644 --- a/tests/test_tokenizer.py +++ b/tests/test_tokenizer.py @@ -29,11 +29,6 @@ class TokenizerTestCase(unittest.TestCase): 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() diff --git a/tests/test_zone.py b/tests/test_zone.py index 71b87515..65655ef8 100644 --- a/tests/test_zone.py +++ b/tests/test_zone.py @@ -236,7 +236,7 @@ class ZoneTestCase(unittest.TestCase): 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