"""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
def _to_rdata(record, origin):
- s = BytesIO()
+ s = io.BytesIO()
record.to_wire(s, origin=origin)
return s.getvalue()
"""DNS Messages"""
-from io import StringIO
+import io
import struct
import time
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)))
"""DNS Names.
"""
-from io import BytesIO
+import copy
+import io
import struct
import sys
-import copy
+
import encodings.idna
try:
import idna
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
"""
if file is None:
- file = BytesIO()
+ file = io.BytesIO()
want_return = True
else:
want_return = False
"""DNS nodes. A node is a set of rdatasets."""
-from io import StringIO
+import io
import dns.rdataset
import dns.rdatatype
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))
"""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
else:
ntext = ''
pad = ''
- s = StringIO()
+ s = io.StringIO()
if override_rdclass is not None:
rdclass = override_rdclass
else:
"""MX-like base classes."""
-from io import BytesIO
+import io
import struct
import dns.exception
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()
"""NS-like base classes."""
-from io import BytesIO
+import io
import dns.exception
import dns.rdata
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()
"""Help for building DNS wire format messages"""
-from io import BytesIO
+import io
import struct
import random
import time
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
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:
"""Tokenize DNS master file format"""
-from io import StringIO
+import io
import sys
import dns.exception
"""
if isinstance(f, str):
- f = StringIO(f)
+ f = io.StringIO(f)
if filename is None:
filename = '<string>'
elif isinstance(f, bytes):
- f = StringIO(f.decode())
+ f = io.StringIO(f.decode())
if filename is None:
filename = '<string>'
else:
"""DNS Zones."""
-import sys
-import re
+import io
import os
-from io import StringIO
+import re
+import sys
import dns.exception
import dns.name
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()