]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/python/ldns_rr.i
import ldns 1.6.16
[FreeBSD/FreeBSD.git] / contrib / python / ldns_rr.i
1 /******************************************************************************
2  * ldns_rr.i: LDNS resource records (RR), RR list
3  *
4  * Copyright (c) 2009, Zdenek Vasicek (vasicek AT fit.vutbr.cz)
5  *                     Karel Slany    (slany AT fit.vutbr.cz)
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  *     * Redistributions of source code must retain the above copyright notice,
12  *       this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in the
15  *       documentation and/or other materials provided with the distribution.
16  *     * Neither the name of the organization nor the names of its
17  *       contributors may be used to endorse or promote products derived from
18  *       this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *****************************************************************************/
32
33
34 /* ========================================================================= */
35 /* SWIG setting and definitions. */
36 /* ========================================================================= */
37
38 /* Creates a temporary instance of (ldns_rr *). */
39 %typemap(in, numinputs=0, noblock=1) (ldns_rr **)
40 {
41   ldns_rr *$1_rr;
42   $1 = &$1_rr;
43 }
44           
45 /* Result generation, appends (ldns_rr *) after the result. */
46 %typemap(argout, noblock=1) (ldns_rr **) 
47 {
48   $result = SWIG_Python_AppendOutput($result,
49     SWIG_NewPointerObj(SWIG_as_voidptr($1_rr),
50       SWIGTYPE_p_ldns_struct_rr, SWIG_POINTER_OWN |  0 ));
51 }
52
53 %nodefaultctor ldns_struct_rr; /* No default constructor. */
54 %nodefaultdtor ldns_struct_rr; /* No default destructor. */
55
56 %ignore ldns_struct_rr::_rdata_fields;
57
58 %newobject ldns_rr_clone;
59 %newobject ldns_rr_new;
60 %newobject ldns_rr_new_frm_type;
61 %newobject ldns_rr_pop_rdf;
62 %delobject ldns_rr_free;
63
64 %rename(ldns_rr) ldns_struct_rr;
65
66 %newobject ldns_rr2str;
67 %newobject ldns_rr_type2str;
68 %newobject ldns_rr_class2str;
69 %newobject ldns_read_anchor_file;
70
71
72 /* Clone rdf data on pull. */
73
74 /* Clone will fail with NULL argument. */
75
76 %newobject _ldns_rr_rdf;
77 %rename(__ldns_rr_rdf) ldns_rr_rdf;
78 %inline
79 %{
80   ldns_rdf * _ldns_rr_rdf(ldns_rr *rr, size_t i)
81   {
82     ldns_rdf *rdf;
83     rdf = ldns_rr_rdf(rr, i);
84     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
85   }
86 %}
87
88 %newobject _ldns_rr_rrsig_algorithm;
89 %rename(__ldns_rr_rrsig_algorithm) ldns_rr_rrsig_algorithm;
90 %inline
91 %{
92   ldns_rdf * _ldns_rr_rrsig_algorithm(ldns_rr *rr) {
93     ldns_rdf *rdf;
94     rdf = ldns_rr_rrsig_algorithm(rr);
95     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
96   }
97 %}
98
99 %newobject _ldns_rr_dnskey_algorithm;
100 %rename(__ldns_rr_dnskey_algorithm) ldns_rr_dnskey_algorithm;
101 %inline
102 %{
103   ldns_rdf * _ldns_rr_dnskey_algorithm(ldns_rr *rr)
104   {
105     ldns_rdf *rdf;
106     rdf = ldns_rr_dnskey_algorithm(rr);
107     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
108   }
109 %}
110
111 %newobject _ldns_rr_dnskey_flags;
112 %rename(__ldns_rr_dnskey_flags) ldns_rr_dnskey_flags;
113 %inline
114  %{
115   ldns_rdf * _ldns_rr_dnskey_flags(ldns_rr *rr)
116   {
117     ldns_rdf *rdf;
118     rdf = ldns_rr_dnskey_flags(rr);
119     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
120   }
121 %}
122
123 %newobject _ldns_rr_dnskey_key;
124 %rename(__ldns_rr_dnskey_key) ldns_rr_dnskey_key;
125 %inline
126 %{
127   ldns_rdf * _ldns_rr_dnskey_key(ldns_rr *rr)
128   {
129     ldns_rdf *rdf;
130     rdf = ldns_rr_dnskey_key(rr);
131     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
132   }
133 %}
134
135 %newobject _ldns_rr_dnskey_protocol;
136 %rename(__ldns_rr_dnskey_protocol) ldns_rr_dnskey_protocol;
137 %inline
138 %{
139   ldns_rdf * _ldns_rr_dnskey_protocol(ldns_rr *rr)
140   {
141     ldns_rdf *rdf;
142     rdf = ldns_rr_dnskey_protocol(rr);
143     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
144   }
145 %}
146
147
148 %newobject _ldns_rr_owner;
149 %rename(__ldns_rr_owner) ldns_rr_owner;
150 %inline
151 %{
152   ldns_rdf * _ldns_rr_owner(ldns_rr *rr)
153   {
154     ldns_rdf *rdf;
155     rdf = ldns_rr_owner(rr);
156     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
157   }
158 %}
159
160
161 %newobject _ldns_rr_a_address;
162 %rename(__ldns_rr_a_address) ldns_rr_a_address;
163 %inline
164 %{
165   ldns_rdf * _ldns_rr_a_address(ldns_rr *rr)
166   {
167     ldns_rdf *rdf;
168     rdf = ldns_rr_a_address(rr);
169     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
170   }
171 %}
172
173
174 %newobject _ldns_rr_mx_exchange;
175 %rename(__ldns_rr_mx_exchange) ldns_rr_mx_exchange;
176 %inline
177 %{
178   ldns_rdf * _ldns_rr_mx_exchange(ldns_rr *rr)
179   {
180     ldns_rdf *rdf;
181     rdf = ldns_rr_mx_exchange(rr);
182     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
183   }
184 %}
185
186
187 %newobject _ldns_rr_mx_preference;
188 %rename(__ldns_rr_mx_preference) ldns_rr_mx_preference;
189 %inline
190 %{
191   ldns_rdf * _ldns_rr_mx_preference(ldns_rr *rr)
192   {
193     ldns_rdf *rdf;
194     rdf = ldns_rr_mx_preference(rr);
195     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
196   }
197 %}
198
199
200 %newobject _ldns_rr_ns_nsdname;
201 %rename(__ldns_rr_ns_nsdname) ldns_rr_ns_nsdname;
202 %inline
203 %{
204   ldns_rdf * _ldns_rr_ns_nsdname(ldns_rr *rr)
205   {
206     ldns_rdf *rdf;
207     rdf = ldns_rr_ns_nsdname(rr);
208     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
209   }
210 %}
211
212
213 %newobject _ldns_rr_rrsig_expiration;
214 %rename(__ldns_rr_rrsig_expiration) ldns_rr_rrsig_expiration;
215 %inline
216 %{
217   ldns_rdf * _ldns_rr_rrsig_expiration(ldns_rr *rr)
218   {
219     ldns_rdf *rdf;
220     rdf = ldns_rr_rrsig_expiration(rr);
221     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
222   }
223 %}
224
225
226 %newobject _ldns_rr_rrsig_inception;
227 %rename(__ldns_rr_rrsig_inception) ldns_rr_rrsig_inception;
228 %inline
229 %{
230   ldns_rdf * _ldns_rr_rrsig_inception(ldns_rr *rr)
231   {
232     ldns_rdf *rdf;
233     rdf = ldns_rr_rrsig_inception(rr);
234     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
235   }
236 %}
237
238
239 %newobject _ldns_rr_rrsig_keytag;
240 %rename(__ldns_rr_rrsig_keytag) ldns_rr_rrsig_keytag;
241 %inline
242 %{
243   ldns_rdf * _ldns_rr_rrsig_keytag(ldns_rr *rr)
244   {
245     ldns_rdf *rdf;
246     rdf = ldns_rr_rrsig_keytag(rr);
247     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
248   }
249 %}
250
251
252 %newobject _ldns_rr_rrsig_labels;
253 %rename(__ldns_rr_rrsig_labels) ldns_rr_rrsig_labels;
254 %inline
255 %{
256   ldns_rdf * _ldns_rr_rrsig_labels(ldns_rr *rr)
257   {
258     ldns_rdf *rdf;
259     rdf = ldns_rr_rrsig_labels(rr);
260     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
261   }
262 %}
263
264
265 %newobject _ldns_rr_rrsig_origttl;
266 %rename(__ldns_rr_rrsig_origttl) ldns_rr_rrsig_origttl;
267 %inline
268 %{
269   ldns_rdf * _ldns_rr_rrsig_origttl(ldns_rr *rr)
270   {
271     ldns_rdf *rdf;
272     rdf = ldns_rr_rrsig_origttl(rr);
273     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
274   }
275 %}
276
277
278 %newobject _ldns_rr_rrsig_sig;
279 %rename(__ldns_rr_rrsig_sig) ldns_rr_rrsig_sig;
280 %inline
281 %{
282   ldns_rdf * _ldns_rr_rrsig_sig(ldns_rr *rr)
283   {
284     ldns_rdf *rdf;
285     rdf = ldns_rr_rrsig_sig(rr);
286     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
287   }
288 %}
289
290
291 %newobject _ldns_rr_rrsig_signame;
292 %rename(__ldns_rr_rrsig_signame) ldns_rr_rrsig_signame;
293 %inline
294 %{
295   ldns_rdf * _ldns_rr_rrsig_signame(ldns_rr *rr)
296   {
297     ldns_rdf *rdf;
298     rdf = ldns_rr_rrsig_signame(rr);
299     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
300   }
301 %}
302
303
304 %newobject _ldns_rr_rrsig_typecovered;
305 %rename(__ldns_rr_rrsig_typecovered) ldns_rr_rrsig_typecovered;
306 %inline
307 %{
308   ldns_rdf * _ldns_rr_rrsig_typecovered(ldns_rr *rr)
309   {
310     ldns_rdf *rdf;
311     rdf = ldns_rr_rrsig_typecovered(rr);
312     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
313   }
314 %}
315
316 /* End of pull cloning. */
317
318 /* Clone rdf data on push. */
319
320 %rename(__ldns_rr_a_set_address) ldns_rr_a_set_address;
321 %inline
322 %{
323   bool _ldns_rr_a_set_address(ldns_rr *rr, ldns_rdf *rdf)
324   {
325     return ldns_rr_a_set_address(rr, ldns_rdf_clone(rdf));
326   }
327 %}
328
329 %rename(__ldns_rr_dnskey_set_algorithm) ldns_rr_dnskey_set_algorithm;
330 %inline
331 %{
332   bool _ldns_rr_dnskey_set_algorithm(ldns_rr *rr, ldns_rdf *rdf)
333   {
334     return ldns_rr_dnskey_set_algorithm(rr, ldns_rdf_clone(rdf));
335   }
336 %}
337
338 %rename(__ldns_rr_dnskey_set_flags) ldns_rr_dnskey_set_flags;
339 %inline
340 %{
341   bool _ldns_rr_dnskey_set_flags(ldns_rr *rr, ldns_rdf *rdf)
342   {
343     return ldns_rr_dnskey_set_flags(rr, ldns_rdf_clone(rdf));
344   }
345 %}
346
347 %rename(__ldns_rr_dnskey_set_key) ldns_rr_dnskey_set_key;
348 %inline
349 %{
350   bool _ldns_rr_dnskey_set_key(ldns_rr *rr, ldns_rdf *rdf)
351   {
352     return ldns_rr_dnskey_set_key(rr, ldns_rdf_clone(rdf));
353   }
354 %}
355
356 %rename(__ldns_rr_dnskey_set_protocol) ldns_rr_dnskey_set_protocol;
357 %inline
358 %{
359   bool _ldns_rr_dnskey_set_protocol(ldns_rr *rr, ldns_rdf *rdf)
360   {
361     return ldns_rr_dnskey_set_protocol(rr, ldns_rdf_clone(rdf));
362   }
363 %}
364
365 %rename(__ldns_rr_push_rdf) ldns_rr_push_rdf;
366 %inline
367 %{
368   bool _ldns_rr_push_rdf(ldns_rr *rr, ldns_rdf *rdf)
369   {
370     return ldns_rr_push_rdf(rr, ldns_rdf_clone(rdf));
371   }
372 %}
373
374 %rename(__ldns_rr_rrsig_set_algorithm) ldns_rr_rrsig_set_algorithm;
375 %inline
376 %{
377   bool _ldns_rr_rrsig_set_algorithm(ldns_rr *rr, ldns_rdf *rdf)
378   {
379     return ldns_rr_rrsig_set_algorithm(rr, ldns_rdf_clone(rdf));
380   }
381 %}
382
383 %rename(__ldns_rr_rrsig_set_expiration) ldns_rr_rrsig_set_expiration;
384 %inline
385 %{
386   bool _ldns_rr_rrsig_set_expiration(ldns_rr *rr, ldns_rdf *rdf)
387   {
388     return ldns_rr_rrsig_set_expiration(rr, ldns_rdf_clone(rdf));
389   }
390 %}
391
392 %rename(__ldns_rr_rrsig_set_inception) ldns_rr_rrsig_set_inception;
393 %inline
394 %{
395   bool _ldns_rr_rrsig_set_inception(ldns_rr *rr, ldns_rdf *rdf)
396   {
397     return ldns_rr_rrsig_set_inception(rr, ldns_rdf_clone(rdf));
398   }
399 %}
400
401 %rename(__ldns_rr_rrsig_set_keytag) ldns_rr_rrsig_set_keytag;
402 %inline
403 %{
404   bool _ldns_rr_rrsig_set_keytag(ldns_rr *rr, ldns_rdf *rdf)
405   {
406     return ldns_rr_rrsig_set_keytag(rr, ldns_rdf_clone(rdf));
407   }
408 %}
409
410 %rename(__ldns_rr_rrsig_set_labels) ldns_rr_rrsig_set_labels;
411 %inline
412 %{
413   bool _ldns_rr_rrsig_set_labels(ldns_rr *rr, ldns_rdf *rdf)
414   {
415     return ldns_rr_rrsig_set_labels(rr, ldns_rdf_clone(rdf));
416   }
417 %}
418
419 %rename(__ldns_rr_rrsig_set_origttl) ldns_rr_rrsig_set_origttl;
420 %inline
421 %{
422   bool _ldns_rr_rrsig_set_origttl(ldns_rr *rr, ldns_rdf *rdf)
423   {
424     return ldns_rr_rrsig_set_origttl(rr, ldns_rdf_clone(rdf));
425   }
426 %}
427
428 %rename(__ldns_rr_rrsig_set_sig) ldns_rr_rrsig_set_sig;
429 %inline
430 %{
431   bool _ldns_rr_rrsig_set_sig(ldns_rr *rr, ldns_rdf *rdf) {
432     return ldns_rr_rrsig_set_sig(rr, ldns_rdf_clone(rdf));
433   }
434 %}
435
436 %rename(__ldns_rr_rrsig_set_signame) ldns_rr_rrsig_set_signame;
437 %inline
438 %{
439   bool _ldns_rr_rrsig_set_signame(ldns_rr *rr, ldns_rdf *rdf)
440   {
441     return ldns_rr_rrsig_set_signame(rr, ldns_rdf_clone(rdf));
442   }
443 %}
444
445 %rename(__ldns_rr_rrsig_set_typecovered) ldns_rr_rrsig_set_typecovered;
446 %inline
447 %{
448   bool _ldns_rr_rrsig_set_typecovered(ldns_rr *rr, ldns_rdf *rdf)
449   {
450     return ldns_rr_rrsig_set_typecovered(rr, ldns_rdf_clone(rdf));
451   }
452 %}
453
454 %rename(__ldns_rr_set_owner) ldns_rr_set_owner;
455 %inline
456 %{
457   void _ldns_rr_set_owner(ldns_rr *rr, ldns_rdf *rdf)
458   {
459     return ldns_rr_set_owner(rr, ldns_rdf_clone(rdf));
460   }
461 %}
462
463 %newobject _ldns_rr_set_rdf;
464 %rename(__ldns_rr_set_rdf) ldns_rr_set_rdf;
465 %inline
466 %{
467   ldns_rdf * _ldns_rr_set_rdf(ldns_rr *rr, ldns_rdf *rdf, size_t pos)
468   {
469     /* May leak memory on unsuccessful calls. */
470     ldns_rdf *new, *ret;
471
472     new = ldns_rdf_clone(rdf);
473
474     if ((ret = ldns_rr_set_rdf(rr, new, pos)) == NULL) {
475         ldns_rdf_deep_free(new);
476     }
477
478     return ret;
479   }
480 %}
481
482 /* End of push cloning. */
483
484 %rename(_ldns_rr_new_frm_str) ldns_rr_new_frm_str;
485 %rename(_ldns_rr_new_frm_fp_l) ldns_rr_new_frm_fp_l;
486 %rename(_ldns_rr_new_frm_fp) ldns_rr_new_frm_fp;
487
488
489 /* ========================================================================= */
490 /* Debugging related code. */
491 /* ========================================================================= */
492
493
494 #ifdef LDNS_DEBUG
495 %rename(__ldns_rr_free) ldns_rr_free;
496 %inline %{
497   void _ldns_rr_free (ldns_rr *r)
498   {
499     printf("******** LDNS_RR free 0x%lX ************\n", (long unsigned int)r);
500     ldns_rr_free(r);
501   }
502 %}
503 #else /* !LDNS_DEBUG */
504 %rename(_ldns_rr_free) ldns_rr_free;
505 #endif /* LDNS_DEBUG */
506
507
508 /* ========================================================================= */
509 /* Added C code. */
510 /* ========================================================================= */
511
512 /* None. */
513
514
515 /* ========================================================================= */
516 /* Encapsulating Python code. */
517 /* ========================================================================= */
518
519
520 %feature("docstring") ldns_struct_rr "Resource Record (RR).
521
522 The RR is the basic DNS element that contains actual data. This class allows
523 to create RR and manipulate with the content.
524
525 Use :meth:`ldns_rr_new`, :meth:`ldns_rr_new_frm_type`, :meth:`new_frm_fp`,
526 :meth:`new_frm_fp_l`, :meth:`new_frm_str` or :meth:`new_question_frm_str`
527 to create :class:`ldns_rr` instances.
528 "
529
530 %extend ldns_struct_rr {
531  
532   %pythoncode
533   %{
534         def __init__(self):
535             raise Exception("This class can't be created directly. " +
536                 "Please use: ldns_rr_new(), ldns_rr_new_frm_type(), " +
537                 "new_frm_fp(), new_frm_fp_l(), new_frm_str() or " +
538                 "new_question_frm_str()")
539        
540         __swig_destroy__ = _ldns._ldns_rr_free
541
542         #
543         # LDNS_RR_CONSTRUCTORS_
544         #
545
546         @staticmethod
547         def new_frm_str(string, default_ttl=0, origin=None, prev=None, raiseException=True):
548             """
549                Creates an rr object from a string.
550
551                The string should be a fully filled-in rr, like "owner_name
552                [space] TTL [space] CLASS [space] TYPE [space] RDATA."
553                
554                :param string: The string to convert.
555                :type string: str
556                :param default_ttl: Default ttl value for the rr.
557                    If 0 DEF_TTL will be used.
558                :type default_ttl: int
559                :param origin: When the owner is relative add this.
560                :type origin: :class:`ldns_dname`
561                :param prev: The previous owner name.
562                :type prev: :class:`ldns_rdf`
563                :param raiseException: If True, an exception occurs in case a rr
564                    instance can't be created.
565                :throws Exception: If `raiseExceprion` is set and fails.
566                :throws TypeError: When parameters of incorrect types.
567                :return: (:class:`ldns_rr`) RR instance or None.
568
569                .. note::
570                    The type checking of `origin` is benevolent.
571                    It allows also to pass a dname :class:`ldns_rdf` object.
572                    This will probably change in future.
573         
574                **Usage**
575
576                >>> import ldns
577                >>> rr = ldns.ldns_rr.new_frm_str("www.nic.cz. IN A 192.168.1.1", 300)
578                >>> print rr
579                www.nic.cz.  300  IN  A  192.168.1.1
580                >>> rr = ldns.ldns_rr.new_frm_str("test.nic.cz. 600 IN A 192.168.1.2")
581                >>> print rr
582                test.nic.cz.  600  IN  A  192.168.1.2
583                
584             """
585             if (not isinstance(origin, ldns_dname)) and \
586                isinstance(origin, ldns_rdf) and \
587                origin.get_type() == _ldns.LDNS_RDF_TYPE_DNAME:
588                 warnings.warn("The ldns_rr.new_frm_str() method will" +
589                     " drop the possibility to accept ldns_rdf as origin." +
590                     " Convert argument to ldns_dname.",
591                     PendingDeprecationWarning, stacklevel=2)
592             status, rr, prev = _ldns.ldns_rr_new_frm_str_(string, default_ttl,
593                 origin, prev)
594             if status != LDNS_STATUS_OK:
595                 if (raiseException):
596                     raise Exception("Can't create RR, error: %d" % status)
597                 return None
598             return rr
599
600         @staticmethod
601         def new_question_frm_str(string, default_ttl=0, origin=None, prev=None, raiseException=True):
602             """
603                Creates an rr object from a string.
604
605                The string is like :meth:`new_frm_str` but without rdata.
606
607                :param string: The string to convert.
608                :type string: str
609                :param origin: When the owner is relative add this.
610                :type origin: :class:`ldns_dname`
611                :param prev: The previous owner name.
612                :type prev: :class:`ldns_rdf`
613                :param raiseException: If True, an exception occurs in case
614                    a rr instance can't be created.
615                :throws Exception: If `raiseExceprion` is set and fails.
616                :throws TypeError: When parameters of incorrect types.
617                :return: (:class:`ldns_rr`) RR instance or None. If the object
618                    can't be created and `raiseException` is True,
619                    an exception occurs.
620
621                .. note::
622                    The type checking of `origin` is benevolent.
623                    It allows also to pass a dname :class:`ldns_rdf` object.
624                    This will probably change in future.
625             """
626             if (not isinstance(origin, ldns_dname)) and \
627                isinstance(origin, ldns_rdf) and \
628                origin.get_type() == _ldns.LDNS_RDF_TYPE_DNAME:
629                 warnings.warn("The ldns_rr.new_question_frm_str() method will" +
630                     " drop the possibility to accept ldns_rdf as origin." +
631                     " Convert argument to ldns_dname.",
632                     PendingDeprecationWarning, stacklevel=2)
633             status, rr, prev = _ldns.ldns_rr_new_question_frm_str_(string,
634                 origin, prev)
635             if status != LDNS_STATUS_OK:
636                 if (raiseException):
637                     raise Exception("Can't create RR, error: %d" % status)
638                 return None
639             return rr
640
641         @staticmethod
642         def new_frm_str_prev(string, default_ttl=0, origin=None, prev=None, raiseException=True):
643             """
644                Creates an rr object from a string.
645
646                The string should be a fully filled-in rr, like "owner_name
647                [space] TTL [space] CLASS [space] TYPE [space] RDATA".
648                
649                :param string: The string to convert.
650                :type string: str
651                :param default_ttl: Default ttl value for the rr.
652                    If 0 DEF_TTL will be used.
653                :type default_ttl: int
654                :param origin: When the owner is relative add this.
655                :type origin: :class:`ldns_dname`
656                :param prev: The previous owner name.
657                :type prev: :class:`ldns_rdf`
658                :param raiseException: If True, an exception occurs in case when
659                    a rr instance can't be created.
660                :throws Exception: If `raiseExceprion` is set and fails.
661                :throws TypeError: When parameters of incorrect types.
662                :return: None when fails, otherwise a tuple containing:
663
664                   * rr - (:class:`ldns_rr`) RR instance or None.
665                     If the object can't be created and `raiseException`
666                     is True, an exception occurs.
667         
668                   * prev - (:class:`ldns_rdf`) Owner name found in this string
669                     or None.
670
671                .. note::
672                    The type checking of `origin` is benevolent.
673                    It allows also to pass a dname :class:`ldns_rdf` object.
674                    This will probably change in future.
675             """
676             if (not isinstance(origin, ldns_dname)) and \
677                isinstance(origin, ldns_rdf) and \
678                origin.get_type() == _ldns.LDNS_RDF_TYPE_DNAME:
679                 warnings.warn("The ldns_rr.new_frm_str_prev() method will" +
680                     " drop the possibility to accept ldns_rdf as origin." +
681                     " Convert argument to ldns_dname.",
682                     PendingDeprecationWarning, stacklevel=2)
683             status, rr, prev = _ldns.ldns_rr_new_frm_str_(string, default_ttl,
684                 origin, prev)
685             if status != LDNS_STATUS_OK:
686                 if (raiseException):
687                     raise Exception("Can't create RR, error: %d" % status)
688                 return None
689             return rr, prev
690
691         @staticmethod
692         def new_frm_fp(file, default_ttl=0, origin=None, prev=None, raiseException=True):
693             """
694                Creates a new rr from a file containing a string.
695               
696                :param file: Opened file.
697                :param default_ttl: If 0 DEF_TTL will be used.
698                :type default_ttl: int
699                :param origin: When the owner is relative add this.
700                :type origin: :class:`ldns_dname`
701                :param prev: When the owner is white spaces use this.
702                :type prev: :class:`ldns_rdf`
703                :param raiseException: If True, an exception occurs in case
704                    a resolver object can't be created.
705                :throws Exception: If `raiseException` is set and the input
706                    cannot be read.
707                :throws TypeError: When parameters of incorrect types.
708                :return: None when fails, otherwise a tuple containing:
709
710                    * rr - (:class:`ldns_rr`) RR object or None. If the object
711                      can't be created and `raiseException` is True,
712                      an exception occurs.
713
714                    * ttl - (int) None or TTL if the file contains a TTL
715                      directive.
716
717                    * origin - (:class:`ldns_rdf`) None or dname rdf if the file
718                      contains a ORIGIN directive.
719
720                    * prev - (:class:`ldns_rdf`) None or updated value
721                      of prev parameter.
722
723                .. note::
724                    The type checking of `origin` is benevolent.
725                    It allows also to pass a dname :class:`ldns_rdf` object.
726                    This will probably change in future.
727             """
728             if (not isinstance(origin, ldns_dname)) and \
729                isinstance(origin, ldns_rdf) and \
730                origin.get_type() == _ldns.LDNS_RDF_TYPE_DNAME:
731                 warnings.warn("The ldns_rr.new_frm_fp() method will" +
732                     " drop the possibility to accept ldns_rdf as origin." +
733                     " Convert argument to ldns_dname.",
734                     PendingDeprecationWarning, stacklevel=2)
735             res = _ldns.ldns_rr_new_frm_fp_(file, default_ttl, origin, prev)
736             if res[0] != LDNS_STATUS_OK:
737                 if (raiseException):
738                     raise Exception("Can't create RR, error: %d" % res[0])
739                 return None
740             return res[1:]
741
742         @staticmethod
743         def new_frm_fp_l(file, default_ttl=0, origin=None, prev=None, raiseException=True):
744             """
745                Creates a new rr from a file containing a string.
746               
747                :param file: Opened file.
748                :param default_ttl: If 0 DEF_TTL will be used.
749                :type default_ttl: int
750                :param origin: When the owner is relative add this.
751                :type origin: :class:`ldns_dname`
752                :param prev: When the owner is white spaces use this.
753                :type prev: :class:`ldns_rdf`
754                :param raiseException: Iif True, an exception occurs in case
755                    a resolver object can't be created.
756                :throws Exception: If `raiseException` is set and the input
757                    cannot be read.
758                :throws TypeError: When parameters of incorrect types.
759                :return: None when fails, otherwise a tuple containing:
760
761                   * rr - (:class:`ldns_rr`) RR object or None. If the object
762                     can't be created and `raiseException` is True,
763                     an exception occurs.
764
765                   * line - (int) line number (for debugging).
766
767                   * ttl - (int) None or TTL if the file contains a TTL
768                     directive .
769
770                   * origin - (:class:`ldns_rdf`) None or dname rdf if the file
771                     contains a ORIGIN directive.
772
773                   * prev - (:class:`ldns_rdf`) None or updated value of prev
774                     parameter.
775
776                .. note::
777                    The type checking of `origin` is benevolent.
778                    It allows also to pass a dname :class:`ldns_rdf` object.
779                    This will probably change in future.
780             """
781             if (not isinstance(origin, ldns_dname)) and \
782                isinstance(origin, ldns_rdf) and \
783                origin.get_type() == _ldns.LDNS_RDF_TYPE_DNAME:
784                 warnings.warn("The ldns_rr.new_frm_fp_l() method will" +
785                     " drop the possibility to accept ldns_rdf as origin." +
786                     " Convert argument to ldns_dname.",
787                     PendingDeprecationWarning, stacklevel=2)
788             res = _ldns.ldns_rr_new_frm_fp_l_(file, default_ttl, origin, prev)
789             if res[0] != LDNS_STATUS_OK:
790                 if (raiseException):
791                     raise Exception("Can't create RR, error: %d" % res[0])
792                 return None
793             return res[1:]
794
795         #
796         # _LDNS_RR_CONSTRUCTORS
797         #
798
799         def __str__(self):
800             """
801                Converts the data in the resource record to presentation format.
802
803                :return: (str)
804             """
805             return _ldns.ldns_rr2str(self)
806
807         def __cmp__(self, other):
808             """
809                Compares two rrs.
810                
811                The TTL is not looked at.
812                
813                :param other: The second RR one.
814                :type other: :class:`ldns_rr`
815                :throws TypeError: When `other` of non-:class:`ldns_rr` type.
816                :return: (int) 0 if equal, -1 if `self` comes before `other`,
817                    1 if `other` RR comes before `self`.
818             """
819             return _ldns.ldns_rr_compare(self, other)
820
821         def __lt__(self, other):
822             """
823                Compares two rrs.
824                
825                The TTL is not looked at.
826                
827                :param other: The second RR one.
828                :type other: :class:`ldns_rr`
829                :throws TypeError: When `other` of non-:class:`ldns_rr` type.
830                :return: (bool) True when `self` is less than 'other'.
831             """
832             return _ldns.ldns_rr_compare(self, other) == -1
833
834         def __le__(self, other):
835             """
836                Compares two rrs.
837                
838                The TTL is not looked at.
839                
840                :param other: The second RR one.
841                :type other: :class:`ldns_rr`
842                :throws TypeError: When `other` of non-:class:`ldns_rr` type.
843                :return: (bool) True when `self` is less than or equal to
844                    'other'.
845             """
846             return _ldns.ldns_rr_compare(self, other) != 1
847
848         def __eq__(self, other):
849             """
850                Compares two rrs.
851                
852                The TTL is not looked at.
853                
854                :param other: The second RR one.
855                :type other: :class:`ldns_rr`
856                :throws TypeError: When `other` of non-:class:`ldns_rr` type.
857                :return: (bool) True when `self` is equal to 'other'.
858             """
859             return _ldns.ldns_rr_compare(self, other) == 0
860
861         def __ne__(self, other):
862             """
863                Compares two rrs.
864                
865                The TTL is not looked at.
866                
867                :param other: The second RR one.
868                :type other: :class:`ldns_rr`
869                :throws TypeError: When `other` of non-:class:`ldns_rr` type.
870                :return: (bool) True when `self` is not equal to 'other'.
871             """
872             return _ldns.ldns_rr_compare(self, other) != 0
873
874         def __gt__(self, other):
875             """
876                Compares two rrs.
877                
878                The TTL is not looked at.
879                
880                :param other: The second RR one.
881                :type other: :class:`ldns_rr`
882                :throws TypeError: When `other` of non-:class:`ldns_rr` type.
883                :return: (bool) True when `self` is greater than 'other'.
884             """
885             return _ldns.ldns_rr_compare(self, other) == 1
886
887         def __ge__(self, other):
888             """
889                Compares two rrs.
890                
891                The TTL is not looked at.
892                
893                :param other: The second RR one.
894                :type other: :class:`ldns_rr`
895                :throws TypeError: When `other` of non-:class:`ldns_rr` type.
896                :return: (bool) True when `self` is greater than or equal to
897                     'other'.
898             """
899             return _ldns.ldns_rr_compare(self, other) != -1
900
901         @staticmethod
902         def class_by_name(string):
903             """
904                Retrieves a class identifier value by looking up its name.
905
906                :param string: Class name.
907                :type string: str
908                :throws TypeError: when `string` of inappropriate type.
909                :return: (int) Class identifier value, or 0 if not valid
910                    class name given.
911             """
912             return _ldns.ldns_get_rr_class_by_name(string)
913
914         def rdfs(self):
915             """
916                Returns a generator object of rdata records.
917
918                :return: Generator of :class:`ldns_rdf`.
919             """
920             for i in range(0, self.rd_count()):
921                 yield self.rdf(i)
922
923         def print_to_file(self, output):
924             """
925                Prints the data in the resource record to the given file stream
926                (in presentation format).
927
928                :param output: Opened file stream.
929                :throws TypeError: When `output` not a file.
930             """
931             _ldns.ldns_rr_print(output, self)
932             #parameters: FILE *, const ldns_rr *,
933
934         def get_type_str(self):
935             """
936                Converts an RR type value to its string representation,
937                and returns that string.
938
939                :return: (str) containing type identification.
940             """
941             return _ldns.ldns_rr_type2str(self.get_type())
942             #parameters: const ldns_rr_type,
943
944         def get_class_str(self):
945             """
946                Converts an RR class value to its string representation,
947                and returns that string.
948
949                :return: (str) containing class identification.
950             """
951             return _ldns.ldns_rr_class2str(self.get_class())
952             #parameters: const ldns_rr_class,
953
954         @staticmethod
955         def dnskey_key_size_raw(keydata, len, alg):
956             """
957                Get the length of the keydata in bits.
958
959                :param keydata: Key raw data.
960                :type keydata: unsigned char \*
961                :param len: Number of bytes of `keydata`.
962                :type len: size_t
963                :param alg: Algorithm identifier.
964                :type alg: ldns_algorithm
965
966                :return: (size_t) The length of key data in bits.
967             """
968             return _ldns.ldns_rr_dnskey_key_size_raw(keydata, len, alg)
969             #parameters: const unsigned char *,const size_t,const ldns_algorithm,
970             #retvals: size_t
971
972         def write_to_buffer(self,buffer,section):
973             """
974                Copies the rr data to the buffer in wire format.
975                
976                :param buffer: Buffer to append the result to.
977                :type buffer: :class:`ldns_buffer`
978                :param section: The section in the packet this rr is supposed
979                    to be in (to determine whether to add rdata or not).
980                :type section: int
981                :throws TypeError: when arguments of mismatching types passed.
982                :return: (ldns_status) ldns_status
983             """
984             return _ldns.ldns_rr2buffer_wire(buffer, self, section)
985             #parameters: ldns_buffer *,const ldns_rr *,int,
986             #retvals: ldns_status
987
988         def write_to_buffer_canonical(self,buffer,section):
989             """
990                Copies the rr data to the buffer in wire format, in canonical
991                format according to RFC3597 (every dname in rdata fields
992                of RR's mentioned in that RFC will be converted to lower-case).
993                
994                :param buffer: Buffer to append the result to.
995                :type buffer: :class:`ldns_buffer`
996                :param section: The section in the packet this rr is supposed
997                    to be in (to determine whether to add rdata or not).
998                :type section: int
999                :throws TypeError: when arguments of mismatching types passed.
1000                :return: (ldns_status) ldns_status
1001             """
1002             return _ldns.ldns_rr2buffer_wire_canonical(buffer,self,section)
1003             #parameters: ldns_buffer *,const ldns_rr *,int,
1004             #retvals: ldns_status
1005
1006         def write_data_to_buffer(self, buffer):
1007             """
1008                Converts an rr's rdata to wire format, while excluding the
1009                owner name and all the stuff before the rdata.
1010                
1011                This is needed in DNSSEC key-tag calculation, the ds
1012                calculation from the key and maybe elsewhere.
1013                
1014                :param buffer: Buffer to append the result to.
1015                :type buffer: :class:`ldns_buffer`
1016                :throws TypeError: when `buffer` of non-:class:`ldns_buffer`
1017                    type.
1018                :return: (ldns_status) ldns_status
1019             """
1020             return _ldns.ldns_rr_rdata2buffer_wire(buffer,self)
1021             #parameters: ldns_buffer *, const ldns_rr *,
1022             #retvals: ldns_status
1023
1024         def write_rrsig_to_buffer(self, buffer):
1025             """
1026                Converts a rrsig to wire format BUT EXCLUDE the rrsig rdata.
1027
1028                This is needed in DNSSEC verification.
1029                
1030                :param buffer: Buffer to append the result to.
1031                :type buffer: :class:`ldns_buffer`
1032                :throws TypeError: when `buffer` of non-:class:`ldns_buffer`
1033                    type.
1034                :return: (ldns_status) ldns_status
1035             """
1036             return _ldns.ldns_rrsig2buffer_wire(buffer,self)
1037             #parameters: ldns_buffer *,const ldns_rr *,
1038             #retvals: ldns_status
1039
1040         #
1041         # LDNS_RR_METHODS_
1042         #
1043
1044         def a_address(self):
1045             """
1046                Returns the address rdf of a LDNS_RR_TYPE_A or LDNS_RR_TYPE_AAAA
1047                rr.
1048                
1049                :return: (:class:`ldns_rdf`) with the address or None on
1050                    failure.
1051             """
1052             return _ldns._ldns_rr_a_address(self)
1053             #parameters: const ldns_rr *,
1054             #retvals: ldns_rdf *
1055
1056         def a_set_address(self, f):
1057             """
1058                Sets the address of a LDNS_RR_TYPE_A or LDNS_RR_TYPE_AAAA rr.
1059                
1060                :param f: The address to be set.
1061                :type f: :class:`ldns_rdf`
1062                :throws TypeError: When `f` of non-:class:`ldns_rdf` type.
1063                :return: (bool) True on success, False otherwise.
1064             """
1065             return _ldns._ldns_rr_a_set_address(self, f)
1066             #parameters: ldns_rr *, ldns_rdf *,
1067             #retvals: bool
1068
1069         def clone(self):
1070             """
1071                Clones a rr and all its data.
1072                
1073                :return: (:class:`ldns_rr`) The new rr or None on failure.
1074             """
1075             return _ldns.ldns_rr_clone(self)
1076             #parameters: const ldns_rr *,
1077             #retvals: ldns_rr *
1078
1079         def compare_ds(self, rr2):
1080             """
1081                Returns True if the given rr's are equal. 
1082                
1083                Also returns True if one record is a DS that represents the
1084                same DNSKEY record as the other record.
1085                
1086                :param rr2: The second rr.
1087                :type rr2: :class:`ldns_rr`
1088                :throws TypeError: When `rr2` of non-:class:`ldns_rr` type.
1089                :return: (bool) True if equal otherwise False.
1090             """
1091             return _ldns.ldns_rr_compare_ds(self, rr2)
1092             #parameters: const ldns_rr *, const ldns_rr *,
1093             #retvals: bool
1094
1095         def compare_no_rdata(self, rr2):
1096             """
1097                Compares two rrs, up to the rdata.
1098                
1099                :param rr2: Rhe second rr.
1100                :type rr2: :class:`ldns_rr`
1101                :throws TypeError: When `rr2` of non-:class:`ldns_rr` type.
1102                :return: (int) 0 if equal, negative integer if `self` comes
1103                    before `rr2`, positive integer if `rr2` comes before `self`.
1104             """
1105             return _ldns.ldns_rr_compare_no_rdata(self, rr2)
1106             #parameters: const ldns_rr *, const ldns_rr *,
1107             #retvals: int
1108
1109         def dnskey_algorithm(self):
1110             """
1111                Returns the algorithm of a LDNS_RR_TYPE_DNSKEY rr.
1112                
1113                :return: (:class:`ldns_rdf`) with the algorithm or None
1114                    on failure.
1115             """
1116             return _ldns._ldns_rr_dnskey_algorithm(self)
1117             #parameters: const ldns_rr *,
1118             #retvals: ldns_rdf *
1119
1120         def dnskey_flags(self):
1121             """
1122                Returns the flags of a LDNS_RR_TYPE_DNSKEY rr.
1123                
1124                :return: (:class:`ldns_rdf`) with the flags or None on failure.
1125             """
1126             return _ldns._ldns_rr_dnskey_flags(self)
1127             #parameters: const ldns_rr *,
1128             #retvals: ldns_rdf *
1129
1130         def dnskey_key(self):
1131             """
1132                Returns the key data of a LDNS_RR_TYPE_DNSKEY rr.
1133                
1134                :return: (:class:`ldns_rdf`) with the key data or None on
1135                    failure.
1136             """
1137             return _ldns._ldns_rr_dnskey_key(self)
1138             #parameters: const ldns_rr *,
1139             #retvals: ldns_rdf *
1140
1141         def dnskey_key_size(self):
1142             """
1143                Get the length of the keydata in bits.
1144                
1145                :return: (size_t) the keysize in bits.
1146             """
1147             return _ldns.ldns_rr_dnskey_key_size(self)
1148             #parameters: const ldns_rr *,
1149             #retvals: size_t
1150
1151         def dnskey_protocol(self):
1152             """
1153                Returns the protocol of a LDNS_RR_TYPE_DNSKEY rr.
1154                
1155                :return: (:class:`ldns_rdf`) with the protocol or None on
1156                    failure.
1157             """
1158             return _ldns._ldns_rr_dnskey_protocol(self)
1159             #parameters: const ldns_rr *,
1160             #retvals: ldns_rdf *
1161
1162         def dnskey_set_algorithm(self, f):
1163             """
1164                Sets the algorithm of a LDNS_RR_TYPE_DNSKEY rr
1165                
1166                :param f: The algorithm to set.
1167                :type f: :class:`ldns_rdf`
1168                :throws TypeError: When `f` of non-:class:`ldns_rdf` type.
1169                :return: (bool) True on success, False otherwise.
1170             """
1171             return _ldns._ldns_rr_dnskey_set_algorithm(self, f)
1172             #parameters: ldns_rr *, ldns_rdf *,
1173             #retvals: bool
1174
1175         def dnskey_set_flags(self, f):
1176             """
1177                Sets the flags of a LDNS_RR_TYPE_DNSKEY rr.
1178                
1179                :param f: The flags to be set.
1180                :type f: :class:`ldns_rdf`
1181                :throws TypeError: When `f` of non-:class:`ldns_rdf` type.
1182                :return: (bool) True on success, False otherwise.
1183             """
1184             return _ldns._ldns_rr_dnskey_set_flags(self, f)
1185             #parameters: ldns_rr *, ldns_rdf *,
1186             #retvals: bool
1187
1188         def dnskey_set_key(self, f):
1189             """
1190                Sets the key data of a LDNS_RR_TYPE_DNSKEY rr.
1191                
1192                :param f: The key data to set.
1193                :type f: :class:`ldns_rdf`
1194                :throws TypeError: When `f` of non-:class:`ldns_rdf` type.
1195                :return: (bool) True on success, False otherwise.
1196             """
1197             return _ldns._ldns_rr_dnskey_set_key(self, f)
1198             #parameters: ldns_rr *, ldns_rdf *,
1199             #retvals: bool
1200
1201         def dnskey_set_protocol(self,f):
1202             """
1203                Sets the protocol of a LDNS_RR_TYPE_DNSKEY rr.
1204                
1205                :param f: The protocol to set.
1206                :type f: :class:`ldns_rdf`
1207                :throws TypeError: When `f` of non-:class:`ldns_rdf` type.
1208                :return: (bool) True on success, False otherwise.
1209             """
1210             return _ldns._ldns_rr_dnskey_set_protocol(self,f)
1211             #parameters: ldns_rr *,ldns_rdf *,
1212             #retvals: bool
1213
1214         def get_class(self):
1215             """
1216                Returns the class of the rr.
1217                
1218                :return: (int) The class identifier of the rr.
1219             """
1220             return _ldns.ldns_rr_get_class(self)
1221             #parameters: const ldns_rr *,
1222             #retvals: ldns_rr_class
1223
1224         def get_type(self):
1225             """
1226                Returns the type of the rr.
1227                
1228                :return: (int) The type identifier of the rr.
1229             """
1230             return _ldns.ldns_rr_get_type(self)
1231             #parameters: const ldns_rr *,
1232             #retvals: ldns_rr_type
1233
1234         def is_question(self):
1235             """
1236                Returns the question flag of a rr structure.
1237
1238                :return: (bool) True if question flag is set.
1239             """
1240             return _ldns.ldns_rr_is_question(self)
1241
1242         def label_count(self):
1243             """
1244                Counts the number of labels of the owner name.
1245                
1246                :return: (int) The number of labels.
1247             """
1248             return _ldns.ldns_rr_label_count(self)
1249             #parameters: ldns_rr *,
1250             #retvals: uint8_t
1251
1252         def mx_exchange(self):
1253             """
1254                Returns the mx host of a LDNS_RR_TYPE_MX rr.
1255                
1256                :return: (:class:`ldns_rdf`) with the name of the MX host
1257                   or None on failure.
1258             """
1259             return _ldns._ldns_rr_mx_exchange(self)
1260             #parameters: const ldns_rr *,
1261             #retvals: ldns_rdf *
1262
1263         def mx_preference(self):
1264             """
1265                Returns the mx preference of a LDNS_RR_TYPE_MX rr.
1266                
1267                :return: (:class:`ldns_rdf`) with the preference or None
1268                    on failure.
1269             """
1270             return _ldns._ldns_rr_mx_preference(self)
1271             #parameters: const ldns_rr *,
1272             #retvals: ldns_rdf *
1273
1274         def ns_nsdname(self):
1275             """
1276                Returns the name of a LDNS_RR_TYPE_NS rr.
1277                
1278                :return: (:class:`ldns_rdf`) A dname rdf with the name or
1279                    None on failure.
1280             """
1281             return _ldns._ldns_rr_ns_nsdname(self)
1282             #parameters: const ldns_rr *,
1283             #retvals: ldns_rdf *
1284
1285         def owner(self):
1286             """
1287                Returns the owner name of an rr structure.
1288                
1289                :return: (:class:`ldns_dname`) Owner name or None on failure.
1290             """
1291             rdf = _ldns._ldns_rr_owner(self)
1292             if rdf:
1293                 rdf = ldns_dname(rdf, clone=False)
1294             return rdf
1295             #parameters: const ldns_rr *,
1296             #retvals: ldns_rdf *
1297
1298         def pop_rdf(self):
1299             """
1300                Removes a rd_field member, it will be popped from the last
1301                position.
1302                
1303                :return: (:class:`ldns_rdf`) rdf which was popped, None if
1304                    nothing.
1305             """
1306             return _ldns.ldns_rr_pop_rdf(self)
1307             #parameters: ldns_rr *,
1308             #retvals: ldns_rdf *
1309
1310         def push_rdf(self,f):
1311             """
1312                Sets rd_field member, it will be placed in the next available
1313                spot.
1314                
1315                :param f: The rdf to be appended.
1316                :type f: :class:`ldns_rdf`
1317                :throws TypeError: When `f` of non-:class:`ldns_rdf` type.
1318                :return: (bool) Returns True if success, False otherwise.
1319             """
1320             return _ldns._ldns_rr_push_rdf(self, f)
1321             #parameters: ldns_rr *, const ldns_rdf *,
1322             #retvals: bool
1323
1324         def rd_count(self):
1325             """
1326                Returns the rd_count of an rr structure.
1327                
1328                :return: (size_t) the rd count of the rr.
1329             """
1330             return _ldns.ldns_rr_rd_count(self)
1331             #parameters: const ldns_rr *,
1332             #retvals: size_t
1333
1334         def rdf(self, nr):
1335             """
1336                Returns the rdata field with the given index.
1337                
1338                :param nr: The index of the rdf to return.
1339                :type nr: positive int
1340                :throws TypeError: When `nr` not a positive integer.
1341                :return: (:class:`ldns_rdf`) The given rdf or None if fails.
1342             """
1343             return _ldns._ldns_rr_rdf(self, nr)
1344             #parameters: const ldns_rr *, size_t,
1345             #retvals: ldns_rdf *
1346
1347         def rrsig_algorithm(self):
1348             """
1349                Returns the algorithm identifier of a LDNS_RR_TYPE_RRSIG RR.
1350                
1351                :return: (:class:`ldns_rdf`) with the algorithm or None
1352                    on failure.
1353             """
1354             return _ldns._ldns_rr_rrsig_algorithm(self)
1355             #parameters: const ldns_rr *,
1356             #retvals: ldns_rdf *
1357
1358         def rrsig_expiration(self):
1359             """
1360                Returns the expiration time of a LDNS_RR_TYPE_RRSIG RR.
1361                
1362                :return: (:class:`ldns_rdf`) with the expiration time or None
1363                    on failure.
1364             """
1365             return _ldns._ldns_rr_rrsig_expiration(self)
1366             #parameters: const ldns_rr *,
1367             #retvals: ldns_rdf *
1368
1369         def rrsig_inception(self):
1370             """
1371                Returns the inception time of a LDNS_RR_TYPE_RRSIG RR.
1372                
1373                :return: (:class:`ldns_rdf`) with the inception time or None
1374                    on failure.
1375             """
1376             return _ldns._ldns_rr_rrsig_inception(self)
1377             #parameters: const ldns_rr *,
1378             #retvals: ldns_rdf *
1379
1380         def rrsig_keytag(self):
1381             """
1382                Returns the keytag of a LDNS_RR_TYPE_RRSIG RR.
1383                
1384                :return: (:class:`ldns_rdf`) with the keytag or None on failure.
1385             """
1386             return _ldns._ldns_rr_rrsig_keytag(self)
1387             #parameters: const ldns_rr *,
1388             #retvals: ldns_rdf *
1389
1390         def rrsig_labels(self):
1391             """
1392                Returns the number of labels of a LDNS_RR_TYPE_RRSIG RR.
1393                
1394                :return: (:class:`ldns_rdf`) with the number of labels or None
1395                    on failure.
1396             """
1397             return _ldns._ldns_rr_rrsig_labels(self)
1398             #parameters: const ldns_rr *,
1399             #retvals: ldns_rdf *
1400
1401         def rrsig_origttl(self):
1402             """
1403                Returns the original TTL of a LDNS_RR_TYPE_RRSIG RR.
1404                
1405                :return: (:class:`ldns_rdf`) with the original TTL or None
1406                    on failure.
1407             """
1408             return _ldns._ldns_rr_rrsig_origttl(self)
1409             #parameters: const ldns_rr *,
1410             #retvals: ldns_rdf *
1411
1412         def rrsig_set_algorithm(self, f):
1413             """
1414                Sets the algorithm of a LDNS_RR_TYPE_RRSIG rr.
1415                
1416                :param f: The algorithm to set.
1417                :type f: :class:`ldns_rdf`
1418                :throws TypeError: when `f` of non-:class:`ldns_rdf` type.
1419                :return: (bool) True on success, False otherwise.
1420             """
1421             return _ldns._ldns_rr_rrsig_set_algorithm(self, f)
1422             #parameters: ldns_rr *, ldns_rdf *,
1423             #retvals: bool
1424
1425         def rrsig_set_expiration(self, f):
1426             """
1427                Sets the expireation date of a LDNS_RR_TYPE_RRSIG rr.
1428                
1429                :param f: The expireation date to set.
1430                :type f: :class:`ldns_rdf`
1431                :throws TypeError: when `f` of non-:class:`ldns_rdf` type.
1432                :return: (bool) True on success, False otherwise.
1433             """
1434             return _ldns._ldns_rr_rrsig_set_expiration(self, f)
1435             #parameters: ldns_rr *, ldns_rdf *,
1436             #retvals: bool
1437
1438         def rrsig_set_inception(self, f):
1439             """
1440                Sets the inception date of a LDNS_RR_TYPE_RRSIG rr.
1441                
1442                :param f: The inception date to set.
1443                :type f: :class:`ldns_rdf`
1444                :throws TypeError: when `f` of non-:class:`ldns_rdf` type.
1445                :return: (bool) True on success, False otherwise.
1446             """
1447             return _ldns._ldns_rr_rrsig_set_inception(self, f)
1448             #parameters: ldns_rr *, ldns_rdf *,
1449             #retvals: bool
1450
1451         def rrsig_set_keytag(self, f):
1452             """
1453                Sets the keytag of a LDNS_RR_TYPE_RRSIG rr.
1454                
1455                :param f: The keytag to set.
1456                :type f: :class:`ldns_rdf`
1457                :throws TypeError: when `f` of non-:class:`ldns_rdf` type.
1458                :return: (bool) True on success, False otherwise.
1459             """
1460             return _ldns._ldns_rr_rrsig_set_keytag(self, f)
1461             #parameters: ldns_rr *, ldns_rdf *,
1462             #retvals: bool
1463
1464         def rrsig_set_labels(self, f):
1465             """
1466                Sets the number of labels of a LDNS_RR_TYPE_RRSIG rr.
1467                
1468                :param f: The number of labels to set.
1469                :type f: :class:`ldns_rdf`
1470                :throws TypeError: when `f` of non-:class:`ldns_rdf` type.
1471                :return: (bool) True on success, False otherwise.
1472             """
1473             return _ldns._ldns_rr_rrsig_set_labels(self, f)
1474             #parameters: ldns_rr *, ldns_rdf *,
1475             #retvals: bool
1476
1477         def rrsig_set_origttl(self, f):
1478             """
1479                Sets the original TTL of a LDNS_RR_TYPE_RRSIG rr.
1480                
1481                :param f: The original TTL to set.
1482                :type f: :class:`ldns_rdf`
1483                :throws TypeError: when `f` of non-:class:`ldns_rdf` type.
1484                :return: (bool) True on success, False otherwise.
1485             """
1486             return _ldns._ldns_rr_rrsig_set_origttl(self, f)
1487             #parameters: ldns_rr *, ldns_rdf *,
1488             #retvals: bool
1489
1490         def rrsig_set_sig(self, f):
1491             """
1492                Sets the signature data of a LDNS_RR_TYPE_RRSIG rr.
1493                
1494                :param f: The signature data to set.
1495                :type f: :class:`ldns_rdf`
1496                :throws TypeError: when `f` of non-:class:`ldns_rdf` type.
1497                :return: (bool) True on success, False otherwise.
1498             """
1499             return _ldns._ldns_rr_rrsig_set_sig(self, f)
1500             #parameters: ldns_rr *, ldns_rdf *,
1501             #retvals: bool
1502
1503         def rrsig_set_signame(self, f):
1504             """
1505                Sets the signers name of a LDNS_RR_TYPE_RRSIG rr.
1506                
1507                :param f: The signers name to set.
1508                :type f: :class:`ldns_rdf`
1509                :throws TypeError: when `f` of non-:class:`ldns_rdf` type.
1510                :return: (bool) True on success, False otherwise.
1511             """
1512             return _ldns._ldns_rr_rrsig_set_signame(self, f)
1513             #parameters: ldns_rr *, ldns_rdf *,
1514             #retvals: bool
1515
1516         def rrsig_set_typecovered(self, f):
1517             """
1518                Sets the typecovered of a LDNS_RR_TYPE_RRSIG rr.
1519                
1520                :param f: The type covered to set.
1521                :type f: :class:`ldns_rdf`
1522                :throws TypeError: when `f` of non-:class:`ldns_rdf` type.
1523                :return: (bool) True on success, False otherwise.
1524             """
1525             return _ldns._ldns_rr_rrsig_set_typecovered(self, f)
1526             #parameters: ldns_rr *, ldns_rdf *,
1527             #retvals: bool
1528
1529         def rrsig_sig(self):
1530             """
1531                Returns the signature data of a LDNS_RR_TYPE_RRSIG RR.
1532                
1533                :return: (:class:`ldns_rdf`) with the signature data or None
1534                    on failure.
1535             """
1536             return _ldns._ldns_rr_rrsig_sig(self)
1537             #parameters: const ldns_rr *,
1538             #retvals: ldns_rdf *
1539
1540         def rrsig_signame(self):
1541             """
1542                Returns the signers name of a LDNS_RR_TYPE_RRSIG RR.
1543                
1544                :return: (:class:`ldns_rdf`) with the signers name or None
1545                    on failure.
1546             """
1547             return _ldns._ldns_rr_rrsig_signame(self)
1548             #parameters: const ldns_rr *,
1549             #retvals: ldns_rdf *
1550
1551         def rrsig_typecovered(self):
1552             """
1553                Returns the type covered of a LDNS_RR_TYPE_RRSIG rr.
1554                
1555                :return: (:class:`ldns_rdf`) with the type covered or None
1556                    on failure.
1557             """
1558             return _ldns._ldns_rr_rrsig_typecovered(self)
1559             #parameters: const ldns_rr *,
1560             #retvals: ldns_rdf *
1561
1562         def set_class(self, rr_class):
1563             """
1564                Sets the class in the rr.
1565                
1566                :param rr_class: Set to this class.
1567                :type rr_class: int
1568                :throws TypeError: when `rr_class` of non-integer type.
1569             """
1570             _ldns.ldns_rr_set_class(self, rr_class)
1571             #parameters: ldns_rr *, ldns_rr_class,
1572             #retvals: 
1573
1574         def set_owner(self, owner):
1575             """
1576                Sets the owner in the rr structure.
1577                
1578                :param owner: Owner name.
1579                :type owner: :class:`ldns_dname`
1580                :throws TypeError: when `owner` of non-:class:`ldns_dname` type.
1581
1582                .. note::
1583                    The type checking of `owner` is benevolent.
1584                    It allows also to pass a dname :class:`ldns_rdf` object.
1585                    This will probably change in future.
1586             """
1587             if (not isinstance(owner, ldns_dname)) and \
1588                isinstance(owner, ldns_rdf) and \
1589                owner.get_type() == _ldns.LDNS_RDF_TYPE_DNAME:
1590                 warnings.warn("The ldns_rr.new_frm_str() method will" +
1591                     " drop the possibility to accept ldns_rdf as owner." +
1592                     " Convert argument to ldns_dname.",
1593                     PendingDeprecationWarning, stacklevel=2)
1594             _ldns._ldns_rr_set_owner(self, owner)
1595             #parameters: ldns_rr *, ldns_rdf *,
1596             #retvals:
1597
1598         def set_question(self, question):
1599             """
1600                Sets the question flag in the rr structure.
1601
1602                :param question: Question flag.
1603                :type question: bool
1604             """
1605             _ldns.ldns_rr_set_question(self, question)
1606             #parameters: ldns_rr *, bool,
1607             #retvals:
1608
1609         def set_rd_count(self, count):
1610             """
1611                Sets the rd_count in the rr.
1612                
1613                :param count: Set to this count.
1614                :type count: positive int
1615                :throws TypeError: when `count` of non-integer type.
1616             """
1617             _ldns.ldns_rr_set_rd_count(self, count)
1618             #parameters: ldns_rr *, size_t,
1619             #retvals: 
1620
1621         def set_rdf(self, f, position):
1622             """
1623                Sets a rdf member, it will be set on the position given.
1624                
1625                The old value is returned, like pop.
1626                
1627                :param f: The rdf to be set.
1628                :type f: :class:`ldns_rdf`
1629                :param position: The position the set the rdf.
1630                :type position: positive int
1631                :throws TypeError: when mismatching types passed.
1632                :return: (:class:`ldns_rdf`) the old value in the rr, None
1633                    on failure.
1634             """
1635             return _ldns._ldns_rr_set_rdf(self, f, position)
1636             #parameters: ldns_rr *, const ldns_rdf *, size_t,
1637             #retvals: ldns_rdf *
1638
1639         def set_ttl(self, ttl):
1640             """
1641                Sets the ttl in the rr structure.
1642                
1643                :param ttl: Set to this ttl.
1644                :type ttl: positive int
1645                :throws TypeError: when `ttl` of non-integer type.
1646             """
1647             _ldns.ldns_rr_set_ttl(self, ttl)
1648             #parameters: ldns_rr *, uint32_t,
1649             #retvals: 
1650
1651         def set_type(self, rr_type):
1652             """
1653                Sets the type in the rr.
1654                
1655                :param rr_type: Set to this type.
1656                :type rr_type: ineteger
1657                :throws TypeError: when `rr_type` of non-integer type.
1658             """
1659             _ldns.ldns_rr_set_type(self, rr_type)
1660             #parameters: ldns_rr *, ldns_rr_type,
1661             #retvals:
1662
1663         def to_canonical(self):
1664             """
1665                Converts each dname in a rr to its canonical form.
1666             """
1667             _ldns.ldns_rr2canonical(self)
1668
1669         def ttl(self):
1670             """
1671                Returns the ttl of an rr structure.
1672                
1673                :return: (int) the ttl of the rr.
1674             """
1675             return _ldns.ldns_rr_ttl(self)
1676             #parameters: const ldns_rr *,
1677             #retvals: uint32_t
1678
1679         @staticmethod
1680         def type_by_name(string):
1681             """
1682                Retrieves a rr type identifier value by looking up its name.
1683
1684                Returns 0 if invalid name passed.
1685
1686                :param string: RR type name.
1687                :type string: str
1688                :throws TypeError: when `string` of inappropriate type.
1689                :return: (int) RR type identifier, or 0 if no matching value
1690                    to identifier found.
1691             """
1692             return _ldns.ldns_get_rr_type_by_name(string)
1693
1694         def uncompressed_size(self):
1695             """
1696                Calculates the uncompressed size of an RR.
1697                
1698                :return: (inetger) size of the rr.
1699             """
1700             return _ldns.ldns_rr_uncompressed_size(self)
1701             #parameters: const ldns_rr *,
1702             #retvals: size_t
1703
1704         #
1705         # _LDNS_RR_METHODS
1706         #
1707   %}
1708 }
1709
1710
1711 /* ========================================================================= */
1712 /* SWIG setting and definitions. */
1713 /* ========================================================================= */
1714
1715
1716 %nodefaultctor ldns_struct_rr_list; /* No default constructor. */
1717 %nodefaultdtor ldns_struct_rr_list; /* No default destructor. */
1718
1719 %ignore ldns_struct_rr_list::_rrs;
1720
1721 %newobject ldns_rr_list_cat_clone;
1722 %newobject ldns_rr_list_clone;
1723 %newobject ldns_rr_list_pop_rr;
1724 %newobject ldns_rr_list_pop_rr_list;
1725 %newobject ldns_rr_list_pop_rrset;
1726 %newobject ldns_rr_list_rr;
1727 %newobject ldns_rr_list_new;
1728 %newobject ldns_get_rr_list_hosts_frm_file;
1729 %newobject ldns_rr_list_subtype_by_rdf;
1730 %newobject ldns_rr_list2str;
1731 %delobject ldns_rr_list_deep_free;
1732 %delobject ldns_rr_list_free;
1733
1734 /* Clone data on push. */
1735
1736 %rename(__ldns_rr_list_push_rr) ldns_rr_list_push_rr;
1737 %inline
1738 %{
1739   bool _ldns_rr_list_push_rr(ldns_rr_list* r, ldns_rr *rr)
1740   {
1741     bool ret;
1742     ldns_rr *new;
1743
1744     new = ldns_rr_clone(rr);
1745     if (!(ret = ldns_rr_list_push_rr(r, new))) {
1746       ldns_rr_free(new);
1747     }
1748     return ret;
1749   }
1750 %}
1751
1752 %rename(__ldns_rr_list_push_rr_list) ldns_rr_list_push_rr_list;
1753 %inline
1754 %{
1755   bool _ldns_rr_list_push_rr_list(ldns_rr_list* r, ldns_rr_list *r2)
1756   {
1757     bool ret;
1758     ldns_rr_list *new;
1759
1760     new = ldns_rr_list_clone(r2);
1761     if (!(ret = ldns_rr_list_push_rr_list(r, new))) {
1762       ldns_rr_list_deep_free(new);
1763     }
1764     return ret;
1765   }
1766 %}
1767
1768
1769 %newobject _ldns_rr_list_set_rr;
1770 %rename(__ldns_rr_list_set_rr) ldns_rr_list_set_rr;
1771 %inline
1772 %{
1773   ldns_rr * _ldns_rr_list_set_rr(ldns_rr_list * rrl, ldns_rr *rr,
1774     size_t idx)
1775   {
1776     ldns_rr *ret;
1777     ldns_rr *new;
1778
1779     new = ldns_rr_clone(rr);
1780     if ((ret = ldns_rr_list_set_rr(rrl, new, idx)) == NULL) {
1781        ldns_rr_free(new);
1782     }
1783     return ret;
1784   }
1785 %}
1786
1787
1788 %rename(__ldns_rr_list_cat) ldns_rr_list_cat;
1789 %inline
1790 %{
1791   bool _ldns_rr_list_cat(ldns_rr_list *r, ldns_rr_list *r2)
1792   {
1793     return ldns_rr_list_cat(r, ldns_rr_list_clone(r2));
1794   }
1795 %}
1796
1797
1798 /* End clone data on push. */
1799
1800
1801 /* Clone data on pull. */
1802
1803 %newobject _ldns_rr_list_rr;
1804 %rename(__ldns_rr_list_rr) ldns_rr_list_rr;
1805 %inline
1806 %{
1807   ldns_rr * _ldns_rr_list_rr(ldns_rr_list *r, int i)
1808   {
1809     ldns_rr *rr;
1810     rr = ldns_rr_list_rr(r, i);
1811     return (rr != NULL) ? ldns_rr_clone(rr) : NULL;
1812   }
1813 %}
1814
1815 %newobject _ldns_rr_list_owner;
1816 %rename(__ldns_rr_list_owner) ldns_rr_list_owner;
1817 %inline
1818 %{
1819   ldns_rdf * _ldns_rr_list_owner(ldns_rr_list *r)
1820   {
1821     ldns_rdf *rdf;
1822     rdf = ldns_rr_list_owner(r);
1823     return (rdf != NULL) ? ldns_rdf_clone(rdf) : NULL;
1824   }
1825 %}
1826
1827
1828 /* End clone data on pull. */
1829
1830
1831 /* ========================================================================= */
1832 /* Debugging related code. */
1833 /* ========================================================================= */
1834
1835
1836 %rename(ldns_rr_list) ldns_struct_rr_list;
1837 #ifdef LDNS_DEBUG
1838 %rename(__ldns_rr_list_deep_free) ldns_rr_list_deep_free;
1839 %rename(__ldns_rr_list_free) ldns_rr_list_free;
1840 %inline
1841 %{
1842   void _ldns_rr_list_deep_free(ldns_rr_list *r)
1843   {
1844     printf("******** LDNS_RR_LIST deep free 0x%lX ************\n",
1845       (long unsigned int) r);
1846     ldns_rr_list_deep_free(r);
1847   }
1848
1849   void _ldns_rr_list_free(ldns_rr_list *r)
1850   {
1851     printf("******** LDNS_RR_LIST deep free 0x%lX ************\n",
1852       (long unsigned int) r);
1853     ldns_rr_list_free(r);
1854   }
1855 %}
1856 #else
1857 %rename(_ldns_rr_list_deep_free) ldns_rr_list_deep_free;
1858 %rename(_ldns_rr_list_free) ldns_rr_list_free;
1859 #endif
1860
1861
1862 /* ========================================================================= */
1863 /* Added C code. */
1864 /* ========================================================================= */
1865
1866
1867 /* None. */
1868
1869
1870 /* ========================================================================= */
1871 /* Encapsulating Python code. */
1872 /* ========================================================================= */
1873
1874
1875 %feature("docstring") ldns_struct_rr_list "List of Resource Records.
1876
1877 This class contains a list of RR's (see :class:`ldns.ldns_rr`).
1878 "
1879
1880 %extend ldns_struct_rr_list {
1881  
1882   %pythoncode
1883   %{
1884         def __init__(self):
1885             self.this = _ldns.ldns_rr_list_new()
1886             if not self.this:
1887                 raise Exception("Can't create new RR_LIST")
1888        
1889         __swig_destroy__ = _ldns._ldns_rr_list_deep_free
1890
1891         #
1892         # LDNS_RR_LIST_CONSTRUCTORS_
1893         #
1894
1895         @staticmethod
1896         def new(raiseException=True):
1897             """
1898                Creates an empty RR List object.
1899
1900                :param raiseException: Set to True if an exception should
1901                    signal an error.
1902                :type raiseException: bool
1903                :throws Exception: when `raiseException` is True and error
1904                    occurs.
1905                :return: :class:`ldns_rr_list` Empty RR list.
1906             """
1907             rrl = _ldns.ldns_rr_list_new()
1908             if (not rrl) and raiseException:
1909                 raise Exception("Can't create RR List.")
1910             return rrl
1911
1912         @staticmethod
1913         def new_frm_file(filename="/etc/hosts", raiseException=True):
1914             """
1915                Creates an RR List object from file content.
1916
1917                Goes through a file and returns a rr list containing
1918                all the defined hosts in there.
1919
1920                :param filename: The filename to use.
1921                :type filename: str
1922                :param raiseException: Set to True if an exception should
1923                    signal an error.
1924                :type raiseException: bool
1925                :throws TypeError: when `filename` of inappropriate type.
1926                :throws Exception: when `raiseException` is True and error
1927                    occurs.
1928                :return: RR List object or None. If the object can't be
1929                    created and `raiseException` is True, an exception occurs.
1930
1931                **Usage**
1932
1933                >>> alist = ldns.ldns_rr_list.new_frm_file()
1934                >>> print alist
1935                localhost.       3600    IN      A       127.0.0.1
1936                ...
1937
1938             """
1939             rr = _ldns.ldns_get_rr_list_hosts_frm_file(filename)
1940             if (not rr) and (raiseException):
1941                 raise Exception("Can't create RR List.")
1942             return rr
1943
1944         #
1945         # _LDNS_RR_LIST_CONSTRUCTORS
1946         #
1947
1948         def __str__(self):
1949             """
1950                Converts a list of resource records to presentation format.
1951
1952                :return: (str) Presentation format.
1953             """
1954             return _ldns.ldns_rr_list2str(self)
1955
1956         def print_to_file(self, output):
1957             """
1958                Print a rr_list to output.
1959
1960                :param output: Opened file to print to.
1961                :throws TypeError: when `output` of inappropriate type.
1962             """
1963             _ldns.ldns_rr_list_print(output, self)
1964
1965
1966         def to_canonical(self):
1967             """
1968                Converts each dname in each rr in a rr_list to its canonical
1969                form.
1970             """
1971             _ldns.ldns_rr_list2canonical(self)
1972             #parameters: ldns_rr_list *,
1973             #retvals: 
1974
1975         def rrs(self):
1976             """
1977                Returns a generator object of a list of rr records.
1978
1979                :return: (generator) generator object.
1980             """
1981             for i in range(0, self.rr_count()):
1982                 yield self.rr(i)
1983
1984         def is_rrset(self):
1985             """
1986                Checks if the rr list is a rr set.
1987
1988                :return: (bool) True if rr list is a rr set.
1989             """
1990             return _ldns.ldns_is_rrset(self)
1991
1992         def __cmp__(self, rrl2):
1993             """
1994                Compares two rr lists.
1995                
1996                :param rrl2: The second one.
1997                :type rrl2: :class:`ldns_rr_list`
1998                :throws TypeError: when `rrl2` of non-:class:`ldns_rr_list`
1999                    type.
2000                :return: (int) 0 if equal, -1 if this list comes before
2001                    `rrl2`, 1 if `rrl2` comes before this list.
2002             """
2003             return _ldns.ldns_rr_list_compare(self, rrl2)
2004
2005         def __lt__(self, other):
2006             """
2007                Compares two rr lists.
2008                
2009                :param other: The second one.
2010                :type other: :class:`ldns_rr_list`
2011                :throws TypeError: when `other` of non-:class:`ldns_rr_list`
2012                    type.
2013                :return: (bool) True when `self` is less than 'other'.
2014             """
2015             return _ldns.ldns_rr_list_compare(self, other) == -1
2016
2017         def __le__(self, other):
2018             """
2019                Compares two rr lists.
2020                
2021                :param other: The second one.
2022                :type other: :class:`ldns_rr_list`
2023                :throws TypeError: when `other` of non-:class:`ldns_rr_list`
2024                    type.
2025                :return: (bool) True when `self` is less than or equal to
2026                    'other'.
2027             """
2028             return _ldns.ldns_rr_list_compare(self, other) != 1
2029
2030         def __eq__(self, other):
2031             """
2032                Compares two rr lists.
2033                
2034                :param other: The second one.
2035                :type other: :class:`ldns_rr_list`
2036                :throws TypeError: when `other` of non-:class:`ldns_rr_list`
2037                    type.
2038                :return: (bool) True when `self` is equal to 'other'.
2039             """
2040             return _ldns.ldns_rr_list_compare(self, other) == 0
2041
2042         def __ne__(self, other):
2043             """
2044                Compares two rr lists.
2045                
2046                :param other: The second one.
2047                :type other: :class:`ldns_rr_list`
2048                :throws TypeError: when `other` of non-:class:`ldns_rr_list`
2049                    type.
2050                :return: (bool) True when `self` is not equal to 'other'.
2051             """
2052             return _ldns.ldns_rr_list_compare(self, other) != 0
2053
2054         def __gt__(self, other):
2055             """
2056                Compares two rr lists.
2057                
2058                :param other: The second one.
2059                :type other: :class:`ldns_rr_list`
2060                :throws TypeError: when `other` of non-:class:`ldns_rr_list`
2061                    type.
2062                :return: (bool) True when `self` is greater than 'other'.
2063             """
2064             return _ldns.ldns_rr_list_compare(self, other) == 1
2065
2066         def __ge__(self, other):
2067             """
2068                Compares two rr lists.
2069                
2070                :param other: The second one.
2071                :type other: :class:`ldns_rr_list`
2072                :throws TypeError: when `other` of non-:class:`ldns_rr_list`
2073                    type.
2074                :return: (bool) True when `self` is greater than or equal to
2075                    'other'.
2076             """
2077             return _ldns.ldns_rr_list_compare(self, other) != -1
2078
2079         def write_to_buffer(self, buffer):
2080             """
2081                Copies the rr_list data to the buffer in wire format.
2082                
2083                :param buffer: Output buffer to append the result to.
2084                :type buffer: :class:`ldns_buffer`
2085                :throws TypeError: when `buffer` of non-:class:`ldns_buffer`
2086                    type.
2087                :return: (ldns_status) ldns_status
2088             """
2089             return _ldns.ldns_rr_list2buffer_wire(buffer, self)
2090
2091         #
2092         # LDNS_RR_LIST_METHODS_
2093         #
2094
2095         def cat(self, right):
2096             """
2097                Concatenates two ldns_rr_lists together.
2098                
2099                This modifies rr list (to extend it and adds RRs from right).
2100                
2101                :param right: The right-hand side.
2102                :type right: :class:`ldns_rr_list`
2103                :throws TypeError: when `right` of non-:class:`ldns_rr_list`
2104                    type.
2105                :return: (bool) True if success.
2106             """
2107             return _ldns._ldns_rr_list_cat(self, right)
2108             #parameters: ldns_rr_list *, ldns_rr_list *,
2109             #retvals: bool
2110
2111         def cat_clone(self, right):
2112             """
2113                Concatenates two ldns_rr_lists together, creates a new list
2114                of the rr's (instead of appending the content to an existing
2115                list).
2116                
2117                :param right: The right-hand side.
2118                :type right: :class:`ldns_rr_list`
2119                :throws TypeError: when `right` of non-:class:`ldns_rr_list`
2120                    type.
2121                :return: (:class:`ldns_rr_list`) rr list with left-hand side +
2122                    right-hand side concatenated, on None on error.
2123             """
2124             return _ldns.ldns_rr_list_cat_clone(self, right)
2125             #parameters: ldns_rr_list *, ldns_rr_list *,
2126             #retvals: ldns_rr_list *
2127
2128         def clone(self):
2129             """
2130                Clones an rrlist.
2131                
2132                :return: (:class:`ldns_rr_list`) the cloned rr list,
2133                    or None on error.
2134             """
2135             return _ldns.ldns_rr_list_clone(self)
2136             #parameters: const ldns_rr_list *,
2137             #retvals: ldns_rr_list *
2138
2139         def contains_rr(self, rr):
2140             """
2141                Returns True if the given rr is one of the rrs in the list,
2142                or if it is equal to one.
2143                
2144                :param rr: The rr to check.
2145                :type rr: :class:`ldns_rr`
2146                :throws TypeError: when `rr` of non-:class:`ldns_rr` type.
2147                :return: (bool) True if rr_list contains `rr`, False otherwise.
2148             """
2149             return _ldns.ldns_rr_list_contains_rr(self, rr)
2150             #parameters: const ldns_rr_list *, ldns_rr *,
2151             #retvals: bool
2152
2153         def owner(self):
2154             """
2155                Returns the owner domain name rdf of the first element of
2156                the RR. If there are no elements present, None is returned.
2157                
2158                :return: (:class:`ldns_dname`) dname of the first element,
2159                    or None if the list is empty.
2160             """
2161             rdf = _ldns._ldns_rr_list_owner(self)
2162             if rdf:
2163                 rdf = ldns_dname(rdf, clone=False)
2164             return rdf
2165             #parameters: const ldns_rr_list *,
2166             #retvals: ldns_rdf *
2167
2168         def pop_rr(self):
2169             """
2170                Pops the last rr from an rrlist.
2171                
2172                :return: (:class:`ldns_rr`) None if nothing to pop.
2173                    Otherwise the popped RR.
2174             """
2175             rr = _ldns.ldns_rr_list_pop_rr(self)
2176             return rr
2177             #parameters: ldns_rr_list *,
2178             #retvals: ldns_rr *
2179
2180         def pop_rr_list(self, size):
2181             """
2182                Pops an rr_list of size s from an rrlist.
2183                
2184                :param size: The number of rr's to pop.
2185                :type size: positive int
2186                :throws TypeError: when `size` of inappropriate type.
2187                :return: (:class:`ldns_rr_list`) None if nothing to pop.
2188                    Otherwise the popped rr list.
2189             """
2190             return _ldns.ldns_rr_list_pop_rr_list(self, size)
2191             #parameters: ldns_rr_list *, size_t,
2192             #retvals: ldns_rr_list *
2193
2194         def pop_rrset(self):
2195             """
2196                Pops the first rrset from the list, the list must be sorted,
2197                so that all rr's from each rrset are next to each other.
2198                
2199                :return: (:class:`ldns_rr_list`) the first rrset, or None when
2200                    empty.
2201             """
2202             return _ldns.ldns_rr_list_pop_rrset(self)
2203             #parameters: ldns_rr_list *,
2204             #retvals: ldns_rr_list *
2205
2206         def push_rr(self, rr):
2207             """
2208                Pushes an rr to an rrlist.
2209                
2210                :param rr: The rr to push.
2211                :type rr: :class:`ldns_rr`
2212                :throws TypeError: when `rr` of non-:class:`ldns_rr` type.
2213                :return: (bool) False on error, otherwise True.
2214             """
2215             return _ldns._ldns_rr_list_push_rr(self, rr)
2216             #parameters: ldns_rr_list *, const ldns_rr *,
2217             #retvals: bool
2218
2219         def push_rr_list(self, push_list):
2220             """
2221                Pushes an rr list to an rr list.
2222                
2223                :param push_list: The rr_list to push.
2224                :type push_list: :class:`ldns_rr_list`
2225                :throws TypeError: when `push_list` of non-:class:`ldns_rr_list`
2226                    type.
2227                :returns: (bool) False on error, otherwise True.
2228             """
2229             return _ldns._ldns_rr_list_push_rr_list(self, push_list)
2230             #parameters: ldns_rr_list *, const ldns_rr_list *,
2231             #retvals: bool
2232
2233         def rr(self, nr):
2234             """
2235                Returns a specific rr of an rrlist.
2236                
2237                :param nr: Index of the desired rr.
2238                :type nr: positive int
2239                :throws TypeError: when `nr` of inappropriate type.
2240                :return: (:class:`ldns_rr`) The rr at position `nr`, or None
2241                    if failed.
2242             """
2243             return _ldns._ldns_rr_list_rr(self, nr)
2244             #parameters: const ldns_rr_list *, size_t,
2245             #retvals: ldns_rr *
2246
2247         def rr_count(self):
2248             """
2249                Returns the number of rr's in an rr_list.
2250                
2251                :return: (int) The number of rr's.
2252             """
2253             return _ldns.ldns_rr_list_rr_count(self)
2254             #parameters: const ldns_rr_list *,
2255             #retvals: size_t
2256
2257         def set_rr(self, r, idx):
2258             """
2259                Set a rr on a specific index in a ldns_rr_list.
2260                
2261                :param r: The rr to set.
2262                :type r: :class:`ldns_rr`
2263                :param idx: Index into the rr_list.
2264                :type idx: positive int
2265                :throws TypeError: when parameters of inappropriate types.
2266                :return: (:class:`ldns_rr`) the old rr which was stored in
2267                    the rr_list, or None if the index was too large
2268                    to set a specific rr.
2269             """
2270             return _ldns._ldns_rr_list_set_rr(self, r, idx)
2271             #parameters: ldns_rr_list *, const ldns_rr *, size_t,
2272             #retvals: ldns_rr *
2273
2274         def set_rr_count(self, count):
2275             """
2276                Sets the number of rr's in an rr_list.
2277                
2278                :param count: The number of rr in this list.
2279                :type count: positive int
2280                :throws TypeError: when `count` of non-integer type.
2281                :throws Exception: when `count` out of acceptable range.
2282
2283                .. warning::
2284                    Don't use this method unless you really know what you
2285                    are doing.
2286             """
2287             # The function C has a tendency to generate an assertion fail when 
2288             # the count exceeds the list's capacity -- therefore the checking
2289             # code.
2290             if isinstance(count, int) and \
2291                ((count < 0) or (count > self._rr_capacity)):
2292                 raise Exception("Given count %d is out of range " % (count) +
2293                     "of the rr list's capacity %d." % (self._rr_capacity))
2294             _ldns.ldns_rr_list_set_rr_count(self, count)
2295             #parameters: ldns_rr_list *, size_t,
2296             #retvals: 
2297
2298         def sort(self):
2299             """
2300                Sorts an rr_list (canonical wire format).
2301             """
2302             _ldns.ldns_rr_list_sort(self)
2303             #parameters: ldns_rr_list *,
2304             #retvals: 
2305
2306         def subtype_by_rdf(self, r, pos):
2307             """
2308                Return the rr_list which matches the rdf at position field.
2309                
2310                Think type-covered stuff for RRSIG.
2311                
2312                :param r: The rdf to use for the comparison.
2313                :type r: :class:`ldns_rdf`
2314                :param pos: At which position we can find the rdf.
2315                :type pos: positive int
2316                :throws TypeError: when parameters of inappropriate types.
2317                :return: (:class:`ldns_rr_list`) a new rr list with only
2318                    the RRs that match, or None when nothing matches.
2319             """
2320             return _ldns.ldns_rr_list_subtype_by_rdf(self, r, pos)
2321             #parameters: ldns_rr_list *, ldns_rdf *, size_t,
2322             #retvals: ldns_rr_list *
2323
2324         def type(self):
2325             """
2326                Returns the type of the first element of the RR.
2327
2328                If there are no elements present, 0 is returned.
2329                
2330                :return: (int) rr_type of the first element,
2331                    or 0 if the list is empty.
2332             """
2333             return _ldns.ldns_rr_list_type(self)
2334             #parameters: const ldns_rr_list *,
2335             #retvals: ldns_rr_type
2336
2337         #
2338         # _LDNS_RR_LIST_METHODS
2339         #
2340   %}
2341 }
2342
2343
2344 /* ========================================================================= */
2345 /* SWIG setting and definitions. */
2346 /* ========================================================================= */
2347
2348
2349 %newobject ldns_rr_descript;
2350
2351 %nodefaultctor ldns_struct_rr_descriptor; /* No default constructor. */
2352 %nodefaultdtor ldns_struct_rr_descriptor; /* No default destructor.*/
2353 %rename(ldns_rr_descriptor) ldns_struct_rr_descriptor;
2354
2355
2356 /* ========================================================================= */
2357 /* Debugging related code. */
2358 /* ========================================================================= */
2359
2360 /* None. */
2361
2362
2363 /* ========================================================================= */
2364 /* Added C code. */
2365 /* ========================================================================= */
2366
2367
2368 %inline
2369 %{
2370    /*
2371     * Does nothing, but keeps the SWIG wrapper quiet about absent destructor.
2372     */
2373    void ldns_rr_descriptor_dummy_free(const ldns_rr_descriptor *rd)
2374    {
2375      (void) rd;
2376    }
2377 %}
2378
2379
2380 /* ========================================================================= */
2381 /* Encapsulating Python code. */
2382 /* ========================================================================= */
2383
2384
2385 %feature("docstring") ldns_struct_rr_descriptor "Resource Record descriptor.
2386
2387 This structure contains, for all rr types, the rdata fields that are defined.
2388
2389 In order to create a class instance use :meth:`ldns_rr_descriptor`.
2390 "
2391
2392 %extend ldns_struct_rr_descriptor {
2393   %pythoncode
2394   %{
2395         def __init__(self, rr_type):
2396             """
2397                Returns the resource record descriptor for the given type.
2398
2399                :param rr_type: RR type. 
2400                :type rr_type: int
2401                :throws TypeError: when `rr_type` of inappropriate type.
2402                :return: (:class:`ldns_rr_descriptor`) RR descriptor class.
2403             """
2404             self.this = self.ldns_rr_descriptor(rr_type)
2405
2406         def __str__(self):
2407             raise Exception("The content of this class cannot be printed.")
2408
2409         __swig_destroy__ = _ldns.ldns_rr_descriptor_dummy_free
2410
2411         #
2412         # LDNS_RR_DESCRIPTOR_CONSTRUCTORS_
2413         #
2414
2415         @staticmethod
2416         def ldns_rr_descriptor(rr_type):
2417             """
2418                Returns the resource record descriptor for the given type.
2419
2420                :param rr_type: RR type. 
2421                :type rr_type: int
2422                :throws TypeError: when `rr_type` of inappropriate type.
2423                :return: (:class:`ldns_rr_descriptor`) RR descriptor class.
2424             """
2425             return _ldns.ldns_rr_descript(rr_type)
2426             #parameters: uint16_t
2427             #retvals: const ldns_rr_descriptor *
2428
2429         #
2430         # _LDNS_RR_DESCRIPTOR_CONSTRUCTORS
2431         #
2432
2433         #
2434         # LDNS_RR_DESCRIPTOR_METHODS_
2435         #
2436
2437         def field_type(self, field):
2438             """
2439                Returns the rdf type for the given rdata field number of the
2440                rr type for the given descriptor.
2441                
2442                :param field: The field number.
2443                :type field: positive int
2444                :throws TypeError: when `field` of non-inetger type.
2445                :return: (int) the rdf type for the field.
2446             """
2447             return _ldns.ldns_rr_descriptor_field_type(self, field)
2448             #parameters: const ldns_rr_descriptor *, size_t,
2449             #retvals: ldns_rdf_type
2450
2451         def maximum(self):
2452             """
2453                Returns the maximum number of rdata fields of the rr type this
2454                descriptor describes.
2455                
2456                :return: (int) the maximum number of rdata fields.
2457             """
2458             return _ldns.ldns_rr_descriptor_maximum(self)
2459             #parameters: const ldns_rr_descriptor *,
2460             #retvals: size_t
2461
2462         def minimum(self):
2463             """
2464                Returns the minimum number of rdata fields of the rr type this
2465                descriptor describes.
2466                
2467                :return: (int) the minimum number of rdata fields.
2468             """
2469             return _ldns.ldns_rr_descriptor_minimum(self)
2470             #parameters: const ldns_rr_descriptor *,
2471             #retvals: size_t
2472
2473         #
2474         # _LDNS_RR_DESCRIPTOR_METHODS
2475         #
2476   %}
2477 }
2478
2479
2480 /* ========================================================================= */
2481 /* Added C code. */
2482 /* ========================================================================= */
2483
2484
2485 /*
2486  * rrsig checking wrappers
2487  *
2488  * Copying of rr pointers into the good_keys list leads to double free
2489  * problems, therefore we provide two options - either ignore the keys
2490  * or get list of indexes of the keys. The latter allows fetching of the
2491  * keys later on from the original key set.
2492  */
2493
2494 %rename(__ldns_verify_rrsig_keylist) ldns_verify_rrsig_keylist;
2495 %inline
2496 %{
2497   ldns_status ldns_verify_rrsig_keylist_status_only(ldns_rr_list *rrset,
2498     ldns_rr *rrsig, const ldns_rr_list *keys)
2499   {
2500     ldns_rr_list *good_keys = ldns_rr_list_new();
2501     ldns_status status = ldns_verify_rrsig_keylist(rrset, rrsig, keys,
2502         good_keys);
2503     ldns_rr_list_free(good_keys);
2504     return status;
2505   }
2506 %}
2507
2508 %rename(__ldns_verify_rrsig_keylist) ldns_verify_rrsig_keylist;
2509 %inline
2510 %{
2511   PyObject* ldns_verify_rrsig_keylist_(ldns_rr_list *rrset,
2512     ldns_rr *rrsig, const ldns_rr_list *keys)
2513   {
2514     PyObject* tuple;
2515     PyObject* keylist;
2516     ldns_rr_list *good_keys = ldns_rr_list_new();
2517     ldns_status status = ldns_verify_rrsig_keylist(rrset, rrsig, keys,
2518       good_keys);
2519
2520     tuple = PyTuple_New(2);
2521     PyTuple_SetItem(tuple, 0, SWIG_From_int(status)); 
2522     keylist = PyList_New(0);
2523     if (status == LDNS_STATUS_OK) {
2524       unsigned int i;
2525       for (i = 0; i < ldns_rr_list_rr_count(keys); i++) {
2526          if (ldns_rr_list_contains_rr(good_keys, ldns_rr_list_rr(keys, i))) {
2527            PyList_Append(keylist, SWIG_From_int(i));
2528          }
2529       }
2530     }
2531     PyTuple_SetItem(tuple, 1, keylist);
2532     ldns_rr_list_free(good_keys);
2533     return tuple;
2534   }
2535 %}
2536
2537
2538 %rename(__ldns_verify_rrsig_keylist_notime) ldns_verify_rrsig_keylist_notime;
2539 %inline
2540 %{
2541   ldns_status ldns_verify_rrsig_keylist_notime_status_only(ldns_rr_list *rrset,
2542     ldns_rr *rrsig, const ldns_rr_list *keys)
2543   {
2544     ldns_rr_list *good_keys = ldns_rr_list_new();
2545     ldns_status status = ldns_verify_rrsig_keylist_notime(rrset, rrsig, keys,
2546       good_keys);
2547     ldns_rr_list_free(good_keys);
2548     return status;
2549   }
2550 %}
2551
2552 %rename(__ldns_verify_rrsig_keylist_notime) ldns_verify_rrsig_keylist_notime;
2553 %inline
2554 %{
2555   PyObject* ldns_verify_rrsig_keylist_notime_(ldns_rr_list *rrset,
2556     ldns_rr *rrsig, const ldns_rr_list *keys)
2557   {
2558     PyObject* tuple;
2559     PyObject* keylist;
2560     ldns_rr_list *good_keys = ldns_rr_list_new();
2561     ldns_status status = ldns_verify_rrsig_keylist_notime(rrset, rrsig, keys,
2562       good_keys);
2563
2564     tuple = PyTuple_New(2);
2565     PyTuple_SetItem(tuple, 0, SWIG_From_int(status)); 
2566     keylist = PyList_New(0);
2567     if (status == LDNS_STATUS_OK) {
2568       unsigned int i;
2569       for (i = 0; i < ldns_rr_list_rr_count(keys); i++) {
2570         if (ldns_rr_list_contains_rr(good_keys, ldns_rr_list_rr(keys, i))) {
2571           PyList_Append(keylist, SWIG_From_int(i));
2572         }
2573       }
2574     }
2575     PyTuple_SetItem(tuple, 1, keylist);
2576     ldns_rr_list_free(good_keys);
2577     return tuple;
2578   }
2579 %}
2580
2581 /* End of rrsig checking wrappers. */