Non-digits in the text are ignored, i.e. "16505551212",
"+1.650.555.1212" and "1 (650) 555-1212" are all the same.
- *text*, a ``text``, is an E.164 number in textual form.
+ *text*, a ``str``, is an E.164 number in textual form.
*origin*, a ``dns.name.Name``, the domain in which the number
should be constructed. The default is ``e164.arpa.``.
*want_plus_prefix* is a ``bool``. If True, add a '+' to the beginning of
the returned number.
- Returns a ``text``.
+ Returns a ``str``.
"""
if origin is not None:
e.g. lookup('16505551212', ['e164.dnspython.org.', 'e164.arpa.'])
- *number*, a ``text`` is the number to look for.
+ *number*, a ``str`` is the number to look for.
*domains* is an iterable containing ``dns.name.Name`` values.
*otype*, an ``int``, is the option type.
- *wire*, a ``binary``, is the wire-format message.
+ *wire*, a ``bytes``, is the wire-format message.
*current*, an ``int``, is the offset in *wire* of the beginning
of the rdata.
"""EDNS Client Subnet (ECS, RFC7871)"""
def __init__(self, address, srclen=None, scopelen=0):
- """*address*, a ``text``, is the client address information.
+ """*address*, a ``str``, is the client address information.
*srclen*, an ``int``, the source prefix length, which is the
leftmost number of bits of the address to be used for the
*otype*, an ``int``, is the option type.
- *wire*, a ``binary``, is the wire-format message.
+ *wire*, a ``bytes``, is the wire-format message.
*current*, an ``int``, is the offset in *wire* of the beginning
of the rdata.
"""Convert a flags value into a space-separated list of flag text
values.
- Returns a ``text``.
+ Returns a ``str``.
"""
return _to_text(flags, _by_value, _flags_order)
"""Convert an EDNS flags value into a space-separated list of EDNS flag
text values.
- Returns a ``text``.
+ Returns a ``str``.
"""
return _to_text(flags, _edns_by_value, _edns_flags_order)
*family* is an ``int``, the address family.
- *text* is a ``text``, the textual address.
+ *text* is a ``str``, the textual address.
Raises ``NotImplementedError`` if the address family specified is not
implemented.
- Returns a ``binary``.
+ Returns a ``bytes``.
"""
if family == AF_INET:
*family* is an ``int``, the address family.
- *address* is a ``binary``, the network address in binary form.
+ *address* is a ``bytes``, the network address in binary form.
Raises ``NotImplementedError`` if the address family specified is not
implemented.
- Returns a ``text``.
+ Returns a ``str``.
"""
if family == AF_INET:
def af_for_address(text):
"""Determine the address family of a textual-form network address.
- *text*, a ``text``, the textual address.
+ *text*, a ``str``, the textual address.
Raises ``ValueError`` if the address family cannot be determined
from the input.
def is_multicast(text):
"""Is the textual-form network address a multicast address?
- *text*, a ``text``, the textual address.
+ *text*, a ``str``, the textual address.
Raises ``ValueError`` if the address family cannot be determined
from the input.
def inet_aton(text, ignore_scope=False):
"""Convert an IPv6 address in text form to binary form.
- *text*, a ``text``, the IPv6 address in textual 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.
The *origin*, *relativize*, and any other keyword
arguments are passed to the RRset ``to_wire()`` method.
- Returns a ``text``.
+ Returns a ``str``.
"""
s = io.StringIO()
Raises ``dns.exception.TooBig`` if *max_size* was exceeded.
- Returns a ``binary``.
+ Returns a ``bytes``.
"""
if max_size == 0:
*tsig_error*, an ``int``, the TSIG error code.
- *other_data*, a ``binary``, the TSIG other data.
+ *other_data*, a ``bytes``, the TSIG other data.
*algorithm*, a ``dns.name.Name``, the TSIG algorithm to use.
"""
*keyring*, a ``dict``, the keyring to use if the message is signed.
- *request_mac*, a ``binary``. If the message is a response to a
+ *request_mac*, a ``bytes``. If the message is a response to a
TSIG-signed request, *request_mac* should be set to the MAC of
that request.
facilitate reading multiple messages from a single file with
``dns.message.from_file()``.
- *text*, a ``text``, the text format message.
+ *text*, a ``str``, the text format message.
*idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA
encoder/decoder. If ``None``, the default IDNA 2003 encoder/decoder
Message blocks are separated by a single blank line.
- *f*, a ``file`` or ``text``. If *f* is text, it is treated as the
+ *f*, a ``file`` or ``str``. If *f* is text, it is treated as the
pathname of a file to open.
Raises ``dns.message.UnknownHeaderField`` if a header is unknown.
The query will have a randomly chosen query id, and its DNS flags
will be set to dns.flags.RD.
- qname, a ``dns.name.Name`` or ``text``, the query name.
+ qname, a ``dns.name.Name`` or ``str``, the query name.
- *rdtype*, an ``int`` or ``text``, the desired rdata type.
+ *rdtype*, an ``int`` or ``str``, the desired rdata type.
- *rdclass*, an ``int`` or ``text``, the desired rdata class; the default
+ *rdclass*, an ``int`` or ``str``, the desired rdata class; the default
is class IN.
*use_edns*, an ``int``, ``bool`` or ``None``. The EDNS level to use; the
def _maybe_convert_to_binary(label):
- """If label is ``text``, convert it to ``binary``. If it is already
- ``binary`` just return it.
+ """If label is ``str``, convert it to ``bytes``. If it is already
+ ``bytes`` just return it.
"""
"""A DNS name.
The dns.name.Name class represents a DNS name as a tuple of
- labels. Each label is a `binary` in DNS wire format. Instances
+ labels. Each label is a ``bytes`` in DNS wire format. Instances
of the class are immutable.
"""
__slots__ = ['labels']
def __init__(self, labels):
- """*labels* is any iterable whose values are ``text`` or ``binary``.
+ """*labels* is any iterable whose values are ``str`` or ``bytes``.
"""
labels = [_maybe_convert_to_binary(x) for x in labels]
dot (denoting the root label) for absolute names. The default
is False.
- Returns a ``text``.
+ Returns a ``str``.
"""
if len(self.labels) == 0:
don't want checking for compliance, you can use this decoder
for IDNA2008 as well.
- Returns a ``text``.
+ Returns a ``str``.
"""
if len(self.labels) == 0:
Raises ``dns.name.NeedAbsoluteNameOrOrigin`` if the name is
relative and no origin was provided.
- Returns a ``binary``.
+ Returns a ``bytes``.
"""
if not self.is_absolute():
"""Convert name to wire format, possibly compressing it.
*file* is the file where the name is emitted (typically an
- io.BytesIO file). If ``None`` (the default), a ``binary``
+ io.BytesIO file). If ``None`` (the default), a ``bytes``
containing the wire name will be returned.
*compress*, a ``dict``, is the compression table to use. If
Raises ``dns.name.NeedAbsoluteNameOrOrigin`` if the name is
relative and no origin was provided.
- Returns a ``binary`` or ``None``.
+ Returns a ``bytes`` or ``None``.
"""
if file is None:
Labels are encoded in IDN ACE form according to rules specified by
the IDNA codec.
- *text*, a ``text``, is the text to convert into a name.
+ *text*, a ``str``, is the text to convert into a name.
*origin*, a ``dns.name.Name``, specifies the origin to
append to non-absolute names. The default is the root name.
def from_text(text, origin=root, idna_codec=None):
"""Convert text into a Name object.
- *text*, a ``text``, is the text to convert into a name.
+ *text*, a ``str``, is the text to convert into a name.
*origin*, a ``dns.name.Name``, specifies the origin to
append to non-absolute names. The default is the root name.
def from_wire(message, current):
"""Convert possibly compressed wire format into a Name.
- *message* is a ``binary`` containing an entire DNS message in DNS
+ *message* is a ``bytes`` containing an entire DNS message in DNS
wire form.
*current*, an ``int``, is the offset of the beginning of the name
Each rdataset at the node is printed. Any keyword arguments
to this method are passed on to the rdataset's to_text() method.
- *name*, a ``dns.name.Name`` or ``text``, the owner name of the
+ *name*, a ``dns.name.Name`` or ``str``, the owner name of the
rdatasets.
- Returns a ``text``.
+ Returns a ``str``.
"""
def from_text(text):
"""Convert text into an opcode.
- *text*, a ``text``, the textual opcode
+ *text*, a ``str``, the textual opcode
Raises ``dns.opcode.UnknownOpcode`` if the opcode is unknown.
Raises ``dns.opcode.UnknownOpcode`` if the opcode is unknown.
- Returns a ``text``.
+ Returns a ``str``.
"""
text = _by_value.get(value)
*bootstrap_address*, a ``str``, the IP address to use to bypass the
system's DNS resolver.
- *verify*, a ``str`, containing a path to a certificate file or directory.
+ *verify*, a ``str``, containing a path to a certificate file or directory.
Returns a ``dns.message.Message``.
"""
*sock*, a ``socket``.
- *what*, a ``binary`` or ``dns.message.Message``, the message to send.
+ *what*, a ``bytes`` or ``dns.message.Message``, the message to send.
*destination*, a destination tuple appropriate for the address family
of the socket, specifying where to send the query.
*keyring*, a ``dict``, the keyring to use for TSIG.
- *request_mac*, a ``binary``, the MAC of the request (for TSIG).
+ *request_mac*, a ``bytes``, the MAC of the request (for TSIG).
*ignore_trailing*, a ``bool``. If ``True``, ignore trailing
junk at end of the received message.
*q*, a ``dns.message.Message``, the query to send
- *where*, a ``text`` containing an IPv4 or IPv6 address, where
+ *where*, a ``str`` containing an IPv4 or IPv6 address, where
to send the message.
*timeout*, a ``float`` or ``None``, the number of seconds to wait before the
*where*. If the inference attempt fails, AF_INET is used. This
parameter is historical; you need never set it.
- *source*, a ``text`` containing an IPv4 or IPv6 address, specifying
+ *source*, a ``str`` containing an IPv4 or IPv6 address, specifying
the source address. The default is the wildcard address.
*source_port*, an ``int``, the port from which to send the message.
*sock*, a ``socket``.
- *what*, a ``binary`` or ``dns.message.Message``, the message to send.
+ *what*, a ``bytes`` or ``dns.message.Message``, the message to send.
*expiration*, a ``float`` or ``None``, the absolute time at which
a timeout exception should be raised. If ``None``, no timeout will
*keyring*, a ``dict``, the keyring to use for TSIG.
- *request_mac*, a ``binary``, the MAC of the request (for TSIG).
+ *request_mac*, a ``bytes``, the MAC of the request (for TSIG).
*ignore_trailing*, a ``bool``. If ``True``, ignore trailing
junk at end of the received message.
*q*, a ``dns.message.Message``, the query to send
- *where*, a ``text`` containing an IPv4 or IPv6 address, where
+ *where*, a ``str`` containing an IPv4 or IPv6 address, where
to send the message.
*timeout*, a ``float`` or ``None``, the number of seconds to wait before the
*where*. If the inference attempt fails, AF_INET is used. This
parameter is historical; you need never set it.
- *source*, a ``text`` containing an IPv4 or IPv6 address, specifying
+ *source*, a ``str`` containing an IPv4 or IPv6 address, specifying
the source address. The default is the wildcard address.
*source_port*, an ``int``, the port from which to send the message.
*q*, a ``dns.message.Message``, the query to send
- *where*, a ``text`` containing an IPv4 or IPv6 address, where
+ *where*, a ``str`` containing an IPv4 or IPv6 address, where
to send the message.
*timeout*, a ``float`` or ``None``, the number of seconds to wait before the
*where*. If the inference attempt fails, AF_INET is used. This
parameter is historical; you need never set it.
- *source*, a ``text`` containing an IPv4 or IPv6 address, specifying
+ *source*, a ``str`` containing an IPv4 or IPv6 address, specifying
the source address. The default is the wildcard address.
*source_port*, an ``int``, the port from which to send the message.
a TLS connection. If ``None``, the default, creates one with the default
configuration.
- *server_hostname*, a ``text`` containing the server's hostname. The
+ *server_hostname*, a ``str`` containing the server's hostname. The
default is ``None``, which means that no hostname is known, and if an
SSL context is created, hostname checking will be disabled.
*where*. If the inference attempt fails, AF_INET is used. This
parameter is historical; you need never set it.
- *zone*, a ``dns.name.Name`` or ``text``, the name of the zone to transfer.
+ *zone*, a ``dns.name.Name`` or ``str``, the name of the zone to transfer.
- *rdtype*, an ``int`` or ``text``, the type of zone transfer. The
+ *rdtype*, an ``int`` or ``str``, the type of zone transfer. The
default is ``dns.rdatatype.AXFR``. ``dns.rdatatype.IXFR`` can be
used to do an incremental transfer instead.
- *rdclass*, an ``int`` or ``text``, the class of the zone transfer.
+ *rdclass*, an ``int`` or ``str``, the class of the zone transfer.
The default is ``dns.rdataclass.IN``.
*timeout*, a ``float``, the number of seconds to wait for each
*keyring*, a ``dict``, the keyring to use for TSIG.
- *keyname*, a ``dns.name.Name`` or ``text``, the name of the TSIG
+ *keyname*, a ``dns.name.Name`` or ``str``, the name of the TSIG
key to use.
*relativize*, a ``bool``. If ``True``, all names in the zone will be
doing the transfer. If ``None``, the default, then there is no
limit on the time the transfer may take.
- *source*, a ``text`` containing an IPv4 or IPv6 address, specifying
+ *source*, a ``str`` containing an IPv4 or IPv6 address, specifying
the source address. The default is the wildcard address.
*source_port*, an ``int``, the port from which to send the message.
*use_udp*, a ``bool``. If ``True``, use UDP (only meaningful for IXFR).
- *keyalgorithm*, a ``dns.name.Name`` or ``text``, the TSIG algorithm to use.
+ *keyalgorithm*, a ``dns.name.Name`` or ``str``, the TSIG algorithm to use.
Raises on errors, and so does the generator.
def from_text(text):
"""Convert text into an rcode.
- *text*, a ``text``, the textual rcode or an integer in textual form.
+ *text*, a ``str``, the textual rcode or an integer in textual form.
Raises ``dns.rcode.UnknownRcode`` if the rcode mnemonic is unknown.
Raises ``ValueError`` if rcode is < 0 or > 4095.
- Returns a ``text``.
+ Returns a ``str``.
"""
if value < 0 or value > 4095:
def to_text(self, origin=None, relativize=True, **kw):
"""Convert an rdata to text format.
- Returns a ``text``.
+ Returns a ``str``.
"""
raise NotImplementedError
"""Convert rdata to a format suitable for digesting in hashes. This
is also the DNSSEC canonical form.
- Returns a ``binary``.
+ Returns a ``bytes``.
"""
f = io.BytesIO()
Once a class is chosen, its from_text() class method is called
with the parameters to this function.
- If *tok* is a ``text``, then a tokenizer is created and the string
+ If *tok* is a ``str``, then a tokenizer is created and the string
is used as its input.
*rdclass*, an ``int``, the rdataclass.
*rdtype*, an ``int``, the rdatatype.
- *tok*, a ``dns.tokenizer.Tokenizer`` or a ``text``.
+ *tok*, a ``dns.tokenizer.Tokenizer`` or a ``str``.
*origin*, a ``dns.name.Name`` (or ``None``), the
origin to use for relative names.
*rdtype*, an ``int``, the rdatatype.
- *wire*, a ``binary``, the wire-format message.
+ *wire*, a ``bytes``, the wire-format message.
*current*, an ``int``, the offset in wire of the beginning of
the rdata.
*rdtype*, an ``int``, the rdatatype to register.
- *rdtype_text*, a ``text``, the textual form of the rdatatype.
+ *rdtype_text*, a ``str``, the textual form of the rdatatype.
*is_singleton*, a ``bool``, indicating if the type is a singleton (i.e.
RRsets of the type can have only one member.)
*rdtype*, an ``int``, the rdatatype to register.
- *rdtype_text*, a ``text``, the textual form of the rdatatype.
+ *rdtype_text*, a ``str``, the textual form of the rdatatype.
*is_singleton*, a ``bool``, indicating if the type is a singleton (i.e.
RRsets of the type can have only one member.)
"""DNS stub resolver."""
def __init__(self, filename='/etc/resolv.conf', configure=True):
- """*filename*, a ``text`` or file object, specifying a file
+ """*filename*, a ``str`` or file object, specifying a file
in standard /etc/resolv.conf format. This parameter is meaningful
only when *configure* is true and the platform is POSIX.
def read_resolv_conf(self, f):
"""Process *f* as a file in the /etc/resolv.conf format. If f is
- a ``text``, it is used as the name of the file to open; otherwise it
+ a ``str``, it is used as the name of the file to open; otherwise it
is treated as the file itself.
Interprets the following items:
of the appropriate type, or strings that can be converted into objects
of the appropriate type.
- *qname*, a ``dns.name.Name`` or ``text``, the query name.
+ *qname*, a ``dns.name.Name`` or ``str``, the query name.
- *rdtype*, an ``int`` or ``text``, the query type.
+ *rdtype*, an ``int`` or ``str``, the query type.
- *rdclass*, an ``int`` or ``text``, the query class.
+ *rdclass*, an ``int`` or ``str``, the query class.
*tcp*, a ``bool``. If ``True``, use TCP to make the query.
- *source*, a ``text`` or ``None``. If not ``None``, bind to this IP
+ *source*, a ``str`` or ``None``. If not ``None``, bind to this IP
address when making queries.
*raise_on_no_answer*, a ``bool``. If ``True``, raise
def zone_for_name(name, rdclass=dns.rdataclass.IN, tcp=False, resolver=None):
"""Find the name of the zone which contains the specified name.
- *name*, an absolute ``dns.name.Name`` or ``text``, the query name.
+ *name*, an absolute ``dns.name.Name`` or ``str``, the query name.
*rdclass*, an ``int``, the query class.
"""Convert an IPv4 or IPv6 address in textual form into a Name object whose
value is the reverse-map domain name of the address.
- *text*, a ``text``, is an IPv4 or IPv6 address in textual form
+ *text*, a ``str``, is an IPv4 or IPv6 address in textual form
(e.g. '127.0.0.1', '::1')
*v4_origin*, a ``dns.name.Name`` to append to the labels corresponding to
Raises ``dns.exception.SyntaxError`` if the name does not have a
reverse-map form.
- Returns a ``text``.
+ Returns a ``str``.
"""
if name.is_subdomain(v4_origin):
The BIND 8 units syntax for TTLs (e.g. '1w6d4h3m10s') is supported.
- *text*, a ``text``, the textual TTL.
+ *text*, a ``str``, the textual TTL.
Raises ``dns.ttl.BadTTL`` if the TTL is not well-formed.
See the documentation of the Message class for a complete
description of the keyring dictionary.
- *zone*, a ``dns.name.Name`` or ``text``, the zone which is being
+ *zone*, a ``dns.name.Name`` or ``str``, the zone which is being
updated.
- *rdclass*, an ``int`` or ``text``, the class of the zone.
+ *rdclass*, an ``int`` or ``str``, the class of the zone.
*keyring*, a ``dict``, the TSIG keyring to use. If a
*keyring* is specified but a *keyname* is not, then the key
output; default is 0, which means "the message's request
payload, if nonzero, or 65535".
- Returns a ``binary``.
+ Returns a ``bytes``.
"""
if origin is None: