Go to the latest version of this document.

# ``twisted`.`names`.`dns`.`Name``

class documentation

`class Name: (source)`

Constructor: `Name(name)`

Implements interfaces: `twisted.names.dns.IEncodable`

View In Hierarchy

A name in the domain name system, made up of multiple labels. For example, twistedmatrix.com.

Method | `__eq__` | Undocumented
Method | `__hash__` | Undocumented
Method | `__init__` | No summary
Method | `__str__` | Represent this `Name` instance by its string name.
Method | `decode` | Decode a byte string into this Name.
Method | `encode` | Encode this Name into the appropriate byte format.
Instance Variable | `maxCompressionPointers` | Per-message cap on the total number of compression-pointer dereferences `decode` will follow before raising `DNSDecodeError`. Defaults to `1000`. Override it on a subclass or individual instance to tune the trade-off between tolerance for legitimately verbose messages and resistance to denial-of-service attacks.
Instance Variable | `name` | A byte string giving the name.

def __eq__(self, other: `object`) -> `bool`: (source)

Undocumented

def __hash__(self): (source)

Undocumented

def __init__(self, name: `bytes | str` = b''): (source)

Parameters
name:`bytes` or `str` | A name.

def __str__(self) -> `str`: (source)

Represent this `Name` instance by its string name.

def decode(self, strio, length=None): (source)
from `twisted.names.dns.IEncodable`

Decode a byte string into this Name.

When invoked from `Message.decode`, a shared compression-pointer counter is picked up transparently from the private `_decodeContextVar`. Standalone callers get a fresh per-call counter seeded from `maxCompressionPointers`, so existing code keeps working unchanged while still being protected against pathological inputs.

Parameters
strio:file | Bytes will be read from this file until the full Name is decoded.
length:`int` or `None` | Present for compatibility with the `IEncodable` interface; ignored by this decoder.

Raises
`EOFError` | Raised when there are not enough bytes available from `strio`.
`ValueError` | Raised when the name cannot be decoded because it contains a compression loop.
`DNSDecodeError` | Raised when the cumulative number of compression-pointer jumps exceeds the configured limit.

def encode(self, strio, compDict=None): (source)
from `twisted.names.dns.IEncodable`

Encode this Name into the appropriate byte format.

Parameters
strio:file | The byte representation of this Name will be written to this file.
compDict:dict | dictionary of Names that have already been encoded and whose addresses may be backreferenced by this Name (for the purpose of reducing the message size).

maxCompressionPointers: `int` = (source)

Per-message cap on the total number of compression-pointer dereferences `decode` will follow before raising `DNSDecodeError`. Defaults to `1000`. Override it on a subclass or individual instance to tune the trade-off between tolerance for legitimately verbose messages and resistance to denial-of-service attacks.

name: `bytes` = (source)

A byte string giving the name.