Miscellaneous Utilities

Generic Internet address helper functions.

dns.inet.af_for_address(text)[source]

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

text, a str, the textual address.

Raises ValueError if the address family cannot be determined from the input.

Returns an int.

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

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

family is an int, the address family.

address is a bytes, the network address in binary form.

Raises NotImplementedError if the address family specified is not implemented.

Returns a str.

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

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

family is an int, the address family.

text is a str, the textual address.

Raises NotImplementedError if the address family specified is not implemented.

Returns a bytes.

dns.inet.is_address(text)[source]

Is the specified string an IPv4 or IPv6 address?

text, a str, the textual address.

Returns a bool.

dns.inet.is_multicast(text)[source]

Is the textual-form network address a multicast address?

text, a str, the textual address.

Raises ValueError if the address family cannot be determined from the input.

Returns a bool.

dns.inet.low_level_address_tuple(high_tuple, af=None)[source]

Given a “high-level” address tuple, i.e. an (address, port) return the appropriate “low-level” address tuple suitable for use in socket calls.

If an af other than None is provided, it is assumed the address in the high-level tuple is valid and has that af. If af is None, then af_for_address will be called.

IPv4 helper functions.

dns.ipv4.inet_aton(text)[source]

Convert an IPv4 address in text form to binary form.

text, a str, the IPv4 address in textual form.

Returns a bytes.

dns.ipv4.inet_ntoa(address)[source]

Convert an IPv4 address in binary form to text form.

address, a bytes, the IPv4 address in binary form.

Returns a str.

IPv6 helper functions.

dns.ipv6.inet_aton(text, ignore_scope=False)[source]

Convert an IPv6 address in text form to binary form.

text, a str, the IPv6 address in textual form.

ignore_scope, a bool. If True, a scope will be ignored. If False, the default, it is an error for a scope to be present.

Returns a bytes.

dns.ipv6.inet_ntoa(address)[source]

Convert an IPv6 address in binary form to text form.

address, a bytes, the IPv6 address in binary form.

Raises ValueError if the address isn’t 16 bytes long. Returns a str.

dns.ipv6.is_mapped(address)[source]

Is the specified address a mapped IPv4 address?

address, a bytes is an IPv6 address in binary form.

Returns a bool.

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.

text, a str, the textual TTL.

Raises dns.ttl.BadTTL if the TTL is not well-formed.

Returns an int.

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

A simple set class.

This class was originally used to deal with sets being missing in ancient versions of python, but dnspython will continue to use it as these sets are based on lists and are thus indexable, and this ability is widely used in dnspython applications.

Initialize the set.

items, an iterable or None, the initial set of items.

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 self - other, i.e. the items in self which are not also in other.

Returns the same Set type as this set.

difference_update(other)[source]

Update the set, removing any elements from other which are in the set.

discard(item)[source]

Remove an item from the set if present.

intersection(other)[source]

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

Returns the same Set type as this set.

intersection_update(other)[source]

Update the set, removing any elements from other which are not in both sets.

issubset(other)[source]

Is this set a subset of other?

Returns a bool.

issuperset(other)[source]

Is this set a superset of other?

Returns a bool.

remove(item)[source]

Remove an item from the set.

union(other)[source]

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

Returns the same Set type as this set.

union_update(other)[source]

Update the set, adding any elements from other which are not already in the set.

update(other)[source]

Update the set, adding any elements from other which are not already in the set.

other, the collection of items with which to update the set, which may be any iterable type.

dnspython release version information.

dns.version.MAJOR = 2

MAJOR

dns.version.MICRO = 0

MICRO

dns.version.MINOR = 1

MINOR

dns.version.RELEASELEVEL = 0

RELEASELEVEL

dns.version.SERIAL = 1

SERIAL

dns.version.hexversion = 33619969

hexversion

dns.version.version = '2.1.0dev1'

version