Domain name.
This class contains methods to read and manipulate domain name drfs. Domain names are stored in ldns_rdf structures, with the type LDNS_RDF_TYPE_DNAME. This class encapsulates such rdfs.
Usage
>>> import ldns
>>> dn1 = ldns.ldns_dname("test.nic.cz")
>>> print dn1
test.nic.cz.
>>> dn2 = ldns.ldns_dname("nic.cz")
>>> if dn2.is_subdomain(dn1): print dn2, "is sub-domain of", dn1
>>> if dn1.is_subdomain(dn2): print dn1, "is sub-domain of", dn2
test.nic.cz. is sub-domain of nic.cz.
The following two examples show the creation of ldns_dname from ldns_rdf. The first shows the creation of ldns_dname instance which is independent of the original rdf.
>>> import ldns
>>> rdf = ldns.ldns_rdf.new_frm_str("a.ns.nic.cz", ldns.LDNS_RDF_TYPE_DNAME)
>>> dn = ldns.ldns_dname(rdf)
>>> print dn
a.ns.nic.cz.
The latter shows the wrapping of a ldns_rdf onto a ldns_dname without the creation of a copy.
>>> import ldns
>>> dn = ldns.ldns_dname(ldns.ldns_rdf.new_frm_str("a.ns.nic.cz", ldns.LDNS_RDF_TYPE_DNAME), clone=False)
>>> print dn
a.ns.nic.cz.
Checks whether the given dname string is absolute (i.e., ends with a ‘.’).
Returns: | (bool) True or False |
---|
Concatenates rd2 after this dname (rd2 is copied, this dname is modified).
Parameters: | rd2 (ldns_dname) – The right-hand side. |
---|---|
Throws TypeError: | |
When rd2 of invalid type. | |
Returns: | (ldns_status) LDNS_STATUS_OK on success |
Note
The type checking of parameter rd2 is benevolent. It allows also to pass a dname ldns_rdf object. This will probably change in future.
Concatenates two dnames together.
Parameters: | rd2 (ldns_dname) – The right-hand side. |
---|---|
Throws TypeError: | |
When rd2 of invalid type. | |
Returns: | (ldns_dname) A new rdf with left-hand side + right-hand side content None when error. |
Note
The type checking of parameter rd2 is benevolent. It allows also to pass a dname ldns_rdf object. This will probably change in future.
Check whether middle lays in the interval defined by this and next (this <= middle < next).
This method is useful for nsec checking.
Parameters: |
|
---|---|
Throws TypeError: | |
When middle or next of non-ldns_rdf type. |
|
Throws Exception: | |
When non-dname rdfs compared. |
|
Returns: | (int) 0 on error or unknown, -1 when middle is in the interval, 1 when not. |
Note
The type checking of parameters is benevolent. It allows also to pass a dname ldns_rdf object. This will probably change in future.
Tests whether the name of the instance falls under parent (i.e., is a sub-domain of parent).
This function will return false if the given dnames are equal.
Parameters: | parent (ldns_dname) – The parent’s name. |
---|---|
Throws TypeError: | |
When parent of non-ldns_rdf or derived type. | |
Returns: | (bool) True if this falls under parent, otherwise False. |
Note
The type checking of parameters is benevolent. It allows also to pass a dname ldns_rdf object. This will probably change in future.
Look inside the rdf and retrieve a specific label.
The labels are numbered starting from 0 (left most).
Parameters: | labelpos (integer) – Index of the label. (Labels are numbered 0, which is the left most.) |
---|---|
Throws TypeError: | |
When labelpos of non-integer type. | |
Returns: | (ldns_dname) A new rdf with the label as name or None on error. |
Counts the number of labels.
Returns: | (uint8_t) the number of labels. Will return 0 if not a dname. |
---|
Chop one label off the left side of a dname.
(e.g., wwww.nlnetlabs.nl, becomes nlnetlabs.nl)
Returns: | (ldns_dname) The remaining dname or None when error. |
---|
Put a dname into canonical format (i.e., convert to lower case).
Creates a new dname rdf instance from a dname ldns_rdf.
This static method is equivalent to using the default ldns_dname constructor.
Parameters: | |
---|---|
Throws TypeError: | |
When rdf of inappropriate type. |
|
Returns: | (ldns_dname) dname rdf. |
Creates a new dname rdf instance from a string.
This static method is equivalent to using default ldns_dname constructor.
Parameters: | string (string) – String to use. |
---|---|
Throws TypeError: | |
When string not a string. | |
Returns: | (ldns_dname) dname rdf. |
Returns a clone of the given dname with the labels reversed.
Returns: | (ldns_dname) A clone of the dname with the labels reversed. |
---|
Copies the dname data to the buffer in wire format.
Parameters: | buffer – Buffer to append the result to. |
---|---|
Throws TypeError: | |
When buffer of non-ldns_buffer type. | |
Returns: | (ldns_status) ldns_status |