diff options
| author | Bob Halley <halley@dnspython.org> | 2009-03-30 22:58:26 +0000 |
|---|---|---|
| committer | Bob Halley <halley@dnspython.org> | 2009-03-30 22:58:26 +0000 |
| commit | 6e34247de18bc8327929328dec6280941b25983b (patch) | |
| tree | 3bf6070b7877458893b897fb1399ab4cff027891 | |
| parent | a90dcee4134aae76cb4d68b7fa37eb4f9dd3b65b (diff) | |
| download | dnspython-6e34247de18bc8327929328dec6280941b25983b.tar.gz | |
add one_rr_per_rrset mode switch to methods which parse messages from wire format
| -rw-r--r-- | ChangeLog | 7 | ||||
| -rw-r--r-- | dns/message.py | 14 | ||||
| -rw-r--r-- | dns/query.py | 21 |
3 files changed, 32 insertions, 10 deletions
@@ -1,5 +1,12 @@ 2009-03-30 Bob Halley <halley@dnspython.org> + * Add "one_rr_per_rrset" mode switch to methods which parse + messages from wire format (e.g. dns.message.from_wire(), + dns.query.udp(), dns.query.tcp()). If set, each RR read is + placed in its own RRset (instead of being coalesced). + +2009-03-30 Bob Halley <halley@dnspython.org> + * Added EDNS option support. 2008-10-16 Bob Halley <halley@dnspython.org> diff --git a/dns/message.py b/dns/message.py index 4786bed..9afbd3d 100644 --- a/dns/message.py +++ b/dns/message.py @@ -553,18 +553,22 @@ class _WireReader(object): @type current: int @ivar updating: Is the message a dynamic update? @type updating: bool + @ivar one_rr_per_rrset: Put each RR into its own RRset? + @type one_rr_per_rrset: bool @ivar zone_rdclass: The class of the zone in messages which are DNS dynamic updates. @type zone_rdclass: int """ - def __init__(self, wire, message, question_only=False): + def __init__(self, wire, message, question_only=False, + one_rr_per_rrset=False): self.wire = wire self.message = message self.current = 0 self.updating = False self.zone_rdclass = dns.rdataclass.IN self.question_only = question_only + self.one_rr_per_rrset = one_rr_per_rrset def _get_question(self, qcount): """Read the next I{qcount} records from the wire data and add them to @@ -598,7 +602,7 @@ class _WireReader(object): @param count: the number of records to read @type count: int""" - if self.updating: + if self.updating or self.one_rr_per_rrset: force_unique = True else: force_unique = False @@ -709,7 +713,7 @@ class _WireReader(object): def from_wire(wire, keyring=None, request_mac='', xfr=False, origin=None, tsig_ctx = None, multi = False, first = True, - question_only = False): + question_only = False, one_rr_per_rrset = False): """Convert a DNS wire format message into a message object. @@ -733,6 +737,8 @@ def from_wire(wire, keyring=None, request_mac='', xfr=False, origin=None, @type first: bool @param question_only: Read only up to the end of the question section? @type question_only: bool + @param one_rr_per_rrset: Put each RR into its own RRset + @type one_rr_per_rrset: bool @raises ShortHeader: The message is less than 12 octets long. @raises TrailingJunk: There were octets in the message past the end of the proper DNS message. @@ -751,7 +757,7 @@ def from_wire(wire, keyring=None, request_mac='', xfr=False, origin=None, m.multi = multi m.first = first - reader = _WireReader(wire, m, question_only) + reader = _WireReader(wire, m, question_only, one_rr_per_rrset) reader.read() return m diff --git a/dns/query.py b/dns/query.py index c6f1f65..7e305ce 100644 --- a/dns/query.py +++ b/dns/query.py @@ -73,7 +73,7 @@ def _wait_for_writable(s, expiration): _wait_for([], [s], [s], expiration) def udp(q, where, timeout=None, port=53, af=None, source=None, source_port=0, - ignore_unexpected=False): + ignore_unexpected=False, one_rr_per_rrset=False): """Return the response obtained after sending a query via UDP. @param q: the query @@ -97,7 +97,10 @@ def udp(q, where, timeout=None, port=53, af=None, source=None, source_port=0, @type source_port: int @param ignore_unexpected: If True, ignore responses from unexpected sources. The default is False. - @type ignore_unexpected: bool""" + @type ignore_unexpected: bool + @param one_rr_per_rrset: Put each RR into its own RRset + @type one_rr_per_rrset: bool + """ wire = q.to_wire() if af is None: @@ -134,7 +137,8 @@ def udp(q, where, timeout=None, port=53, af=None, source=None, source_port=0, destination) finally: s.close() - r = dns.message.from_wire(wire, keyring=q.keyring, request_mac=q.mac) + r = dns.message.from_wire(wire, keyring=q.keyring, request_mac=q.mac, + one_rr_per_rrset=one_rr_per_rrset) if not q.is_response(r): raise BadResponse return r @@ -176,7 +180,8 @@ def _connect(s, address): v[0] != errno.EALREADY: raise ty, v -def tcp(q, where, timeout=None, port=53, af=None, source=None, source_port=0): +def tcp(q, where, timeout=None, port=53, af=None, source=None, source_port=0, + one_rr_per_rrset=False): """Return the response obtained after sending a query via TCP. @param q: the query @@ -197,7 +202,10 @@ def tcp(q, where, timeout=None, port=53, af=None, source=None, source_port=0): @type source: string @param source_port: The port from which to send the message. The default is 0. - @type source_port: int""" + @type source_port: int + @param one_rr_per_rrset: Put each RR into its own RRset + @type one_rr_per_rrset: bool + """ wire = q.to_wire() if af is None: @@ -233,7 +241,8 @@ def tcp(q, where, timeout=None, port=53, af=None, source=None, source_port=0): wire = _net_read(s, l, expiration) finally: s.close() - r = dns.message.from_wire(wire, keyring=q.keyring, request_mac=q.mac) + r = dns.message.from_wire(wire, keyring=q.keyring, request_mac=q.mac, + one_rr_per_rrset=one_rr_per_rrset) if not q.is_response(r): raise BadResponse return r |
