<commit_before>
/*
 * Copyright (C) NGINX, Inc.
 */

#ifndef _NXT_PYTHON_H_INCLUDED_
#define _NXT_PYTHON_H_INCLUDED_


#include <Python.h>
#include <nxt_main.h>
#include <nxt_unit.h>


#if PY_MAJOR_VERSION == 3
#define NXT_PYTHON_BYTES_TYPE       "bytestring"

#define PyString_FromStringAndSize(str, size)                                 \
            PyUnicode_DecodeLatin1((str), (size), "strict")
#define PyString_AS_STRING          PyUnicode_DATA

#else
#define NXT_PYTHON_BYTES_TYPE       "string"

#define PyBytes_FromStringAndSize   PyString_FromStringAndSize
#define PyBytes_Check               PyString_Check
#define PyBytes_GET_SIZE            PyString_GET_SIZE
#define PyBytes_AS_STRING           PyString_AS_STRING
#define PyUnicode_InternInPlace     PyString_InternInPlace
#define PyUnicode_AsUTF8            PyString_AS_STRING
#define PyUnicode_GET_LENGTH        PyUnicode_GET_SIZE
#endif

#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 5
#define NXT_HAVE_ASGI  1
#endif

extern PyObject  *nxt_py_application;

typedef struct {
    nxt_str_t  string;
    PyObject   **object_p;
} nxt_python_string_t;


nxt_int_t nxt_python_init_strings(nxt_python_string_t *pstr);
void nxt_python_done_strings(nxt_python_string_t *pstr);
<commit_msg>Python: introducting macro to simplify minor version check.<commit_after>
/*
 * Copyright (C) NGINX, Inc.
 */

#ifndef _NXT_PYTHON_H_INCLUDED_
#define _NXT_PYTHON_H_INCLUDED_


#include <Python.h>
#include <nxt_main.h>
#include <nxt_unit.h>

#define NXT_PYTHON_VER(maj, min)    ((maj << 24) | (min << 16))


#if PY_MAJOR_VERSION == 3
#define NXT_PYTHON_BYTES_TYPE       "bytestring"

#define PyString_FromStringAndSize(str, size)                                 \
            PyUnicode_DecodeLatin1((str), (size), "strict")
#define PyString_AS_STRING          PyUnicode_DATA

#else
#define NXT_PYTHON_BYTES_TYPE       "string"

#define PyBytes_FromStringAndSize   PyString_FromStringAndSize
#define PyBytes_Check               PyString_Check
#define PyBytes_GET_SIZE            PyString_GET_SIZE
#define PyBytes_AS_STRING           PyString_AS_STRING
#define PyUnicode_InternInPlace     PyString_InternInPlace
#define PyUnicode_AsUTF8            PyString_AS_STRING
#define PyUnicode_GET_LENGTH        PyUnicode_GET_SIZE
#endif

#if PY_VERSION_HEX >= NXT_PYTHON_VER(3, 5)
#define NXT_HAVE_ASGI  1
#endif

extern PyObject  *nxt_py_application;

typedef struct {
    nxt_str_t  string;
    PyObject   **object_p;
} nxt_python_string_t;


nxt_int_t nxt_python_init_strings(nxt_python_string_t *pstr);
void nxt_python_done_strings(nxt_python_string_t *pstr);

{'fraction_non_alphanumeric': 0.07216890595009597, 'fraction_numerical': 0.006142034548944338, 'mean_word_length': 4.0115384615384615, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '2324490', 'n_tokens_mistral': 974, 'n_tokens_neox': 954, 'n_words': 175}