Miscellaneous Utilities
Generic Internet address helper functions.
- dns.inet.af_for_address(text: str) int[source]
Determine the address family of a textual-form network address.
- Parameters:
text (str) – The textual address.
- Raises:
ValueError – If the address family cannot be determined.
- Return type:
- dns.inet.canonicalize(text: str) str[source]
Verify that address is a valid text form IPv4 or IPv6 address and return its canonical text form. IPv6 addresses with scopes are rejected.
- Parameters:
text (str) – The address in textual form.
- Raises:
ValueError – If the text is not a valid address.
- dns.inet.inet_ntop(family: int, address: bytes) str[source]
Convert the binary form of a network address into its textual form.
- Parameters:
- Raises:
NotImplementedError – If the address family is not implemented.
- Return type:
- dns.inet.inet_pton(family: int, text: str) bytes[source]
Convert the textual form of a network address into its binary form.
- Parameters:
- Raises:
NotImplementedError – If the address family is not implemented.
- Return type:
- dns.inet.is_multicast(text: str) bool[source]
Is the textual-form network address a multicast address?
- Parameters:
text (str) – The textual address.
- Raises:
ValueError – If the address family cannot be determined.
- Return type:
- dns.inet.low_level_address_tuple(high_tuple: tuple[str, int], af: int | None = None) Any[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
Noneis provided, it is assumed the address in the high-level tuple is valid and has that af. If af isNone, then af_for_address will be called.
IPv4 helper functions.
- dns.ipv4.canonicalize(text: str | bytes) str[source]
Verify that address is a valid text form IPv4 address and return its canonical text form.
- Parameters:
- Raises:
dns.exception.SyntaxError – If the text is not valid.
- dns.ipv4.inet_aton(text: str | bytes) bytes[source]
Convert an IPv4 address in text form to binary form.
- dns.ipv4.inet_ntoa(address: bytes) str[source]
Convert an IPv4 address in binary form to text form.
IPv6 helper functions.
- dns.ipv6.canonicalize(text: str | bytes) str[source]
Verify that address is a valid text form IPv6 address and return its canonical text form. Addresses with scopes are rejected.
- Parameters:
- Raises:
dns.exception.SyntaxError – If the text is not valid.
- dns.ipv6.inet_aton(text: str | bytes, ignore_scope: bool = False) bytes[source]
Convert an IPv6 address in text form to binary form.
- dns.ipv6.inet_ntoa(address: bytes) str[source]
Convert an IPv6 address in binary form to text form.
- Parameters:
address (bytes) – The IPv6 address in binary form.
- Raises:
ValueError – If the address is not 16 bytes long.
- Return type:
- dns.ttl.from_text(text: str) int[source]
Convert the text form of a TTL to an integer.
The BIND 8 units syntax for TTLs (e.g. ‘1w6d4h3m10s’) is supported.
- Parameters:
text (str) – The textual TTL.
- Raises:
dns.ttl.BadTTL – If the TTL is not well-formed.
- Return type:
- class dns.set.Set(items=None)[source]
A simple set class.
This class was originally used to deal with python not having a set class, and originally the class used lists in its implementation. The ordered and indexable nature of RRsets and Rdatasets is unfortunately widely used in dnspython applications, so for backwards compatibility sets continue to be a custom class, now based on an ordered dictionary.
Initialize the set.
items, an iterable or
None, the initial set of items.- difference(other)[source]
Return a new set which
self-other, i.e. the items inselfwhich are not also inother.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.
- intersection(other)[source]
Return a new set which is the intersection of
selfandother.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.
- symmetric_difference(other)[source]
Return a new set which (
self-other) | (other-self), ie: the items in either ``selforotherwhich are not contained in their intersection.Returns the same Set type as this set.
- symmetric_difference_update(other)[source]
Update the set, retaining only elements unique to both sets.
- union(other)[source]
Return a new set which is the union of
selfandother.Returns the same Set type as this set.
dnspython release version information.
- dns.version.MAJOR = 2
MAJOR
- dns.version.MICRO = 0
MICRO
- dns.version.MINOR = 9
MINOR
- dns.version.RELEASELEVEL = 0
RELEASELEVEL
- dns.version.SERIAL = 0
SERIAL
- dns.version.hexversion = 34144256
hexversion
- dns.version.version = '2.9.0dev0'
version