| 
									
										
										
										
											2021-08-24 17:50:05 +01:00
										 |  |  | /*[clinic input]
 | 
					
						
							|  |  |  | preserve | 
					
						
							|  |  |  | [clinic start generated code]*/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
 | 
					
						
							| 
									
										
										
										
											2023-08-31 23:42:34 +02:00
										 |  |  | #  include "pycore_gc.h"          // PyGC_Head
 | 
					
						
							|  |  |  | #  include "pycore_runtime.h"     // _Py_ID()
 | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2023-10-17 14:30:31 +02:00
										 |  |  | #include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
 | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-24 17:50:05 +01:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2023-05-30 22:43:34 +01:00
										 |  |  | tokenizeriter_new_impl(PyTypeObject *type, PyObject *readline, | 
					
						
							|  |  |  |                        int extra_tokens, const char *encoding); | 
					
						
							| 
									
										
										
										
											2021-08-24 17:50:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | tokenizeriter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     PyObject *return_value = NULL; | 
					
						
							| 
									
										
										
										
											2022-08-13 12:09:40 +02:00
										 |  |  |     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
 | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-21 02:03:02 +02:00
										 |  |  |     #define NUM_KEYWORDS 2
 | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  |     static struct { | 
					
						
							|  |  |  |         PyGC_Head _this_is_not_used; | 
					
						
							|  |  |  |         PyObject_VAR_HEAD | 
					
						
							| 
									
										
										
										
											2025-03-27 09:57:06 -04:00
										 |  |  |         Py_hash_t ob_hash; | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  |         PyObject *ob_item[NUM_KEYWORDS]; | 
					
						
							|  |  |  |     } _kwtuple = { | 
					
						
							|  |  |  |         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) | 
					
						
							| 
									
										
										
										
											2025-03-27 09:57:06 -04:00
										 |  |  |         .ob_hash = -1, | 
					
						
							| 
									
										
										
										
											2023-05-30 22:43:34 +01:00
										 |  |  |         .ob_item = { &_Py_ID(extra_tokens), &_Py_ID(encoding), }, | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  |     }; | 
					
						
							|  |  |  |     #undef NUM_KEYWORDS
 | 
					
						
							| 
									
										
										
										
											2022-08-13 12:09:40 +02:00
										 |  |  |     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     #else  // !Py_BUILD_CORE
 | 
					
						
							|  |  |  |     #  define KWTUPLE NULL
 | 
					
						
							|  |  |  |     #endif  // !Py_BUILD_CORE
 | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-30 22:43:34 +01:00
										 |  |  |     static const char * const _keywords[] = {"", "extra_tokens", "encoding", NULL}; | 
					
						
							| 
									
										
										
										
											2022-08-11 15:25:49 -06:00
										 |  |  |     static _PyArg_Parser _parser = { | 
					
						
							|  |  |  |         .keywords = _keywords, | 
					
						
							|  |  |  |         .fname = "tokenizeriter", | 
					
						
							|  |  |  |         .kwtuple = KWTUPLE, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     #undef KWTUPLE
 | 
					
						
							| 
									
										
										
										
											2023-05-30 22:43:34 +01:00
										 |  |  |     PyObject *argsbuf[3]; | 
					
						
							| 
									
										
										
										
											2021-08-24 17:50:05 +01:00
										 |  |  |     PyObject * const *fastargs; | 
					
						
							|  |  |  |     Py_ssize_t nargs = PyTuple_GET_SIZE(args); | 
					
						
							| 
									
										
										
										
											2023-05-30 22:43:34 +01:00
										 |  |  |     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 2; | 
					
						
							|  |  |  |     PyObject *readline; | 
					
						
							| 
									
										
										
										
											2023-05-21 02:03:02 +02:00
										 |  |  |     int extra_tokens; | 
					
						
							| 
									
										
										
										
											2023-05-30 22:43:34 +01:00
										 |  |  |     const char *encoding = NULL; | 
					
						
							| 
									
										
										
										
											2021-08-24 17:50:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-08 14:23:50 +02:00
										 |  |  |     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, | 
					
						
							|  |  |  |             /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 1, /*varpos*/ 0, argsbuf); | 
					
						
							| 
									
										
										
										
											2021-08-24 17:50:05 +01:00
										 |  |  |     if (!fastargs) { | 
					
						
							|  |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-05-30 22:43:34 +01:00
										 |  |  |     readline = fastargs[0]; | 
					
						
							|  |  |  |     extra_tokens = PyObject_IsTrue(fastargs[1]); | 
					
						
							|  |  |  |     if (extra_tokens < 0) { | 
					
						
							| 
									
										
										
										
											2021-08-24 17:50:05 +01:00
										 |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-05-30 22:43:34 +01:00
										 |  |  |     if (!noptargs) { | 
					
						
							|  |  |  |         goto skip_optional_kwonly; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (!PyUnicode_Check(fastargs[2])) { | 
					
						
							|  |  |  |         _PyArg_BadArgument("tokenizeriter", "argument 'encoding'", "str", fastargs[2]); | 
					
						
							| 
									
										
										
										
											2021-08-24 17:50:05 +01:00
										 |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-11-07 23:36:13 +01:00
										 |  |  |     Py_ssize_t encoding_length; | 
					
						
							|  |  |  |     encoding = PyUnicode_AsUTF8AndSize(fastargs[2], &encoding_length); | 
					
						
							| 
									
										
										
										
											2023-05-30 22:43:34 +01:00
										 |  |  |     if (encoding == NULL) { | 
					
						
							| 
									
										
										
										
											2021-08-24 17:50:05 +01:00
										 |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-11-07 23:36:13 +01:00
										 |  |  |     if (strlen(encoding) != (size_t)encoding_length) { | 
					
						
							|  |  |  |         PyErr_SetString(PyExc_ValueError, "embedded null character"); | 
					
						
							|  |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-05-30 22:43:34 +01:00
										 |  |  | skip_optional_kwonly: | 
					
						
							|  |  |  |     return_value = tokenizeriter_new_impl(type, readline, extra_tokens, encoding); | 
					
						
							| 
									
										
										
										
											2021-08-24 17:50:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | exit: | 
					
						
							|  |  |  |     return return_value; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-03-27 09:57:06 -04:00
										 |  |  | /*[clinic end generated code: output=4c448f34d9c835c0 input=a9049054013a1b77]*/ |