BIND 10 trac1396, updated. 5410f9ce9d90585e00828253cedce1e024ad4524 [1396] Add Python binding for RRset::getLength()

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Jan 28 04:07:07 UTC 2014


The branch, trac1396 has been updated
       via  5410f9ce9d90585e00828253cedce1e024ad4524 (commit)
      from  000f7efd1c2d316c3ee02902713cedc355efefba (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5410f9ce9d90585e00828253cedce1e024ad4524
Author: Mukund Sivaraman <muks at isc.org>
Date:   Tue Jan 28 09:29:26 2014 +0530

    [1396] Add Python binding for RRset::getLength()

-----------------------------------------------------------------------

Summary of changes:
 src/lib/dns/python/rrset_python.cc            |   15 +++++++++++++++
 src/lib/dns/python/tests/rrset_python_test.py |   18 ++++++++++++++++++
 2 files changed, 33 insertions(+)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/python/rrset_python.cc b/src/lib/dns/python/rrset_python.cc
index de5925a..07af4ea 100644
--- a/src/lib/dns/python/rrset_python.cc
+++ b/src/lib/dns/python/rrset_python.cc
@@ -53,6 +53,7 @@ int RRset_init(s_RRset* self, PyObject* args);
 void RRset_destroy(s_RRset* self);
 
 PyObject* RRset_getRdataCount(PyObject* self, PyObject* args);
+PyObject* RRset_getLength(PyObject* self, PyObject* args);
 PyObject* RRset_getName(PyObject* self, PyObject* args);
 PyObject* RRset_getClass(PyObject* self, PyObject* args);
 PyObject* RRset_getType(PyObject* self, PyObject* args);
@@ -70,6 +71,8 @@ PyObject* RRset_removeRRsig(PyObject* self, PyObject* args);
 PyMethodDef RRset_methods[] = {
     { "get_rdata_count", RRset_getRdataCount, METH_NOARGS,
       "Returns the number of rdata fields." },
+    { "get_length", RRset_getLength, METH_NOARGS,
+      "Returns the wire format length of the RRset." },
     { "get_name", RRset_getName, METH_NOARGS,
       "Returns the name of the RRset, as a Name object." },
     { "get_class", RRset_getClass, METH_NOARGS,
@@ -136,6 +139,18 @@ RRset_getRdataCount(PyObject* self, PyObject*) {
 }
 
 PyObject*
+RRset_getLength(PyObject* self, PyObject*) {
+    try {
+        return (Py_BuildValue("H", static_cast<const s_RRset*>(self)->cppobj->
+                              getLength()));
+    } catch (const EmptyRRset& ers) {
+        PyErr_Clear();
+        PyErr_SetString(po_EmptyRRset, ers.what());
+        return (NULL);
+    }
+}
+
+PyObject*
 RRset_getName(PyObject* self, PyObject*) {
     try {
         return (createNameObject(static_cast<const s_RRset*>(self)->cppobj->
diff --git a/src/lib/dns/python/tests/rrset_python_test.py b/src/lib/dns/python/tests/rrset_python_test.py
index 9592b42..4298181 100644
--- a/src/lib/dns/python/tests/rrset_python_test.py
+++ b/src/lib/dns/python/tests/rrset_python_test.py
@@ -45,6 +45,24 @@ class TestModuleSpec(unittest.TestCase):
             self.assertEqual(i, self.rrset_a_empty.get_rdata_count())
             self.rrset_a_empty.add_rdata(Rdata(RRType("A"), RRClass("IN"), "192.0.2.1"))
 
+    def test_get_length(self):
+        # Empty RRset should throw
+        self.assertRaises(EmptyRRset, self.rrset_a_empty.get_length);
+
+        # Unless it is type ANY or NONE:
+        # test.example.com = 1 + 4 + 1 + 7 + 1 + 3 + 1 = 18 octets
+        # TYPE field = 2 octets
+        # CLASS field = 2 octets
+        # TTL field = 2 octets
+        # RDLENGTH field = 2 octets
+        # Total = 18 + 2 + 2 + 2 + 2 = 26 octets
+        self.assertEqual(26, self.rrset_any_a_empty.get_length())
+
+        # Single A RR:
+        # 26 octets (above) + 4 octets (A RDATA) = 30 octets
+        # With 2 A RRs:
+        self.assertEqual(30 + 30, self.rrset_a.get_length())
+
     def test_get_name(self):
         self.assertEqual(self.test_name, self.rrset_a.get_name())
         self.assertEqual(self.test_domain, self.rrset_ns.get_name())



More information about the bind10-changes mailing list