1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 PyDoc_STRVAR(EncodingMap_size__doc__,
6 "size($self, /)\n"
7 "--\n"
8 "\n"
9 "Return the size (in bytes) of this object.");
10 
11 #define ENCODINGMAP_SIZE_METHODDEF    \
12     {"size", (PyCFunction)EncodingMap_size, METH_NOARGS, EncodingMap_size__doc__},
13 
14 static PyObject *
15 EncodingMap_size_impl(struct encoding_map *self);
16 
17 static PyObject *
EncodingMap_size(struct encoding_map * self,PyObject * Py_UNUSED (ignored))18 EncodingMap_size(struct encoding_map *self, PyObject *Py_UNUSED(ignored))
19 {
20     return EncodingMap_size_impl(self);
21 }
22 
23 PyDoc_STRVAR(unicode_title__doc__,
24 "title($self, /)\n"
25 "--\n"
26 "\n"
27 "Return a version of the string where each word is titlecased.\n"
28 "\n"
29 "More specifically, words start with uppercased characters and all remaining\n"
30 "cased characters have lower case.");
31 
32 #define UNICODE_TITLE_METHODDEF    \
33     {"title", (PyCFunction)unicode_title, METH_NOARGS, unicode_title__doc__},
34 
35 static PyObject *
36 unicode_title_impl(PyObject *self);
37 
38 static PyObject *
unicode_title(PyObject * self,PyObject * Py_UNUSED (ignored))39 unicode_title(PyObject *self, PyObject *Py_UNUSED(ignored))
40 {
41     return unicode_title_impl(self);
42 }
43 
44 PyDoc_STRVAR(unicode_capitalize__doc__,
45 "capitalize($self, /)\n"
46 "--\n"
47 "\n"
48 "Return a capitalized version of the string.\n"
49 "\n"
50 "More specifically, make the first character have upper case and the rest lower\n"
51 "case.");
52 
53 #define UNICODE_CAPITALIZE_METHODDEF    \
54     {"capitalize", (PyCFunction)unicode_capitalize, METH_NOARGS, unicode_capitalize__doc__},
55 
56 static PyObject *
57 unicode_capitalize_impl(PyObject *self);
58 
59 static PyObject *
unicode_capitalize(PyObject * self,PyObject * Py_UNUSED (ignored))60 unicode_capitalize(PyObject *self, PyObject *Py_UNUSED(ignored))
61 {
62     return unicode_capitalize_impl(self);
63 }
64 
65 PyDoc_STRVAR(unicode_casefold__doc__,
66 "casefold($self, /)\n"
67 "--\n"
68 "\n"
69 "Return a version of the string suitable for caseless comparisons.");
70 
71 #define UNICODE_CASEFOLD_METHODDEF    \
72     {"casefold", (PyCFunction)unicode_casefold, METH_NOARGS, unicode_casefold__doc__},
73 
74 static PyObject *
75 unicode_casefold_impl(PyObject *self);
76 
77 static PyObject *
unicode_casefold(PyObject * self,PyObject * Py_UNUSED (ignored))78 unicode_casefold(PyObject *self, PyObject *Py_UNUSED(ignored))
79 {
80     return unicode_casefold_impl(self);
81 }
82 
83 PyDoc_STRVAR(unicode_center__doc__,
84 "center($self, width, fillchar=\' \', /)\n"
85 "--\n"
86 "\n"
87 "Return a centered string of length width.\n"
88 "\n"
89 "Padding is done using the specified fill character (default is a space).");
90 
91 #define UNICODE_CENTER_METHODDEF    \
92     {"center", _PyCFunction_CAST(unicode_center), METH_FASTCALL, unicode_center__doc__},
93 
94 static PyObject *
95 unicode_center_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar);
96 
97 static PyObject *
unicode_center(PyObject * self,PyObject * const * args,Py_ssize_t nargs)98 unicode_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
99 {
100     PyObject *return_value = NULL;
101     Py_ssize_t width;
102     Py_UCS4 fillchar = ' ';
103 
104     if (!_PyArg_CheckPositional("center", nargs, 1, 2)) {
105         goto exit;
106     }
107     {
108         Py_ssize_t ival = -1;
109         PyObject *iobj = _PyNumber_Index(args[0]);
110         if (iobj != NULL) {
111             ival = PyLong_AsSsize_t(iobj);
112             Py_DECREF(iobj);
113         }
114         if (ival == -1 && PyErr_Occurred()) {
115             goto exit;
116         }
117         width = ival;
118     }
119     if (nargs < 2) {
120         goto skip_optional;
121     }
122     if (!convert_uc(args[1], &fillchar)) {
123         goto exit;
124     }
125 skip_optional:
126     return_value = unicode_center_impl(self, width, fillchar);
127 
128 exit:
129     return return_value;
130 }
131 
132 PyDoc_STRVAR(unicode_encode__doc__,
133 "encode($self, /, encoding=\'utf-8\', errors=\'strict\')\n"
134 "--\n"
135 "\n"
136 "Encode the string using the codec registered for encoding.\n"
137 "\n"
138 "  encoding\n"
139 "    The encoding in which to encode the string.\n"
140 "  errors\n"
141 "    The error handling scheme to use for encoding errors.\n"
142 "    The default is \'strict\' meaning that encoding errors raise a\n"
143 "    UnicodeEncodeError.  Other possible values are \'ignore\', \'replace\' and\n"
144 "    \'xmlcharrefreplace\' as well as any other name registered with\n"
145 "    codecs.register_error that can handle UnicodeEncodeErrors.");
146 
147 #define UNICODE_ENCODE_METHODDEF    \
148     {"encode", _PyCFunction_CAST(unicode_encode), METH_FASTCALL|METH_KEYWORDS, unicode_encode__doc__},
149 
150 static PyObject *
151 unicode_encode_impl(PyObject *self, const char *encoding, const char *errors);
152 
153 static PyObject *
unicode_encode(PyObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)154 unicode_encode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
155 {
156     PyObject *return_value = NULL;
157     static const char * const _keywords[] = {"encoding", "errors", NULL};
158     static _PyArg_Parser _parser = {NULL, _keywords, "encode", 0};
159     PyObject *argsbuf[2];
160     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
161     const char *encoding = NULL;
162     const char *errors = NULL;
163 
164     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
165     if (!args) {
166         goto exit;
167     }
168     if (!noptargs) {
169         goto skip_optional_pos;
170     }
171     if (args[0]) {
172         if (!PyUnicode_Check(args[0])) {
173             _PyArg_BadArgument("encode", "argument 'encoding'", "str", args[0]);
174             goto exit;
175         }
176         Py_ssize_t encoding_length;
177         encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length);
178         if (encoding == NULL) {
179             goto exit;
180         }
181         if (strlen(encoding) != (size_t)encoding_length) {
182             PyErr_SetString(PyExc_ValueError, "embedded null character");
183             goto exit;
184         }
185         if (!--noptargs) {
186             goto skip_optional_pos;
187         }
188     }
189     if (!PyUnicode_Check(args[1])) {
190         _PyArg_BadArgument("encode", "argument 'errors'", "str", args[1]);
191         goto exit;
192     }
193     Py_ssize_t errors_length;
194     errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
195     if (errors == NULL) {
196         goto exit;
197     }
198     if (strlen(errors) != (size_t)errors_length) {
199         PyErr_SetString(PyExc_ValueError, "embedded null character");
200         goto exit;
201     }
202 skip_optional_pos:
203     return_value = unicode_encode_impl(self, encoding, errors);
204 
205 exit:
206     return return_value;
207 }
208 
209 PyDoc_STRVAR(unicode_expandtabs__doc__,
210 "expandtabs($self, /, tabsize=8)\n"
211 "--\n"
212 "\n"
213 "Return a copy where all tab characters are expanded using spaces.\n"
214 "\n"
215 "If tabsize is not given, a tab size of 8 characters is assumed.");
216 
217 #define UNICODE_EXPANDTABS_METHODDEF    \
218     {"expandtabs", _PyCFunction_CAST(unicode_expandtabs), METH_FASTCALL|METH_KEYWORDS, unicode_expandtabs__doc__},
219 
220 static PyObject *
221 unicode_expandtabs_impl(PyObject *self, int tabsize);
222 
223 static PyObject *
unicode_expandtabs(PyObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)224 unicode_expandtabs(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
225 {
226     PyObject *return_value = NULL;
227     static const char * const _keywords[] = {"tabsize", NULL};
228     static _PyArg_Parser _parser = {NULL, _keywords, "expandtabs", 0};
229     PyObject *argsbuf[1];
230     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
231     int tabsize = 8;
232 
233     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
234     if (!args) {
235         goto exit;
236     }
237     if (!noptargs) {
238         goto skip_optional_pos;
239     }
240     tabsize = _PyLong_AsInt(args[0]);
241     if (tabsize == -1 && PyErr_Occurred()) {
242         goto exit;
243     }
244 skip_optional_pos:
245     return_value = unicode_expandtabs_impl(self, tabsize);
246 
247 exit:
248     return return_value;
249 }
250 
251 PyDoc_STRVAR(unicode_isascii__doc__,
252 "isascii($self, /)\n"
253 "--\n"
254 "\n"
255 "Return True if all characters in the string are ASCII, False otherwise.\n"
256 "\n"
257 "ASCII characters have code points in the range U+0000-U+007F.\n"
258 "Empty string is ASCII too.");
259 
260 #define UNICODE_ISASCII_METHODDEF    \
261     {"isascii", (PyCFunction)unicode_isascii, METH_NOARGS, unicode_isascii__doc__},
262 
263 static PyObject *
264 unicode_isascii_impl(PyObject *self);
265 
266 static PyObject *
unicode_isascii(PyObject * self,PyObject * Py_UNUSED (ignored))267 unicode_isascii(PyObject *self, PyObject *Py_UNUSED(ignored))
268 {
269     return unicode_isascii_impl(self);
270 }
271 
272 PyDoc_STRVAR(unicode_islower__doc__,
273 "islower($self, /)\n"
274 "--\n"
275 "\n"
276 "Return True if the string is a lowercase string, False otherwise.\n"
277 "\n"
278 "A string is lowercase if all cased characters in the string are lowercase and\n"
279 "there is at least one cased character in the string.");
280 
281 #define UNICODE_ISLOWER_METHODDEF    \
282     {"islower", (PyCFunction)unicode_islower, METH_NOARGS, unicode_islower__doc__},
283 
284 static PyObject *
285 unicode_islower_impl(PyObject *self);
286 
287 static PyObject *
unicode_islower(PyObject * self,PyObject * Py_UNUSED (ignored))288 unicode_islower(PyObject *self, PyObject *Py_UNUSED(ignored))
289 {
290     return unicode_islower_impl(self);
291 }
292 
293 PyDoc_STRVAR(unicode_isupper__doc__,
294 "isupper($self, /)\n"
295 "--\n"
296 "\n"
297 "Return True if the string is an uppercase string, False otherwise.\n"
298 "\n"
299 "A string is uppercase if all cased characters in the string are uppercase and\n"
300 "there is at least one cased character in the string.");
301 
302 #define UNICODE_ISUPPER_METHODDEF    \
303     {"isupper", (PyCFunction)unicode_isupper, METH_NOARGS, unicode_isupper__doc__},
304 
305 static PyObject *
306 unicode_isupper_impl(PyObject *self);
307 
308 static PyObject *
unicode_isupper(PyObject * self,PyObject * Py_UNUSED (ignored))309 unicode_isupper(PyObject *self, PyObject *Py_UNUSED(ignored))
310 {
311     return unicode_isupper_impl(self);
312 }
313 
314 PyDoc_STRVAR(unicode_istitle__doc__,
315 "istitle($self, /)\n"
316 "--\n"
317 "\n"
318 "Return True if the string is a title-cased string, False otherwise.\n"
319 "\n"
320 "In a title-cased string, upper- and title-case characters may only\n"
321 "follow uncased characters and lowercase characters only cased ones.");
322 
323 #define UNICODE_ISTITLE_METHODDEF    \
324     {"istitle", (PyCFunction)unicode_istitle, METH_NOARGS, unicode_istitle__doc__},
325 
326 static PyObject *
327 unicode_istitle_impl(PyObject *self);
328 
329 static PyObject *
unicode_istitle(PyObject * self,PyObject * Py_UNUSED (ignored))330 unicode_istitle(PyObject *self, PyObject *Py_UNUSED(ignored))
331 {
332     return unicode_istitle_impl(self);
333 }
334 
335 PyDoc_STRVAR(unicode_isspace__doc__,
336 "isspace($self, /)\n"
337 "--\n"
338 "\n"
339 "Return True if the string is a whitespace string, False otherwise.\n"
340 "\n"
341 "A string is whitespace if all characters in the string are whitespace and there\n"
342 "is at least one character in the string.");
343 
344 #define UNICODE_ISSPACE_METHODDEF    \
345     {"isspace", (PyCFunction)unicode_isspace, METH_NOARGS, unicode_isspace__doc__},
346 
347 static PyObject *
348 unicode_isspace_impl(PyObject *self);
349 
350 static PyObject *
unicode_isspace(PyObject * self,PyObject * Py_UNUSED (ignored))351 unicode_isspace(PyObject *self, PyObject *Py_UNUSED(ignored))
352 {
353     return unicode_isspace_impl(self);
354 }
355 
356 PyDoc_STRVAR(unicode_isalpha__doc__,
357 "isalpha($self, /)\n"
358 "--\n"
359 "\n"
360 "Return True if the string is an alphabetic string, False otherwise.\n"
361 "\n"
362 "A string is alphabetic if all characters in the string are alphabetic and there\n"
363 "is at least one character in the string.");
364 
365 #define UNICODE_ISALPHA_METHODDEF    \
366     {"isalpha", (PyCFunction)unicode_isalpha, METH_NOARGS, unicode_isalpha__doc__},
367 
368 static PyObject *
369 unicode_isalpha_impl(PyObject *self);
370 
371 static PyObject *
unicode_isalpha(PyObject * self,PyObject * Py_UNUSED (ignored))372 unicode_isalpha(PyObject *self, PyObject *Py_UNUSED(ignored))
373 {
374     return unicode_isalpha_impl(self);
375 }
376 
377 PyDoc_STRVAR(unicode_isalnum__doc__,
378 "isalnum($self, /)\n"
379 "--\n"
380 "\n"
381 "Return True if the string is an alpha-numeric string, False otherwise.\n"
382 "\n"
383 "A string is alpha-numeric if all characters in the string are alpha-numeric and\n"
384 "there is at least one character in the string.");
385 
386 #define UNICODE_ISALNUM_METHODDEF    \
387     {"isalnum", (PyCFunction)unicode_isalnum, METH_NOARGS, unicode_isalnum__doc__},
388 
389 static PyObject *
390 unicode_isalnum_impl(PyObject *self);
391 
392 static PyObject *
unicode_isalnum(PyObject * self,PyObject * Py_UNUSED (ignored))393 unicode_isalnum(PyObject *self, PyObject *Py_UNUSED(ignored))
394 {
395     return unicode_isalnum_impl(self);
396 }
397 
398 PyDoc_STRVAR(unicode_isdecimal__doc__,
399 "isdecimal($self, /)\n"
400 "--\n"
401 "\n"
402 "Return True if the string is a decimal string, False otherwise.\n"
403 "\n"
404 "A string is a decimal string if all characters in the string are decimal and\n"
405 "there is at least one character in the string.");
406 
407 #define UNICODE_ISDECIMAL_METHODDEF    \
408     {"isdecimal", (PyCFunction)unicode_isdecimal, METH_NOARGS, unicode_isdecimal__doc__},
409 
410 static PyObject *
411 unicode_isdecimal_impl(PyObject *self);
412 
413 static PyObject *
unicode_isdecimal(PyObject * self,PyObject * Py_UNUSED (ignored))414 unicode_isdecimal(PyObject *self, PyObject *Py_UNUSED(ignored))
415 {
416     return unicode_isdecimal_impl(self);
417 }
418 
419 PyDoc_STRVAR(unicode_isdigit__doc__,
420 "isdigit($self, /)\n"
421 "--\n"
422 "\n"
423 "Return True if the string is a digit string, False otherwise.\n"
424 "\n"
425 "A string is a digit string if all characters in the string are digits and there\n"
426 "is at least one character in the string.");
427 
428 #define UNICODE_ISDIGIT_METHODDEF    \
429     {"isdigit", (PyCFunction)unicode_isdigit, METH_NOARGS, unicode_isdigit__doc__},
430 
431 static PyObject *
432 unicode_isdigit_impl(PyObject *self);
433 
434 static PyObject *
unicode_isdigit(PyObject * self,PyObject * Py_UNUSED (ignored))435 unicode_isdigit(PyObject *self, PyObject *Py_UNUSED(ignored))
436 {
437     return unicode_isdigit_impl(self);
438 }
439 
440 PyDoc_STRVAR(unicode_isnumeric__doc__,
441 "isnumeric($self, /)\n"
442 "--\n"
443 "\n"
444 "Return True if the string is a numeric string, False otherwise.\n"
445 "\n"
446 "A string is numeric if all characters in the string are numeric and there is at\n"
447 "least one character in the string.");
448 
449 #define UNICODE_ISNUMERIC_METHODDEF    \
450     {"isnumeric", (PyCFunction)unicode_isnumeric, METH_NOARGS, unicode_isnumeric__doc__},
451 
452 static PyObject *
453 unicode_isnumeric_impl(PyObject *self);
454 
455 static PyObject *
unicode_isnumeric(PyObject * self,PyObject * Py_UNUSED (ignored))456 unicode_isnumeric(PyObject *self, PyObject *Py_UNUSED(ignored))
457 {
458     return unicode_isnumeric_impl(self);
459 }
460 
461 PyDoc_STRVAR(unicode_isidentifier__doc__,
462 "isidentifier($self, /)\n"
463 "--\n"
464 "\n"
465 "Return True if the string is a valid Python identifier, False otherwise.\n"
466 "\n"
467 "Call keyword.iskeyword(s) to test whether string s is a reserved identifier,\n"
468 "such as \"def\" or \"class\".");
469 
470 #define UNICODE_ISIDENTIFIER_METHODDEF    \
471     {"isidentifier", (PyCFunction)unicode_isidentifier, METH_NOARGS, unicode_isidentifier__doc__},
472 
473 static PyObject *
474 unicode_isidentifier_impl(PyObject *self);
475 
476 static PyObject *
unicode_isidentifier(PyObject * self,PyObject * Py_UNUSED (ignored))477 unicode_isidentifier(PyObject *self, PyObject *Py_UNUSED(ignored))
478 {
479     return unicode_isidentifier_impl(self);
480 }
481 
482 PyDoc_STRVAR(unicode_isprintable__doc__,
483 "isprintable($self, /)\n"
484 "--\n"
485 "\n"
486 "Return True if the string is printable, False otherwise.\n"
487 "\n"
488 "A string is printable if all of its characters are considered printable in\n"
489 "repr() or if it is empty.");
490 
491 #define UNICODE_ISPRINTABLE_METHODDEF    \
492     {"isprintable", (PyCFunction)unicode_isprintable, METH_NOARGS, unicode_isprintable__doc__},
493 
494 static PyObject *
495 unicode_isprintable_impl(PyObject *self);
496 
497 static PyObject *
unicode_isprintable(PyObject * self,PyObject * Py_UNUSED (ignored))498 unicode_isprintable(PyObject *self, PyObject *Py_UNUSED(ignored))
499 {
500     return unicode_isprintable_impl(self);
501 }
502 
503 PyDoc_STRVAR(unicode_join__doc__,
504 "join($self, iterable, /)\n"
505 "--\n"
506 "\n"
507 "Concatenate any number of strings.\n"
508 "\n"
509 "The string whose method is called is inserted in between each given string.\n"
510 "The result is returned as a new string.\n"
511 "\n"
512 "Example: \'.\'.join([\'ab\', \'pq\', \'rs\']) -> \'ab.pq.rs\'");
513 
514 #define UNICODE_JOIN_METHODDEF    \
515     {"join", (PyCFunction)unicode_join, METH_O, unicode_join__doc__},
516 
517 PyDoc_STRVAR(unicode_ljust__doc__,
518 "ljust($self, width, fillchar=\' \', /)\n"
519 "--\n"
520 "\n"
521 "Return a left-justified string of length width.\n"
522 "\n"
523 "Padding is done using the specified fill character (default is a space).");
524 
525 #define UNICODE_LJUST_METHODDEF    \
526     {"ljust", _PyCFunction_CAST(unicode_ljust), METH_FASTCALL, unicode_ljust__doc__},
527 
528 static PyObject *
529 unicode_ljust_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar);
530 
531 static PyObject *
unicode_ljust(PyObject * self,PyObject * const * args,Py_ssize_t nargs)532 unicode_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
533 {
534     PyObject *return_value = NULL;
535     Py_ssize_t width;
536     Py_UCS4 fillchar = ' ';
537 
538     if (!_PyArg_CheckPositional("ljust", nargs, 1, 2)) {
539         goto exit;
540     }
541     {
542         Py_ssize_t ival = -1;
543         PyObject *iobj = _PyNumber_Index(args[0]);
544         if (iobj != NULL) {
545             ival = PyLong_AsSsize_t(iobj);
546             Py_DECREF(iobj);
547         }
548         if (ival == -1 && PyErr_Occurred()) {
549             goto exit;
550         }
551         width = ival;
552     }
553     if (nargs < 2) {
554         goto skip_optional;
555     }
556     if (!convert_uc(args[1], &fillchar)) {
557         goto exit;
558     }
559 skip_optional:
560     return_value = unicode_ljust_impl(self, width, fillchar);
561 
562 exit:
563     return return_value;
564 }
565 
566 PyDoc_STRVAR(unicode_lower__doc__,
567 "lower($self, /)\n"
568 "--\n"
569 "\n"
570 "Return a copy of the string converted to lowercase.");
571 
572 #define UNICODE_LOWER_METHODDEF    \
573     {"lower", (PyCFunction)unicode_lower, METH_NOARGS, unicode_lower__doc__},
574 
575 static PyObject *
576 unicode_lower_impl(PyObject *self);
577 
578 static PyObject *
unicode_lower(PyObject * self,PyObject * Py_UNUSED (ignored))579 unicode_lower(PyObject *self, PyObject *Py_UNUSED(ignored))
580 {
581     return unicode_lower_impl(self);
582 }
583 
584 PyDoc_STRVAR(unicode_strip__doc__,
585 "strip($self, chars=None, /)\n"
586 "--\n"
587 "\n"
588 "Return a copy of the string with leading and trailing whitespace removed.\n"
589 "\n"
590 "If chars is given and not None, remove characters in chars instead.");
591 
592 #define UNICODE_STRIP_METHODDEF    \
593     {"strip", _PyCFunction_CAST(unicode_strip), METH_FASTCALL, unicode_strip__doc__},
594 
595 static PyObject *
596 unicode_strip_impl(PyObject *self, PyObject *chars);
597 
598 static PyObject *
unicode_strip(PyObject * self,PyObject * const * args,Py_ssize_t nargs)599 unicode_strip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
600 {
601     PyObject *return_value = NULL;
602     PyObject *chars = Py_None;
603 
604     if (!_PyArg_CheckPositional("strip", nargs, 0, 1)) {
605         goto exit;
606     }
607     if (nargs < 1) {
608         goto skip_optional;
609     }
610     chars = args[0];
611 skip_optional:
612     return_value = unicode_strip_impl(self, chars);
613 
614 exit:
615     return return_value;
616 }
617 
618 PyDoc_STRVAR(unicode_lstrip__doc__,
619 "lstrip($self, chars=None, /)\n"
620 "--\n"
621 "\n"
622 "Return a copy of the string with leading whitespace removed.\n"
623 "\n"
624 "If chars is given and not None, remove characters in chars instead.");
625 
626 #define UNICODE_LSTRIP_METHODDEF    \
627     {"lstrip", _PyCFunction_CAST(unicode_lstrip), METH_FASTCALL, unicode_lstrip__doc__},
628 
629 static PyObject *
630 unicode_lstrip_impl(PyObject *self, PyObject *chars);
631 
632 static PyObject *
unicode_lstrip(PyObject * self,PyObject * const * args,Py_ssize_t nargs)633 unicode_lstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
634 {
635     PyObject *return_value = NULL;
636     PyObject *chars = Py_None;
637 
638     if (!_PyArg_CheckPositional("lstrip", nargs, 0, 1)) {
639         goto exit;
640     }
641     if (nargs < 1) {
642         goto skip_optional;
643     }
644     chars = args[0];
645 skip_optional:
646     return_value = unicode_lstrip_impl(self, chars);
647 
648 exit:
649     return return_value;
650 }
651 
652 PyDoc_STRVAR(unicode_rstrip__doc__,
653 "rstrip($self, chars=None, /)\n"
654 "--\n"
655 "\n"
656 "Return a copy of the string with trailing whitespace removed.\n"
657 "\n"
658 "If chars is given and not None, remove characters in chars instead.");
659 
660 #define UNICODE_RSTRIP_METHODDEF    \
661     {"rstrip", _PyCFunction_CAST(unicode_rstrip), METH_FASTCALL, unicode_rstrip__doc__},
662 
663 static PyObject *
664 unicode_rstrip_impl(PyObject *self, PyObject *chars);
665 
666 static PyObject *
unicode_rstrip(PyObject * self,PyObject * const * args,Py_ssize_t nargs)667 unicode_rstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
668 {
669     PyObject *return_value = NULL;
670     PyObject *chars = Py_None;
671 
672     if (!_PyArg_CheckPositional("rstrip", nargs, 0, 1)) {
673         goto exit;
674     }
675     if (nargs < 1) {
676         goto skip_optional;
677     }
678     chars = args[0];
679 skip_optional:
680     return_value = unicode_rstrip_impl(self, chars);
681 
682 exit:
683     return return_value;
684 }
685 
686 PyDoc_STRVAR(unicode_replace__doc__,
687 "replace($self, old, new, count=-1, /)\n"
688 "--\n"
689 "\n"
690 "Return a copy with all occurrences of substring old replaced by new.\n"
691 "\n"
692 "  count\n"
693 "    Maximum number of occurrences to replace.\n"
694 "    -1 (the default value) means replace all occurrences.\n"
695 "\n"
696 "If the optional argument count is given, only the first count occurrences are\n"
697 "replaced.");
698 
699 #define UNICODE_REPLACE_METHODDEF    \
700     {"replace", _PyCFunction_CAST(unicode_replace), METH_FASTCALL, unicode_replace__doc__},
701 
702 static PyObject *
703 unicode_replace_impl(PyObject *self, PyObject *old, PyObject *new,
704                      Py_ssize_t count);
705 
706 static PyObject *
unicode_replace(PyObject * self,PyObject * const * args,Py_ssize_t nargs)707 unicode_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
708 {
709     PyObject *return_value = NULL;
710     PyObject *old;
711     PyObject *new;
712     Py_ssize_t count = -1;
713 
714     if (!_PyArg_CheckPositional("replace", nargs, 2, 3)) {
715         goto exit;
716     }
717     if (!PyUnicode_Check(args[0])) {
718         _PyArg_BadArgument("replace", "argument 1", "str", args[0]);
719         goto exit;
720     }
721     if (PyUnicode_READY(args[0]) == -1) {
722         goto exit;
723     }
724     old = args[0];
725     if (!PyUnicode_Check(args[1])) {
726         _PyArg_BadArgument("replace", "argument 2", "str", args[1]);
727         goto exit;
728     }
729     if (PyUnicode_READY(args[1]) == -1) {
730         goto exit;
731     }
732     new = args[1];
733     if (nargs < 3) {
734         goto skip_optional;
735     }
736     {
737         Py_ssize_t ival = -1;
738         PyObject *iobj = _PyNumber_Index(args[2]);
739         if (iobj != NULL) {
740             ival = PyLong_AsSsize_t(iobj);
741             Py_DECREF(iobj);
742         }
743         if (ival == -1 && PyErr_Occurred()) {
744             goto exit;
745         }
746         count = ival;
747     }
748 skip_optional:
749     return_value = unicode_replace_impl(self, old, new, count);
750 
751 exit:
752     return return_value;
753 }
754 
755 PyDoc_STRVAR(unicode_removeprefix__doc__,
756 "removeprefix($self, prefix, /)\n"
757 "--\n"
758 "\n"
759 "Return a str with the given prefix string removed if present.\n"
760 "\n"
761 "If the string starts with the prefix string, return string[len(prefix):].\n"
762 "Otherwise, return a copy of the original string.");
763 
764 #define UNICODE_REMOVEPREFIX_METHODDEF    \
765     {"removeprefix", (PyCFunction)unicode_removeprefix, METH_O, unicode_removeprefix__doc__},
766 
767 static PyObject *
768 unicode_removeprefix_impl(PyObject *self, PyObject *prefix);
769 
770 static PyObject *
unicode_removeprefix(PyObject * self,PyObject * arg)771 unicode_removeprefix(PyObject *self, PyObject *arg)
772 {
773     PyObject *return_value = NULL;
774     PyObject *prefix;
775 
776     if (!PyUnicode_Check(arg)) {
777         _PyArg_BadArgument("removeprefix", "argument", "str", arg);
778         goto exit;
779     }
780     if (PyUnicode_READY(arg) == -1) {
781         goto exit;
782     }
783     prefix = arg;
784     return_value = unicode_removeprefix_impl(self, prefix);
785 
786 exit:
787     return return_value;
788 }
789 
790 PyDoc_STRVAR(unicode_removesuffix__doc__,
791 "removesuffix($self, suffix, /)\n"
792 "--\n"
793 "\n"
794 "Return a str with the given suffix string removed if present.\n"
795 "\n"
796 "If the string ends with the suffix string and that suffix is not empty,\n"
797 "return string[:-len(suffix)]. Otherwise, return a copy of the original\n"
798 "string.");
799 
800 #define UNICODE_REMOVESUFFIX_METHODDEF    \
801     {"removesuffix", (PyCFunction)unicode_removesuffix, METH_O, unicode_removesuffix__doc__},
802 
803 static PyObject *
804 unicode_removesuffix_impl(PyObject *self, PyObject *suffix);
805 
806 static PyObject *
unicode_removesuffix(PyObject * self,PyObject * arg)807 unicode_removesuffix(PyObject *self, PyObject *arg)
808 {
809     PyObject *return_value = NULL;
810     PyObject *suffix;
811 
812     if (!PyUnicode_Check(arg)) {
813         _PyArg_BadArgument("removesuffix", "argument", "str", arg);
814         goto exit;
815     }
816     if (PyUnicode_READY(arg) == -1) {
817         goto exit;
818     }
819     suffix = arg;
820     return_value = unicode_removesuffix_impl(self, suffix);
821 
822 exit:
823     return return_value;
824 }
825 
826 PyDoc_STRVAR(unicode_rjust__doc__,
827 "rjust($self, width, fillchar=\' \', /)\n"
828 "--\n"
829 "\n"
830 "Return a right-justified string of length width.\n"
831 "\n"
832 "Padding is done using the specified fill character (default is a space).");
833 
834 #define UNICODE_RJUST_METHODDEF    \
835     {"rjust", _PyCFunction_CAST(unicode_rjust), METH_FASTCALL, unicode_rjust__doc__},
836 
837 static PyObject *
838 unicode_rjust_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar);
839 
840 static PyObject *
unicode_rjust(PyObject * self,PyObject * const * args,Py_ssize_t nargs)841 unicode_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
842 {
843     PyObject *return_value = NULL;
844     Py_ssize_t width;
845     Py_UCS4 fillchar = ' ';
846 
847     if (!_PyArg_CheckPositional("rjust", nargs, 1, 2)) {
848         goto exit;
849     }
850     {
851         Py_ssize_t ival = -1;
852         PyObject *iobj = _PyNumber_Index(args[0]);
853         if (iobj != NULL) {
854             ival = PyLong_AsSsize_t(iobj);
855             Py_DECREF(iobj);
856         }
857         if (ival == -1 && PyErr_Occurred()) {
858             goto exit;
859         }
860         width = ival;
861     }
862     if (nargs < 2) {
863         goto skip_optional;
864     }
865     if (!convert_uc(args[1], &fillchar)) {
866         goto exit;
867     }
868 skip_optional:
869     return_value = unicode_rjust_impl(self, width, fillchar);
870 
871 exit:
872     return return_value;
873 }
874 
875 PyDoc_STRVAR(unicode_split__doc__,
876 "split($self, /, sep=None, maxsplit=-1)\n"
877 "--\n"
878 "\n"
879 "Return a list of the substrings in the string, using sep as the separator string.\n"
880 "\n"
881 "  sep\n"
882 "    The separator used to split the string.\n"
883 "\n"
884 "    When set to None (the default value), will split on any whitespace\n"
885 "    character (including \\\\n \\\\r \\\\t \\\\f and spaces) and will discard\n"
886 "    empty strings from the result.\n"
887 "  maxsplit\n"
888 "    Maximum number of splits (starting from the left).\n"
889 "    -1 (the default value) means no limit.\n"
890 "\n"
891 "Note, str.split() is mainly useful for data that has been intentionally\n"
892 "delimited.  With natural text that includes punctuation, consider using\n"
893 "the regular expression module.");
894 
895 #define UNICODE_SPLIT_METHODDEF    \
896     {"split", _PyCFunction_CAST(unicode_split), METH_FASTCALL|METH_KEYWORDS, unicode_split__doc__},
897 
898 static PyObject *
899 unicode_split_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit);
900 
901 static PyObject *
unicode_split(PyObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)902 unicode_split(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
903 {
904     PyObject *return_value = NULL;
905     static const char * const _keywords[] = {"sep", "maxsplit", NULL};
906     static _PyArg_Parser _parser = {NULL, _keywords, "split", 0};
907     PyObject *argsbuf[2];
908     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
909     PyObject *sep = Py_None;
910     Py_ssize_t maxsplit = -1;
911 
912     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
913     if (!args) {
914         goto exit;
915     }
916     if (!noptargs) {
917         goto skip_optional_pos;
918     }
919     if (args[0]) {
920         sep = args[0];
921         if (!--noptargs) {
922             goto skip_optional_pos;
923         }
924     }
925     {
926         Py_ssize_t ival = -1;
927         PyObject *iobj = _PyNumber_Index(args[1]);
928         if (iobj != NULL) {
929             ival = PyLong_AsSsize_t(iobj);
930             Py_DECREF(iobj);
931         }
932         if (ival == -1 && PyErr_Occurred()) {
933             goto exit;
934         }
935         maxsplit = ival;
936     }
937 skip_optional_pos:
938     return_value = unicode_split_impl(self, sep, maxsplit);
939 
940 exit:
941     return return_value;
942 }
943 
944 PyDoc_STRVAR(unicode_partition__doc__,
945 "partition($self, sep, /)\n"
946 "--\n"
947 "\n"
948 "Partition the string into three parts using the given separator.\n"
949 "\n"
950 "This will search for the separator in the string.  If the separator is found,\n"
951 "returns a 3-tuple containing the part before the separator, the separator\n"
952 "itself, and the part after it.\n"
953 "\n"
954 "If the separator is not found, returns a 3-tuple containing the original string\n"
955 "and two empty strings.");
956 
957 #define UNICODE_PARTITION_METHODDEF    \
958     {"partition", (PyCFunction)unicode_partition, METH_O, unicode_partition__doc__},
959 
960 PyDoc_STRVAR(unicode_rpartition__doc__,
961 "rpartition($self, sep, /)\n"
962 "--\n"
963 "\n"
964 "Partition the string into three parts using the given separator.\n"
965 "\n"
966 "This will search for the separator in the string, starting at the end. If\n"
967 "the separator is found, returns a 3-tuple containing the part before the\n"
968 "separator, the separator itself, and the part after it.\n"
969 "\n"
970 "If the separator is not found, returns a 3-tuple containing two empty strings\n"
971 "and the original string.");
972 
973 #define UNICODE_RPARTITION_METHODDEF    \
974     {"rpartition", (PyCFunction)unicode_rpartition, METH_O, unicode_rpartition__doc__},
975 
976 PyDoc_STRVAR(unicode_rsplit__doc__,
977 "rsplit($self, /, sep=None, maxsplit=-1)\n"
978 "--\n"
979 "\n"
980 "Return a list of the substrings in the string, using sep as the separator string.\n"
981 "\n"
982 "  sep\n"
983 "    The separator used to split the string.\n"
984 "\n"
985 "    When set to None (the default value), will split on any whitespace\n"
986 "    character (including \\\\n \\\\r \\\\t \\\\f and spaces) and will discard\n"
987 "    empty strings from the result.\n"
988 "  maxsplit\n"
989 "    Maximum number of splits (starting from the left).\n"
990 "    -1 (the default value) means no limit.\n"
991 "\n"
992 "Splitting starts at the end of the string and works to the front.");
993 
994 #define UNICODE_RSPLIT_METHODDEF    \
995     {"rsplit", _PyCFunction_CAST(unicode_rsplit), METH_FASTCALL|METH_KEYWORDS, unicode_rsplit__doc__},
996 
997 static PyObject *
998 unicode_rsplit_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit);
999 
1000 static PyObject *
unicode_rsplit(PyObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1001 unicode_rsplit(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1002 {
1003     PyObject *return_value = NULL;
1004     static const char * const _keywords[] = {"sep", "maxsplit", NULL};
1005     static _PyArg_Parser _parser = {NULL, _keywords, "rsplit", 0};
1006     PyObject *argsbuf[2];
1007     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1008     PyObject *sep = Py_None;
1009     Py_ssize_t maxsplit = -1;
1010 
1011     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
1012     if (!args) {
1013         goto exit;
1014     }
1015     if (!noptargs) {
1016         goto skip_optional_pos;
1017     }
1018     if (args[0]) {
1019         sep = args[0];
1020         if (!--noptargs) {
1021             goto skip_optional_pos;
1022         }
1023     }
1024     {
1025         Py_ssize_t ival = -1;
1026         PyObject *iobj = _PyNumber_Index(args[1]);
1027         if (iobj != NULL) {
1028             ival = PyLong_AsSsize_t(iobj);
1029             Py_DECREF(iobj);
1030         }
1031         if (ival == -1 && PyErr_Occurred()) {
1032             goto exit;
1033         }
1034         maxsplit = ival;
1035     }
1036 skip_optional_pos:
1037     return_value = unicode_rsplit_impl(self, sep, maxsplit);
1038 
1039 exit:
1040     return return_value;
1041 }
1042 
1043 PyDoc_STRVAR(unicode_splitlines__doc__,
1044 "splitlines($self, /, keepends=False)\n"
1045 "--\n"
1046 "\n"
1047 "Return a list of the lines in the string, breaking at line boundaries.\n"
1048 "\n"
1049 "Line breaks are not included in the resulting list unless keepends is given and\n"
1050 "true.");
1051 
1052 #define UNICODE_SPLITLINES_METHODDEF    \
1053     {"splitlines", _PyCFunction_CAST(unicode_splitlines), METH_FASTCALL|METH_KEYWORDS, unicode_splitlines__doc__},
1054 
1055 static PyObject *
1056 unicode_splitlines_impl(PyObject *self, int keepends);
1057 
1058 static PyObject *
unicode_splitlines(PyObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1059 unicode_splitlines(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1060 {
1061     PyObject *return_value = NULL;
1062     static const char * const _keywords[] = {"keepends", NULL};
1063     static _PyArg_Parser _parser = {NULL, _keywords, "splitlines", 0};
1064     PyObject *argsbuf[1];
1065     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1066     int keepends = 0;
1067 
1068     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
1069     if (!args) {
1070         goto exit;
1071     }
1072     if (!noptargs) {
1073         goto skip_optional_pos;
1074     }
1075     keepends = _PyLong_AsInt(args[0]);
1076     if (keepends == -1 && PyErr_Occurred()) {
1077         goto exit;
1078     }
1079 skip_optional_pos:
1080     return_value = unicode_splitlines_impl(self, keepends);
1081 
1082 exit:
1083     return return_value;
1084 }
1085 
1086 PyDoc_STRVAR(unicode_swapcase__doc__,
1087 "swapcase($self, /)\n"
1088 "--\n"
1089 "\n"
1090 "Convert uppercase characters to lowercase and lowercase characters to uppercase.");
1091 
1092 #define UNICODE_SWAPCASE_METHODDEF    \
1093     {"swapcase", (PyCFunction)unicode_swapcase, METH_NOARGS, unicode_swapcase__doc__},
1094 
1095 static PyObject *
1096 unicode_swapcase_impl(PyObject *self);
1097 
1098 static PyObject *
unicode_swapcase(PyObject * self,PyObject * Py_UNUSED (ignored))1099 unicode_swapcase(PyObject *self, PyObject *Py_UNUSED(ignored))
1100 {
1101     return unicode_swapcase_impl(self);
1102 }
1103 
1104 PyDoc_STRVAR(unicode_maketrans__doc__,
1105 "maketrans(x, y=<unrepresentable>, z=<unrepresentable>, /)\n"
1106 "--\n"
1107 "\n"
1108 "Return a translation table usable for str.translate().\n"
1109 "\n"
1110 "If there is only one argument, it must be a dictionary mapping Unicode\n"
1111 "ordinals (integers) or characters to Unicode ordinals, strings or None.\n"
1112 "Character keys will be then converted to ordinals.\n"
1113 "If there are two arguments, they must be strings of equal length, and\n"
1114 "in the resulting dictionary, each character in x will be mapped to the\n"
1115 "character at the same position in y. If there is a third argument, it\n"
1116 "must be a string, whose characters will be mapped to None in the result.");
1117 
1118 #define UNICODE_MAKETRANS_METHODDEF    \
1119     {"maketrans", _PyCFunction_CAST(unicode_maketrans), METH_FASTCALL|METH_STATIC, unicode_maketrans__doc__},
1120 
1121 static PyObject *
1122 unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z);
1123 
1124 static PyObject *
unicode_maketrans(void * null,PyObject * const * args,Py_ssize_t nargs)1125 unicode_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs)
1126 {
1127     PyObject *return_value = NULL;
1128     PyObject *x;
1129     PyObject *y = NULL;
1130     PyObject *z = NULL;
1131 
1132     if (!_PyArg_CheckPositional("maketrans", nargs, 1, 3)) {
1133         goto exit;
1134     }
1135     x = args[0];
1136     if (nargs < 2) {
1137         goto skip_optional;
1138     }
1139     if (!PyUnicode_Check(args[1])) {
1140         _PyArg_BadArgument("maketrans", "argument 2", "str", args[1]);
1141         goto exit;
1142     }
1143     if (PyUnicode_READY(args[1]) == -1) {
1144         goto exit;
1145     }
1146     y = args[1];
1147     if (nargs < 3) {
1148         goto skip_optional;
1149     }
1150     if (!PyUnicode_Check(args[2])) {
1151         _PyArg_BadArgument("maketrans", "argument 3", "str", args[2]);
1152         goto exit;
1153     }
1154     if (PyUnicode_READY(args[2]) == -1) {
1155         goto exit;
1156     }
1157     z = args[2];
1158 skip_optional:
1159     return_value = unicode_maketrans_impl(x, y, z);
1160 
1161 exit:
1162     return return_value;
1163 }
1164 
1165 PyDoc_STRVAR(unicode_translate__doc__,
1166 "translate($self, table, /)\n"
1167 "--\n"
1168 "\n"
1169 "Replace each character in the string using the given translation table.\n"
1170 "\n"
1171 "  table\n"
1172 "    Translation table, which must be a mapping of Unicode ordinals to\n"
1173 "    Unicode ordinals, strings, or None.\n"
1174 "\n"
1175 "The table must implement lookup/indexing via __getitem__, for instance a\n"
1176 "dictionary or list.  If this operation raises LookupError, the character is\n"
1177 "left untouched.  Characters mapped to None are deleted.");
1178 
1179 #define UNICODE_TRANSLATE_METHODDEF    \
1180     {"translate", (PyCFunction)unicode_translate, METH_O, unicode_translate__doc__},
1181 
1182 PyDoc_STRVAR(unicode_upper__doc__,
1183 "upper($self, /)\n"
1184 "--\n"
1185 "\n"
1186 "Return a copy of the string converted to uppercase.");
1187 
1188 #define UNICODE_UPPER_METHODDEF    \
1189     {"upper", (PyCFunction)unicode_upper, METH_NOARGS, unicode_upper__doc__},
1190 
1191 static PyObject *
1192 unicode_upper_impl(PyObject *self);
1193 
1194 static PyObject *
unicode_upper(PyObject * self,PyObject * Py_UNUSED (ignored))1195 unicode_upper(PyObject *self, PyObject *Py_UNUSED(ignored))
1196 {
1197     return unicode_upper_impl(self);
1198 }
1199 
1200 PyDoc_STRVAR(unicode_zfill__doc__,
1201 "zfill($self, width, /)\n"
1202 "--\n"
1203 "\n"
1204 "Pad a numeric string with zeros on the left, to fill a field of the given width.\n"
1205 "\n"
1206 "The string is never truncated.");
1207 
1208 #define UNICODE_ZFILL_METHODDEF    \
1209     {"zfill", (PyCFunction)unicode_zfill, METH_O, unicode_zfill__doc__},
1210 
1211 static PyObject *
1212 unicode_zfill_impl(PyObject *self, Py_ssize_t width);
1213 
1214 static PyObject *
unicode_zfill(PyObject * self,PyObject * arg)1215 unicode_zfill(PyObject *self, PyObject *arg)
1216 {
1217     PyObject *return_value = NULL;
1218     Py_ssize_t width;
1219 
1220     {
1221         Py_ssize_t ival = -1;
1222         PyObject *iobj = _PyNumber_Index(arg);
1223         if (iobj != NULL) {
1224             ival = PyLong_AsSsize_t(iobj);
1225             Py_DECREF(iobj);
1226         }
1227         if (ival == -1 && PyErr_Occurred()) {
1228             goto exit;
1229         }
1230         width = ival;
1231     }
1232     return_value = unicode_zfill_impl(self, width);
1233 
1234 exit:
1235     return return_value;
1236 }
1237 
1238 PyDoc_STRVAR(unicode___format____doc__,
1239 "__format__($self, format_spec, /)\n"
1240 "--\n"
1241 "\n"
1242 "Return a formatted version of the string as described by format_spec.");
1243 
1244 #define UNICODE___FORMAT___METHODDEF    \
1245     {"__format__", (PyCFunction)unicode___format__, METH_O, unicode___format____doc__},
1246 
1247 static PyObject *
1248 unicode___format___impl(PyObject *self, PyObject *format_spec);
1249 
1250 static PyObject *
unicode___format__(PyObject * self,PyObject * arg)1251 unicode___format__(PyObject *self, PyObject *arg)
1252 {
1253     PyObject *return_value = NULL;
1254     PyObject *format_spec;
1255 
1256     if (!PyUnicode_Check(arg)) {
1257         _PyArg_BadArgument("__format__", "argument", "str", arg);
1258         goto exit;
1259     }
1260     if (PyUnicode_READY(arg) == -1) {
1261         goto exit;
1262     }
1263     format_spec = arg;
1264     return_value = unicode___format___impl(self, format_spec);
1265 
1266 exit:
1267     return return_value;
1268 }
1269 
1270 PyDoc_STRVAR(unicode_sizeof__doc__,
1271 "__sizeof__($self, /)\n"
1272 "--\n"
1273 "\n"
1274 "Return the size of the string in memory, in bytes.");
1275 
1276 #define UNICODE_SIZEOF_METHODDEF    \
1277     {"__sizeof__", (PyCFunction)unicode_sizeof, METH_NOARGS, unicode_sizeof__doc__},
1278 
1279 static PyObject *
1280 unicode_sizeof_impl(PyObject *self);
1281 
1282 static PyObject *
unicode_sizeof(PyObject * self,PyObject * Py_UNUSED (ignored))1283 unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored))
1284 {
1285     return unicode_sizeof_impl(self);
1286 }
1287 
1288 static PyObject *
1289 unicode_new_impl(PyTypeObject *type, PyObject *x, const char *encoding,
1290                  const char *errors);
1291 
1292 static PyObject *
unicode_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)1293 unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1294 {
1295     PyObject *return_value = NULL;
1296     static const char * const _keywords[] = {"object", "encoding", "errors", NULL};
1297     static _PyArg_Parser _parser = {NULL, _keywords, "str", 0};
1298     PyObject *argsbuf[3];
1299     PyObject * const *fastargs;
1300     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
1301     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
1302     PyObject *x = NULL;
1303     const char *encoding = NULL;
1304     const char *errors = NULL;
1305 
1306     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 3, 0, argsbuf);
1307     if (!fastargs) {
1308         goto exit;
1309     }
1310     if (!noptargs) {
1311         goto skip_optional_pos;
1312     }
1313     if (fastargs[0]) {
1314         x = fastargs[0];
1315         if (!--noptargs) {
1316             goto skip_optional_pos;
1317         }
1318     }
1319     if (fastargs[1]) {
1320         if (!PyUnicode_Check(fastargs[1])) {
1321             _PyArg_BadArgument("str", "argument 'encoding'", "str", fastargs[1]);
1322             goto exit;
1323         }
1324         Py_ssize_t encoding_length;
1325         encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length);
1326         if (encoding == NULL) {
1327             goto exit;
1328         }
1329         if (strlen(encoding) != (size_t)encoding_length) {
1330             PyErr_SetString(PyExc_ValueError, "embedded null character");
1331             goto exit;
1332         }
1333         if (!--noptargs) {
1334             goto skip_optional_pos;
1335         }
1336     }
1337     if (!PyUnicode_Check(fastargs[2])) {
1338         _PyArg_BadArgument("str", "argument 'errors'", "str", fastargs[2]);
1339         goto exit;
1340     }
1341     Py_ssize_t errors_length;
1342     errors = PyUnicode_AsUTF8AndSize(fastargs[2], &errors_length);
1343     if (errors == NULL) {
1344         goto exit;
1345     }
1346     if (strlen(errors) != (size_t)errors_length) {
1347         PyErr_SetString(PyExc_ValueError, "embedded null character");
1348         goto exit;
1349     }
1350 skip_optional_pos:
1351     return_value = unicode_new_impl(type, x, encoding, errors);
1352 
1353 exit:
1354     return return_value;
1355 }
1356 /*[clinic end generated code: output=b5dd7cefead9a8e7 input=a9049054013a1b77]*/
1357