sre.c.h 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  1. /*[clinic input]
  2. preserve
  3. [clinic start generated code]*/
  4. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5. # include "pycore_gc.h" // PyGC_Head
  6. # include "pycore_runtime.h" // _Py_ID()
  7. #endif
  8. PyDoc_STRVAR(_sre_getcodesize__doc__,
  9. "getcodesize($module, /)\n"
  10. "--\n"
  11. "\n");
  12. #define _SRE_GETCODESIZE_METHODDEF \
  13. {"getcodesize", (PyCFunction)_sre_getcodesize, METH_NOARGS, _sre_getcodesize__doc__},
  14. static int
  15. _sre_getcodesize_impl(PyObject *module);
  16. static PyObject *
  17. _sre_getcodesize(PyObject *module, PyObject *Py_UNUSED(ignored))
  18. {
  19. PyObject *return_value = NULL;
  20. int _return_value;
  21. _return_value = _sre_getcodesize_impl(module);
  22. if ((_return_value == -1) && PyErr_Occurred()) {
  23. goto exit;
  24. }
  25. return_value = PyLong_FromLong((long)_return_value);
  26. exit:
  27. return return_value;
  28. }
  29. PyDoc_STRVAR(_sre_ascii_iscased__doc__,
  30. "ascii_iscased($module, character, /)\n"
  31. "--\n"
  32. "\n");
  33. #define _SRE_ASCII_ISCASED_METHODDEF \
  34. {"ascii_iscased", (PyCFunction)_sre_ascii_iscased, METH_O, _sre_ascii_iscased__doc__},
  35. static int
  36. _sre_ascii_iscased_impl(PyObject *module, int character);
  37. static PyObject *
  38. _sre_ascii_iscased(PyObject *module, PyObject *arg)
  39. {
  40. PyObject *return_value = NULL;
  41. int character;
  42. int _return_value;
  43. character = _PyLong_AsInt(arg);
  44. if (character == -1 && PyErr_Occurred()) {
  45. goto exit;
  46. }
  47. _return_value = _sre_ascii_iscased_impl(module, character);
  48. if ((_return_value == -1) && PyErr_Occurred()) {
  49. goto exit;
  50. }
  51. return_value = PyBool_FromLong((long)_return_value);
  52. exit:
  53. return return_value;
  54. }
  55. PyDoc_STRVAR(_sre_unicode_iscased__doc__,
  56. "unicode_iscased($module, character, /)\n"
  57. "--\n"
  58. "\n");
  59. #define _SRE_UNICODE_ISCASED_METHODDEF \
  60. {"unicode_iscased", (PyCFunction)_sre_unicode_iscased, METH_O, _sre_unicode_iscased__doc__},
  61. static int
  62. _sre_unicode_iscased_impl(PyObject *module, int character);
  63. static PyObject *
  64. _sre_unicode_iscased(PyObject *module, PyObject *arg)
  65. {
  66. PyObject *return_value = NULL;
  67. int character;
  68. int _return_value;
  69. character = _PyLong_AsInt(arg);
  70. if (character == -1 && PyErr_Occurred()) {
  71. goto exit;
  72. }
  73. _return_value = _sre_unicode_iscased_impl(module, character);
  74. if ((_return_value == -1) && PyErr_Occurred()) {
  75. goto exit;
  76. }
  77. return_value = PyBool_FromLong((long)_return_value);
  78. exit:
  79. return return_value;
  80. }
  81. PyDoc_STRVAR(_sre_ascii_tolower__doc__,
  82. "ascii_tolower($module, character, /)\n"
  83. "--\n"
  84. "\n");
  85. #define _SRE_ASCII_TOLOWER_METHODDEF \
  86. {"ascii_tolower", (PyCFunction)_sre_ascii_tolower, METH_O, _sre_ascii_tolower__doc__},
  87. static int
  88. _sre_ascii_tolower_impl(PyObject *module, int character);
  89. static PyObject *
  90. _sre_ascii_tolower(PyObject *module, PyObject *arg)
  91. {
  92. PyObject *return_value = NULL;
  93. int character;
  94. int _return_value;
  95. character = _PyLong_AsInt(arg);
  96. if (character == -1 && PyErr_Occurred()) {
  97. goto exit;
  98. }
  99. _return_value = _sre_ascii_tolower_impl(module, character);
  100. if ((_return_value == -1) && PyErr_Occurred()) {
  101. goto exit;
  102. }
  103. return_value = PyLong_FromLong((long)_return_value);
  104. exit:
  105. return return_value;
  106. }
  107. PyDoc_STRVAR(_sre_unicode_tolower__doc__,
  108. "unicode_tolower($module, character, /)\n"
  109. "--\n"
  110. "\n");
  111. #define _SRE_UNICODE_TOLOWER_METHODDEF \
  112. {"unicode_tolower", (PyCFunction)_sre_unicode_tolower, METH_O, _sre_unicode_tolower__doc__},
  113. static int
  114. _sre_unicode_tolower_impl(PyObject *module, int character);
  115. static PyObject *
  116. _sre_unicode_tolower(PyObject *module, PyObject *arg)
  117. {
  118. PyObject *return_value = NULL;
  119. int character;
  120. int _return_value;
  121. character = _PyLong_AsInt(arg);
  122. if (character == -1 && PyErr_Occurred()) {
  123. goto exit;
  124. }
  125. _return_value = _sre_unicode_tolower_impl(module, character);
  126. if ((_return_value == -1) && PyErr_Occurred()) {
  127. goto exit;
  128. }
  129. return_value = PyLong_FromLong((long)_return_value);
  130. exit:
  131. return return_value;
  132. }
  133. PyDoc_STRVAR(_sre_SRE_Pattern_match__doc__,
  134. "match($self, /, string, pos=0, endpos=sys.maxsize)\n"
  135. "--\n"
  136. "\n"
  137. "Matches zero or more characters at the beginning of the string.");
  138. #define _SRE_SRE_PATTERN_MATCH_METHODDEF \
  139. {"match", _PyCFunction_CAST(_sre_SRE_Pattern_match), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_match__doc__},
  140. static PyObject *
  141. _sre_SRE_Pattern_match_impl(PatternObject *self, PyTypeObject *cls,
  142. PyObject *string, Py_ssize_t pos,
  143. Py_ssize_t endpos);
  144. static PyObject *
  145. _sre_SRE_Pattern_match(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  146. {
  147. PyObject *return_value = NULL;
  148. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  149. #define NUM_KEYWORDS 3
  150. static struct {
  151. PyGC_Head _this_is_not_used;
  152. PyObject_VAR_HEAD
  153. PyObject *ob_item[NUM_KEYWORDS];
  154. } _kwtuple = {
  155. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  156. .ob_item = { &_Py_ID(string), &_Py_ID(pos), &_Py_ID(endpos), },
  157. };
  158. #undef NUM_KEYWORDS
  159. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  160. #else // !Py_BUILD_CORE
  161. # define KWTUPLE NULL
  162. #endif // !Py_BUILD_CORE
  163. static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
  164. static _PyArg_Parser _parser = {
  165. .keywords = _keywords,
  166. .fname = "match",
  167. .kwtuple = KWTUPLE,
  168. };
  169. #undef KWTUPLE
  170. PyObject *argsbuf[3];
  171. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  172. PyObject *string;
  173. Py_ssize_t pos = 0;
  174. Py_ssize_t endpos = PY_SSIZE_T_MAX;
  175. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
  176. if (!args) {
  177. goto exit;
  178. }
  179. string = args[0];
  180. if (!noptargs) {
  181. goto skip_optional_pos;
  182. }
  183. if (args[1]) {
  184. {
  185. Py_ssize_t ival = -1;
  186. PyObject *iobj = _PyNumber_Index(args[1]);
  187. if (iobj != NULL) {
  188. ival = PyLong_AsSsize_t(iobj);
  189. Py_DECREF(iobj);
  190. }
  191. if (ival == -1 && PyErr_Occurred()) {
  192. goto exit;
  193. }
  194. pos = ival;
  195. }
  196. if (!--noptargs) {
  197. goto skip_optional_pos;
  198. }
  199. }
  200. {
  201. Py_ssize_t ival = -1;
  202. PyObject *iobj = _PyNumber_Index(args[2]);
  203. if (iobj != NULL) {
  204. ival = PyLong_AsSsize_t(iobj);
  205. Py_DECREF(iobj);
  206. }
  207. if (ival == -1 && PyErr_Occurred()) {
  208. goto exit;
  209. }
  210. endpos = ival;
  211. }
  212. skip_optional_pos:
  213. return_value = _sre_SRE_Pattern_match_impl(self, cls, string, pos, endpos);
  214. exit:
  215. return return_value;
  216. }
  217. PyDoc_STRVAR(_sre_SRE_Pattern_fullmatch__doc__,
  218. "fullmatch($self, /, string, pos=0, endpos=sys.maxsize)\n"
  219. "--\n"
  220. "\n"
  221. "Matches against all of the string.");
  222. #define _SRE_SRE_PATTERN_FULLMATCH_METHODDEF \
  223. {"fullmatch", _PyCFunction_CAST(_sre_SRE_Pattern_fullmatch), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_fullmatch__doc__},
  224. static PyObject *
  225. _sre_SRE_Pattern_fullmatch_impl(PatternObject *self, PyTypeObject *cls,
  226. PyObject *string, Py_ssize_t pos,
  227. Py_ssize_t endpos);
  228. static PyObject *
  229. _sre_SRE_Pattern_fullmatch(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  230. {
  231. PyObject *return_value = NULL;
  232. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  233. #define NUM_KEYWORDS 3
  234. static struct {
  235. PyGC_Head _this_is_not_used;
  236. PyObject_VAR_HEAD
  237. PyObject *ob_item[NUM_KEYWORDS];
  238. } _kwtuple = {
  239. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  240. .ob_item = { &_Py_ID(string), &_Py_ID(pos), &_Py_ID(endpos), },
  241. };
  242. #undef NUM_KEYWORDS
  243. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  244. #else // !Py_BUILD_CORE
  245. # define KWTUPLE NULL
  246. #endif // !Py_BUILD_CORE
  247. static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
  248. static _PyArg_Parser _parser = {
  249. .keywords = _keywords,
  250. .fname = "fullmatch",
  251. .kwtuple = KWTUPLE,
  252. };
  253. #undef KWTUPLE
  254. PyObject *argsbuf[3];
  255. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  256. PyObject *string;
  257. Py_ssize_t pos = 0;
  258. Py_ssize_t endpos = PY_SSIZE_T_MAX;
  259. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
  260. if (!args) {
  261. goto exit;
  262. }
  263. string = args[0];
  264. if (!noptargs) {
  265. goto skip_optional_pos;
  266. }
  267. if (args[1]) {
  268. {
  269. Py_ssize_t ival = -1;
  270. PyObject *iobj = _PyNumber_Index(args[1]);
  271. if (iobj != NULL) {
  272. ival = PyLong_AsSsize_t(iobj);
  273. Py_DECREF(iobj);
  274. }
  275. if (ival == -1 && PyErr_Occurred()) {
  276. goto exit;
  277. }
  278. pos = ival;
  279. }
  280. if (!--noptargs) {
  281. goto skip_optional_pos;
  282. }
  283. }
  284. {
  285. Py_ssize_t ival = -1;
  286. PyObject *iobj = _PyNumber_Index(args[2]);
  287. if (iobj != NULL) {
  288. ival = PyLong_AsSsize_t(iobj);
  289. Py_DECREF(iobj);
  290. }
  291. if (ival == -1 && PyErr_Occurred()) {
  292. goto exit;
  293. }
  294. endpos = ival;
  295. }
  296. skip_optional_pos:
  297. return_value = _sre_SRE_Pattern_fullmatch_impl(self, cls, string, pos, endpos);
  298. exit:
  299. return return_value;
  300. }
  301. PyDoc_STRVAR(_sre_SRE_Pattern_search__doc__,
  302. "search($self, /, string, pos=0, endpos=sys.maxsize)\n"
  303. "--\n"
  304. "\n"
  305. "Scan through string looking for a match, and return a corresponding match object instance.\n"
  306. "\n"
  307. "Return None if no position in the string matches.");
  308. #define _SRE_SRE_PATTERN_SEARCH_METHODDEF \
  309. {"search", _PyCFunction_CAST(_sre_SRE_Pattern_search), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_search__doc__},
  310. static PyObject *
  311. _sre_SRE_Pattern_search_impl(PatternObject *self, PyTypeObject *cls,
  312. PyObject *string, Py_ssize_t pos,
  313. Py_ssize_t endpos);
  314. static PyObject *
  315. _sre_SRE_Pattern_search(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  316. {
  317. PyObject *return_value = NULL;
  318. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  319. #define NUM_KEYWORDS 3
  320. static struct {
  321. PyGC_Head _this_is_not_used;
  322. PyObject_VAR_HEAD
  323. PyObject *ob_item[NUM_KEYWORDS];
  324. } _kwtuple = {
  325. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  326. .ob_item = { &_Py_ID(string), &_Py_ID(pos), &_Py_ID(endpos), },
  327. };
  328. #undef NUM_KEYWORDS
  329. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  330. #else // !Py_BUILD_CORE
  331. # define KWTUPLE NULL
  332. #endif // !Py_BUILD_CORE
  333. static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
  334. static _PyArg_Parser _parser = {
  335. .keywords = _keywords,
  336. .fname = "search",
  337. .kwtuple = KWTUPLE,
  338. };
  339. #undef KWTUPLE
  340. PyObject *argsbuf[3];
  341. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  342. PyObject *string;
  343. Py_ssize_t pos = 0;
  344. Py_ssize_t endpos = PY_SSIZE_T_MAX;
  345. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
  346. if (!args) {
  347. goto exit;
  348. }
  349. string = args[0];
  350. if (!noptargs) {
  351. goto skip_optional_pos;
  352. }
  353. if (args[1]) {
  354. {
  355. Py_ssize_t ival = -1;
  356. PyObject *iobj = _PyNumber_Index(args[1]);
  357. if (iobj != NULL) {
  358. ival = PyLong_AsSsize_t(iobj);
  359. Py_DECREF(iobj);
  360. }
  361. if (ival == -1 && PyErr_Occurred()) {
  362. goto exit;
  363. }
  364. pos = ival;
  365. }
  366. if (!--noptargs) {
  367. goto skip_optional_pos;
  368. }
  369. }
  370. {
  371. Py_ssize_t ival = -1;
  372. PyObject *iobj = _PyNumber_Index(args[2]);
  373. if (iobj != NULL) {
  374. ival = PyLong_AsSsize_t(iobj);
  375. Py_DECREF(iobj);
  376. }
  377. if (ival == -1 && PyErr_Occurred()) {
  378. goto exit;
  379. }
  380. endpos = ival;
  381. }
  382. skip_optional_pos:
  383. return_value = _sre_SRE_Pattern_search_impl(self, cls, string, pos, endpos);
  384. exit:
  385. return return_value;
  386. }
  387. PyDoc_STRVAR(_sre_SRE_Pattern_findall__doc__,
  388. "findall($self, /, string, pos=0, endpos=sys.maxsize)\n"
  389. "--\n"
  390. "\n"
  391. "Return a list of all non-overlapping matches of pattern in string.");
  392. #define _SRE_SRE_PATTERN_FINDALL_METHODDEF \
  393. {"findall", _PyCFunction_CAST(_sre_SRE_Pattern_findall), METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_findall__doc__},
  394. static PyObject *
  395. _sre_SRE_Pattern_findall_impl(PatternObject *self, PyObject *string,
  396. Py_ssize_t pos, Py_ssize_t endpos);
  397. static PyObject *
  398. _sre_SRE_Pattern_findall(PatternObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  399. {
  400. PyObject *return_value = NULL;
  401. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  402. #define NUM_KEYWORDS 3
  403. static struct {
  404. PyGC_Head _this_is_not_used;
  405. PyObject_VAR_HEAD
  406. PyObject *ob_item[NUM_KEYWORDS];
  407. } _kwtuple = {
  408. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  409. .ob_item = { &_Py_ID(string), &_Py_ID(pos), &_Py_ID(endpos), },
  410. };
  411. #undef NUM_KEYWORDS
  412. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  413. #else // !Py_BUILD_CORE
  414. # define KWTUPLE NULL
  415. #endif // !Py_BUILD_CORE
  416. static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
  417. static _PyArg_Parser _parser = {
  418. .keywords = _keywords,
  419. .fname = "findall",
  420. .kwtuple = KWTUPLE,
  421. };
  422. #undef KWTUPLE
  423. PyObject *argsbuf[3];
  424. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  425. PyObject *string;
  426. Py_ssize_t pos = 0;
  427. Py_ssize_t endpos = PY_SSIZE_T_MAX;
  428. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
  429. if (!args) {
  430. goto exit;
  431. }
  432. string = args[0];
  433. if (!noptargs) {
  434. goto skip_optional_pos;
  435. }
  436. if (args[1]) {
  437. {
  438. Py_ssize_t ival = -1;
  439. PyObject *iobj = _PyNumber_Index(args[1]);
  440. if (iobj != NULL) {
  441. ival = PyLong_AsSsize_t(iobj);
  442. Py_DECREF(iobj);
  443. }
  444. if (ival == -1 && PyErr_Occurred()) {
  445. goto exit;
  446. }
  447. pos = ival;
  448. }
  449. if (!--noptargs) {
  450. goto skip_optional_pos;
  451. }
  452. }
  453. {
  454. Py_ssize_t ival = -1;
  455. PyObject *iobj = _PyNumber_Index(args[2]);
  456. if (iobj != NULL) {
  457. ival = PyLong_AsSsize_t(iobj);
  458. Py_DECREF(iobj);
  459. }
  460. if (ival == -1 && PyErr_Occurred()) {
  461. goto exit;
  462. }
  463. endpos = ival;
  464. }
  465. skip_optional_pos:
  466. return_value = _sre_SRE_Pattern_findall_impl(self, string, pos, endpos);
  467. exit:
  468. return return_value;
  469. }
  470. PyDoc_STRVAR(_sre_SRE_Pattern_finditer__doc__,
  471. "finditer($self, /, string, pos=0, endpos=sys.maxsize)\n"
  472. "--\n"
  473. "\n"
  474. "Return an iterator over all non-overlapping matches for the RE pattern in string.\n"
  475. "\n"
  476. "For each match, the iterator returns a match object.");
  477. #define _SRE_SRE_PATTERN_FINDITER_METHODDEF \
  478. {"finditer", _PyCFunction_CAST(_sre_SRE_Pattern_finditer), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_finditer__doc__},
  479. static PyObject *
  480. _sre_SRE_Pattern_finditer_impl(PatternObject *self, PyTypeObject *cls,
  481. PyObject *string, Py_ssize_t pos,
  482. Py_ssize_t endpos);
  483. static PyObject *
  484. _sre_SRE_Pattern_finditer(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  485. {
  486. PyObject *return_value = NULL;
  487. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  488. #define NUM_KEYWORDS 3
  489. static struct {
  490. PyGC_Head _this_is_not_used;
  491. PyObject_VAR_HEAD
  492. PyObject *ob_item[NUM_KEYWORDS];
  493. } _kwtuple = {
  494. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  495. .ob_item = { &_Py_ID(string), &_Py_ID(pos), &_Py_ID(endpos), },
  496. };
  497. #undef NUM_KEYWORDS
  498. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  499. #else // !Py_BUILD_CORE
  500. # define KWTUPLE NULL
  501. #endif // !Py_BUILD_CORE
  502. static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
  503. static _PyArg_Parser _parser = {
  504. .keywords = _keywords,
  505. .fname = "finditer",
  506. .kwtuple = KWTUPLE,
  507. };
  508. #undef KWTUPLE
  509. PyObject *argsbuf[3];
  510. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  511. PyObject *string;
  512. Py_ssize_t pos = 0;
  513. Py_ssize_t endpos = PY_SSIZE_T_MAX;
  514. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
  515. if (!args) {
  516. goto exit;
  517. }
  518. string = args[0];
  519. if (!noptargs) {
  520. goto skip_optional_pos;
  521. }
  522. if (args[1]) {
  523. {
  524. Py_ssize_t ival = -1;
  525. PyObject *iobj = _PyNumber_Index(args[1]);
  526. if (iobj != NULL) {
  527. ival = PyLong_AsSsize_t(iobj);
  528. Py_DECREF(iobj);
  529. }
  530. if (ival == -1 && PyErr_Occurred()) {
  531. goto exit;
  532. }
  533. pos = ival;
  534. }
  535. if (!--noptargs) {
  536. goto skip_optional_pos;
  537. }
  538. }
  539. {
  540. Py_ssize_t ival = -1;
  541. PyObject *iobj = _PyNumber_Index(args[2]);
  542. if (iobj != NULL) {
  543. ival = PyLong_AsSsize_t(iobj);
  544. Py_DECREF(iobj);
  545. }
  546. if (ival == -1 && PyErr_Occurred()) {
  547. goto exit;
  548. }
  549. endpos = ival;
  550. }
  551. skip_optional_pos:
  552. return_value = _sre_SRE_Pattern_finditer_impl(self, cls, string, pos, endpos);
  553. exit:
  554. return return_value;
  555. }
  556. PyDoc_STRVAR(_sre_SRE_Pattern_scanner__doc__,
  557. "scanner($self, /, string, pos=0, endpos=sys.maxsize)\n"
  558. "--\n"
  559. "\n");
  560. #define _SRE_SRE_PATTERN_SCANNER_METHODDEF \
  561. {"scanner", _PyCFunction_CAST(_sre_SRE_Pattern_scanner), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_scanner__doc__},
  562. static PyObject *
  563. _sre_SRE_Pattern_scanner_impl(PatternObject *self, PyTypeObject *cls,
  564. PyObject *string, Py_ssize_t pos,
  565. Py_ssize_t endpos);
  566. static PyObject *
  567. _sre_SRE_Pattern_scanner(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  568. {
  569. PyObject *return_value = NULL;
  570. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  571. #define NUM_KEYWORDS 3
  572. static struct {
  573. PyGC_Head _this_is_not_used;
  574. PyObject_VAR_HEAD
  575. PyObject *ob_item[NUM_KEYWORDS];
  576. } _kwtuple = {
  577. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  578. .ob_item = { &_Py_ID(string), &_Py_ID(pos), &_Py_ID(endpos), },
  579. };
  580. #undef NUM_KEYWORDS
  581. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  582. #else // !Py_BUILD_CORE
  583. # define KWTUPLE NULL
  584. #endif // !Py_BUILD_CORE
  585. static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
  586. static _PyArg_Parser _parser = {
  587. .keywords = _keywords,
  588. .fname = "scanner",
  589. .kwtuple = KWTUPLE,
  590. };
  591. #undef KWTUPLE
  592. PyObject *argsbuf[3];
  593. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  594. PyObject *string;
  595. Py_ssize_t pos = 0;
  596. Py_ssize_t endpos = PY_SSIZE_T_MAX;
  597. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
  598. if (!args) {
  599. goto exit;
  600. }
  601. string = args[0];
  602. if (!noptargs) {
  603. goto skip_optional_pos;
  604. }
  605. if (args[1]) {
  606. {
  607. Py_ssize_t ival = -1;
  608. PyObject *iobj = _PyNumber_Index(args[1]);
  609. if (iobj != NULL) {
  610. ival = PyLong_AsSsize_t(iobj);
  611. Py_DECREF(iobj);
  612. }
  613. if (ival == -1 && PyErr_Occurred()) {
  614. goto exit;
  615. }
  616. pos = ival;
  617. }
  618. if (!--noptargs) {
  619. goto skip_optional_pos;
  620. }
  621. }
  622. {
  623. Py_ssize_t ival = -1;
  624. PyObject *iobj = _PyNumber_Index(args[2]);
  625. if (iobj != NULL) {
  626. ival = PyLong_AsSsize_t(iobj);
  627. Py_DECREF(iobj);
  628. }
  629. if (ival == -1 && PyErr_Occurred()) {
  630. goto exit;
  631. }
  632. endpos = ival;
  633. }
  634. skip_optional_pos:
  635. return_value = _sre_SRE_Pattern_scanner_impl(self, cls, string, pos, endpos);
  636. exit:
  637. return return_value;
  638. }
  639. PyDoc_STRVAR(_sre_SRE_Pattern_split__doc__,
  640. "split($self, /, string, maxsplit=0)\n"
  641. "--\n"
  642. "\n"
  643. "Split string by the occurrences of pattern.");
  644. #define _SRE_SRE_PATTERN_SPLIT_METHODDEF \
  645. {"split", _PyCFunction_CAST(_sre_SRE_Pattern_split), METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_split__doc__},
  646. static PyObject *
  647. _sre_SRE_Pattern_split_impl(PatternObject *self, PyObject *string,
  648. Py_ssize_t maxsplit);
  649. static PyObject *
  650. _sre_SRE_Pattern_split(PatternObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  651. {
  652. PyObject *return_value = NULL;
  653. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  654. #define NUM_KEYWORDS 2
  655. static struct {
  656. PyGC_Head _this_is_not_used;
  657. PyObject_VAR_HEAD
  658. PyObject *ob_item[NUM_KEYWORDS];
  659. } _kwtuple = {
  660. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  661. .ob_item = { &_Py_ID(string), &_Py_ID(maxsplit), },
  662. };
  663. #undef NUM_KEYWORDS
  664. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  665. #else // !Py_BUILD_CORE
  666. # define KWTUPLE NULL
  667. #endif // !Py_BUILD_CORE
  668. static const char * const _keywords[] = {"string", "maxsplit", NULL};
  669. static _PyArg_Parser _parser = {
  670. .keywords = _keywords,
  671. .fname = "split",
  672. .kwtuple = KWTUPLE,
  673. };
  674. #undef KWTUPLE
  675. PyObject *argsbuf[2];
  676. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  677. PyObject *string;
  678. Py_ssize_t maxsplit = 0;
  679. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
  680. if (!args) {
  681. goto exit;
  682. }
  683. string = args[0];
  684. if (!noptargs) {
  685. goto skip_optional_pos;
  686. }
  687. {
  688. Py_ssize_t ival = -1;
  689. PyObject *iobj = _PyNumber_Index(args[1]);
  690. if (iobj != NULL) {
  691. ival = PyLong_AsSsize_t(iobj);
  692. Py_DECREF(iobj);
  693. }
  694. if (ival == -1 && PyErr_Occurred()) {
  695. goto exit;
  696. }
  697. maxsplit = ival;
  698. }
  699. skip_optional_pos:
  700. return_value = _sre_SRE_Pattern_split_impl(self, string, maxsplit);
  701. exit:
  702. return return_value;
  703. }
  704. PyDoc_STRVAR(_sre_SRE_Pattern_sub__doc__,
  705. "sub($self, /, repl, string, count=0)\n"
  706. "--\n"
  707. "\n"
  708. "Return the string obtained by replacing the leftmost non-overlapping occurrences of pattern in string by the replacement repl.");
  709. #define _SRE_SRE_PATTERN_SUB_METHODDEF \
  710. {"sub", _PyCFunction_CAST(_sre_SRE_Pattern_sub), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_sub__doc__},
  711. static PyObject *
  712. _sre_SRE_Pattern_sub_impl(PatternObject *self, PyTypeObject *cls,
  713. PyObject *repl, PyObject *string, Py_ssize_t count);
  714. static PyObject *
  715. _sre_SRE_Pattern_sub(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  716. {
  717. PyObject *return_value = NULL;
  718. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  719. #define NUM_KEYWORDS 3
  720. static struct {
  721. PyGC_Head _this_is_not_used;
  722. PyObject_VAR_HEAD
  723. PyObject *ob_item[NUM_KEYWORDS];
  724. } _kwtuple = {
  725. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  726. .ob_item = { &_Py_ID(repl), &_Py_ID(string), &_Py_ID(count), },
  727. };
  728. #undef NUM_KEYWORDS
  729. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  730. #else // !Py_BUILD_CORE
  731. # define KWTUPLE NULL
  732. #endif // !Py_BUILD_CORE
  733. static const char * const _keywords[] = {"repl", "string", "count", NULL};
  734. static _PyArg_Parser _parser = {
  735. .keywords = _keywords,
  736. .fname = "sub",
  737. .kwtuple = KWTUPLE,
  738. };
  739. #undef KWTUPLE
  740. PyObject *argsbuf[3];
  741. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
  742. PyObject *repl;
  743. PyObject *string;
  744. Py_ssize_t count = 0;
  745. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
  746. if (!args) {
  747. goto exit;
  748. }
  749. repl = args[0];
  750. string = args[1];
  751. if (!noptargs) {
  752. goto skip_optional_pos;
  753. }
  754. {
  755. Py_ssize_t ival = -1;
  756. PyObject *iobj = _PyNumber_Index(args[2]);
  757. if (iobj != NULL) {
  758. ival = PyLong_AsSsize_t(iobj);
  759. Py_DECREF(iobj);
  760. }
  761. if (ival == -1 && PyErr_Occurred()) {
  762. goto exit;
  763. }
  764. count = ival;
  765. }
  766. skip_optional_pos:
  767. return_value = _sre_SRE_Pattern_sub_impl(self, cls, repl, string, count);
  768. exit:
  769. return return_value;
  770. }
  771. PyDoc_STRVAR(_sre_SRE_Pattern_subn__doc__,
  772. "subn($self, /, repl, string, count=0)\n"
  773. "--\n"
  774. "\n"
  775. "Return the tuple (new_string, number_of_subs_made) found by replacing the leftmost non-overlapping occurrences of pattern with the replacement repl.");
  776. #define _SRE_SRE_PATTERN_SUBN_METHODDEF \
  777. {"subn", _PyCFunction_CAST(_sre_SRE_Pattern_subn), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_subn__doc__},
  778. static PyObject *
  779. _sre_SRE_Pattern_subn_impl(PatternObject *self, PyTypeObject *cls,
  780. PyObject *repl, PyObject *string,
  781. Py_ssize_t count);
  782. static PyObject *
  783. _sre_SRE_Pattern_subn(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  784. {
  785. PyObject *return_value = NULL;
  786. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  787. #define NUM_KEYWORDS 3
  788. static struct {
  789. PyGC_Head _this_is_not_used;
  790. PyObject_VAR_HEAD
  791. PyObject *ob_item[NUM_KEYWORDS];
  792. } _kwtuple = {
  793. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  794. .ob_item = { &_Py_ID(repl), &_Py_ID(string), &_Py_ID(count), },
  795. };
  796. #undef NUM_KEYWORDS
  797. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  798. #else // !Py_BUILD_CORE
  799. # define KWTUPLE NULL
  800. #endif // !Py_BUILD_CORE
  801. static const char * const _keywords[] = {"repl", "string", "count", NULL};
  802. static _PyArg_Parser _parser = {
  803. .keywords = _keywords,
  804. .fname = "subn",
  805. .kwtuple = KWTUPLE,
  806. };
  807. #undef KWTUPLE
  808. PyObject *argsbuf[3];
  809. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
  810. PyObject *repl;
  811. PyObject *string;
  812. Py_ssize_t count = 0;
  813. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
  814. if (!args) {
  815. goto exit;
  816. }
  817. repl = args[0];
  818. string = args[1];
  819. if (!noptargs) {
  820. goto skip_optional_pos;
  821. }
  822. {
  823. Py_ssize_t ival = -1;
  824. PyObject *iobj = _PyNumber_Index(args[2]);
  825. if (iobj != NULL) {
  826. ival = PyLong_AsSsize_t(iobj);
  827. Py_DECREF(iobj);
  828. }
  829. if (ival == -1 && PyErr_Occurred()) {
  830. goto exit;
  831. }
  832. count = ival;
  833. }
  834. skip_optional_pos:
  835. return_value = _sre_SRE_Pattern_subn_impl(self, cls, repl, string, count);
  836. exit:
  837. return return_value;
  838. }
  839. PyDoc_STRVAR(_sre_SRE_Pattern___copy____doc__,
  840. "__copy__($self, /)\n"
  841. "--\n"
  842. "\n");
  843. #define _SRE_SRE_PATTERN___COPY___METHODDEF \
  844. {"__copy__", (PyCFunction)_sre_SRE_Pattern___copy__, METH_NOARGS, _sre_SRE_Pattern___copy____doc__},
  845. static PyObject *
  846. _sre_SRE_Pattern___copy___impl(PatternObject *self);
  847. static PyObject *
  848. _sre_SRE_Pattern___copy__(PatternObject *self, PyObject *Py_UNUSED(ignored))
  849. {
  850. return _sre_SRE_Pattern___copy___impl(self);
  851. }
  852. PyDoc_STRVAR(_sre_SRE_Pattern___deepcopy____doc__,
  853. "__deepcopy__($self, memo, /)\n"
  854. "--\n"
  855. "\n");
  856. #define _SRE_SRE_PATTERN___DEEPCOPY___METHODDEF \
  857. {"__deepcopy__", (PyCFunction)_sre_SRE_Pattern___deepcopy__, METH_O, _sre_SRE_Pattern___deepcopy____doc__},
  858. #if defined(Py_DEBUG)
  859. PyDoc_STRVAR(_sre_SRE_Pattern__fail_after__doc__,
  860. "_fail_after($self, count, exception, /)\n"
  861. "--\n"
  862. "\n"
  863. "For debugging.");
  864. #define _SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF \
  865. {"_fail_after", _PyCFunction_CAST(_sre_SRE_Pattern__fail_after), METH_FASTCALL, _sre_SRE_Pattern__fail_after__doc__},
  866. static PyObject *
  867. _sre_SRE_Pattern__fail_after_impl(PatternObject *self, int count,
  868. PyObject *exception);
  869. static PyObject *
  870. _sre_SRE_Pattern__fail_after(PatternObject *self, PyObject *const *args, Py_ssize_t nargs)
  871. {
  872. PyObject *return_value = NULL;
  873. int count;
  874. PyObject *exception;
  875. if (!_PyArg_CheckPositional("_fail_after", nargs, 2, 2)) {
  876. goto exit;
  877. }
  878. count = _PyLong_AsInt(args[0]);
  879. if (count == -1 && PyErr_Occurred()) {
  880. goto exit;
  881. }
  882. exception = args[1];
  883. return_value = _sre_SRE_Pattern__fail_after_impl(self, count, exception);
  884. exit:
  885. return return_value;
  886. }
  887. #endif /* defined(Py_DEBUG) */
  888. PyDoc_STRVAR(_sre_compile__doc__,
  889. "compile($module, /, pattern, flags, code, groups, groupindex,\n"
  890. " indexgroup)\n"
  891. "--\n"
  892. "\n");
  893. #define _SRE_COMPILE_METHODDEF \
  894. {"compile", _PyCFunction_CAST(_sre_compile), METH_FASTCALL|METH_KEYWORDS, _sre_compile__doc__},
  895. static PyObject *
  896. _sre_compile_impl(PyObject *module, PyObject *pattern, int flags,
  897. PyObject *code, Py_ssize_t groups, PyObject *groupindex,
  898. PyObject *indexgroup);
  899. static PyObject *
  900. _sre_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  901. {
  902. PyObject *return_value = NULL;
  903. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  904. #define NUM_KEYWORDS 6
  905. static struct {
  906. PyGC_Head _this_is_not_used;
  907. PyObject_VAR_HEAD
  908. PyObject *ob_item[NUM_KEYWORDS];
  909. } _kwtuple = {
  910. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  911. .ob_item = { &_Py_ID(pattern), &_Py_ID(flags), &_Py_ID(code), &_Py_ID(groups), &_Py_ID(groupindex), &_Py_ID(indexgroup), },
  912. };
  913. #undef NUM_KEYWORDS
  914. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  915. #else // !Py_BUILD_CORE
  916. # define KWTUPLE NULL
  917. #endif // !Py_BUILD_CORE
  918. static const char * const _keywords[] = {"pattern", "flags", "code", "groups", "groupindex", "indexgroup", NULL};
  919. static _PyArg_Parser _parser = {
  920. .keywords = _keywords,
  921. .fname = "compile",
  922. .kwtuple = KWTUPLE,
  923. };
  924. #undef KWTUPLE
  925. PyObject *argsbuf[6];
  926. PyObject *pattern;
  927. int flags;
  928. PyObject *code;
  929. Py_ssize_t groups;
  930. PyObject *groupindex;
  931. PyObject *indexgroup;
  932. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 6, 6, 0, argsbuf);
  933. if (!args) {
  934. goto exit;
  935. }
  936. pattern = args[0];
  937. flags = _PyLong_AsInt(args[1]);
  938. if (flags == -1 && PyErr_Occurred()) {
  939. goto exit;
  940. }
  941. if (!PyList_Check(args[2])) {
  942. _PyArg_BadArgument("compile", "argument 'code'", "list", args[2]);
  943. goto exit;
  944. }
  945. code = args[2];
  946. {
  947. Py_ssize_t ival = -1;
  948. PyObject *iobj = _PyNumber_Index(args[3]);
  949. if (iobj != NULL) {
  950. ival = PyLong_AsSsize_t(iobj);
  951. Py_DECREF(iobj);
  952. }
  953. if (ival == -1 && PyErr_Occurred()) {
  954. goto exit;
  955. }
  956. groups = ival;
  957. }
  958. if (!PyDict_Check(args[4])) {
  959. _PyArg_BadArgument("compile", "argument 'groupindex'", "dict", args[4]);
  960. goto exit;
  961. }
  962. groupindex = args[4];
  963. if (!PyTuple_Check(args[5])) {
  964. _PyArg_BadArgument("compile", "argument 'indexgroup'", "tuple", args[5]);
  965. goto exit;
  966. }
  967. indexgroup = args[5];
  968. return_value = _sre_compile_impl(module, pattern, flags, code, groups, groupindex, indexgroup);
  969. exit:
  970. return return_value;
  971. }
  972. PyDoc_STRVAR(_sre_template__doc__,
  973. "template($module, pattern, template, /)\n"
  974. "--\n"
  975. "\n"
  976. "\n"
  977. "\n"
  978. " template\n"
  979. " A list containing interleaved literal strings (str or bytes) and group\n"
  980. " indices (int), as returned by re._parser.parse_template():\n"
  981. " [literal1, group1, ..., literalN, groupN]");
  982. #define _SRE_TEMPLATE_METHODDEF \
  983. {"template", _PyCFunction_CAST(_sre_template), METH_FASTCALL, _sre_template__doc__},
  984. static PyObject *
  985. _sre_template_impl(PyObject *module, PyObject *pattern, PyObject *template);
  986. static PyObject *
  987. _sre_template(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  988. {
  989. PyObject *return_value = NULL;
  990. PyObject *pattern;
  991. PyObject *template;
  992. if (!_PyArg_CheckPositional("template", nargs, 2, 2)) {
  993. goto exit;
  994. }
  995. pattern = args[0];
  996. if (!PyList_Check(args[1])) {
  997. _PyArg_BadArgument("template", "argument 2", "list", args[1]);
  998. goto exit;
  999. }
  1000. template = args[1];
  1001. return_value = _sre_template_impl(module, pattern, template);
  1002. exit:
  1003. return return_value;
  1004. }
  1005. PyDoc_STRVAR(_sre_SRE_Match_expand__doc__,
  1006. "expand($self, /, template)\n"
  1007. "--\n"
  1008. "\n"
  1009. "Return the string obtained by doing backslash substitution on the string template, as done by the sub() method.");
  1010. #define _SRE_SRE_MATCH_EXPAND_METHODDEF \
  1011. {"expand", _PyCFunction_CAST(_sre_SRE_Match_expand), METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Match_expand__doc__},
  1012. static PyObject *
  1013. _sre_SRE_Match_expand_impl(MatchObject *self, PyObject *template);
  1014. static PyObject *
  1015. _sre_SRE_Match_expand(MatchObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1016. {
  1017. PyObject *return_value = NULL;
  1018. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1019. #define NUM_KEYWORDS 1
  1020. static struct {
  1021. PyGC_Head _this_is_not_used;
  1022. PyObject_VAR_HEAD
  1023. PyObject *ob_item[NUM_KEYWORDS];
  1024. } _kwtuple = {
  1025. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1026. .ob_item = { &_Py_ID(template), },
  1027. };
  1028. #undef NUM_KEYWORDS
  1029. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1030. #else // !Py_BUILD_CORE
  1031. # define KWTUPLE NULL
  1032. #endif // !Py_BUILD_CORE
  1033. static const char * const _keywords[] = {"template", NULL};
  1034. static _PyArg_Parser _parser = {
  1035. .keywords = _keywords,
  1036. .fname = "expand",
  1037. .kwtuple = KWTUPLE,
  1038. };
  1039. #undef KWTUPLE
  1040. PyObject *argsbuf[1];
  1041. PyObject *template;
  1042. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  1043. if (!args) {
  1044. goto exit;
  1045. }
  1046. template = args[0];
  1047. return_value = _sre_SRE_Match_expand_impl(self, template);
  1048. exit:
  1049. return return_value;
  1050. }
  1051. PyDoc_STRVAR(_sre_SRE_Match_groups__doc__,
  1052. "groups($self, /, default=None)\n"
  1053. "--\n"
  1054. "\n"
  1055. "Return a tuple containing all the subgroups of the match, from 1.\n"
  1056. "\n"
  1057. " default\n"
  1058. " Is used for groups that did not participate in the match.");
  1059. #define _SRE_SRE_MATCH_GROUPS_METHODDEF \
  1060. {"groups", _PyCFunction_CAST(_sre_SRE_Match_groups), METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Match_groups__doc__},
  1061. static PyObject *
  1062. _sre_SRE_Match_groups_impl(MatchObject *self, PyObject *default_value);
  1063. static PyObject *
  1064. _sre_SRE_Match_groups(MatchObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1065. {
  1066. PyObject *return_value = NULL;
  1067. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1068. #define NUM_KEYWORDS 1
  1069. static struct {
  1070. PyGC_Head _this_is_not_used;
  1071. PyObject_VAR_HEAD
  1072. PyObject *ob_item[NUM_KEYWORDS];
  1073. } _kwtuple = {
  1074. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1075. .ob_item = { &_Py_ID(default), },
  1076. };
  1077. #undef NUM_KEYWORDS
  1078. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1079. #else // !Py_BUILD_CORE
  1080. # define KWTUPLE NULL
  1081. #endif // !Py_BUILD_CORE
  1082. static const char * const _keywords[] = {"default", NULL};
  1083. static _PyArg_Parser _parser = {
  1084. .keywords = _keywords,
  1085. .fname = "groups",
  1086. .kwtuple = KWTUPLE,
  1087. };
  1088. #undef KWTUPLE
  1089. PyObject *argsbuf[1];
  1090. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  1091. PyObject *default_value = Py_None;
  1092. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
  1093. if (!args) {
  1094. goto exit;
  1095. }
  1096. if (!noptargs) {
  1097. goto skip_optional_pos;
  1098. }
  1099. default_value = args[0];
  1100. skip_optional_pos:
  1101. return_value = _sre_SRE_Match_groups_impl(self, default_value);
  1102. exit:
  1103. return return_value;
  1104. }
  1105. PyDoc_STRVAR(_sre_SRE_Match_groupdict__doc__,
  1106. "groupdict($self, /, default=None)\n"
  1107. "--\n"
  1108. "\n"
  1109. "Return a dictionary containing all the named subgroups of the match, keyed by the subgroup name.\n"
  1110. "\n"
  1111. " default\n"
  1112. " Is used for groups that did not participate in the match.");
  1113. #define _SRE_SRE_MATCH_GROUPDICT_METHODDEF \
  1114. {"groupdict", _PyCFunction_CAST(_sre_SRE_Match_groupdict), METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Match_groupdict__doc__},
  1115. static PyObject *
  1116. _sre_SRE_Match_groupdict_impl(MatchObject *self, PyObject *default_value);
  1117. static PyObject *
  1118. _sre_SRE_Match_groupdict(MatchObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1119. {
  1120. PyObject *return_value = NULL;
  1121. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1122. #define NUM_KEYWORDS 1
  1123. static struct {
  1124. PyGC_Head _this_is_not_used;
  1125. PyObject_VAR_HEAD
  1126. PyObject *ob_item[NUM_KEYWORDS];
  1127. } _kwtuple = {
  1128. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1129. .ob_item = { &_Py_ID(default), },
  1130. };
  1131. #undef NUM_KEYWORDS
  1132. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1133. #else // !Py_BUILD_CORE
  1134. # define KWTUPLE NULL
  1135. #endif // !Py_BUILD_CORE
  1136. static const char * const _keywords[] = {"default", NULL};
  1137. static _PyArg_Parser _parser = {
  1138. .keywords = _keywords,
  1139. .fname = "groupdict",
  1140. .kwtuple = KWTUPLE,
  1141. };
  1142. #undef KWTUPLE
  1143. PyObject *argsbuf[1];
  1144. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  1145. PyObject *default_value = Py_None;
  1146. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
  1147. if (!args) {
  1148. goto exit;
  1149. }
  1150. if (!noptargs) {
  1151. goto skip_optional_pos;
  1152. }
  1153. default_value = args[0];
  1154. skip_optional_pos:
  1155. return_value = _sre_SRE_Match_groupdict_impl(self, default_value);
  1156. exit:
  1157. return return_value;
  1158. }
  1159. PyDoc_STRVAR(_sre_SRE_Match_start__doc__,
  1160. "start($self, group=0, /)\n"
  1161. "--\n"
  1162. "\n"
  1163. "Return index of the start of the substring matched by group.");
  1164. #define _SRE_SRE_MATCH_START_METHODDEF \
  1165. {"start", _PyCFunction_CAST(_sre_SRE_Match_start), METH_FASTCALL, _sre_SRE_Match_start__doc__},
  1166. static Py_ssize_t
  1167. _sre_SRE_Match_start_impl(MatchObject *self, PyObject *group);
  1168. static PyObject *
  1169. _sre_SRE_Match_start(MatchObject *self, PyObject *const *args, Py_ssize_t nargs)
  1170. {
  1171. PyObject *return_value = NULL;
  1172. PyObject *group = NULL;
  1173. Py_ssize_t _return_value;
  1174. if (!_PyArg_CheckPositional("start", nargs, 0, 1)) {
  1175. goto exit;
  1176. }
  1177. if (nargs < 1) {
  1178. goto skip_optional;
  1179. }
  1180. group = args[0];
  1181. skip_optional:
  1182. _return_value = _sre_SRE_Match_start_impl(self, group);
  1183. if ((_return_value == -1) && PyErr_Occurred()) {
  1184. goto exit;
  1185. }
  1186. return_value = PyLong_FromSsize_t(_return_value);
  1187. exit:
  1188. return return_value;
  1189. }
  1190. PyDoc_STRVAR(_sre_SRE_Match_end__doc__,
  1191. "end($self, group=0, /)\n"
  1192. "--\n"
  1193. "\n"
  1194. "Return index of the end of the substring matched by group.");
  1195. #define _SRE_SRE_MATCH_END_METHODDEF \
  1196. {"end", _PyCFunction_CAST(_sre_SRE_Match_end), METH_FASTCALL, _sre_SRE_Match_end__doc__},
  1197. static Py_ssize_t
  1198. _sre_SRE_Match_end_impl(MatchObject *self, PyObject *group);
  1199. static PyObject *
  1200. _sre_SRE_Match_end(MatchObject *self, PyObject *const *args, Py_ssize_t nargs)
  1201. {
  1202. PyObject *return_value = NULL;
  1203. PyObject *group = NULL;
  1204. Py_ssize_t _return_value;
  1205. if (!_PyArg_CheckPositional("end", nargs, 0, 1)) {
  1206. goto exit;
  1207. }
  1208. if (nargs < 1) {
  1209. goto skip_optional;
  1210. }
  1211. group = args[0];
  1212. skip_optional:
  1213. _return_value = _sre_SRE_Match_end_impl(self, group);
  1214. if ((_return_value == -1) && PyErr_Occurred()) {
  1215. goto exit;
  1216. }
  1217. return_value = PyLong_FromSsize_t(_return_value);
  1218. exit:
  1219. return return_value;
  1220. }
  1221. PyDoc_STRVAR(_sre_SRE_Match_span__doc__,
  1222. "span($self, group=0, /)\n"
  1223. "--\n"
  1224. "\n"
  1225. "For match object m, return the 2-tuple (m.start(group), m.end(group)).");
  1226. #define _SRE_SRE_MATCH_SPAN_METHODDEF \
  1227. {"span", _PyCFunction_CAST(_sre_SRE_Match_span), METH_FASTCALL, _sre_SRE_Match_span__doc__},
  1228. static PyObject *
  1229. _sre_SRE_Match_span_impl(MatchObject *self, PyObject *group);
  1230. static PyObject *
  1231. _sre_SRE_Match_span(MatchObject *self, PyObject *const *args, Py_ssize_t nargs)
  1232. {
  1233. PyObject *return_value = NULL;
  1234. PyObject *group = NULL;
  1235. if (!_PyArg_CheckPositional("span", nargs, 0, 1)) {
  1236. goto exit;
  1237. }
  1238. if (nargs < 1) {
  1239. goto skip_optional;
  1240. }
  1241. group = args[0];
  1242. skip_optional:
  1243. return_value = _sre_SRE_Match_span_impl(self, group);
  1244. exit:
  1245. return return_value;
  1246. }
  1247. PyDoc_STRVAR(_sre_SRE_Match___copy____doc__,
  1248. "__copy__($self, /)\n"
  1249. "--\n"
  1250. "\n");
  1251. #define _SRE_SRE_MATCH___COPY___METHODDEF \
  1252. {"__copy__", (PyCFunction)_sre_SRE_Match___copy__, METH_NOARGS, _sre_SRE_Match___copy____doc__},
  1253. static PyObject *
  1254. _sre_SRE_Match___copy___impl(MatchObject *self);
  1255. static PyObject *
  1256. _sre_SRE_Match___copy__(MatchObject *self, PyObject *Py_UNUSED(ignored))
  1257. {
  1258. return _sre_SRE_Match___copy___impl(self);
  1259. }
  1260. PyDoc_STRVAR(_sre_SRE_Match___deepcopy____doc__,
  1261. "__deepcopy__($self, memo, /)\n"
  1262. "--\n"
  1263. "\n");
  1264. #define _SRE_SRE_MATCH___DEEPCOPY___METHODDEF \
  1265. {"__deepcopy__", (PyCFunction)_sre_SRE_Match___deepcopy__, METH_O, _sre_SRE_Match___deepcopy____doc__},
  1266. PyDoc_STRVAR(_sre_SRE_Scanner_match__doc__,
  1267. "match($self, /)\n"
  1268. "--\n"
  1269. "\n");
  1270. #define _SRE_SRE_SCANNER_MATCH_METHODDEF \
  1271. {"match", _PyCFunction_CAST(_sre_SRE_Scanner_match), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Scanner_match__doc__},
  1272. static PyObject *
  1273. _sre_SRE_Scanner_match_impl(ScannerObject *self, PyTypeObject *cls);
  1274. static PyObject *
  1275. _sre_SRE_Scanner_match(ScannerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1276. {
  1277. if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
  1278. PyErr_SetString(PyExc_TypeError, "match() takes no arguments");
  1279. return NULL;
  1280. }
  1281. return _sre_SRE_Scanner_match_impl(self, cls);
  1282. }
  1283. PyDoc_STRVAR(_sre_SRE_Scanner_search__doc__,
  1284. "search($self, /)\n"
  1285. "--\n"
  1286. "\n");
  1287. #define _SRE_SRE_SCANNER_SEARCH_METHODDEF \
  1288. {"search", _PyCFunction_CAST(_sre_SRE_Scanner_search), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Scanner_search__doc__},
  1289. static PyObject *
  1290. _sre_SRE_Scanner_search_impl(ScannerObject *self, PyTypeObject *cls);
  1291. static PyObject *
  1292. _sre_SRE_Scanner_search(ScannerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1293. {
  1294. if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
  1295. PyErr_SetString(PyExc_TypeError, "search() takes no arguments");
  1296. return NULL;
  1297. }
  1298. return _sre_SRE_Scanner_search_impl(self, cls);
  1299. }
  1300. #ifndef _SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF
  1301. #define _SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF
  1302. #endif /* !defined(_SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF) */
  1303. /*[clinic end generated code: output=2165ecf43a7c20e8 input=a9049054013a1b77]*/