Commit 6af6a082 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

some final comments: use constants from cpp version, updated a few c-style...

some final comments: use constants from cpp version, updated a few c-style casts, and replaced obj.__str__() calls in tests with str(obj)


git-svn-id: svn://bind10.isc.org/svn/bind10/experiments/python-binding@2323 e5f2f494-b856-4b98-b285-d166d9295462
parent f58095d1
......@@ -415,7 +415,7 @@ Name_toWire(s_Name* self, PyObject* args) {
OutputBuffer buffer(Name::MAX_WIRE);
self->name->toWire(buffer);
PyObject* name_bytes = PyBytes_FromStringAndSize((const char*) buffer.getData(), buffer.getLength());
PyObject* name_bytes = PyBytes_FromStringAndSize(static_cast<const char*>(buffer.getData()), buffer.getLength());
PyObject* result = PySequence_InPlaceConcat(bytes_o, name_bytes);
// We need to release the object we temporarily created here
// to prevent memory leak
......@@ -634,17 +634,18 @@ initModulePart_Name(PyObject* mod) {
Py_INCREF(&name_type);
// Add the constants to the module
addClassVariable(name_type, "MAX_WIRE", Py_BuildValue("I", 255U));
addClassVariable(name_type, "MAX_LABELS", Py_BuildValue("I", 128U));
addClassVariable(name_type, "MAX_LABELLEN", Py_BuildValue("I", 63U));
addClassVariable(name_type, "MAX_COMPRESS_POINTER", Py_BuildValue("I", 0x3fffU));
addClassVariable(name_type, "COMPRESS_POINTER_MARK8", Py_BuildValue("I", 0xc0U));
addClassVariable(name_type, "COMPRESS_POINTER_MARK16", Py_BuildValue("I", 0xc000U));
addClassVariable(name_type, "MAX_WIRE", Py_BuildValue("I", Name::MAX_WIRE));
addClassVariable(name_type, "MAX_LABELS", Py_BuildValue("I", Name::MAX_LABELS));
addClassVariable(name_type, "MAX_LABELLEN", Py_BuildValue("I", Name::MAX_LABELLEN));
addClassVariable(name_type, "MAX_COMPRESS_POINTER", Py_BuildValue("I", Name::MAX_COMPRESS_POINTER));
addClassVariable(name_type, "COMPRESS_POINTER_MARK8", Py_BuildValue("I", Name::COMPRESS_POINTER_MARK8));
addClassVariable(name_type, "COMPRESS_POINTER_MARK16", Py_BuildValue("I", Name::COMPRESS_POINTER_MARK16));
s_Name* root_name = PyObject_New(s_Name, &name_type);
root_name->name = new Name(".");
// casting const away here should be safe, as it should be impossible
// to modify attributes of built-in/extension types.
root_name->name = const_cast<Name*>(&Name::ROOT_NAME());
PyObject* po_ROOT_NAME = root_name;
Py_INCREF(po_ROOT_NAME);
addClassVariable(name_type, "ROOT_NAME", po_ROOT_NAME);
PyModule_AddObject(mod, "Name",
......
......@@ -247,7 +247,7 @@ Question_toWire(s_Question* self, PyObject* args) {
// Max length is Name::MAX_WIRE + rrclass (2) + rrtype (2)
OutputBuffer buffer(Name::MAX_WIRE + 4);
self->question->toWire(buffer);
PyObject* n = PyBytes_FromStringAndSize((const char*) buffer.getData(),
PyObject* n = PyBytes_FromStringAndSize(static_cast<const char*>(buffer.getData()),
buffer.getLength());
PyObject* result = PySequence_InPlaceConcat(bytes_o, n);
// We need to release the object we temporarily created here
......
......@@ -189,7 +189,7 @@ Rdata_toWire(s_Rdata* self, PyObject* args) {
OutputBuffer buffer(4);
self->rdata->toWire(buffer);
PyObject* rd_bytes = PyBytes_FromStringAndSize((const char*) buffer.getData(), buffer.getLength());
PyObject* rd_bytes = PyBytes_FromStringAndSize(static_cast<const char*>(buffer.getData()), buffer.getLength());
PyObject* result = PySequence_InPlaceConcat(bytes_o, rd_bytes);
// We need to release the object we temporarily created here
// to prevent memory leak
......
......@@ -231,7 +231,7 @@ RRClass_toWire(s_RRClass* self, PyObject* args) {
OutputBuffer buffer(2);
self->rrclass->toWire(buffer);
PyObject* n = PyBytes_FromStringAndSize((const char*) buffer.getData(), buffer.getLength());
PyObject* n = PyBytes_FromStringAndSize(static_cast<const char*>(buffer.getData()), buffer.getLength());
PyObject* result = PySequence_InPlaceConcat(bytes_o, n);
// We need to release the object we temporarily created here
// to prevent memory leak
......
......@@ -309,7 +309,7 @@ RRset_toWire(s_RRset* self, PyObject* args) {
OutputBuffer buffer(4096);
self->rrset->toWire(buffer);
PyObject* n = PyBytes_FromStringAndSize((const char*) buffer.getData(), buffer.getLength());
PyObject* n = PyBytes_FromStringAndSize(static_cast<const char*>(buffer.getData()), buffer.getLength());
PyObject* result = PySequence_InPlaceConcat(bytes_o, n);
// We need to release the object we temporarily created here
// to prevent memory leak
......
......@@ -224,7 +224,8 @@ RRTTL_toWire(s_RRTTL* self, PyObject* args) {
OutputBuffer buffer(4);
self->rrttl->toWire(buffer);
PyObject* n = PyBytes_FromStringAndSize((const char*) buffer.getData(), buffer.getLength());
PyObject* n = PyBytes_FromStringAndSize(static_cast<const char*>(buffer.getData()),
buffer.getLength());
PyObject* result = PySequence_InPlaceConcat(bytes_o, n);
// We need to release the object we temporarily created here
// to prevent memory leak
......
......@@ -264,7 +264,7 @@ RRType_toWire(s_RRType* self, PyObject* args) {
OutputBuffer buffer(2);
self->rrtype->toWire(buffer);
PyObject* n = PyBytes_FromStringAndSize((const char*) buffer.getData(), buffer.getLength());
PyObject* n = PyBytes_FromStringAndSize(static_cast<const char*>(buffer.getData()), buffer.getLength());
PyObject* result = PySequence_InPlaceConcat(bytes_o, n);
// We need to release the object we temporarily created here
// to prevent memory leak
......
......@@ -141,7 +141,7 @@ class RcodeTest(unittest.TestCase):
def test_to_text(self):
self.assertEqual("NOERROR", Rcode(0).to_text())
self.assertEqual("NOERROR", Rcode(0).__str__())
self.assertEqual("NOERROR", str(Rcode(0)))
self.assertEqual("FORMERR", Rcode(1).to_text())
self.assertEqual("SERVFAIL", Rcode(2).to_text())
self.assertEqual("NXDOMAIN", Rcode(3).to_text())
......
......@@ -64,7 +64,7 @@ class TestModuleSpec(unittest.TestCase):
def test_to_text(self):
self.assertEqual("A", RRType(1).to_text());
self.assertEqual("A", RRType(1).__str__());
self.assertEqual("A", str(RRType(1)));
self.assertEqual("TYPE65000", RRType(65000).to_text());
def test_to_wire_buffer(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment