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.
text, a
str
, the textual address.Raises
ValueError
if the address family cannot be determined from the input.Returns an
int
.
- 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.
text, a
str
, the address in textual form.Raises
ValueError
if the text is not valid.
- dns.inet.inet_ntop(family: int, address: bytes) str [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: int, text: str) bytes [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: str) bool [source]
Is the specified string an IPv4 or IPv6 address?
text, a
str
, the textual address.Returns a
bool
.
- dns.inet.is_multicast(text: str) bool [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: 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
None
is 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.
text, a
str
orbytes
, the IPv4 address in textual form.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.
text, a
str
orbytes
, the IPv4 address in textual form.Returns a
bytes
.
- dns.ipv4.inet_ntoa(address: bytes) str [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.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.
text, a
str
orbytes
, the IPv6 address in textual form.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.
text, a
str
orbytes
, the IPv6 address in textual form.ignore_scope, a
bool
. IfTrue
, a scope will be ignored. IfFalse
, the default, it is an error for a scope to be present.Returns a
bytes
.
- dns.ipv6.inet_ntoa(address: bytes) str [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 astr
.
- dns.ipv6.is_mapped(address: bytes) bool [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: 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.
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 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 inself
which 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
self
andother
.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 ``self
orother
which 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
self
andother
.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 = 8
MINOR
- dns.version.RELEASELEVEL = 0
RELEASELEVEL
- dns.version.SERIAL = 0
SERIAL
- dns.version.hexversion = 34078720
hexversion
- dns.version.version = '2.8.0dev0'
version