summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Halley <halley@nominum.com>2011-05-03 11:05:35 +0100
committerBob Halley <halley@nominum.com>2011-05-03 11:05:35 +0100
commit1e9286535941f168a5c6ac0ec938285cd31802c3 (patch)
tree13cb05be67de7b6faca74ec59d74fe074b272315
parent2fadf943d2098120dc89ca404550db073f10caf3 (diff)
downloaddnspython-1e9286535941f168a5c6ac0ec938285cd31802c3.tar.gz
more strings that should be bytes
-rw-r--r--dns/message.py18
-rw-r--r--dns/query.py4
-rw-r--r--dns/rdtypes/ANY/DNSKEY.py2
-rw-r--r--dns/renderer.py9
-rw-r--r--dns/tsig.py3
-rw-r--r--dns/tsigkeyring.py8
6 files changed, 23 insertions, 21 deletions
diff --git a/dns/message.py b/dns/message.py
index bd904fb..a8bc3ab 100644
--- a/dns/message.py
+++ b/dns/message.py
@@ -111,9 +111,9 @@ class Message(object):
@ivar tsig_error: TSIG error code; default is 0.
@type tsig_error: int
@ivar other_data: TSIG other data.
- @type other_data: string
+ @type other_data: bytes
@ivar mac: The TSIG MAC for this message.
- @type mac: string
+ @type mac: bytes
@ivar xfr: Is the message being used to contain the results of a DNS
zone transfer? The default is False.
@type xfr: bool
@@ -158,12 +158,12 @@ class Message(object):
self.keyring = None
self.keyname = None
self.keyalgorithm = dns.tsig.default_algorithm
- self.request_mac = ''
- self.other_data = ''
+ self.request_mac = b''
+ self.other_data = b''
self.tsig_error = 0
self.fudge = 300
self.original_id = self.id
- self.mac = ''
+ self.mac = b''
self.xfr = False
self.origin = None
self.tsig_ctx = None
@@ -426,7 +426,7 @@ class Message(object):
return r.get_wire()
def use_tsig(self, keyring, keyname=None, fudge=300,
- original_id=None, tsig_error=0, other_data='',
+ original_id=None, tsig_error=0, other_data=b'',
algorithm=dns.tsig.default_algorithm):
"""When sending, a TSIG signature using the specified keyring
and keyname should be added.
@@ -447,7 +447,7 @@ class Message(object):
@param tsig_error: TSIG error code; default is 0.
@type tsig_error: int
@param other_data: TSIG other data.
- @type other_data: string
+ @type other_data: bytes
@param algorithm: The TSIG algorithm to use; defaults to
dns.tsig.default_algorithm
"""
@@ -730,7 +730,7 @@ class _WireReader(object):
self.message.tsig_ctx.update(self.wire)
-def from_wire(wire, keyring=None, request_mac='', xfr=False, origin=None,
+def from_wire(wire, keyring=None, request_mac=b'', xfr=False, origin=None,
tsig_ctx = None, multi = False, first = True,
question_only = False, one_rr_per_rrset = False):
"""Convert a DNS wire format message into a message
@@ -740,7 +740,7 @@ def from_wire(wire, keyring=None, request_mac='', xfr=False, origin=None,
@type keyring: dict
@param request_mac: If the message is a response to a TSIG-signed request,
I{request_mac} should be set to the MAC of that request.
- @type request_mac: string
+ @type request_mac: bytes
@param xfr: Is this message part of a zone transfer?
@type xfr: bool
@param origin: If the message is part of a zone transfer, I{origin}
diff --git a/dns/query.py b/dns/query.py
index c41b444..1be34cc 100644
--- a/dns/query.py
+++ b/dns/query.py
@@ -221,11 +221,11 @@ def _net_read(sock, count, expiration):
A Timeout exception will be raised if the operation is not completed
by the expiration time.
"""
- s = ''
+ s = b''
while count > 0:
_wait_for_readable(sock, expiration)
n = sock.recv(count)
- if n == '':
+ if n == b'':
raise EOFError
count = count - len(n)
s = s + n
diff --git a/dns/rdtypes/ANY/DNSKEY.py b/dns/rdtypes/ANY/DNSKEY.py
index 3362872..321b174 100644
--- a/dns/rdtypes/ANY/DNSKEY.py
+++ b/dns/rdtypes/ANY/DNSKEY.py
@@ -49,7 +49,7 @@ class DNSKEY(dns.rdata.Rdata):
def to_text(self, origin=None, relativize=True, **kw):
return '%d %d %d %s' % (self.flags, self.protocol, self.algorithm,
- dns.rdata._base64ify(self.key))
+ dns.rdata._base64ify(self.key).decode('ascii'))
@classmethod
def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
diff --git a/dns/renderer.py b/dns/renderer.py
index b0a081d..a66f9a5 100644
--- a/dns/renderer.py
+++ b/dns/renderer.py
@@ -47,7 +47,7 @@ class Renderer(object):
r.add_rrset(dns.renderer.ADDTIONAL, ad_rrset_1)
r.add_rrset(dns.renderer.ADDTIONAL, ad_rrset_2)
r.write_header()
- r.add_tsig(keyname, secret, 300, 1, 0, '', request_mac)
+ r.add_tsig(keyname, secret, 300, 1, 0, b'', request_mac)
wire = r.get_wire()
@ivar output: where rendering is written
@@ -68,7 +68,7 @@ class Renderer(object):
@ivar counts: list of the number of RRs in each section
@type counts: int list of length 4
@ivar mac: the MAC of the rendered message (if TSIG was used)
- @type mac: string
+ @type mac: bytes
"""
def __init__(self, id=None, flags=0, max_size=65535, origin=None):
@@ -98,7 +98,7 @@ class Renderer(object):
self.section = QUESTION
self.counts = [0, 0, 0, 0]
self.output.write(b'\x00' * 12)
- self.mac = ''
+ self.mac = b''
def _rollback(self, where):
"""Truncate the output buffer at offset I{where}, and remove any
@@ -267,8 +267,9 @@ class Renderer(object):
@type other_data: string
@param request_mac: This message is a response to the request which
had the specified MAC.
+ @type request_mac: bytes
@param algorithm: the TSIG algorithm to use
- @type request_mac: string
+ @type algorithm: dns.name.Name object
"""
self._set_section(ADDITIONAL)
diff --git a/dns/tsig.py b/dns/tsig.py
index e1f706a..c3d0b0f 100644
--- a/dns/tsig.py
+++ b/dns/tsig.py
@@ -21,6 +21,7 @@ import struct
import sys
import dns.exception
+import dns.hash
import dns.rdataclass
import dns.name
@@ -74,7 +75,7 @@ def sign(wire, keyname, secret, time, fudge, original_id, error,
"""Return a (tsig_rdata, mac, ctx) tuple containing the HMAC TSIG rdata
for the input parameters, the HMAC MAC calculated by applying the
TSIG signature algorithm, and the TSIG digest context.
- @rtype: (string, string, hmac.HMAC object)
+ @rtype: (bytes, bytes, hmac.HMAC object)
@raises ValueError: I{other_data} is too long
@raises NotImplementedError: I{algorithm} is not supported
"""
diff --git a/dns/tsigkeyring.py b/dns/tsigkeyring.py
index cbd1a27..85b62f4 100644
--- a/dns/tsigkeyring.py
+++ b/dns/tsigkeyring.py
@@ -21,13 +21,13 @@ import dns.name
def from_text(textring):
"""Convert a dictionary containing (textual DNS name, base64 secret) pairs
- into a binary keyring which has (dns.name.Name, binary secret) pairs.
+ into a binary keyring which has (dns.name.Name, bytes) pairs.
@rtype: dict"""
-
+
keyring = {}
for keytext in textring:
keyname = dns.name.from_text(keytext)
- secret = base64.decodestring(textring[keytext])
+ secret = base64.decodestring(textring[keytext].encode('ascii'))
keyring[keyname] = secret
return keyring
@@ -35,7 +35,7 @@ def to_text(keyring):
"""Convert a dictionary containing (dns.name.Name, binary secret) pairs
into a text keyring which has (textual DNS name, base64 secret) pairs.
@rtype: dict"""
-
+
textring = {}
for keyname in keyring:
keytext = dns.name.to_text(keyname)