Skip to content

Commit 646ddf7

Browse files
committed
added getdns.get_errorstr_by_id() method, added it to doc, updated version number in docs
1 parent 13a092d commit 646ddf7

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

doc/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
# built documents.
4949
#
5050
# The short X.Y version.
51-
version = '0.3.1'
51+
version = '0.1.1'
5252
# The full version, including alpha/beta/rc tags.
53-
release = '0.3.1'
53+
release = '0.2.1'
5454

5555
# The language for content autogenerated by Sphinx. Refer to documentation
5656
# for a list of supported languages.

doc/functions.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,3 +493,23 @@ This is an example callback function:
493493
print 'Query timed out'
494494
else:
495495
print 'Unknown error'
496+
497+
498+
Utility methods
499+
---------------
500+
501+
At the present time we support one utility method.
502+
503+
.. py:method:: get_errorstr_by_id(id)
504+
505+
``getdns.get_errorstr_by_id`` returns a string containing
506+
text describing a getdns return code, helping to make
507+
reporting errors to users a little easier. For example:
508+
509+
.. code-block:: python
510+
511+
if results.replies_full['status'] != getdns.GETDNS_RESPSTATUS_GOOD:
512+
print(getdns.get_errorstr_by_id(id=results.replies_full['status'])
513+
sys.exit(1)
514+
515+

doc/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This version of getdns has been built and tested against Python
2929
2.7. We also expect these other prerequisites to be
3030
installed:
3131

32-
* `libgetdns <http://getdnsapi.net/>`_, version 0.1.2 or later
32+
* `libgetdns <http://getdnsapi.net/>`_, version 0.1.7 or later
3333
* `libldns <https://www.nlnetlabs.nl/projects/ldns/>`_,
3434
version 1.6.11 or later
3535
* `libunbound
@@ -45,7 +45,7 @@ as follows:
4545

4646
./configure --with-libevent
4747

48-
This release has been tested against libgetdns 0.1.5.
48+
This release has been tested against libgetdns 0.1.7.
4949

5050
Building
5151
========

getdns.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,34 @@ PyTypeObject getdns_ContextType = {
211211
(initproc)context_init, /* tp_init */
212212
};
213213

214-
214+
static PyObject *get_errorstr_by_id(PyObject *self, PyObject *args, PyObject *keywds);
215215

216216
static struct PyMethodDef getdns_methods[] = {
217+
{ "get_errorstr_by_id", (PyCFunction)get_errorstr_by_id,
218+
METH_VARARGS|METH_KEYWORDS, "return getdns error text by error id" },
217219
{ 0, 0, 0 }
218220
};
219221

222+
223+
static PyObject *
224+
get_errorstr_by_id(PyObject *self, PyObject *args, PyObject *keywds)
225+
{
226+
static char *kwlist[] = { "id",
227+
NULL };
228+
int id;
229+
char *errstr;
230+
231+
if (!PyArg_ParseTupleAndKeywords(args, keywds, "i", kwlist, &id)) {
232+
PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
233+
return NULL;
234+
}
235+
if ((errstr = (char *)getdns_get_errorstr_by_id((uint16_t)id)) == 0)
236+
return Py_None;
237+
else
238+
return PyString_FromString(errstr);
239+
}
240+
241+
220242
PyMODINIT_FUNC
221243
initgetdns(void)
222244
{

0 commit comments

Comments
 (0)