Skip to content

Commit

Permalink
cleanup prior to merge
Browse files Browse the repository at this point in the history
  • Loading branch information
MelindaShore committed Nov 14, 2015
2 parents ac9ee3d + dd4d542 commit 4a2d2bf
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
3 changes: 0 additions & 3 deletions context.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
#include <getdns/getdns_extra.h>
#include <arpa/inet.h>
#include <event2/event.h>
<<<<<<< HEAD
#include <getdns/getdns_ext_libevent.h>
=======
>>>>>>> develop
#include <sys/wait.h>
#include "pygetdns.h"

Expand Down
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ you must compile support for them into libgetdns, by
including the --enable-draft-edns-cookies argument to
configure.

This release has been tested against libgetdns 0.1.7.
This release has been tested against libgetdns 0.3.1.

Building
========
Expand Down
20 changes: 20 additions & 0 deletions examples/idn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python
# coding=utf-8

import getdns, sys

try:
ulabel = getdns.alabel_to_ulabel('xn--p1acf')
# Next line contains a utf-8 string
alabel = getdns.ulabel_to_alabel('рус')
ulabel1 = getdns.alabel_to_ulabel('xn--vermgensberatung-pwb')
# Next line contains a utf-8 string
alabel1 = getdns.ulabel_to_alabel('vermögensberatung')
except getdns.error as e:
print(str(e))
sys.exit(1)

print (ulabel)
print (alabel)
print (ulabel1)
print (alabel1)
44 changes: 43 additions & 1 deletion getdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,18 @@ PyObject *getdns_error;
static PyObject *get_errorstr_by_id(PyObject *self, PyObject *args, PyObject *keywds);
static PyObject *root_trust_anchor(PyObject *self, PyObject *args, PyObject *keywds);
static void add_getdns_constants(PyObject *g);

static PyObject *ulabel_to_alabel(PyObject *self, PyObject *args, PyObject *keywds);
static PyObject *alabel_to_ulabel(PyObject *self, PyObject *args, PyObject *keywds);

static struct PyMethodDef getdns_methods[] = {
{ "get_errorstr_by_id", (PyCFunction)get_errorstr_by_id,
METH_VARARGS|METH_KEYWORDS, "return getdns error text by error id" },
{ "root_trust_anchor", (PyCFunction)root_trust_anchor, METH_NOARGS,
"retrieve default list of trust anchor records used to validate DNSSEC" },
{ "alabel_to_ulabel", (PyCFunction)alabel_to_ulabel,
METH_VARARGS|METH_KEYWORDS, "return ulabel from alabel" },
{ "ulabel_to_alabel", (PyCFunction)ulabel_to_alabel,
METH_VARARGS|METH_KEYWORDS, "return alabel from ulabel" },
{ 0, 0, 0 }
};

Expand Down Expand Up @@ -258,6 +264,42 @@ PyTypeObject getdns_ContextType = {
(initproc)context_init, /* tp_init */
};

static PyObject *
alabel_to_ulabel(PyObject *self, PyObject *args, PyObject *keywds)
{
static char *kwlist[] = { "alabel", NULL };
char *alabel;
char *ulabel;
if (!PyArg_ParseTupleAndKeywords(args, keywds, "s", kwlist, &alabel)) {
PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
return NULL;
}
ulabel = (char*)getdns_convert_alabel_to_ulabel((char*)alabel);
#if PY_MAJOR_VERSION >= 3
return PyUnicode_FromString(ulabel);
#else
return PyString_FromString(ulabel);
#endif
}

static PyObject *
ulabel_to_alabel(PyObject *self, PyObject *args, PyObject *keywds)
{
static char *kwlist[] = { "ulabel", NULL };
char *alabel;
char *ulabel;
if (!PyArg_ParseTupleAndKeywords(args, keywds, "s", kwlist, &ulabel)) {
PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
return NULL;
}
alabel = (char*)getdns_convert_ulabel_to_alabel((char*)ulabel);

#if PY_MAJOR_VERSION >= 3
return PyUnicode_FromString(alabel);
#else
return PyString_FromString(alabel);
#endif
}

static PyObject *
get_errorstr_by_id(PyObject *self, PyObject *args, PyObject *keywds)
Expand Down

0 comments on commit 4a2d2bf

Please sign in to comment.