Class ldns_rr_list

Class ldns_rr_list

class ldns.ldns_rr_list

List of Resource Records.

This class contains a list of RR’s (see ldns.ldns_rr).

cat(right)

Concatenates two ldns_rr_lists together.

This modifies rr list (to extend it and adds RRs from right).

Parameters:right (ldns_rr_list) – The right-hand side.
Throws TypeError:
 when right of non-ldns_rr_list type.
Returns:(bool) True if success.
cat_clone(right)

Concatenates two ldns_rr_lists together, creates a new list of the rr’s (instead of appending the content to an existing list).

Parameters:right (ldns_rr_list) – The right-hand side.
Throws TypeError:
 when right of non-ldns_rr_list type.
Returns:(ldns_rr_list) rr list with left-hand side + right-hand side concatenated, on None on error.
clone()

Clones an rrlist.

Returns:(ldns_rr_list) the cloned rr list, or None on error.
contains_rr(rr)

Returns True if the given rr is one of the rrs in the list, or if it is equal to one.

Parameters:rr (ldns_rr) – The rr to check.
Throws TypeError:
 when rr of non-ldns_rr type.
Returns:(bool) True if rr_list contains rr, False otherwise.
is_rrset()

Checks if the rr list is a rr set.

Returns:(bool) True if rr list is a rr set.
static new(raiseException=True)

Creates an empty RR List object.

Parameters:raiseException (bool) – Set to True if an exception should signal an error.
Throws Exception:
 when raiseException is True and error occurs.
Returns:ldns_rr_list Empty RR list.
static new_frm_file(filename='/etc/hosts', raiseException=True)

Creates an RR List object from file content.

Goes through a file and returns a rr list containing all the defined hosts in there.

Parameters:
  • filename (str) – The filename to use.
  • raiseException (bool) – Set to True if an exception should signal an error.
Throws TypeError:
 

when filename of inappropriate type.

Throws Exception:
 

when raiseException is True and error occurs.

Returns:

RR List object or None. If the object can’t be created and raiseException is True, an exception occurs.

Usage

>>> alist = ldns.ldns_rr_list.new_frm_file()
>>> print alist
localhost.   3600    IN      A       127.0.0.1
...
owner()

Returns the owner domain name rdf of the first element of the RR. If there are no elements present, None is returned.

Returns:(ldns_dname) dname of the first element, or None if the list is empty.
pop_rr()

Pops the last rr from an rrlist.

Returns:(ldns_rr) None if nothing to pop. Otherwise the popped RR.
pop_rr_list(size)

Pops an rr_list of size s from an rrlist.

Parameters:size (positive int) – The number of rr’s to pop.
Throws TypeError:
 when size of inappropriate type.
Returns:(ldns_rr_list) None if nothing to pop. Otherwise the popped rr list.
pop_rrset()

Pops the first rrset from the list, the list must be sorted, so that all rr’s from each rrset are next to each other.

Returns:(ldns_rr_list) the first rrset, or None when empty.
print_to_file(output)

Print a rr_list to output.

Parameters:output – Opened file to print to.
Throws TypeError:
 when output of inappropriate type.
push_rr(rr)

Pushes an rr to an rrlist.

Parameters:rr (ldns_rr) – The rr to push.
Throws TypeError:
 when rr of non-ldns_rr type.
Returns:(bool) False on error, otherwise True.
push_rr_list(push_list)

Pushes an rr list to an rr list.

Parameters:push_list (ldns_rr_list) – The rr_list to push.
Throws TypeError:
 when push_list of non-ldns_rr_list type.
Returns:(bool) False on error, otherwise True.
rr(nr)

Returns a specific rr of an rrlist.

Parameters:nr (positive int) – Index of the desired rr.
Throws TypeError:
 when nr of inappropriate type.
Returns:(ldns_rr) The rr at position nr, or None if failed.
rr_count()

Returns the number of rr’s in an rr_list.

Returns:(int) The number of rr’s.
rrs()

Returns a generator object of a list of rr records.

Returns:(generator) generator object.
set_rr(r, idx)

Set a rr on a specific index in a ldns_rr_list.

Parameters:
  • r (ldns_rr) – The rr to set.
  • idx (positive int) – Index into the rr_list.
Throws TypeError:
 

when parameters of inappropriate types.

Returns:

(ldns_rr) the old rr which was stored in the rr_list, or None if the index was too large to set a specific rr.

set_rr_count(count)

Sets the number of rr’s in an rr_list.

Parameters:count (positive int) – The number of rr in this list.
Throws TypeError:
 when count of non-integer type.
Throws Exception:
 when count out of acceptable range.

Warning

Don’t use this method unless you really know what you are doing.

sort()

Sorts an rr_list (canonical wire format).

subtype_by_rdf(r, pos)

Return the rr_list which matches the rdf at position field.

Think type-covered stuff for RRSIG.

Parameters:
  • r (ldns_rdf) – The rdf to use for the comparison.
  • pos (positive int) – At which position we can find the rdf.
Throws TypeError:
 

when parameters of inappropriate types.

Returns:

(ldns_rr_list) a new rr list with only the RRs that match, or None when nothing matches.

to_canonical()

Converts each dname in each rr in a rr_list to its canonical form.

type()

Returns the type of the first element of the RR.

If there are no elements present, 0 is returned.

Returns:(int) rr_type of the first element, or 0 if the list is empty.
write_to_buffer(buffer)

Copies the rr_list data to the buffer in wire format.

Parameters:buffer (ldns_buffer) – Output buffer to append the result to.
Throws TypeError:
 when buffer of non-ldns_buffer type.
Returns:(ldns_status) ldns_status

Table Of Contents

Previous topic

Class ldns_dname

Next topic

Class ldns_zone