dns Package

dns Package

dnspython DNS toolkit

dnssec Module

Common DNSSEC-related functions and constants.

exception pytomo.dns.dnssec.UnsupportedAlgorithm[source]

Bases: pytomo.dns.exception.DNSException

Raised if an algorithm is not supported.

exception pytomo.dns.dnssec.ValidationFailure[source]

Bases: pytomo.dns.exception.DNSException

The DNSSEC signature is invalid.

pytomo.dns.dnssec.algorithm_from_text(text)[source]

Convert text into a DNSSEC algorithm value @rtype: int

pytomo.dns.dnssec.algorithm_to_text(value)[source]

Convert a DNSSEC algorithm value to text @rtype: string

pytomo.dns.dnssec.key_id(key, origin=None)[source]
pytomo.dns.dnssec.make_ds(name, key, algorithm, origin=None)[source]
pytomo.dns.dnssec.validate(rrset, rrsigset, keys, origin=None, now=None)

Validate an RRset

@param rrset: The RRset to validate @type rrset: dns_rrset.RRset or (dns_name.Name, dns_rdataset.Rdataset) tuple @param rrsigset: The signature RRset @type rrsigset: dns_rrset.RRset or (dns_name.Name, dns_rdataset.Rdataset) tuple @param keys: The key dictionary. @type keys: a dictionary keyed by dns_name.Name with node or rdataset values @param origin: The origin to use for relative names @type origin: dns_name.Name or None @param now: The time to use when validating the signatures. The default is the current time. @type now: int

pytomo.dns.dnssec.validate_rrsig(rrset, rrsig, keys, origin=None, now=None)

Validate an RRset against a single signature rdata

The owner name of the rrsig is assumed to be the same as the owner name of the rrset.

@param rrset: The RRset to validate @type rrset: dns_rrset.RRset or (dns_name.Name, dns_rdataset.Rdataset) tuple @param rrsig: The signature rdata @type rrsig: dns_rrset.Rdata @param keys: The key dictionary. @type keys: a dictionary keyed by dns_name.Name with node or rdataset values @param origin: The origin to use for relative names @type origin: dns_name.Name or None @param now: The time to use when validating the signatures. The default is the current time. @type now: int

e164 Module

DNS E.164 helpers

@var public_enum_domain: The DNS public ENUM domain, e164.arpa. @type public_enum_domain: dns_name.Name object

pytomo.dns.e164.from_e164(text, origin=<DNS name e164.arpa.>)[source]

Convert an E.164 number in textual form into a Name object whose value is the ENUM domain name for that number. @param text: an E.164 number in textual form. @type text: str @param origin: The domain in which the number should be constructed. The default is e164.arpa. @type: dns_name.Name object or None @rtype: dns_name.Name object

pytomo.dns.e164.query(number, domains, resolver=None)[source]

Look for NAPTR RRs for the specified number in the specified domains.

e.g. lookup(‘16505551212’, [‘e164.dnspython.org.’, ‘e164.arpa.’])

pytomo.dns.e164.to_e164(name, origin=<DNS name e164.arpa.>, want_plus_prefix=True)[source]

Convert an ENUM domain name into an E.164 number. @param name: the ENUM domain name. @type name: dns_name.Name object. @param origin: A domain containing the ENUM domain name. The name is relativized to this domain before being converted to text. @type: dns_name.Name object or None @param want_plus_prefix: if True, add a ‘+’ to the beginning of the returned number. @rtype: str

edns Module

EDNS Options

class pytomo.dns.edns.GenericOption(otype, data)[source]

Bases: pytomo.dns.edns.Option

Generate Rdata Class

This class is used for EDNS option types for which we have no better implementation.

classmethod from_wire(otype, wire, current, olen)[source]
to_wire(file)[source]
class pytomo.dns.edns.Option(otype)[source]

Bases: object

Base class for all EDNS option types.

classmethod from_wire(otype, wire, current, olen)[source]

Build an EDNS option object from wire format

@param otype: The option type @type otype: int @param wire: The wire-format message @type wire: string @param current: The offet in wire of the beginning of the rdata. @type current: int @param olen: The length of the wire-format option data @type olen: int @rtype: dns_ends.Option instance

to_wire(file)[source]

Convert an option to wire format.

pytomo.dns.edns.get_option_class(otype)[source]
pytomo.dns.edns.option_from_wire(otype, wire, current, olen)[source]

Build an EDNS option object from wire format

@param otype: The option type @type otype: int @param wire: The wire-format message @type wire: string @param current: The offet in wire of the beginning of the rdata. @type current: int @param olen: The length of the wire-format option data @type olen: int @rtype: dns_ends.Option instance

entropy Module

class pytomo.dns.entropy.EntropyPool(seed=None)[source]

Bases: object

random_16()[source]
random_32()[source]
random_8()[source]
random_between(first, last)[source]
stir(entropy, already_locked=False)[source]
pytomo.dns.entropy.between(first, last)[source]
pytomo.dns.entropy.random_16()[source]

exception Module

Common DNS Exceptions.

exception pytomo.dns.exception.DNSException[source]

Bases: exceptions.Exception

Abstract base class shared by all dnspython exceptions.

exception pytomo.dns.exception.FormError[source]

Bases: pytomo.dns.exception.DNSException

DNS message is malformed.

exception pytomo.dns.exception.SyntaxError[source]

Bases: pytomo.dns.exception.DNSException

Text input is malformed.

exception pytomo.dns.exception.Timeout[source]

Bases: pytomo.dns.exception.DNSException

The operation timed out.

exception pytomo.dns.exception.TooBig[source]

Bases: pytomo.dns.exception.DNSException

The message is too big.

exception pytomo.dns.exception.UnexpectedEnd[source]

Bases: pytomo.dns.exception.SyntaxError

Raised if text input ends unexpectedly.

flags Module

DNS Message Flags.

pytomo.dns.flags.edns_from_text(text)[source]

Convert a space-separated list of EDNS flag text values into a EDNS flags value. @rtype: int

pytomo.dns.flags.edns_to_text(flags)[source]

Convert an EDNS flags value into a space-separated list of EDNS flag text values. @rtype: string

pytomo.dns.flags.from_text(text)[source]

Convert a space-separated list of flag text values into a flags value. @rtype: int

pytomo.dns.flags.to_text(flags)[source]

Convert a flags value into a space-separated list of flag text values. @rtype: string

hash Module

Hashing backwards compatibility wrapper

pytomo.dns.hash.get(algorithm)[source]

inet Module

Generic Internet address helper functions.

pytomo.dns.inet.af_for_address(text)[source]

Determine the address family of a textual-form network address.

@param text: the textual address @type text: string @raises ValueError: the address family cannot be determined from the input. @rtype: int

pytomo.dns.inet.inet_ntop(family, address)[source]

Convert the binary form of a network address into its textual form.

@param family: the address family @type family: int @param address: the binary address @type address: string @raises NotImplementedError: the address family specified is not implemented. @rtype: string

pytomo.dns.inet.inet_pton(family, text)[source]

Convert the textual form of a network address into its binary form.

@param family: the address family @type family: int @param text: the textual address @type text: string @raises NotImplementedError: the address family specified is not implemented. @rtype: string

pytomo.dns.inet.is_multicast(text)[source]

Is the textual-form network address a multicast address?

@param text: the textual address @raises ValueError: the address family cannot be determined from the input. @rtype: bool

ipv4 Module

IPv4 helper functions.

ipv6 Module

IPv6 helper functions.

pytomo.dns.ipv6.inet_aton(text)[source]

Convert a text format IPv6 address into network format.

@param text: the textual address @type text: string @rtype: string @raises dns_exception.SyntaxError: the text was not properly formatted

pytomo.dns.ipv6.inet_ntoa(address)[source]

Convert a network format IPv6 address into text.

@param address: the binary address @type address: string @rtype: string @raises ValueError: the address isn’t 16 bytes long

message Module

DNS Messages

exception pytomo.dns.message.BadEDNS[source]

Bases: pytomo.dns.exception.FormError

Raised if an OPT record occurs somewhere other than the start of the additional data section.

exception pytomo.dns.message.BadTSIG[source]

Bases: pytomo.dns.exception.FormError

Raised if a TSIG record occurs somewhere other than the end of the additional data section.

class pytomo.dns.message.Message(id=None)[source]

Bases: object

A DNS message.

@ivar id: The query id; the default is a randomly chosen id. @type id: int @ivar flags: The DNS flags of the message. @see: RFC 1035 for an explanation of these flags. @type flags: int @ivar question: The question section. @type question: list of dns_rrset.RRset objects @ivar answer: The answer section. @type answer: list of dns_rrset.RRset objects @ivar authority: The authority section. @type authority: list of dns_rrset.RRset objects @ivar additional: The additional data section. @type additional: list of dns_rrset.RRset objects @ivar edns: The EDNS level to use. The default is -1, no Edns. @type edns: int @ivar ednsflags: The EDNS flags @type ednsflags: long @ivar payload: The EDNS payload size. The default is 0. @type payload: int @ivar options: The EDNS options @type options: list of dns_edns_Option objects @ivar request_payload: The associated request’s EDNS payload size. @type request_payload: int @ivar keyring: The TSIG keyring to use. The default is None. @type keyring: dict @ivar keyname: The TSIG keyname to use. The default is None. @type keyname: dns_name.Name object @ivar keyalgorithm: The TSIG algorithm to use; defaults to dns_tsig.default_algorithm. Constants for TSIG algorithms are defined in dns_tsig, and the currently implemented algorithms are HMAC_MD5, HMAC_SHA1, HMAC_SHA224, HMAC_SHA256, HMAC_SHA384, and HMAC_SHA512. @type keyalgorithm: string @ivar request_mac: The TSIG MAC of the request message associated with this message; used when validating TSIG signatures. @see: RFC 2845 for more information on TSIG fields. @type request_mac: string @ivar fudge: TSIG time fudge; default is 300 seconds. @type fudge: int @ivar original_id: TSIG original id; defaults to the message’s id @type original_id: int @ivar tsig_error: TSIG error code; default is 0. @type tsig_error: int @ivar other_data: TSIG other data. @type other_data: string @ivar mac: The TSIG MAC for this message. @type mac: string @ivar xfr: Is the message being used to contain the results of a DNS zone transfer? The default is False. @type xfr: bool @ivar origin: The origin of the zone in messages which are used for zone transfers or for DNS dynamic updates. The default is None. @type origin: dns_name.Name object @ivar tsig_ctx: The TSIG signature context associated with this message. The default is None. @type tsig_ctx: hmac.HMAC object @ivar had_tsig: Did the message decoded from wire format have a TSIG signature? @type had_tsig: bool @ivar multi: Is this message part of a multi-message sequence? The default is false. This variable is used when validating TSIG signatures on messages which are part of a zone transfer. @type multi: bool @ivar first: Is this message standalone, or the first of a multi message sequence? This variable is used when validating TSIG signatures on messages which are part of a zone transfer. @type first: bool @ivar index: An index of rrsets in the message. The index key is (section, name, rdclass, rdtype, covers, deleting). Indexing can be disabled by setting the index to None. @type index: dict

find_rrset(section, name, rdclass, rdtype, covers=0, deleting=None, create=False, force_unique=False)[source]

Find the RRset with the given attributes in the specified section.

@param section: the section of the message to look in, e.g. self.answer. @type section: list of dns_rrset.RRset objects @param name: the name of the RRset @type name: dns_name.Name object @param rdclass: the class of the RRset @type rdclass: int @param rdtype: the type of the RRset @type rdtype: int @param covers: the covers value of the RRset @type covers: int @param deleting: the deleting value of the RRset @type deleting: int @param create: If True, create the RRset if it is not found. The created RRset is appended to I{section}. @type create: bool @param force_unique: If True and create is also True, create a new RRset regardless of whether a matching RRset exists already. @type force_unique: bool @raises KeyError: the RRset was not found and create was False @rtype: dns_rrset.RRset object

get_rrset(section, name, rdclass, rdtype, covers=0, deleting=None, create=False, force_unique=False)[source]

Get the RRset with the given attributes in the specified section.

If the RRset is not found, None is returned.

@param section: the section of the message to look in, e.g. self.answer. @type section: list of dns_rrset.RRset objects @param name: the name of the RRset @type name: dns_name.Name object @param rdclass: the class of the RRset @type rdclass: int @param rdtype: the type of the RRset @type rdtype: int @param covers: the covers value of the RRset @type covers: int @param deleting: the deleting value of the RRset @type deleting: int @param create: If True, create the RRset if it is not found. The created RRset is appended to I{section}. @type create: bool @param force_unique: If True and create is also True, create a new RRset regardless of whether a matching RRset exists already. @type force_unique: bool @rtype: dns_rrset.RRset object or None

is_response(other)[source]

Is other a response to self? @rtype: bool

opcode()[source]

Return the opcode. @rtype: int

rcode()[source]

Return the rcode. @rtype: int

section_number(section)[source]
set_opcode(opcode)[source]

Set the opcode. @param opcode: the opcode @type opcode: int

set_rcode(rcode)[source]

Set the rcode. @param rcode: the rcode @type rcode: int

to_text(origin=None, relativize=True, **kw)[source]

Convert the message to text.

The I{origin}, I{relativize}, and any other keyword arguments are passed to the rrset to_wire() method.

@rtype: string

to_wire(origin=None, max_size=0, **kw)[source]

Return a string containing the message in DNS compressed wire format.

Additional keyword arguments are passed to the rrset to_wire() method.

@param origin: The origin to be appended to any relative names. @type origin: dns_name.Name object @param max_size: The maximum size of the wire format output; default is 0, which means ‘the message’s request payload, if nonzero, or 65536’. @type max_size: int @raises dns_exception.TooBig: max_size was exceeded @rtype: string

use_edns(edns=0, ednsflags=0, payload=1280, request_payload=None, options=None)[source]

Configure EDNS behavior. @param edns: The EDNS level to use. Specifying None, False, or -1 means ‘do not use EDNS’, and in this case the other parameters are ignored. Specifying True is equivalent to specifying 0, i.e. ‘use EDNS0’. @type edns: int or bool or None @param ednsflags: EDNS flag values. @type ednsflags: int @param payload: The EDNS sender’s payload field, which is the maximum size of UDP datagram the sender can handle. @type payload: int @param request_payload: The EDNS payload size to use when sending this message. If not specified, defaults to the value of payload. @type request_payload: int or None @param options: The EDNS options @type options: None or list of dns_edns_Option objects @see: RFC 2671

use_tsig(keyring, keyname=None, fudge=300, original_id=None, tsig_error=0, other_data='', algorithm=<DNS name HMAC-MD5.SIG-ALG.REG.INT.>)[source]

When sending, a TSIG signature using the specified keyring and keyname should be added.

@param keyring: The TSIG keyring to use; defaults to None. @type keyring: dict @param keyname: The name of the TSIG key to use; defaults to None. The key must be defined in the keyring. If a keyring is specified but a keyname is not, then the key used will be the first key in the keyring. Note that the order of keys in a dictionary is not defined, so applications should supply a keyname when a keyring is used, unless they know the keyring contains only one key. @type keyname: dns_name.Name or string @param fudge: TSIG time fudge; default is 300 seconds. @type fudge: int @param original_id: TSIG original id; defaults to the message’s id @type original_id: int @param tsig_error: TSIG error code; default is 0. @type tsig_error: int @param other_data: TSIG other data. @type other_data: string @param algorithm: The TSIG algorithm to use; defaults to dns_tsig.default_algorithm

want_dnssec(wanted=True)[source]

Enable or disable ‘DNSSEC desired’ flag in requests. @param wanted: Is DNSSEC desired? If True, EDNS is enabled if required, and then the DO bit is set. If False, the DO bit is cleared if EDNS is enabled. @type wanted: bool

exception pytomo.dns.message.ShortHeader[source]

Bases: pytomo.dns.exception.FormError

Raised if the DNS packet passed to from_wire() is too short.

exception pytomo.dns.message.TrailingJunk[source]

Bases: pytomo.dns.exception.FormError

Raised if the DNS packet passed to from_wire() has extra junk at the end of it.

exception pytomo.dns.message.UnknownHeaderField[source]

Bases: pytomo.dns.exception.DNSException

Raised if a header field name is not recognized when converting from text into a message.

exception pytomo.dns.message.UnknownTSIGKey[source]

Bases: pytomo.dns.exception.DNSException

Raised if we got a TSIG but don’t know the key.

pytomo.dns.message.from_file(f)[source]

Read the next text format message from the specified file.

@param f: file or string. If I{f} is a string, it is treated as the name of a file to open. @raises UnknownHeaderField: @raises dns_exception.SyntaxError: @rtype: dns_message.Message object

pytomo.dns.message.from_text(text)[source]

Convert the text format message into a message object.

@param text: The text format message. @type text: string @raises UnknownHeaderField: @raises dns_exception.SyntaxError: @rtype: dns_message.Message object

pytomo.dns.message.from_wire(wire, keyring=None, request_mac='', xfr=False, origin=None, tsig_ctx=None, multi=False, first=True, question_only=False, one_rr_per_rrset=False)[source]

Convert a DNS wire format message into a message object.

@param keyring: The keyring to use if the message is signed. @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 @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} should be the origin name of the zone. @type origin: dns_name.Name object @param tsig_ctx: The ongoing TSIG context, used when validating zone transfers. @type tsig_ctx: hmac.HMAC object @param multi: Is this message part of a multiple message sequence? @type multi: bool @param first: Is this message standalone, or the first of a multi message sequence? @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. @raises BadEDNS: An OPT record was in the wrong section, or occurred more than once. @raises BadTSIG: A TSIG record was not the last record of the additional data section. @rtype: dns_message.Message object

pytomo.dns.message.make_query(qname, rdtype, rdclass=1, use_edns=None, want_dnssec=False)[source]

Make a query message.

The query name, type, and class may all be specified either as objects of the appropriate type, or as strings.

The query will have a randomly choosen query id, and its DNS flags will be set to dns_flags.RD.

@param qname: The query name. @type qname: dns_name.Name object or string @param rdtype: The desired rdata type. @type rdtype: int @param rdclass: The desired rdata class; the default is class IN. @type rdclass: int @param use_edns: The EDNS level to use; the default is None (no EDNS). See the description of dns_message.Message.use_edns() for the possible values for use_edns and their meanings. @type use_edns: int or bool or None @param want_dnssec: Should the query indicate that DNSSEC is desired? @type want_dnssec: bool @rtype: dns_message.Message object

pytomo.dns.message.make_response(query, recursion_available=False, our_payload=8192)[source]

Make a message which is a response for the specified query. The message returned is really a response skeleton; it has all of the infrastructure required of a response, but none of the content.

The response’s question section is a shallow copy of the query’s question section, so the query’s question RRsets should not be changed.

@param query: the query to respond to @type query: dns_message.Message object @param recursion_available: should RA be set in the response? @type recursion_available: bool @param our_payload: payload size to advertise in EDNS responses; default is 8192. @type our_payload: int @rtype: dns_message.Message object

name Module

DNS Names.

@var root: The DNS root name. @type root: dns_name.Name object @var empty: The empty DNS name. @type empty: dns_name.Name object

exception pytomo.dns.name.AbsoluteConcatenation[source]

Bases: pytomo.dns.exception.DNSException

Raised if an attempt is made to append anything other than the empty name to an absolute name.

exception pytomo.dns.name.BadEscape[source]

Bases: pytomo.dns.exception.SyntaxError

Raised if an escaped code in a text format name is invalid.

exception pytomo.dns.name.BadLabelType[source]

Bases: pytomo.dns.exception.FormError

Raised if the label type of a wire format name is unknown.

exception pytomo.dns.name.BadPointer[source]

Bases: pytomo.dns.exception.FormError

Raised if a compression pointer points forward instead of backward.

exception pytomo.dns.name.EmptyLabel[source]

Bases: pytomo.dns.exception.SyntaxError

Raised if a label is empty.

exception pytomo.dns.name.LabelTooLong[source]

Bases: pytomo.dns.exception.SyntaxError

Raised if a label is > 63 octets long.

class pytomo.dns.name.Name(labels)[source]

Bases: object

A DNS name.

The dns_name.Name class represents a DNS name as a tuple of labels. Instances of the class are immutable.

@ivar labels: The tuple of labels in the name. Each label is a string of up to 63 octets.

canonicalize()[source]

Return a name which is equal to the current name, but is in DNSSEC canonical form. @rtype: dns_name.Name object

choose_relativity(origin=None, relativize=True)[source]

Return a name with the relativity desired by the caller. If origin is None, then self is returned. Otherwise, if relativize is true the name is relativized, and if relativize is false the name is derelativized. @rtype: dns_name.Name object

concatenate(other)[source]

Return a new name which is the concatenation of self and other. @rtype: dns_name.Name object @raises AbsoluteConcatenation: self is absolute and other is not the empty name

derelativize(origin)[source]

If self is a relative name, return a new name which is the concatenation of self and origin. Otherwise return self. @rtype: dns_name.Name object

fullcompare(other)[source]

Compare two names, returning a 3-tuple (relation, order, nlabels).

I{relation} describes the relation ship beween the names, and is one of: dns_name.NAMERELN_NONE, dns_name.NAMERELN_SUPERDOMAIN, dns_name.NAMERELN_SUBDOMAIN, dns_name.NAMERELN_EQUAL, or dns_name.NAMERELN_COMMONANCESTOR

I{order} is < 0 if self < other, > 0 if self > other, and == 0 if self == other. A relative name is always less than an absolute name. If both names have the same relativity, then the DNSSEC order relation is used to order them.

I{nlabels} is the number of significant labels that the two names have in common.

is_absolute()[source]

Is the most significant label of this name the root label? @rtype: bool

is_subdomain(other)[source]

Is self a subdomain of other?

The notion of subdomain includes equality. @rtype: bool

is_superdomain(other)[source]

Is self a superdomain of other?

The notion of subdomain includes equality. @rtype: bool

is_wild()[source]

Is this name wild? (I.e. Is the least significant label ‘*’?) @rtype: bool

labels
parent()[source]

Return the parent of the name. @rtype: dns_name.Name object @raises NoParent: the name is either the root name or the empty name, and thus has no parent.

relativize(origin)[source]

If self is a subdomain of origin, return a new name which is self relative to origin. Otherwise return self. @rtype: dns_name.Name object

split(depth)[source]

Split a name into a prefix and suffix at depth.

@param depth: the number of labels in the suffix @type depth: int @raises ValueError: the depth was not >= 0 and <= the length of the name. @returns: the tuple (prefix, suffix) @rtype: tuple

to_digestable(origin=None)[source]

Convert name to a format suitable for digesting in hashes.

The name is canonicalized and converted to uncompressed wire format.

@param origin: If the name is relative and origin is not None, then origin will be appended to it. @type origin: dns_name.Name object @raises NeedAbsoluteNameOrOrigin: All names in wire format are absolute. If self is a relative name, then an origin must be supplied; if it is missing, then this exception is raised @rtype: string

to_text(omit_final_dot=False)[source]

Convert name to text format. @param omit_final_dot: If True, don’t emit the final dot (denoting the root label) for absolute names. The default is False. @rtype: string

to_unicode(omit_final_dot=False)[source]

Convert name to Unicode text format.

IDN ACE lables are converted to Unicode.

@param omit_final_dot: If True, don’t emit the final dot (denoting the root label) for absolute names. The default is False. @rtype: string

to_wire(file=None, compress=None, origin=None)[source]

Convert name to wire format, possibly compressing it.

@param file: the file where the name is emitted (typically a cStringIO file). If None, a string containing the wire name will be returned. @type file: file or None @param compress: The compression table. If None (the default) names will not be compressed. @type compress: dict @param origin: If the name is relative and origin is not None, then origin will be appended to it. @type origin: dns_name.Name object @raises NeedAbsoluteNameOrOrigin: All names in wire format are absolute. If self is a relative name, then an origin must be supplied; if it is missing, then this exception is raised

exception pytomo.dns.name.NameTooLong[source]

Bases: pytomo.dns.exception.FormError

Raised if a name is > 255 octets long.

exception pytomo.dns.name.NeedAbsoluteNameOrOrigin[source]

Bases: pytomo.dns.exception.DNSException

Raised if an attempt is made to convert a non-absolute name to wire when there is also a non-absolute (or missing) origin.

exception pytomo.dns.name.NoParent[source]

Bases: pytomo.dns.exception.DNSException

Raised if an attempt is made to get the parent of the root name or the empty name.

pytomo.dns.name.from_text(text, origin=<DNS name .>)[source]

Convert text into a Name object. @rtype: dns_name.Name object

pytomo.dns.name.from_unicode(text, origin=<DNS name .>)[source]

Convert unicode text into a Name object.

Lables are encoded in IDN ACE form.

@rtype: dns_name.Name object

pytomo.dns.name.from_wire(message, current)[source]

Convert possibly compressed wire format into a Name. @param message: the entire DNS message @type message: string @param current: the offset of the beginning of the name from the start of the message @type current: int @raises dns_name.BadPointer: a compression pointer did not point backwards in the message @raises dns_name.BadLabelType: an invalid label type was encountered. @returns: a tuple consisting of the name that was read and the number of bytes of the wire format message which were consumed reading it @rtype: (dns_name.Name object, int) tuple

namedict Module

DNS name dictionary

class pytomo.dns.namedict.NameDict(*args, **kwargs)[source]

Bases: dict

A dictionary whose keys are dns_name.Name objects. @ivar max_depth: the maximum depth of the keys that have ever been added to the dictionary. @type max_depth: int

get_deepest_match(name)[source]

Find the deepest match to I{name} in the dictionary.

The deepest match is the longest name in the dictionary which is a superdomain of I{name}.

@param name: the name @type name: dns_name.Name object @rtype: (key, value) tuple

node Module

DNS nodes. A node is a set of rdatasets.

class pytomo.dns.node.Node[source]

Bases: object

A DNS node.

A node is a set of rdatasets

@ivar rdatasets: the node’s rdatasets @type rdatasets: list of dns_rdataset.Rdataset objects

delete_rdataset(rdclass, rdtype, covers=0)[source]

Delete the rdataset matching the specified properties in the current node.

If a matching rdataset does not exist, it is not an error.

@param rdclass: The class of the rdataset @type rdclass: int @param rdtype: The type of the rdataset @type rdtype: int @param covers: The covered type. @type covers: int

find_rdataset(rdclass, rdtype, covers=0, create=False)[source]

Find an rdataset matching the specified properties in the current node.

@param rdclass: The class of the rdataset @type rdclass: int @param rdtype: The type of the rdataset @type rdtype: int @param covers: The covered type. Usually this value is dns_rdatatype.NONE, but if the rdtype is dns_rdatatype.SIG or dns_rdatatype.RRSIG, then the covers value will be the rdata type the SIG/RRSIG covers. The library treats the SIG and RRSIG types as if they were a family of types, e.g. RRSIG(A), RRSIG(NS), RRSIG(SOA). This makes RRSIGs much easier to work with than if RRSIGs covering different rdata types were aggregated into a single RRSIG rdataset. @type covers: int @param create: If True, create the rdataset if it is not found. @type create: bool @raises KeyError: An rdataset of the desired type and class does not exist and I{create} is not True. @rtype: dns_rdataset.Rdataset object

get_rdataset(rdclass, rdtype, covers=0, create=False)[source]

Get an rdataset matching the specified properties in the current node.

None is returned if an rdataset of the specified type and class does not exist and I{create} is not True.

@param rdclass: The class of the rdataset @type rdclass: int @param rdtype: The type of the rdataset @type rdtype: int @param covers: The covered type. @type covers: int @param create: If True, create the rdataset if it is not found. @type create: bool @rtype: dns_rdataset.Rdataset object or None

rdatasets
replace_rdataset(replacement)[source]

Replace an rdataset.

It is not an error if there is no rdataset matching I{replacement}.

Ownership of the I{replacement} object is transferred to the node; in other words, this method does not store a copy of I{replacement} at the node, it stores I{replacement} itself.

to_text(name, **kw)[source]

Convert a node to text format.

Each rdataset at the node is printed. Any keyword arguments to this method are passed on to the rdataset’s to_text() method. @param name: the owner name of the rdatasets @type name: dns_name.Name object @rtype: string

opcode Module

DNS Opcodes.

exception pytomo.dns.opcode.UnknownOpcode[source]

Bases: pytomo.dns.exception.DNSException

Raised if an opcode is unknown.

pytomo.dns.opcode.from_flags(flags)[source]

Extract an opcode from DNS message flags.

@param flags: int @rtype: int

pytomo.dns.opcode.from_text(text)[source]

Convert text into an opcode.

@param text: the textual opcode @type text: string @raises UnknownOpcode: the opcode is unknown @rtype: int

pytomo.dns.opcode.is_update(flags)[source]

True if the opcode in flags is UPDATE.

@param flags: DNS flags @type flags: int @rtype: bool

pytomo.dns.opcode.to_flags(value)[source]

Convert an opcode to a value suitable for ORing into DNS message flags. @rtype: int

pytomo.dns.opcode.to_text(value)[source]

Convert an opcode to text.

@param value: the opcdoe @type value: int @raises UnknownOpcode: the opcode is unknown @rtype: string

query Module

Talk to a DNS server.

exception pytomo.dns.query.BadResponse[source]

Bases: pytomo.dns.exception.FormError

Raised if a query response does not respond to the question asked.

exception pytomo.dns.query.UnexpectedSource[source]

Bases: pytomo.dns.exception.DNSException

Raised if a query response comes from an unexpected address or port.

pytomo.dns.query.tcp(q, where, timeout=None, port=53, af=None, source=None, source_port=0, one_rr_per_rrset=False)[source]

Return the response obtained after sending a query via TCP.

@param q: the query @type q: dns_message.Message object @param where: where to send the message @type where: string containing an IPv4 or IPv6 address @param timeout: The number of seconds to wait before the query times out. If None, the default, wait forever. @type timeout: float @param port: The port to which to send the message. The default is 53. @type port: int @param af: the address family to use. The default is None, which causes the address family to use to be inferred from the form of of where. If the inference attempt fails, AF_INET is used. @type af: int @rtype: dns_message.Message object @param source: source address. The default is the IPv4 wildcard address. @type source: string @param source_port: The port from which to send the message. The default is 0. @type source_port: int @param one_rr_per_rrset: Put each RR into its own RRset @type one_rr_per_rrset: bool

pytomo.dns.query.udp(q, where, timeout=None, port=53, af=None, source=None, source_port=0, ignore_unexpected=False, one_rr_per_rrset=False)[source]

Return the response obtained after sending a query via UDP.

@param q: the query @type q: dns_message.Message @param where: where to send the message @type where: string containing an IPv4 or IPv6 address @param timeout: The number of seconds to wait before the query times out. If None, the default, wait forever. @type timeout: float @param port: The port to which to send the message. The default is 53. @type port: int @param af: the address family to use. The default is None, which causes the address family to use to be inferred from the form of of where. If the inference attempt fails, AF_INET is used. @type af: int @rtype: dns_message.Message object @param source: source address. The default is the IPv4 wildcard address. @type source: string @param source_port: The port from which to send the message. The default is 0. @type source_port: int @param ignore_unexpected: If True, ignore responses from unexpected sources. The default is False. @type ignore_unexpected: bool @param one_rr_per_rrset: Put each RR into its own RRset @type one_rr_per_rrset: bool

pytomo.dns.query.xfr(where, zone, rdtype=252, rdclass=1, timeout=None, port=53, keyring=None, keyname=None, relativize=True, af=None, lifetime=None, source=None, source_port=0, serial=0, use_udp=False, keyalgorithm=<DNS name HMAC-MD5.SIG-ALG.REG.INT.>)[source]

Return a generator for the responses to a zone transfer.

@param where: where to send the message @type where: string containing an IPv4 or IPv6 address @param zone: The name of the zone to transfer @type zone: dns_name.Name object or string @param rdtype: The type of zone transfer. The default is dns_rdatatype.AXFR. @type rdtype: int or string @param rdclass: The class of the zone transfer. The default is dns_rdatatype.IN. @type rdclass: int or string @param timeout: The number of seconds to wait for each response message. If None, the default, wait forever. @type timeout: float @param port: The port to which to send the message. The default is 53. @type port: int @param keyring: The TSIG keyring to use @type keyring: dict @param keyname: The name of the TSIG key to use @type keyname: dns_name.Name object or string @param relativize: If True, all names in the zone will be relativized to the zone origin. It is essential that the relativize setting matches the one specified to dns_zone.from_xfr(). @type relativize: bool @param af: the address family to use. The default is None, which causes the address family to use to be inferred from the form of of where. If the inference attempt fails, AF_INET is used. @type af: int @param lifetime: The total number of seconds to spend doing the transfer. If None, the default, then there is no limit on the time the transfer may take. @type lifetime: float @rtype: generator of dns_message.Message objects. @param source: source address. The default is the IPv4 wildcard address. @type source: string @param source_port: The port from which to send the message. The default is 0. @type source_port: int @param serial: The SOA serial number to use as the base for an IXFR diff sequence (only meaningful if rdtype == dns_rdatatype.IXFR). @type serial: int @param use_udp: Use UDP (only meaningful for IXFR) @type use_udp: bool @param keyalgorithm: The TSIG algorithm to use; defaults to dns_tsig.default_algorithm @type keyalgorithm: string

rcode Module

DNS Result Codes.

exception pytomo.dns.rcode.UnknownRcode[source]

Bases: pytomo.dns.exception.DNSException

Raised if an rcode is unknown.

pytomo.dns.rcode.from_flags(flags, ednsflags)[source]

Return the rcode value encoded by flags and ednsflags.

@param flags: the DNS flags @type flags: int @param ednsflags: the EDNS flags @type ednsflags: int @raises ValueError: rcode is < 0 or > 4095 @rtype: int

pytomo.dns.rcode.from_text(text)[source]

Convert text into an rcode.

@param text: the texual rcode @type text: string @raises UnknownRcode: the rcode is unknown @rtype: int

pytomo.dns.rcode.to_flags(value)[source]

Return a (flags, ednsflags) tuple which encodes the rcode.

@param value: the rcode @type value: int @raises ValueError: rcode is < 0 or > 4095 @rtype: (int, int) tuple

pytomo.dns.rcode.to_text(value)[source]

Convert rcode into text.

@param value: the rcode @type value: int @rtype: string

rdata Module

DNS rdata.

@var _rdata_modules: A dictionary mapping a (rdclass, rdtype) tuple to the module which implements that type. @type _rdata_modules: dict @var _module_prefix: The prefix to use when forming modules names. The default is ‘dns.rdtypes’. Changing this value will break the library. Changed for absolute imports @type _module_prefix: string @var _hex_chunk: At most this many octets that will be represented in each chunk of hexstring that _hexify() produces before whitespace occurs. @type _hex_chunk: int

class pytomo.dns.rdata.GenericRdata(rdclass, rdtype, data)[source]

Bases: pytomo.dns.rdata.Rdata

Generate Rdata Class

This class is used for rdata types for which we have no better implementation. It implements the DNS “unknown RRs” scheme.

data
classmethod from_text(rdclass, rdtype, tok, origin=None, relativize=True)[source]
classmethod from_wire(rdclass, rdtype, wire, current, rdlen, origin=None)[source]
to_text(origin=None, relativize=True, **kw)[source]
to_wire(file, compress=None, origin=None)[source]
class pytomo.dns.rdata.Rdata(rdclass, rdtype)[source]

Bases: object

Base class for all DNS rdata types.

choose_relativity(origin=None, relativize=True)[source]

Convert any domain names in the rdata to the specified relativization.

covers()[source]

DNS SIG/RRSIG rdatas apply to a specific type; this type is returned by the covers() function. If the rdata type is not SIG or RRSIG, dns_rdatatype.NONE is returned. This is useful when creating rdatasets, allowing the rdataset to contain only RRSIGs of a particular type, e.g. RRSIG(NS). @rtype: int

extended_rdatatype()[source]

Return a 32-bit type value, the least significant 16 bits of which are the ordinary DNS type, and the upper 16 bits of which are the “covered” type, if any. @rtype: int

classmethod from_text(rdclass, rdtype, tok, origin=None, relativize=True)[source]

Build an rdata object from text format.

@param rdclass: The rdata class @type rdclass: int @param rdtype: The rdata type @type rdtype: int @param tok: The tokenizer @type tok: dns_tokenizer.Tokenizer @param origin: The origin to use for relative names @type origin: dns_name.Name @param relativize: should names be relativized? @type relativize: bool @rtype: dns_rdata.Rdata instance

classmethod from_wire(rdclass, rdtype, wire, current, rdlen, origin=None)[source]

Build an rdata object from wire format

@param rdclass: The rdata class @type rdclass: int @param rdtype: The rdata type @type rdtype: int @param wire: The wire-format message @type wire: string @param current: The offet in wire of the beginning of the rdata. @type current: int @param rdlen: The length of the wire-format rdata @type rdlen: int @param origin: The origin to use for relative names @type origin: dns_name.Name @rtype: dns_rdata.Rdata instance

rdclass
rdtype
to_digestable(origin=None)[source]

Convert rdata to a format suitable for digesting in hashes. This is also the DNSSEC canonical form.

to_text(origin=None, relativize=True, **kw)[source]

Convert an rdata to text format. @rtype: string

to_wire(file, compress=None, origin=None)[source]

Convert an rdata to wire format. @rtype: string

validate()[source]

Check that the current contents of the rdata’s fields are valid. If you change an rdata by assigning to its fields, it is a good idea to call validate() when you are done making changes.

pytomo.dns.rdata.from_text(rdclass, rdtype, tok, origin=None, relativize=True)[source]

Build an rdata object from text format.

This function attempts to dynamically load a class which implements the specified rdata class and type. If there is no class-and-type-specific implementation, the GenericRdata class is used.

Once a class is chosen, its from_text() class method is called with the parameters to this function.

@param rdclass: The rdata class @type rdclass: int @param rdtype: The rdata type @type rdtype: int @param tok: The tokenizer @type tok: dns_tokenizer.Tokenizer @param origin: The origin to use for relative names @type origin: dns_name.Name @param relativize: Should names be relativized? @type relativize: bool @rtype: dns_rdata.Rdata instance

pytomo.dns.rdata.from_wire(rdclass, rdtype, wire, current, rdlen, origin=None)[source]

Build an rdata object from wire format

This function attempts to dynamically load a class which implements the specified rdata class and type. If there is no class-and-type-specific implementation, the GenericRdata class is used.

Once a class is chosen, its from_wire() class method is called with the parameters to this function.

@param rdclass: The rdata class @type rdclass: int @param rdtype: The rdata type @type rdtype: int @param wire: The wire-format message @type wire: string @param current: The offet in wire of the beginning of the rdata. @type current: int @param rdlen: The length of the wire-format rdata @type rdlen: int @param origin: The origin to use for relative names @type origin: dns_name.Name @rtype: dns_rdata.Rdata instance

pytomo.dns.rdata.get_rdata_class(rdclass, rdtype)[source]

rdataclass Module

DNS Rdata Classes.

@var _by_text: The rdata class textual name to value mapping @type _by_text: dict @var _by_value: The rdata class value to textual name mapping @type _by_value: dict @var _metaclasses: If an rdataclass is a metaclass, there will be a mapping whose key is the rdatatype value and whose value is True in this dictionary. @type _metaclasses: dict

exception pytomo.dns.rdataclass.UnknownRdataclass[source]

Bases: pytomo.dns.exception.DNSException

Raised when a class is unknown.

pytomo.dns.rdataclass.from_text(text)[source]

Convert text into a DNS rdata class value. @param text: the text @type text: string @rtype: int @raises dns_rdataclass.UnknownRdataClass: the class is unknown @raises ValueError: the rdata class value is not >= 0 and <= 65535

pytomo.dns.rdataclass.is_metaclass(rdclass)[source]

True if the class is a metaclass. @param rdclass: the rdata class @type rdclass: int @rtype: bool

pytomo.dns.rdataclass.to_text(value)[source]

Convert a DNS rdata class to text. @param value: the rdata class value @type value: int @rtype: string @raises ValueError: the rdata class value is not >= 0 and <= 65535

rdataset Module

DNS rdatasets (an rdataset is a set of rdatas of a given type and class)

exception pytomo.dns.rdataset.DifferingCovers[source]

Bases: pytomo.dns.exception.DNSException

Raised if an attempt is made to add a SIG/RRSIG whose covered type is not the same as that of the other rdatas in the rdataset.

exception pytomo.dns.rdataset.IncompatibleTypes[source]

Bases: pytomo.dns.exception.DNSException

Raised if an attempt is made to add rdata of an incompatible type.

class pytomo.dns.rdataset.Rdataset(rdclass, rdtype, covers=0)[source]

Bases: pytomo.dns.set.Set

A DNS rdataset.

@ivar rdclass: The class of the rdataset @type rdclass: int @ivar rdtype: The type of the rdataset @type rdtype: int @ivar covers: The covered type. Usually this value is dns_rdatatype.NONE, but if the rdtype is dns_rdatatype.SIG or dns_rdatatype.RRSIG, then the covers value will be the rdata type the SIG/RRSIG covers. The library treats the SIG and RRSIG types as if they were a family of types, e.g. RRSIG(A), RRSIG(NS), RRSIG(SOA). This makes RRSIGs much easier to work with than if RRSIGs covering different rdata types were aggregated into a single RRSIG rdataset. @type covers: int @ivar ttl: The DNS TTL (Time To Live) value @type ttl: int

add(rd, ttl=None)[source]

Add the specified rdata to the rdataset.

If the optional I{ttl} parameter is supplied, then self.update_ttl(ttl) will be called prior to adding the rdata.

@param rd: The rdata @type rd: dns_rdata.Rdata object @param ttl: The TTL @type ttl: int

covers
intersection_update(other)[source]
match(rdclass, rdtype, covers)[source]

Returns True if this rdataset matches the specified class, type, and covers

rdclass
rdtype
to_text(name=None, origin=None, relativize=True, override_rdclass=None, **kw)[source]

Convert the rdataset into DNS master file format.

@see: L{dns_name.Name.choose_relativity} for more information on how I{origin} and I{relativize} determine the way names are emitted.

Any additional keyword arguments are passed on to the rdata to_text() method.

@param name: If name is not None, emit a RRs with I{name} as the owner name. @type name: dns_name.Name object @param origin: The origin for relative names, or None. @type origin: dns_name.Name object @param relativize: True if names should names be relativized @type relativize: bool

to_wire(name, file, compress=None, origin=None, override_rdclass=None, want_shuffle=True)[source]

Convert the rdataset to wire format.

@param name: The owner name of the RRset that will be emitted @type name: dns_name.Name object @param file: The file to which the wire format data will be appended @type file: file @param compress: The compression table to use; the default is None. @type compress: dict @param origin: The origin to be appended to any relative names when they are emitted. The default is None. @returns: the number of records emitted @rtype: int

ttl
union_update(other)[source]
update(other)[source]

Add all rdatas in other to self.

@param other: The rdataset from which to update @type other: dns_rdataset.Rdataset object

update_ttl(ttl)[source]

Set the TTL of the rdataset to be the lesser of the set’s current TTL or the specified TTL. If the set contains no rdatas, set the TTL to the specified TTL. @param ttl: The TTL @type ttl: int

pytomo.dns.rdataset.from_rdata(ttl, *rdatas)[source]

Create an rdataset with the specified TTL, and with the specified rdata objects.

@rtype: dns_rdataset.Rdataset object

pytomo.dns.rdataset.from_rdata_list(ttl, rdatas)[source]

Create an rdataset with the specified TTL, and with the specified list of rdata objects.

@rtype: dns_rdataset.Rdataset object

pytomo.dns.rdataset.from_text(rdclass, rdtype, ttl, *text_rdatas)[source]

Create an rdataset with the specified class, type, and TTL, and with the specified rdatas in text format.

@rtype: dns_rdataset.Rdataset object

pytomo.dns.rdataset.from_text_list(rdclass, rdtype, ttl, text_rdatas)[source]

Create an rdataset with the specified class, type, and TTL, and with the specified list of rdatas in text format.

@rtype: dns_rdataset.Rdataset object

rdatatype Module

DNS Rdata Types.

@var _by_text: The rdata type textual name to value mapping @type _by_text: dict @var _by_value: The rdata type value to textual name mapping @type _by_value: dict @var _metatypes: If an rdatatype is a metatype, there will be a mapping whose key is the rdatatype value and whose value is True in this dictionary. @type _metatypes: dict @var _singletons: If an rdatatype is a singleton, there will be a mapping whose key is the rdatatype value and whose value is True in this dictionary. @type _singletons: dict

exception pytomo.dns.rdatatype.UnknownRdatatype[source]

Bases: pytomo.dns.exception.DNSException

Raised if a type is unknown.

pytomo.dns.rdatatype.from_text(text)[source]

Convert text into a DNS rdata type value. @param text: the text @type text: string @raises dns_rdatatype.UnknownRdatatype: the type is unknown @raises ValueError: the rdata type value is not >= 0 and <= 65535 @rtype: int

pytomo.dns.rdatatype.is_metatype(rdtype)[source]

True if the type is a metatype. @param rdtype: the type @type rdtype: int @rtype: bool

pytomo.dns.rdatatype.is_singleton(rdtype)[source]

True if the type is a singleton. @param rdtype: the type @type rdtype: int @rtype: bool

pytomo.dns.rdatatype.to_text(value)[source]

Convert a DNS rdata type to text. @param value: the rdata type value @type value: int @raises ValueError: the rdata type value is not >= 0 and <= 65535 @rtype: string

renderer Module

Help for building DNS wire format messages

class pytomo.dns.renderer.Renderer(id=None, flags=0, max_size=65535, origin=None)[source]

Bases: object

Helper class for building DNS wire-format messages.

Most applications can use the higher-level L{dns_message.Message} class and its to_wire() method to generate wire-format messages. This class is for those applications which need finer control over the generation of messages.

Typical use:

r = dns_renderer.Renderer(id=1, flags=0x80, max_size=512)
r.add_question(qname, qtype, qclass)
r.add_rrset(dns_renderer.ANSWER, rrset_1)
r.add_rrset(dns_renderer.ANSWER, rrset_2)
r.add_rrset(dns_renderer.AUTHORITY, ns_rrset)
r.add_edns(0, 0, 4096)
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)
wire = r.get_wire()

@ivar output: where rendering is written @type output: cStringIO.StringIO object @ivar id: the message id @type id: int @ivar flags: the message flags @type flags: int @ivar max_size: the maximum size of the message @type max_size: int @ivar origin: the origin to use when rendering relative names @type origin: dns_name.Name object @ivar compress: the compression table @type compress: dict @ivar section: the section currently being rendered @type section: int (dns_renderer.QUESTION, dns_renderer.ANSWER, dns_renderer.AUTHORITY, or dns_renderer.ADDITIONAL) @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

add_edns(edns, ednsflags, payload, options=None)[source]

Add an EDNS OPT record to the message.

@param edns: The EDNS level to use. @type edns: int @param ednsflags: EDNS flag values. @type ednsflags: int @param payload: The EDNS sender’s payload field, which is the maximum size of UDP datagram the sender can handle. @type payload: int @param options: The EDNS options list @type options: list of dns_edns_Option instances @see: RFC 2671

add_question(qname, rdtype, rdclass=1)[source]

Add a question to the message.

@param qname: the question name @type qname: dns_name.Name @param rdtype: the question rdata type @type rdtype: int @param rdclass: the question rdata class @type rdclass: int

add_rdataset(section, name, rdataset, **kw)[source]

Add the rdataset to the specified section, using the specified name as the owner name.

Any keyword arguments are passed on to the rdataset’s to_wire() routine.

@param section: the section @type section: int @param name: the owner name @type name: dns_name.Name object @param rdataset: the rdataset @type rdataset: dns_rdataset.Rdataset object

add_rrset(section, rrset, **kw)[source]

Add the rrset to the specified section.

Any keyword arguments are passed on to the rdataset’s to_wire() routine.

@param section: the section @type section: int @param rrset: the rrset @type rrset: dns_rrset.RRset object

add_tsig(keyname, secret, fudge, id, tsig_error, other_data, request_mac, algorithm=<DNS name HMAC-MD5.SIG-ALG.REG.INT.>)[source]

Add a TSIG signature to the message.

@param keyname: the TSIG key name @type keyname: dns_name.Name object @param secret: the secret to use @type secret: string @param fudge: TSIG time fudge @type fudge: int @param id: the message id to encode in the tsig signature @type id: int @param tsig_error: TSIG error code; default is 0. @type tsig_error: int @param other_data: TSIG other data. @type other_data: string @param request_mac: This message is a response to the request which had the specified MAC. @param algorithm: the TSIG algorithm to use @type request_mac: string

get_wire()[source]

Return the wire format message.

@rtype: string

write_header()[source]

Write the DNS message header.

Writing the DNS message header is done asfter all sections have been rendered, but before the optional TSIG signature is added.

resolver Module

DNS stub resolver.

@var default_resolver: The default resolver object @type default_resolver: dns_resolver.Resolver object

class pytomo.dns.resolver.Answer(qname, rdtype, rdclass, response)[source]

Bases: object

DNS stub resolver answer

Instances of this class bundle up the result of a successful DNS resolution.

For convenience, the answer object implements much of the sequence protocol, forwarding to its rrset. E.g. “for a in answer” is equivalent to “for a in answer.rrset”, “answer[i]” is equivalent to “answer.rrset[i]”, and “answer[i:j]” is equivalent to “answer.rrset[i:j]”.

Note that CNAMEs or DNAMEs in the response may mean that answer node’s name might not be the query name.

@ivar qname: The query name @type qname: dns_name.Name object @ivar rdtype: The query type @type rdtype: int @ivar rdclass: The query class @type rdclass: int @ivar response: The response message @type response: dns_message.Message object @ivar rrset: The answer @type rrset: dns_rrset.RRset object @ivar expiration: The time when the answer expires @type expiration: float (seconds since the epoch)

class pytomo.dns.resolver.Cache(cleaning_interval=300.0)[source]

Bases: object

Simple DNS answer cache.

@ivar data: A dictionary of cached data @type data: dict @ivar cleaning_interval: The number of seconds between cleanings. The default is 300 (5 minutes). @type cleaning_interval: float @ivar next_cleaning: The time the cache should next be cleaned (in seconds since the epoch.) @type next_cleaning: float

flush(key=None)[source]

Flush the cache.

If I{key} is specified, only that item is flushed. Otherwise the entire cache is flushed.

@param key: the key to flush @type key: (dns_name.Name, int, int) tuple or None

get(key)[source]

Get the answer associated with I{key}. Returns None if no answer is cached for the key. @param key: the key @type key: (dns_name.Name, int, int) tuple whose values are the query name, rdtype, and rdclass. @rtype: dns_resolver.Answer object or None

maybe_clean()[source]

Clean the cache if it’s time to do so.

put(key, value)[source]

Associate key and value in the cache. @param key: the key @type key: (dns_name.Name, int, int) tuple whose values are the query name, rdtype, and rdclass. @param value: The answer being cached @type value: dns_resolver.Answer object

exception pytomo.dns.resolver.NXDOMAIN[source]

Bases: pytomo.dns.exception.DNSException

The query name does not exist.

exception pytomo.dns.resolver.NoAnswer[source]

Bases: pytomo.dns.exception.DNSException

The response did not contain an answer to the question.

exception pytomo.dns.resolver.NoNameservers[source]

Bases: pytomo.dns.exception.DNSException

No non-broken nameservers are available to answer the query.

exception pytomo.dns.resolver.NoRootSOA[source]

Bases: pytomo.dns.exception.DNSException

Raised if for some reason there is no SOA at the root name. This should never happen!

exception pytomo.dns.resolver.NotAbsolute[source]

Bases: pytomo.dns.exception.DNSException

Raised if an absolute domain name is required but a relative name was provided.

class pytomo.dns.resolver.Resolver(filename='/etc/resolv.conf', configure=True)[source]

Bases: object

DNS stub resolver

@ivar domain: The domain of this host @type domain: dns_name.Name object @ivar nameservers: A list of nameservers to query. Each nameserver is a string which contains the IP address of a nameserver. @type nameservers: list of strings @ivar search: The search list. If the query name is a relative name, the resolver will construct an absolute query name by appending the search names one by one to the query name. @type search: list of dns_name.Name objects @ivar port: The port to which to send queries. The default is 53. @type port: int @ivar timeout: The number of seconds to wait for a response from a server, before timing out. @type timeout: float @ivar lifetime: The total number of seconds to spend trying to get an answer to the question. If the lifetime expires, a Timeout exception will occur. @type lifetime: float @ivar keyring: The TSIG keyring to use. The default is None. @type keyring: dict @ivar keyname: The TSIG keyname to use. The default is None. @type keyname: dns_name.Name object @ivar keyalgorithm: The TSIG key algorithm to use. The default is dns_tsig.default_algorithm. @type keyalgorithm: string @ivar edns: The EDNS level to use. The default is -1, no Edns. @type edns: int @ivar ednsflags: The EDNS flags @type ednsflags: int @ivar payload: The EDNS payload size. The default is 0. @type payload: int @ivar cache: The cache to use. The default is None. @type cache: dns_resolver.Cache object

query(qname, rdtype=1, rdclass=1, tcp=False, source=None)[source]

Query nameservers to find the answer to the question.

The I{qname}, I{rdtype}, and I{rdclass} parameters may be objects of the appropriate type, or strings that can be converted into objects of the appropriate type. E.g. For I{rdtype} the integer 2 and the the string ‘NS’ both mean to query for records with DNS rdata type NS.

@param qname: the query name @type qname: dns_name.Name object or string @param rdtype: the query type @type rdtype: int or string @param rdclass: the query class @type rdclass: int or string @param tcp: use TCP to make the query (default is False). @type tcp: bool @param source: bind to this IP address (defaults to machine default IP). @type source: IP address in dotted quad notation @rtype: dns_resolver.Answer instance @raises Timeout: no answers could be found in the specified lifetime @raises NXDOMAIN: the query name does not exist @raises NoAnswer: the response did not contain an answer @raises NoNameservers: no non-broken nameservers are available to answer the question.

read_registry()[source]

Extract resolver configuration from the Windows registry.

read_resolv_conf(f)[source]

Process f as a file in the /etc/resolv.conf format. If f is a string, it is used as the name of the file to open; otherwise it is treated as the file itself.

reset()[source]

Reset all resolver configuration to the defaults.

use_edns(edns, ednsflags, payload)[source]

Configure Edns.

@param edns: The EDNS level to use. The default is -1, no Edns. @type edns: int @param ednsflags: The EDNS flags @type ednsflags: int @param payload: The EDNS payload size. The default is 0. @type payload: int

use_tsig(keyring, keyname=None, algorithm=<DNS name HMAC-MD5.SIG-ALG.REG.INT.>)[source]

Add a TSIG signature to the query.

@param keyring: The TSIG keyring to use; defaults to None. @type keyring: dict @param keyname: The name of the TSIG key to use; defaults to None. The key must be defined in the keyring. If a keyring is specified but a keyname is not, then the key used will be the first key in the keyring. Note that the order of keys in a dictionary is not defined, so applications should supply a keyname when a keyring is used, unless they know the keyring contains only one key. @param algorithm: The TSIG key algorithm to use. The default is dns_tsig.default_algorithm. @type algorithm: string

pytomo.dns.resolver.get_default_resolver()[source]

Get the default resolver, initializing it if necessary.

pytomo.dns.resolver.query(qname, rdtype=1, rdclass=1, tcp=False, source=None)[source]

Query nameservers to find the answer to the question.

This is a convenience function that uses the default resolver object to make the query. @see: L{dns_resolver.Resolver.query} for more information on the parameters.

pytomo.dns.resolver.zone_for_name(name, rdclass=1, tcp=False, resolver=None)[source]

Find the name of the zone which contains the specified name.

@param name: the query name @type name: absolute dns_name.Name object or string @param rdclass: The query class @type rdclass: int @param tcp: use TCP to make the query (default is False). @type tcp: bool @param resolver: the resolver to use @type resolver: dns_resolver.Resolver object or None @rtype: dns_name.Name

reversename Module

DNS Reverse Map Names.

@var ipv4_reverse_domain: The DNS IPv4 reverse-map domain, in-addr.arpa. @type ipv4_reverse_domain: dns_name.Name object @var ipv6_reverse_domain: The DNS IPv6 reverse-map domain, ip6.arpa. @type ipv6_reverse_domain: dns_name.Name object

pytomo.dns.reversename.from_address(text)[source]

Convert an IPv4 or IPv6 address in textual form into a Name object whose value is the reverse-map domain name of the address. @param text: an IPv4 or IPv6 address in textual form (e.g. ‘127.0.0.1’, ‘::1’) @type text: str @rtype: dns_name.Name object

pytomo.dns.reversename.to_address(name)[source]

Convert a reverse map domain name into textual address form. @param name: an IPv4 or IPv6 address in reverse-map form. @type name: dns_name.Name object @rtype: str

rrset Module

DNS RRsets (an RRset is a named rdataset)

class pytomo.dns.rrset.RRset(name, rdclass, rdtype, covers=0, deleting=None)[source]

Bases: pytomo.dns.rdataset.Rdataset

A DNS RRset (named rdataset).

RRset inherits from Rdataset, and RRsets can be treated as Rdatasets in most cases. There are, however, a few notable exceptions. RRsets have different to_wire() and to_text() method arguments, reflecting the fact that RRsets always have an owner name.

deleting
match(name, rdclass, rdtype, covers, deleting=None)[source]

Returns True if this rrset matches the specified class, type, covers, and deletion state.

name
to_rdataset()[source]

Convert an RRset into an Rdataset.

@rtype: dns_rdataset.Rdataset object

to_text(origin=None, relativize=True, **kw)[source]

Convert the RRset into DNS master file format.

@see: L{dns_name.Name.choose_relativity} for more information on how I{origin} and I{relativize} determine the way names are emitted.

Any additional keyword arguments are passed on to the rdata to_text() method.

@param origin: The origin for relative names, or None. @type origin: dns_name.Name object @param relativize: True if names should names be relativized @type relativize: bool

to_wire(file, compress=None, origin=None, **kw)[source]

Convert the RRset to wire format.

pytomo.dns.rrset.from_rdata(name, ttl, *rdatas)[source]

Create an RRset with the specified name and TTL, and with the specified rdata objects.

@rtype: dns_rrset.RRset object

pytomo.dns.rrset.from_rdata_list(name, ttl, rdatas)[source]

Create an RRset with the specified name and TTL, and with the specified list of rdata objects.

@rtype: dns_rrset.RRset object

pytomo.dns.rrset.from_text(name, ttl, rdclass, rdtype, *text_rdatas)[source]

Create an RRset with the specified name, TTL, class, and type and with the specified rdatas in text format.

@rtype: dns_rrset.RRset object

pytomo.dns.rrset.from_text_list(name, ttl, rdclass, rdtype, text_rdatas)[source]

Create an RRset with the specified name, TTL, class, and type, and with the specified list of rdatas in text format.

@rtype: dns_rrset.RRset object

set Module

A simple Set class.

class pytomo.dns.set.Set(items=None)[source]

Bases: object

A simple set class.

Sets are not in Python until 2.3, and rdata are not immutable so we cannot use sets.Set anyway. This class implements subset of the 2.3 Set interface using a list as the container.

@ivar items: A list of the items which are in the set @type items: list

add(item)[source]

Add an item to the set.

clear()[source]

Make the set empty.

copy()[source]

Make a (shallow) copy of the set.

difference(other)[source]

Return a new set which I{self} - I{other}, i.e. the items in I{self} which are not also in I{other}.

@param other: the other set @type other: Set object @rtype: the same type as I{self}

difference_update(other)[source]

Update the set, removing any elements from other which are in the set. @param other: the collection of items with which to update the set @type other: Set object

discard(item)[source]

Remove an item from the set if present.

intersection(other)[source]

Return a new set which is the intersection of I{self} and I{other}.

@param other: the other set @type other: Set object @rtype: the same type as I{self}

intersection_update(other)[source]

Update the set, removing any elements from other which are not in both sets. @param other: the collection of items with which to update the set @type other: Set object

issubset(other)[source]

Is I{self} a subset of I{other}?

@rtype: bool

issuperset(other)[source]

Is I{self} a superset of I{other}?

@rtype: bool

items
remove(item)[source]

Remove an item from the set.

union(other)[source]

Return a new set which is the union of I{self} and I{other}.

@param other: the other set @type other: Set object @rtype: the same type as I{self}

union_update(other)[source]

Update the set, adding any elements from other which are not already in the set. @param other: the collection of items with which to update the set @type other: Set object

update(other)[source]

Update the set, adding any elements from other which are not already in the set. @param other: the collection of items with which to update the set @type other: any iterable type

tokenizer Module

Tokenize DNS master file format

class pytomo.dns.tokenizer.Token(ttype, value='', has_escape=False)[source]

Bases: object

A DNS master file format token.

@ivar ttype: The token type @type ttype: int @ivar value: The token value @type value: string @ivar has_escape: Does the token value contain escapes? @type has_escape: bool

is_comment()[source]
is_delimiter()[source]
is_eof()[source]
is_eol()[source]
is_eol_or_eof()[source]
is_identifier()[source]
is_quoted_string()[source]
is_whitespace()[source]
unescape()[source]
class pytomo.dns.tokenizer.Tokenizer(f=<open file '<stdin>', mode 'r' at 0x2b7dca47f0c0>, filename=None)[source]

Bases: object

A DNS master file format tokenizer.

A token is a (type, value) tuple, where I{type} is an int, and I{value} is a string. The valid types are EOF, EOL, WHITESPACE, IDENTIFIER, QUOTED_STRING, COMMENT, and DELIMITER.

@ivar file: The file to tokenize @type file: file @ivar ungotten_char: The most recently ungotten character, or None. @type ungotten_char: string @ivar ungotten_token: The most recently ungotten token, or None. @type ungotten_token: (int, string) token tuple @ivar multiline: The current multiline level. This value is increased by one every time a ‘(‘ delimiter is read, and decreased by one every time a ‘)’ delimiter is read. @type multiline: int @ivar quoting: This variable is true if the tokenizer is currently reading a quoted string. @type quoting: bool @ivar eof: This variable is true if the tokenizer has encountered EOF. @type eof: bool @ivar delimiters: The current delimiter dictionary. @type delimiters: dict @ivar line_number: The current line number @type line_number: int @ivar filename: A filename that will be returned by the L{where} method. @type filename: string

get(want_leading=False, want_comment=False)[source]

Get the next token.

@param want_leading: If True, return a WHITESPACE token if the first character read is whitespace. The default is False. @type want_leading: bool @param want_comment: If True, return a COMMENT token if the first token read is a comment. The default is False. @type want_comment: bool @rtype: Token object @raises dns_exception.UnexpectedEnd: input ended prematurely @raises dns_exception.SyntaxError: input was badly formed

get_eol()[source]

Read the next token and raise an exception if it isn’t EOL or EOF.

@raises dns_exception.SyntaxError: @rtype: string

get_identifier(origin=None)[source]

Read the next token and raise an exception if it is not an identifier.

@raises dns_exception.SyntaxError: @rtype: string

get_int()[source]

Read the next token and interpret it as an integer.

@raises dns_exception.SyntaxError: @rtype: int

get_name(origin=None)[source]

Read the next token and interpret it as a DNS name.

@raises dns_exception.SyntaxError: @rtype: dns_name.Name object

get_string(origin=None)[source]

Read the next token and interpret it as a string.

@raises dns_exception.SyntaxError: @rtype: string

get_ttl()[source]
get_uint16()[source]

Read the next token and interpret it as a 16-bit unsigned integer.

@raises dns_exception.SyntaxError: @rtype: int

get_uint32()[source]

Read the next token and interpret it as a 32-bit unsigned integer.

@raises dns_exception.SyntaxError: @rtype: int

get_uint8()[source]

Read the next token and interpret it as an 8-bit unsigned integer.

@raises dns_exception.SyntaxError: @rtype: int

next()[source]

Return the next item in an iteration. @rtype: (int, string)

skip_whitespace()[source]

Consume input until a non-whitespace character is encountered.

The non-whitespace character is then ungotten, and the number of whitespace characters consumed is returned.

If the tokenizer is in multiline mode, then newlines are whitespace.

@rtype: int

unget(token)[source]

Unget a token.

The unget buffer for tokens is only one token large; it is an error to try to unget a token when the unget buffer is not empty.

@param token: the token to unget @type token: Token object @raises UngetBufferFull: there is already an ungotten token

where()[source]

Return the current location in the input.

@rtype: (string, int) tuple. The first item is the filename of the input, the second is the current line number.

exception pytomo.dns.tokenizer.UngetBufferFull[source]

Bases: pytomo.dns.exception.DNSException

Raised when an attempt is made to unget a token when the unget buffer is full.

tsig Module

DNS TSIG support.

exception pytomo.dns.tsig.BadSignature[source]

Bases: pytomo.dns.exception.DNSException

Raised if the TSIG signature fails to verify.

exception pytomo.dns.tsig.BadTime[source]

Bases: pytomo.dns.exception.DNSException

Raised if the current time is not within the TSIG’s validity time.

exception pytomo.dns.tsig.PeerBadKey[source]

Bases: pytomo.dns.tsig.PeerError

Raised if the peer didn’t know the key we used

exception pytomo.dns.tsig.PeerBadSignature[source]

Bases: pytomo.dns.tsig.PeerError

Raised if the peer didn’t like the signature we sent

exception pytomo.dns.tsig.PeerBadTime[source]

Bases: pytomo.dns.tsig.PeerError

Raised if the peer didn’t like the time we sent

exception pytomo.dns.tsig.PeerBadTruncation[source]

Bases: pytomo.dns.tsig.PeerError

Raised if the peer didn’t like amount of truncation in the TSIG we sent

exception pytomo.dns.tsig.PeerError[source]

Bases: pytomo.dns.exception.DNSException

Base class for all TSIG errors generated by the remote peer

pytomo.dns.tsig.get_algorithm(algorithm)[source]

Returns the wire format string and the hash module to use for the specified TSIG algorithm

@rtype: (string, hash constructor) @raises NotImplementedError: I{algorithm} is not supported

pytomo.dns.tsig.hmac_md5(wire, keyname, secret, time, fudge, original_id, error, other_data, request_mac, ctx=None, multi=False, first=True, algorithm=<DNS name HMAC-MD5.SIG-ALG.REG.INT.>)[source]
pytomo.dns.tsig.sign(wire, keyname, secret, time, fudge, original_id, error, other_data, request_mac, ctx=None, multi=False, first=True, algorithm=<DNS name HMAC-MD5.SIG-ALG.REG.INT.>)[source]

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) @raises ValueError: I{other_data} is too long @raises NotImplementedError: I{algorithm} is not supported

pytomo.dns.tsig.validate(wire, keyname, secret, now, request_mac, tsig_start, tsig_rdata, tsig_rdlen, ctx=None, multi=False, first=True)[source]

Validate the specified TSIG rdata against the other input parameters.

@raises FormError: The TSIG is badly formed. @raises BadTime: There is too much time skew between the client and the server. @raises BadSignature: The TSIG signature did not validate @rtype: hmac.HMAC object

tsigkeyring Module

A place to store TSIG keys.

pytomo.dns.tsigkeyring.from_text(textring)[source]

Convert a dictionary containing (textual DNS name, base64 secret) pairs into a binary keyring which has (dns_name.Name, binary secret) pairs. @rtype: dict

pytomo.dns.tsigkeyring.to_text(keyring)[source]

Convert a dictionary containing (dns_name.Name, binary secret) pairs into a text keyring which has (textual DNS name, base64 secret) pairs. @rtype: dict

ttl Module

DNS TTL conversion.

exception pytomo.dns.ttl.BadTTL[source]

Bases: pytomo.dns.exception.SyntaxError

pytomo.dns.ttl.from_text(text)[source]

Convert the text form of a TTL to an integer.

The BIND 8 units syntax for TTLs (e.g. ‘1w6d4h3m10s’) is supported.

@param text: the textual TTL @type text: string @raises dns_ttl.BadTTL: the TTL is not well-formed @rtype: int

update Module

DNS Dynamic Update Support

class pytomo.dns.update.Update(zone, rdclass=1, keyring=None, keyname=None, keyalgorithm=<DNS name HMAC-MD5.SIG-ALG.REG.INT.>)[source]

Bases: pytomo.dns.message.Message

absent(name, rdtype=None)[source]

Require that an owner name (and optionally an rdata type) does not exist as a prerequisite to the execution of the update.

add(name, *args)[source]

Add records. The first argument is always a name. The other arguments can be:

  • rdataset...
  • ttl, rdata...
  • ttl, rdtype, string...
delete(name, *args)[source]

Delete records. The first argument is always a name. The other arguments can be:

  • I{nothing}
  • rdataset...
  • rdata...
  • rdtype, [string...]
present(name, *args)[source]

Require that an owner name (and optionally an rdata type, or specific rdataset) exists as a prerequisite to the execution of the update. The first argument is always a name. The other arguments can be:

  • rdataset...
  • rdata...
  • rdtype, string...
replace(name, *args)[source]

Replace records. The first argument is always a name. The other arguments can be:

  • rdataset...
  • ttl, rdata...
  • ttl, rdtype, string...

Note that if you want to replace the entire node, you should do a delete of the name followed by one or more calls to add.

to_wire(origin=None, max_size=65535)[source]

Return a string containing the update in DNS compressed wire format. @rtype: string

version Module

dnspython release version information.

zone Module

DNS Zones.

exception pytomo.dns.zone.BadZone[source]

Bases: pytomo.dns.exception.DNSException

The zone is malformed.

exception pytomo.dns.zone.NoNS[source]

Bases: pytomo.dns.zone.BadZone

The zone has no NS RRset at its origin.

exception pytomo.dns.zone.NoSOA[source]

Bases: pytomo.dns.zone.BadZone

The zone has no SOA RR at its origin.

exception pytomo.dns.zone.UnknownOrigin[source]

Bases: pytomo.dns.zone.BadZone

The zone’s origin is unknown.

class pytomo.dns.zone.Zone(origin, rdclass=1, relativize=True)[source]

Bases: object

A DNS zone.

A Zone is a mapping from names to nodes. The zone object may be treated like a Python dictionary, e.g. zone[name] will retrieve the node associated with that name. The I{name} may be a dns_name.Name object, or it may be a string. In the either case, if the name is relative it is treated as relative to the origin of the zone.

@ivar rdclass: The zone’s rdata class; the default is class IN. @type rdclass: int @ivar origin: The origin of the zone. @type origin: dns_name.Name object @ivar nodes: A dictionary mapping the names of nodes in the zone to the nodes themselves. @type nodes: dict @ivar relativize: should names in the zone be relativized? @type relativize: bool @cvar node_factory: the factory used to create a new node @type node_factory: class or callable

check_origin()[source]

Do some simple checking of the zone’s origin.

@raises dns_zone.NoSOA: there is no SOA RR @raises dns_zone.NoNS: there is no NS RRset @raises KeyError: there is no origin node

delete_node(name)[source]

Delete the specified node if it exists.

It is not an error if the node does not exist.

delete_rdataset(name, rdtype, covers=0)[source]

Delete the rdataset matching I{rdtype} and I{covers}, if it exists at the node specified by I{name}.

The I{name}, I{rdtype}, and I{covers} parameters may be strings, in which case they will be converted to their proper type.

It is not an error if the node does not exist, or if there is no matching rdataset at the node.

If the node has no rdatasets after the deletion, it will itself be deleted.

@param name: the owner name to look for @type name: DNS.name.Name object or string @param rdtype: the rdata type desired @type rdtype: int or string @param covers: the covered type (defaults to None) @type covers: int or string

find_node(name, create=False)[source]

Find a node in the zone, possibly creating it.

@param name: the name of the node to find @type name: dns_name.Name object or string @param create: should the node be created if it doesn’t exist? @type create: bool @raises KeyError: the name is not known and create was not specified. @rtype: dns_node.Node object

find_rdataset(name, rdtype, covers=0, create=False)[source]

Look for rdata with the specified name and type in the zone, and return an rdataset encapsulating it.

The I{name}, I{rdtype}, and I{covers} parameters may be strings, in which case they will be converted to their proper type.

The rdataset returned is not a copy; changes to it will change the zone.

KeyError is raised if the name or type are not found. Use L{get_rdataset} if you want to have None returned instead.

@param name: the owner name to look for @type name: DNS.name.Name object or string @param rdtype: the rdata type desired @type rdtype: int or string @param covers: the covered type (defaults to None) @type covers: int or string @param create: should the node and rdataset be created if they do not exist? @type create: bool @raises KeyError: the node or rdata could not be found @rtype: dns_rrset.RRset object

find_rrset(name, rdtype, covers=0)[source]

Look for rdata with the specified name and type in the zone, and return an RRset encapsulating it.

The I{name}, I{rdtype}, and I{covers} parameters may be strings, in which case they will be converted to their proper type.

This method is less efficient than the similar L{find_rdataset} because it creates an RRset instead of returning the matching rdataset. It may be more convenient for some uses since it returns an object which binds the owner name to the rdata.

This method may not be used to create new nodes or rdatasets; use L{find_rdataset} instead.

KeyError is raised if the name or type are not found. Use L{get_rrset} if you want to have None returned instead.

@param name: the owner name to look for @type name: DNS.name.Name object or string @param rdtype: the rdata type desired @type rdtype: int or string @param covers: the covered type (defaults to None) @type covers: int or string @raises KeyError: the node or rdata could not be found @rtype: dns_rrset.RRset object

get(key)[source]
get_node(name, create=False)[source]

Get a node in the zone, possibly creating it.

This method is like L{find_node}, except it returns None instead of raising an exception if the node does not exist and creation has not been requested.

@param name: the name of the node to find @type name: dns_name.Name object or string @param create: should the node be created if it doesn’t exist? @type create: bool @rtype: dns_node.Node object or None

get_rdataset(name, rdtype, covers=0, create=False)[source]

Look for rdata with the specified name and type in the zone, and return an rdataset encapsulating it.

The I{name}, I{rdtype}, and I{covers} parameters may be strings, in which case they will be converted to their proper type.

The rdataset returned is not a copy; changes to it will change the zone.

None is returned if the name or type are not found. Use L{find_rdataset} if you want to have KeyError raised instead.

@param name: the owner name to look for @type name: DNS.name.Name object or string @param rdtype: the rdata type desired @type rdtype: int or string @param covers: the covered type (defaults to None) @type covers: int or string @param create: should the node and rdataset be created if they do not exist? @type create: bool @rtype: dns_rrset.RRset object

get_rrset(name, rdtype, covers=0)[source]

Look for rdata with the specified name and type in the zone, and return an RRset encapsulating it.

The I{name}, I{rdtype}, and I{covers} parameters may be strings, in which case they will be converted to their proper type.

This method is less efficient than the similar L{get_rdataset} because it creates an RRset instead of returning the matching rdataset. It may be more convenient for some uses since it returns an object which binds the owner name to the rdata.

This method may not be used to create new nodes or rdatasets; use L{find_rdataset} instead.

None is returned if the name or type are not found. Use L{find_rrset} if you want to have KeyError raised instead.

@param name: the owner name to look for @type name: DNS.name.Name object or string @param rdtype: the rdata type desired @type rdtype: int or string @param covers: the covered type (defaults to None) @type covers: int or string @rtype: dns_rrset.RRset object

items()[source]
iterate_rdatas(rdtype=255, covers=0)[source]

Return a generator which yields (name, ttl, rdata) tuples for all rdatas in the zone which have the specified I{rdtype} and I{covers}. If I{rdtype} is dns_rdatatype.ANY, the default, then all rdatas will be matched.

@param rdtype: int or string @type rdtype: int or string @param covers: the covered type (defaults to None) @type covers: int or string

iterate_rdatasets(rdtype=255, covers=0)[source]

Return a generator which yields (name, rdataset) tuples for all rdatasets in the zone which have the specified I{rdtype} and I{covers}. If I{rdtype} is dns_rdatatype.ANY, the default, then all rdatasets will be matched.

@param rdtype: int or string @type rdtype: int or string @param covers: the covered type (defaults to None) @type covers: int or string

iteritems()[source]
iterkeys()[source]
itervalues()[source]
keys()[source]
node_factory

alias of Node

nodes
origin
rdclass
relativize
replace_rdataset(name, replacement)[source]

Replace an rdataset at name.

It is not an error if there is no rdataset matching I{replacement}.

Ownership of the I{replacement} object is transferred to the zone; in other words, this method does not store a copy of I{replacement} at the node, it stores I{replacement} itself.

If the I{name} node does not exist, it is created.

@param name: the owner name @type name: DNS.name.Name object or string @param replacement: the replacement rdataset @type replacement: dns_rdataset.Rdataset

to_file(f, sorted=True, relativize=True, nl=None)[source]

Write a zone to a file.

@param f: file or string. If I{f} is a string, it is treated as the name of a file to open. @param sorted: if True, the file will be written with the names sorted in DNSSEC order from least to greatest. Otherwise the names will be written in whatever order they happen to have in the zone’s dictionary. @param relativize: if True, domain names in the output will be relativized to the zone’s origin (if possible). @type relativize: bool @param nl: The end of line string. If not specified, the output will use the platform’s native end-of-line marker (i.e. LF on POSIX, CRLF on Windows, CR on Macintosh). @type nl: string or None

values()[source]
pytomo.dns.zone.from_file(f, origin=None, rdclass=1, relativize=True, zone_factory=<class 'pytomo.dns.zone.Zone'>, filename=None, allow_include=True, check_origin=True)[source]

Read a master file and build a zone object.

@param f: file or string. If I{f} is a string, it is treated as the name of a file to open. @param origin: The origin of the zone; if not specified, the first $ORIGIN statement in the master file will determine the origin of the zone. @type origin: dns_name.Name object or string @param rdclass: The zone’s rdata class; the default is class IN. @type rdclass: int @param relativize: should names be relativized? The default is True @type relativize: bool @param zone_factory: The zone factory to use @type zone_factory: function returning a Zone @param filename: The filename to emit when describing where an error occurred; the default is ‘<file>’, or the value of I{f} if I{f} is a string. @type filename: string @param allow_include: is $INCLUDE allowed? @type allow_include: bool @param check_origin: should sanity checks of the origin node be done? The default is True. @type check_origin: bool @raises dns_zone.NoSOA: No SOA RR was found at the zone origin @raises dns_zone.NoNS: No NS RRset was found at the zone origin @rtype: dns_zone.Zone object

pytomo.dns.zone.from_text(text, origin=None, rdclass=1, relativize=True, zone_factory=<class 'pytomo.dns.zone.Zone'>, filename=None, allow_include=False, check_origin=True)[source]

Build a zone object from a master file format string.

@param text: the master file format input @type text: string. @param origin: The origin of the zone; if not specified, the first $ORIGIN statement in the master file will determine the origin of the zone. @type origin: dns_name.Name object or string @param rdclass: The zone’s rdata class; the default is class IN. @type rdclass: int @param relativize: should names be relativized? The default is True @type relativize: bool @param zone_factory: The zone factory to use @type zone_factory: function returning a Zone @param filename: The filename to emit when describing where an error occurred; the default is ‘<string>’. @type filename: string @param allow_include: is $INCLUDE allowed? @type allow_include: bool @param check_origin: should sanity checks of the origin node be done? The default is True. @type check_origin: bool @raises dns_zone.NoSOA: No SOA RR was found at the zone origin @raises dns_zone.NoNS: No NS RRset was found at the zone origin @rtype: dns_zone.Zone object

pytomo.dns.zone.from_xfr(xfr, zone_factory=<class 'pytomo.dns.zone.Zone'>, relativize=True)[source]

Convert the output of a zone transfer generator into a zone object.

@param xfr: The xfr generator @type xfr: generator of dns_message.Message objects @param relativize: should names be relativized? The default is True. It is essential that the relativize setting matches the one specified to dns_query.xfr(). @type relativize: bool @raises dns_zone.NoSOA: No SOA RR was found at the zone origin @raises dns_zone.NoNS: No NS RRset was found at the zone origin @rtype: dns_zone.Zone object