<commit_before>
/* Borrowed code from Python (Modules/errnomodule.c) */

static void
inscode(PyObject *module_dict, PyObject *other_dict, const char *name, int code)
{
#ifdef PYUV_PYTHON3
    PyObject *error_name = PyUnicode_FromString(name);
#else
    PyObject *error_name = PyString_FromString(name);
#endif
    PyObject *error_code = PyInt_FromLong((long) code);

    /* Don't bother checking for errors; they'll be caught at the end
     * of the module initialization function by the caller of
     * init_errno().
     */
    if (error_name && error_code) {
        PyDict_SetItem(module_dict, error_name, error_code);
        PyDict_SetItem(other_dict, error_code, error_name);
    }
    Py_XDECREF(error_name);
    Py_XDECREF(error_code);
}


static PyObject *
Errno_func_strerror(PyObject *obj, PyObject *args)
{
    int errorno;
    uv_err_t err;

    UNUSED_ARG(obj);

    if (!PyArg_ParseTuple(args, "i:strerror", &errorno)) {
        return NULL;
    }

    err.code = errorno;
    return PyString_FromString(uv_strerror(err));
}


static PyMethodDef
Errno_methods[] = {
    { "strerror", (PyCFunction)Errno_func_strerror, METH_VARARGS, "Get string representation of an error code." },
    { NULL }
};


#ifdef PYUV_PYTHON3
static PyModuleDef pyuv_errorno_module = {
    PyModuleDef_HEAD_INIT,
    "pyuv.errno",           /*m_name*/
    NULL,                   /*m_doc*/
    -1,                     /*m_size*/
    Errno_methods,          /*m_methods*/
};
#endif

PyObject *
init_errno(void)
{
    PyObject *module;
    PyObject *module_dict;
    PyObject *errorcode_dict;
    PyObject *ares_errorcode_dict;
#ifdef PYUV_PYTHON3
    module = PyModule_Create(&pyuv_errorno_module);
#else
    module = Py_InitModule("pyuv.errno", Errno_methods);
#endif<commit_msg>Added ares_strerror function to errno module. It returns a string representation of a c-ares error code<commit_after>
/* Borrowed code from Python (Modules/errnomodule.c) */

static void
inscode(PyObject *module_dict, PyObject *other_dict, const char *name, int code)
{
#ifdef PYUV_PYTHON3
    PyObject *error_name = PyUnicode_FromString(name);
#else
    PyObject *error_name = PyString_FromString(name);
#endif
    PyObject *error_code = PyInt_FromLong((long) code);

    /* Don't bother checking for errors; they'll be caught at the end
     * of the module initialization function by the caller of
     * init_errno().
     */
    if (error_name && error_code) {
        PyDict_SetItem(module_dict, error_name, error_code);
        PyDict_SetItem(other_dict, error_code, error_name);
    }
    Py_XDECREF(error_name);
    Py_XDECREF(error_code);
}


static PyObject *
Errno_func_strerror(PyObject *obj, PyObject *args)
{
    int errorno;
    uv_err_t err;

    UNUSED_ARG(obj);

    if (!PyArg_ParseTuple(args, "i:strerror", &errorno)) {
        return NULL;
    }

    err.code = errorno;
    return PyString_FromString(uv_strerror(err));
}


static PyObject *
Errno_func_ares_strerror(PyObject *obj, PyObject *args)
{
    int errorno;

    UNUSED_ARG(obj);

    if (!PyArg_ParseTuple(args, "i:ares_strerror", &errorno)) {
        return NULL;
    }

    return PyString_FromString(ares_strerror(errorno));
}


static PyMethodDef
Errno_methods[] = {
    { "ares_strerror", (PyCFunction)Errno_func_ares_strerror, METH_VARARGS, "Get string representation of a c-ares error code." },
    { "strerror", (PyCFunction)Errno_func_strerror, METH_VARARGS, "Get string representation of an error code." },
    { NULL }
};


#ifdef PYUV_PYTHON3
static PyModuleDef pyuv_errorno_module = {
    PyModuleDef_HEAD_INIT,
    "pyuv.errno",           /*m_name*/
    NULL,                   /*m_doc*/
    -1,                     /*m_size*/
    Errno_methods,          /*m_methods*/
};
#endif

PyObject *
init_errno(void)
{
    PyObject *module;
    PyObject *module_dict;
    PyObject *errorcode_dict;
    PyObject *ares_errorcode_dict;
#ifdef PYUV_PYTHON3
    module = PyModule_Create(&pyuv_errorno_module);
#else
    module = Py_InitModule("pyuv.errno", Errno_methods);
#endif
{'fraction_non_alphanumeric': 0.10582403965303594, 'fraction_numerical': 0.001982651796778191, 'mean_word_length': 3.47450110864745, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5950101', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1372, 'n_words': 306}