static PyObject * trie_with_prefix_onearg(trieobject *mp, PyObject *py_args) { PyObject *py_arg; if(!PyArg_ParseTuple(py_args, "O", &py_arg)) return NULL; return trie_with_prefix(mp, py_arg); }
static PyObject * trie_with_prefix(trieobject *mp, PyObject *py_prefix) { const char *prefix; PyObject *py_list; #ifdef IS_PY3K PyObject* bytes; #endif /* Make sure prefix is a string. */ #ifdef IS_PY3K if(!PyUnicode_Check(py_prefix)) { #else if(!PyString_Check(py_prefix)) { #endif PyErr_SetString(PyExc_TypeError, "prefix must be a string"); return NULL; } #ifdef IS_PY3K bytes = PyUnicode_AsASCIIString(py_prefix); if(!bytes) { PyErr_SetString(PyExc_TypeError, "prefix must be an ASCII string"); return NULL; } prefix = PyBytes_AsString(bytes); #else prefix = PyString_AS_STRING(py_prefix); #endif if(!(py_list = PyList_New(0))) return NULL; Trie_with_prefix(mp->trie, prefix, _trie_with_prefix_helper, (void *)py_list); #ifdef IS_PY3K Py_DECREF(bytes); #endif if(PyErr_Occurred()) { Py_DECREF(py_list); return NULL; } return py_list; } static PyObject * trie_with_prefix_onearg(trieobject *mp, PyObject *py_args) { PyObject *py_arg; if(!PyArg_ParseTuple(py_args, "O", &py_arg)) return NULL; return trie_with_prefix(mp, py_arg); }