From: Bob Halley Date: Fri, 1 May 2020 19:38:21 +0000 (-0700) Subject: In library code, replace from io import BytesIO (or StringIO) with import io X-Git-Tag: v2.0.0rc1~287 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f115ff2054c8859c9cd280de38b3ce5055178d6;p=thirdparty%2Fdnspython.git In library code, replace from io import BytesIO (or StringIO) with import io --- diff --git a/dns/dnssec.py b/dns/dnssec.py index 0f31df9d..8e3621a2 100644 --- a/dns/dnssec.py +++ b/dns/dnssec.py @@ -18,7 +18,7 @@ """Common DNSSEC-related functions and constants.""" import hashlib # used in make_ds() to avoid pycrypto dependency -from io import BytesIO +import io import struct import time import base64 @@ -133,7 +133,7 @@ def algorithm_to_text(value): def _to_rdata(record, origin): - s = BytesIO() + s = io.BytesIO() record.to_wire(s, origin=origin) return s.getvalue() diff --git a/dns/message.py b/dns/message.py index ee9fc84a..935d6b87 100644 --- a/dns/message.py +++ b/dns/message.py @@ -17,7 +17,7 @@ """DNS Messages""" -from io import StringIO +import io import struct import time @@ -130,7 +130,7 @@ class Message(object): Returns a ``text``. """ - s = StringIO() + s = io.StringIO() s.write('id %d\n' % self.id) s.write('opcode %s\n' % dns.opcode.to_text(dns.opcode.from_flags(self.flags))) diff --git a/dns/name.py b/dns/name.py index cd4b4468..72d2852f 100644 --- a/dns/name.py +++ b/dns/name.py @@ -18,10 +18,11 @@ """DNS Names. """ -from io import BytesIO +import copy +import io import struct import sys -import copy + import encodings.idna try: import idna @@ -610,8 +611,8 @@ class Name(object): def to_wire(self, file=None, compress=None, origin=None): """Convert name to wire format, possibly compressing it. - *file* is the file where the name is emitted (typically a - BytesIO file). If ``None`` (the default), a ``binary`` + *file* is the file where the name is emitted (typically an + io.BytesIO file). If ``None`` (the default), a ``binary`` containing the wire name will be returned. *compress*, a ``dict``, is the compression table to use. If @@ -628,7 +629,7 @@ class Name(object): """ if file is None: - file = BytesIO() + file = io.BytesIO() want_return = True else: want_return = False diff --git a/dns/node.py b/dns/node.py index 36e5ffa8..4f8a16ac 100644 --- a/dns/node.py +++ b/dns/node.py @@ -17,7 +17,7 @@ """DNS nodes. A node is a set of rdatasets.""" -from io import StringIO +import io import dns.rdataset import dns.rdatatype @@ -40,12 +40,14 @@ class Node(object): Each rdataset at the node is printed. Any keyword arguments to this method are passed on to the rdataset's to_text() method. - *name*, a ``dns.name.Name`` or ``text``, the owner name of the rdatasets. + *name*, a ``dns.name.Name`` or ``text``, the owner name of the + rdatasets. Returns a ``text``. + """ - s = StringIO() + s = io.StringIO() for rds in self.rdatasets: if len(rds) > 0: s.write(rds.to_text(name, **kw)) diff --git a/dns/rdataset.py b/dns/rdataset.py index 16a8f891..98049092 100644 --- a/dns/rdataset.py +++ b/dns/rdataset.py @@ -17,8 +17,8 @@ """DNS rdatasets (an rdataset is a set of rdatas of a given type and class)""" +import io import random -from io import StringIO import struct import dns.exception @@ -203,7 +203,7 @@ class Rdataset(dns.set.Set): else: ntext = '' pad = '' - s = StringIO() + s = io.StringIO() if override_rdclass is not None: rdclass = override_rdclass else: diff --git a/dns/rdtypes/mxbase.py b/dns/rdtypes/mxbase.py index a7be7329..7e586f64 100644 --- a/dns/rdtypes/mxbase.py +++ b/dns/rdtypes/mxbase.py @@ -17,7 +17,7 @@ """MX-like base classes.""" -from io import BytesIO +import io import struct import dns.exception @@ -86,7 +86,7 @@ class UncompressedMX(MXBase): super(UncompressedMX, self).to_wire(file, None, origin) def to_digestable(self, origin=None): - f = BytesIO() + f = io.BytesIO() self.to_wire(f, None, origin) return f.getvalue() diff --git a/dns/rdtypes/nsbase.py b/dns/rdtypes/nsbase.py index 0b588a41..6334ce29 100644 --- a/dns/rdtypes/nsbase.py +++ b/dns/rdtypes/nsbase.py @@ -17,7 +17,7 @@ """NS-like base classes.""" -from io import BytesIO +import io import dns.exception import dns.rdata @@ -75,6 +75,6 @@ class UncompressedNS(NSBase): super(UncompressedNS, self).to_wire(file, None, origin) def to_digestable(self, origin=None): - f = BytesIO() + f = io.BytesIO() self.to_wire(f, None, origin) return f.getvalue() diff --git a/dns/renderer.py b/dns/renderer.py index 2325e775..02a9e3d0 100644 --- a/dns/renderer.py +++ b/dns/renderer.py @@ -17,7 +17,7 @@ """Help for building DNS wire format messages""" -from io import BytesIO +import io import struct import random import time @@ -54,7 +54,7 @@ class Renderer(object): r.add_tsig(keyname, secret, 300, 1, 0, '', request_mac) wire = r.get_wire() - output, a BytesIO, where rendering is written + output, an io.BytesIO, where rendering is written id: the message id @@ -76,7 +76,7 @@ class Renderer(object): def __init__(self, id=None, flags=0, max_size=65535, origin=None): """Initialize a new renderer.""" - self.output = BytesIO() + self.output = io.BytesIO() if id is None: self.id = random.randint(0, 65535) else: diff --git a/dns/tokenizer.py b/dns/tokenizer.py index 479c002d..66714b7f 100644 --- a/dns/tokenizer.py +++ b/dns/tokenizer.py @@ -17,7 +17,7 @@ """Tokenize DNS master file format""" -from io import StringIO +import io import sys import dns.exception @@ -189,11 +189,11 @@ class Tokenizer(object): """ if isinstance(f, str): - f = StringIO(f) + f = io.StringIO(f) if filename is None: filename = '' elif isinstance(f, bytes): - f = StringIO(f.decode()) + f = io.StringIO(f.decode()) if filename is None: filename = '' else: diff --git a/dns/zone.py b/dns/zone.py index 556fda05..f403bd84 100644 --- a/dns/zone.py +++ b/dns/zone.py @@ -17,10 +17,10 @@ """DNS Zones.""" -import sys -import re +import io import os -from io import StringIO +import re +import sys import dns.exception import dns.name @@ -551,7 +551,7 @@ class Zone(object): LF on POSIX, CRLF on Windows, CR on Macintosh). @type nl: string or None """ - temp_buffer = StringIO() + temp_buffer = io.StringIO() self.to_file(temp_buffer, sorted, relativize, nl) return_value = temp_buffer.getvalue() temp_buffer.close()