dnspython  1.16.0
About: dnspython is a DNS toolkit (for Python 2.x) that supports almost all record types.
  Fossies Dox: dnspython-1.16.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

dns.name.Name Class Reference
Inheritance diagram for dns.name.Name:
[legend]
Collaboration diagram for dns.name.Name:
[legend]

Public Member Functions

def __init__ (self, labels)
 
def __setattr__ (self, name, value)
 
def __copy__ (self)
 
def __deepcopy__ (self, memo)
 
def __getstate__ (self)
 
def __setstate__ (self, state)
 
def is_absolute (self)
 
def is_wild (self)
 
def __hash__ (self)
 
def fullcompare (self, other)
 
def is_subdomain (self, other)
 
def is_superdomain (self, other)
 
def canonicalize (self)
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
def __lt__ (self, other)
 
def __le__ (self, other)
 
def __ge__ (self, other)
 
def __gt__ (self, other)
 
def __repr__ (self)
 
def __str__ (self)
 
def to_text (self, omit_final_dot=False)
 
def to_unicode (self, omit_final_dot=False, idna_codec=None)
 
def to_digestable (self, origin=None)
 
def to_wire (self, file=None, compress=None, origin=None)
 
def __len__ (self)
 
def __getitem__ (self, index)
 
def __add__ (self, other)
 
def __sub__ (self, other)
 
def split (self, depth)
 
def concatenate (self, other)
 
def relativize (self, origin)
 
def derelativize (self, origin)
 
def choose_relativity (self, origin=None, relativize=True)
 
def parent (self)
 

Static Private Attributes

list __slots__ = ['labels']
 

Detailed Description

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
of the class are immutable.

Definition at line 318 of file name.py.

Constructor & Destructor Documentation

◆ __init__()

def dns.name.Name.__init__ (   self,
  labels 
)
*labels* is any iterable whose values are ``text`` or ``binary``.

Definition at line 329 of file name.py.

References dns.name.Name.__setattr__(), dns.name._maybe_convert_to_binary(), dns.name._validate_labels(), and dns.rdtypes.ANY.RRSIG.RRSIG.labels.

Member Function Documentation

◆ __add__()

def dns.name.Name.__add__ (   self,
  other 
)

Definition at line 684 of file name.py.

References dns.name.Name.concatenate().

◆ __copy__()

def dns.name.Name.__copy__ (   self)

Definition at line 341 of file name.py.

References dns.rdtypes.ANY.RRSIG.RRSIG.labels.

◆ __deepcopy__()

def dns.name.Name.__deepcopy__ (   self,
  memo 
)

Definition at line 344 of file name.py.

References dns.rdtypes.ANY.RRSIG.RRSIG.labels.

◆ __eq__()

def dns.name.Name.__eq__ (   self,
  other 
)

◆ __ge__()

def dns.name.Name.__ge__ (   self,
  other 
)

Definition at line 518 of file name.py.

References dns.name.Name.fullcompare().

◆ __getitem__()

def dns.name.Name.__getitem__ (   self,
  index 
)

◆ __getstate__()

def dns.name.Name.__getstate__ (   self)

Definition at line 347 of file name.py.

References dns.rdtypes.ANY.RRSIG.RRSIG.labels.

◆ __gt__()

def dns.name.Name.__gt__ (   self,
  other 
)

Definition at line 524 of file name.py.

References dns.name.Name.fullcompare().

◆ __hash__()

def dns.name.Name.__hash__ (   self)
Return a case-insensitive hash of the name.

Returns an ``int``.

Definition at line 371 of file name.py.

References dns.rdtypes.ANY.RRSIG.RRSIG.labels, and dns._compat.long.

◆ __le__()

def dns.name.Name.__le__ (   self,
  other 
)

Definition at line 512 of file name.py.

References dns.name.Name.fullcompare().

◆ __len__()

def dns.name.Name.__len__ (   self)
The length of the name (in labels).

Returns an ``int``.

Definition at line 673 of file name.py.

References dns.rdtypes.ANY.RRSIG.RRSIG.labels.

◆ __lt__()

def dns.name.Name.__lt__ (   self,
  other 
)

Definition at line 506 of file name.py.

References dns.name.Name.fullcompare().

◆ __ne__()

def dns.name.Name.__ne__ (   self,
  other 
)

Definition at line 500 of file name.py.

References dns.name.Name.fullcompare().

◆ __repr__()

def dns.name.Name.__repr__ (   self)

◆ __setattr__()

def dns.name.Name.__setattr__ (   self,
  name,
  value 
)

Definition at line 337 of file name.py.

Referenced by dns.name.Name.__init__(), and dns.name.Name.__setstate__().

◆ __setstate__()

def dns.name.Name.__setstate__ (   self,
  state 
)

◆ __str__()

def dns.name.Name.__str__ (   self)

◆ __sub__()

def dns.name.Name.__sub__ (   self,
  other 
)

◆ canonicalize()

def dns.name.Name.canonicalize (   self)
Return a name which is equal to the current name, but is in
DNSSEC canonical form.

Definition at line 487 of file name.py.

References dns.rdtypes.ANY.RRSIG.RRSIG.labels.

◆ choose_relativity()

def dns.name.Name.choose_relativity (   self,
  origin = None,
  relativize = True 
)
Return a name with the relativity desired by the caller.

If *origin* is ``None``, then the name is returned.
Otherwise, if *relativize* is ``True`` the name is
relativized, and if *relativize* is ``False`` the name is
derelativized.

Returns a ``dns.name.Name``.

Definition at line 758 of file name.py.

References dns.name.Name.derelativize(), dns.zone.Zone.relativize, dns.zone._MasterReader.relativize, and dns.name.Name.relativize().

◆ concatenate()

def dns.name.Name.concatenate (   self,
  other 
)
Return a new name which is the concatenation of self and other.

Raises ``dns.name.AbsoluteConcatenation`` if the name is
absolute and *other* is not the empty name.

Returns a ``dns.name.Name``.

Definition at line 711 of file name.py.

References dns.name.Name.is_absolute(), and dns.rdtypes.ANY.RRSIG.RRSIG.labels.

Referenced by dns.name.Name.__add__(), and dns.name.Name.derelativize().

◆ derelativize()

def dns.name.Name.derelativize (   self,
  origin 
)
If the name is a relative name, return a new name which is the
concatenation of the name and origin.  Otherwise return the name.

For example, derelativizing ``www`` to origin ``dnspython.org.``
returns the name ``www.dnspython.org.``.  Derelativizing ``example.``
to origin ``dnspython.org.`` returns ``example.``.

Returns a ``dns.name.Name``.

Definition at line 742 of file name.py.

References dns.name.Name.concatenate(), and dns.name.Name.is_absolute().

Referenced by dns.name.Name.choose_relativity().

◆ fullcompare()

def dns.name.Name.fullcompare (   self,
  other 
)
Compare two names, returning a 3-tuple
``(relation, order, nlabels)``.

*relation* describes the relation ship between 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``.

*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.

*nlabels* is the number of significant labels that the two names
have in common.

Here are some examples.  Names ending in "." are absolute names,
those not ending in "." are relative names.

=============  =============  ===========  =====  =======
self           other          relation     order  nlabels
=============  =============  ===========  =====  =======
www.example.   www.example.   equal        0      3
www.example.   example.       subdomain    > 0    2
example.       www.example.   superdomain  < 0    2
example1.com.  example2.com.  common anc.  < 0    2
example1       example2.      none         < 0    0
example1.      example2       none         > 0    0
=============  =============  ===========  =====  =======

Definition at line 383 of file name.py.

References dns.name.Name.is_absolute(), and dns.rdtypes.ANY.RRSIG.RRSIG.labels.

Referenced by dns.name.Name.__eq__(), dns.name.Name.__ge__(), dns.name.Name.__gt__(), dns.name.Name.__le__(), dns.name.Name.__lt__(), dns.name.Name.__ne__(), dns.name.Name.is_subdomain(), and dns.name.Name.is_superdomain().

◆ is_absolute()

def dns.name.Name.is_absolute (   self)
Is the most significant label of this name the root label?

Returns a ``bool``.

Definition at line 355 of file name.py.

References dns.rdtypes.ANY.RRSIG.RRSIG.labels.

Referenced by dns.name.Name.concatenate(), dns.name.Name.derelativize(), dns.name.Name.fullcompare(), dns.name.Name.to_digestable(), dns.name.Name.to_text(), dns.name.Name.to_unicode(), and dns.name.Name.to_wire().

◆ is_subdomain()

def dns.name.Name.is_subdomain (   self,
  other 
)
Is self a subdomain of other?

Note that the notion of subdomain includes equality, e.g.
"dnpython.org" is a subdomain of itself.

Returns a ``bool``.

Definition at line 459 of file name.py.

References dns.name.Name.fullcompare().

Referenced by dns.name.Name.relativize().

◆ is_superdomain()

def dns.name.Name.is_superdomain (   self,
  other 
)
Is self a superdomain of other?

Note that the notion of superdomain includes equality, e.g.
"dnpython.org" is a superdomain of itself.

Returns a ``bool``.

Definition at line 473 of file name.py.

References dns.name.Name.fullcompare().

◆ is_wild()

def dns.name.Name.is_wild (   self)
Is this name wild?  (I.e. Is the least significant label '*'?)

Returns a ``bool``.

Definition at line 363 of file name.py.

References dns.rdtypes.ANY.RRSIG.RRSIG.labels.

◆ parent()

def dns.name.Name.parent (   self)
Return the parent of the name.

For example, the parent of ``www.dnspython.org.`` is ``dnspython.org``.

Raises ``dns.name.NoParent`` if the name is either the root name or the
empty name, and thus has no parent.

Returns a ``dns.name.Name``.

Definition at line 777 of file name.py.

References dns.rdtypes.ANY.RRSIG.RRSIG.labels.

◆ relativize()

def dns.name.Name.relativize (   self,
  origin 
)
If the name is a subdomain of *origin*, return a new name which is
the name relative to origin.  Otherwise return the name.

For example, relativizing ``www.dnspython.org.`` to origin
``dnspython.org.`` returns the name ``www``.  Relativizing ``example.``
to origin ``dnspython.org.`` returns ``example.``.

Returns a ``dns.name.Name``.

Definition at line 726 of file name.py.

References dns.name.Name.is_subdomain().

Referenced by dns.name.Name.__sub__(), and dns.name.Name.choose_relativity().

◆ split()

def dns.name.Name.split (   self,
  depth 
)
Split a name into a prefix and suffix names at the specified depth.

*depth* is an ``int`` specifying the number of labels in the suffix

Raises ``ValueError`` if *depth* was not >= 0 and <= the length of the
name.

Returns the tuple ``(prefix, suffix)``.

Definition at line 690 of file name.py.

References dns.rdtypes.ANY.RRSIG.RRSIG.labels.

◆ to_digestable()

def dns.name.Name.to_digestable (   self,
  origin = None 
)
Convert name to a format suitable for digesting in hashes.

The name is canonicalized and converted to uncompressed wire
format.  All names in wire format are absolute.  If the name
is a relative name, then an origin must be supplied.

*origin* is a ``dns.name.Name`` or ``None``.  If the name is
relative and origin is not ``None``, then origin will be appended
to the name.

Raises ``dns.name.NeedAbsoluteNameOrOrigin`` if the name is
relative and no origin was provided.

Returns a ``binary``.

Definition at line 587 of file name.py.

References dns.name.Name.is_absolute(), and dns.rdtypes.ANY.RRSIG.RRSIG.labels.

Referenced by dns.rdata.Rdata.__hash__(), and dns.rdata.Rdata._cmp().

◆ to_text()

def dns.name.Name.to_text (   self,
  omit_final_dot = False 
)
Convert name to DNS text format.

*omit_final_dot* is a ``bool``.  If True, don't emit the final
dot (denoting the root label) for absolute names.  The default
is False.

Returns a ``text``.

Definition at line 536 of file name.py.

References dns.name.Name.is_absolute(), dns.rdtypes.ANY.RRSIG.RRSIG.labels, and dns._compat.maybe_decode().

Referenced by dns.rrset.RRset.__str__(), dns.rdataset.Rdataset.__str__(), dns.rdata.Rdata.__str__(), dns.name.Name.__str__(), and dns.rdata.Rdata.validate().

◆ to_unicode()

def dns.name.Name.to_unicode (   self,
  omit_final_dot = False,
  idna_codec = None 
)
Convert name to Unicode text format.

IDN ACE labels are converted to Unicode.

*omit_final_dot* is a ``bool``.  If True, don't emit the final
dot (denoting the root label) for absolute names.  The default
is False.
*idna_codec* specifies the IDNA encoder/decoder.  If None, the
dns.name.IDNA_2003_Practical encoder/decoder is used.
The IDNA_2003_Practical decoder does
not impose any policy, it just decodes punycode, so if you
don't want checking for compliance, you can use this decoder
for IDNA2008 as well.

Returns a ``text``.

Definition at line 557 of file name.py.

References dns.name.Name.is_absolute(), and dns.rdtypes.ANY.RRSIG.RRSIG.labels.

◆ to_wire()

def dns.name.Name.to_wire (   self,
  file = None,
  compress = None,
  origin = None 
)
Convert name to wire format, possibly compressing it.

*file* is the file where the name is emitted (typically a
BytesIO file).  If ``None`` (the default), a ``binary``
containing the wire name will be returned.

*compress*, a ``dict``, is the compression table to use.  If
``None`` (the default), names will not be compressed.

*origin* is a ``dns.name.Name`` or ``None``.  If the name is
relative and origin is not ``None``, then *origin* will be appended
to it.

Raises ``dns.name.NeedAbsoluteNameOrOrigin`` if the name is
relative and no origin was provided.

Returns a ``binary`` or ``None``.

Definition at line 615 of file name.py.

References dns.name.Name.is_absolute(), and dns.rdtypes.ANY.RRSIG.RRSIG.labels.

Referenced by dns.rdtypes.nsbase.UncompressedNS.to_digestable(), dns.rdtypes.mxbase.UncompressedMX.to_digestable(), and dns.rdata.Rdata.to_digestable().

Member Data Documentation

◆ __slots__

list dns.name.Name.__slots__ = ['labels']
staticprivate

Definition at line 327 of file name.py.


The documentation for this class was generated from the following file: