<commit_before>/*
	This is part of pyahocorasick Python module.
	
	Automaton class implementation.
	(this file includes Automaton_pickle.c)

	Author    : <NAME>, <EMAIL>
	License   : 3-clauses BSD (see LICENSE)
*/

#include "Automaton.h"

static PyTypeObject automaton_type;


static bool
check_store(const int store) {
	switch (store) {
		case STORE_LENGTH:
		case STORE_INTS:
		case STORE_ANY:
			return true;

		default:
			PyErr_SetString(
				PyExc_ValueError,
				"store must have value STORE_LENGTH, STORE_INTS or STORE_ANY"
			);
			return false;
	} // switch
}


static bool
check_kind(const int kind) {
	switch (kind) {
		case EMPTY:
		case TRIE:
		case AHOCORASICK:
			return true;

		default:
			PyErr_SetString(
				PyExc_ValueError,
				"kind must have value EMPTY, TRIE or AHOCORASICK"
			);
			return false;
	}
}


static PyObject*
automaton_new(PyTypeObject* self, PyObject* args, PyObject* kwargs) {
	Automaton* automaton = NULL;
	int store;

	automaton = (Automaton*)PyObject_New(Automaton, &automaton_type);
	if (UNLIKELY(automaton == NULL))
		return NULL;

	// commons settings
	automaton->version = 0;
	automaton->stats.version = -1;
	automaton->count = 0;
	automaton->longest_word = 0;
	automaton->kind  = EMPTY;
	automaton->root  = NULL;

	if (UNLIKELY(PyTuple_Size(args) == 7)) {
		
		// unpickle: count, data, kind, store, version, values
		size_t			count;
		void*			data;
		size_t			size;
		int				version;
		int				longest_word;
		AutomatonKind	kind;
		KeysStore		store;
		PyObject*		values = NULL;

#ifdef PY3K
        const char* fmt = "ky#iiiiO";
#else
        const char* fmt = "is#iiii0";
#endif

		if (not PyArg_ParseTuple(args, fmt, &count, &data, &size, &kind, &store, &version, &longest_word, &values)) {
			PyErr_SetString(PyExc_ValueError, "invalid data to restore");
			goto error;<commit_msg>#12 : Use the correct format code (an O not a zero)<commit_after>/*
	This is part of pyahocorasick Python module.
	
	Automaton class implementation.
	(this file includes Automaton_pickle.c)

	Author    : <NAME>, <EMAIL>
	License   : 3-clauses BSD (see LICENSE)
*/

#include "Automaton.h"

static PyTypeObject automaton_type;


static bool
check_store(const int store) {
	switch (store) {
		case STORE_LENGTH:
		case STORE_INTS:
		case STORE_ANY:
			return true;

		default:
			PyErr_SetString(
				PyExc_ValueError,
				"store must have value STORE_LENGTH, STORE_INTS or STORE_ANY"
			);
			return false;
	} // switch
}


static bool
check_kind(const int kind) {
	switch (kind) {
		case EMPTY:
		case TRIE:
		case AHOCORASICK:
			return true;

		default:
			PyErr_SetString(
				PyExc_ValueError,
				"kind must have value EMPTY, TRIE or AHOCORASICK"
			);
			return false;
	}
}


static PyObject*
automaton_new(PyTypeObject* self, PyObject* args, PyObject* kwargs) {
	Automaton* automaton = NULL;
	int store;

	automaton = (Automaton*)PyObject_New(Automaton, &automaton_type);
	if (UNLIKELY(automaton == NULL))
		return NULL;

	// commons settings
	automaton->version = 0;
	automaton->stats.version = -1;
	automaton->count = 0;
	automaton->longest_word = 0;
	automaton->kind  = EMPTY;
	automaton->root  = NULL;

	if (UNLIKELY(PyTuple_Size(args) == 7)) {
		
		// unpickle: count, data, kind, store, version, values
		size_t			count;
		void*			data;
		size_t			size;
		int				version;
		int				longest_word;
		AutomatonKind	kind;
		KeysStore		store;
		PyObject*		values = NULL;

#ifdef PY3K
        const char* fmt = "ky#iiiiO";
#else
        const char* fmt = "is#iiiiO";
#endif

		if (not PyArg_ParseTuple(args, fmt, &count, &data, &size, &kind, &store, &version, &longest_word, &values)) {
			PyErr_SetString(PyExc_ValueError, "invalid data to restore");
			goto error;
{'fraction_non_alphanumeric': 0.10907127429805616, 'fraction_numerical': 0.00458963282937365, 'mean_word_length': 3.642857142857143, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '2696949', 'n_tokens_mistral': 1544, 'n_tokens_neox': 1376, 'n_words': 365}