Debian Codegraph @

Modules/clinic/binascii.c.h

raw
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 # include "pycore_gc.h" // PyGC_Head
7 # include "pycore_runtime.h" // _Py_ID()
8 #endif
9 #include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
10
11 PyDoc_STRVAR(binascii_a2b_uu__doc__,
12 "a2b_uu($module, data, /)\n"
13 "--\n"
14 "\n"
15 "Decode a line of uuencoded data.");
16
17 #define BINASCII_A2B_UU_METHODDEF \
18 {"a2b_uu", (PyCFunction)binascii_a2b_uu, METH_O, binascii_a2b_uu__doc__},
19
20 static PyObject *
21 binascii_a2b_uu_impl(PyObject *module, Py_buffer *data);
22
23 static PyObject *
24 binascii_a2b_uu(PyObject *module, PyObject *arg)
25 {
26 PyObject *return_value = NULL;
27 Py_buffer data = {NULL, NULL};
28
29 if (!ascii_buffer_converter(arg, &data)) {
30 goto exit;
31 }
32 return_value = binascii_a2b_uu_impl(module, &data);
33
34 exit:
35 /* Cleanup for data */
36 if (data.obj)
37 PyBuffer_Release(&data);
38
39 return return_value;
40 }
41
42 PyDoc_STRVAR(binascii_b2a_uu__doc__,
43 "b2a_uu($module, data, /, *, backtick=False)\n"
44 "--\n"
45 "\n"
46 "Uuencode line of data.");
47
48 #define BINASCII_B2A_UU_METHODDEF \
49 {"b2a_uu", _PyCFunction_CAST(binascii_b2a_uu), METH_FASTCALL|METH_KEYWORDS, binascii_b2a_uu__doc__},
50
51 static PyObject *
52 binascii_b2a_uu_impl(PyObject *module, Py_buffer *data, int backtick);
53
54 static PyObject *
55 binascii_b2a_uu(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
56 {
57 PyObject *return_value = NULL;
58 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
59
60 #define NUM_KEYWORDS 1
61 static struct {
62 PyGC_Head _this_is_not_used;
63 PyObject_VAR_HEAD
64 Py_hash_t ob_hash;
65 PyObject *ob_item[NUM_KEYWORDS];
66 } _kwtuple = {
67 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
68 .ob_hash = -1,
69 .ob_item = { &_Py_ID(backtick), },
70 };
71 #undef NUM_KEYWORDS
72 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
73
74 #else // !Py_BUILD_CORE
75 # define KWTUPLE NULL
76 #endif // !Py_BUILD_CORE
77
78 static const char * const _keywords[] = {"", "backtick", NULL};
79 static _PyArg_Parser _parser = {
80 .keywords = _keywords,
81 .fname = "b2a_uu",
82 .kwtuple = KWTUPLE,
83 };
84 #undef KWTUPLE
85 PyObject *argsbuf[2];
86 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
87 Py_buffer data = {NULL, NULL};
88 int backtick = 0;
89
90 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
91 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
92 if (!args) {
93 goto exit;
94 }
95 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
96 goto exit;
97 }
98 if (!noptargs) {
99 goto skip_optional_kwonly;
100 }
101 backtick = PyObject_IsTrue(args[1]);
102 if (backtick < 0) {
103 goto exit;
104 }
105 skip_optional_kwonly:
106 return_value = binascii_b2a_uu_impl(module, &data, backtick);
107
108 exit:
109 /* Cleanup for data */
110 if (data.obj) {
111 PyBuffer_Release(&data);
112 }
113
114 return return_value;
115 }
116
117 PyDoc_STRVAR(binascii_a2b_base64__doc__,
118 "a2b_base64($module, data, /, *, strict_mode=False)\n"
119 "--\n"
120 "\n"
121 "Decode a line of base64 data.\n"
122 "\n"
123 " strict_mode\n"
124 " When set to True, bytes that are not part of the base64 standard are not allowed.\n"
125 " The same applies to excess data after padding (= / ==).");
126
127 #define BINASCII_A2B_BASE64_METHODDEF \
128 {"a2b_base64", _PyCFunction_CAST(binascii_a2b_base64), METH_FASTCALL|METH_KEYWORDS, binascii_a2b_base64__doc__},
129
130 static PyObject *
131 binascii_a2b_base64_impl(PyObject *module, Py_buffer *data, int strict_mode);
132
133 static PyObject *
134 binascii_a2b_base64(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
135 {
136 PyObject *return_value = NULL;
137 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
138
139 #define NUM_KEYWORDS 1
140 static struct {
141 PyGC_Head _this_is_not_used;
142 PyObject_VAR_HEAD
143 Py_hash_t ob_hash;
144 PyObject *ob_item[NUM_KEYWORDS];
145 } _kwtuple = {
146 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
147 .ob_hash = -1,
148 .ob_item = { &_Py_ID(strict_mode), },
149 };
150 #undef NUM_KEYWORDS
151 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
152
153 #else // !Py_BUILD_CORE
154 # define KWTUPLE NULL
155 #endif // !Py_BUILD_CORE
156
157 static const char * const _keywords[] = {"", "strict_mode", NULL};
158 static _PyArg_Parser _parser = {
159 .keywords = _keywords,
160 .fname = "a2b_base64",
161 .kwtuple = KWTUPLE,
162 };
163 #undef KWTUPLE
164 PyObject *argsbuf[2];
165 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
166 Py_buffer data = {NULL, NULL};
167 int strict_mode = 0;
168
169 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
170 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
171 if (!args) {
172 goto exit;
173 }
174 if (!ascii_buffer_converter(args[0], &data)) {
175 goto exit;
176 }
177 if (!noptargs) {
178 goto skip_optional_kwonly;
179 }
180 strict_mode = PyObject_IsTrue(args[1]);
181 if (strict_mode < 0) {
182 goto exit;
183 }
184 skip_optional_kwonly:
185 return_value = binascii_a2b_base64_impl(module, &data, strict_mode);
186
187 exit:
188 /* Cleanup for data */
189 if (data.obj)
190 PyBuffer_Release(&data);
191
192 return return_value;
193 }
194
195 PyDoc_STRVAR(binascii_b2a_base64__doc__,
196 "b2a_base64($module, data, /, *, newline=True)\n"
197 "--\n"
198 "\n"
199 "Base64-code line of data.");
200
201 #define BINASCII_B2A_BASE64_METHODDEF \
202 {"b2a_base64", _PyCFunction_CAST(binascii_b2a_base64), METH_FASTCALL|METH_KEYWORDS, binascii_b2a_base64__doc__},
203
204 static PyObject *
205 binascii_b2a_base64_impl(PyObject *module, Py_buffer *data, int newline);
206
207 static PyObject *
208 binascii_b2a_base64(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
209 {
210 PyObject *return_value = NULL;
211 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
212
213 #define NUM_KEYWORDS 1
214 static struct {
215 PyGC_Head _this_is_not_used;
216 PyObject_VAR_HEAD
217 Py_hash_t ob_hash;
218 PyObject *ob_item[NUM_KEYWORDS];
219 } _kwtuple = {
220 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
221 .ob_hash = -1,
222 .ob_item = { &_Py_ID(newline), },
223 };
224 #undef NUM_KEYWORDS
225 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
226
227 #else // !Py_BUILD_CORE
228 # define KWTUPLE NULL
229 #endif // !Py_BUILD_CORE
230
231 static const char * const _keywords[] = {"", "newline", NULL};
232 static _PyArg_Parser _parser = {
233 .keywords = _keywords,
234 .fname = "b2a_base64",
235 .kwtuple = KWTUPLE,
236 };
237 #undef KWTUPLE
238 PyObject *argsbuf[2];
239 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
240 Py_buffer data = {NULL, NULL};
241 int newline = 1;
242
243 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
244 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
245 if (!args) {
246 goto exit;
247 }
248 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
249 goto exit;
250 }
251 if (!noptargs) {
252 goto skip_optional_kwonly;
253 }
254 newline = PyObject_IsTrue(args[1]);
255 if (newline < 0) {
256 goto exit;
257 }
258 skip_optional_kwonly:
259 return_value = binascii_b2a_base64_impl(module, &data, newline);
260
261 exit:
262 /* Cleanup for data */
263 if (data.obj) {
264 PyBuffer_Release(&data);
265 }
266
267 return return_value;
268 }
269
270 PyDoc_STRVAR(binascii_crc_hqx__doc__,
271 "crc_hqx($module, data, crc, /)\n"
272 "--\n"
273 "\n"
274 "Compute CRC-CCITT incrementally.");
275
276 #define BINASCII_CRC_HQX_METHODDEF \
277 {"crc_hqx", _PyCFunction_CAST(binascii_crc_hqx), METH_FASTCALL, binascii_crc_hqx__doc__},
278
279 static PyObject *
280 binascii_crc_hqx_impl(PyObject *module, Py_buffer *data, unsigned int crc);
281
282 static PyObject *
283 binascii_crc_hqx(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
284 {
285 PyObject *return_value = NULL;
286 Py_buffer data = {NULL, NULL};
287 unsigned int crc;
288
289 if (!_PyArg_CheckPositional("crc_hqx", nargs, 2, 2)) {
290 goto exit;
291 }
292 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
293 goto exit;
294 }
295 crc = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
296 if (crc == (unsigned int)-1 && PyErr_Occurred()) {
297 goto exit;
298 }
299 return_value = binascii_crc_hqx_impl(module, &data, crc);
300
301 exit:
302 /* Cleanup for data */
303 if (data.obj) {
304 PyBuffer_Release(&data);
305 }
306
307 return return_value;
308 }
309
310 PyDoc_STRVAR(binascii_crc32__doc__,
311 "crc32($module, data, crc=0, /)\n"
312 "--\n"
313 "\n"
314 "Compute CRC-32 incrementally.");
315
316 #define BINASCII_CRC32_METHODDEF \
317 {"crc32", _PyCFunction_CAST(binascii_crc32), METH_FASTCALL, binascii_crc32__doc__},
318
319 static unsigned int
320 binascii_crc32_impl(PyObject *module, Py_buffer *data, unsigned int crc);
321
322 static PyObject *
323 binascii_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
324 {
325 PyObject *return_value = NULL;
326 Py_buffer data = {NULL, NULL};
327 unsigned int crc = 0;
328 unsigned int _return_value;
329
330 if (!_PyArg_CheckPositional("crc32", nargs, 1, 2)) {
331 goto exit;
332 }
333 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
334 goto exit;
335 }
336 if (nargs < 2) {
337 goto skip_optional;
338 }
339 crc = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
340 if (crc == (unsigned int)-1 && PyErr_Occurred()) {
341 goto exit;
342 }
343 skip_optional:
344 _return_value = binascii_crc32_impl(module, &data, crc);
345 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
346 goto exit;
347 }
348 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
349
350 exit:
351 /* Cleanup for data */
352 if (data.obj) {
353 PyBuffer_Release(&data);
354 }
355
356 return return_value;
357 }
358
359 PyDoc_STRVAR(binascii_b2a_hex__doc__,
360 "b2a_hex($module, /, data, sep=<unrepresentable>, bytes_per_sep=1)\n"
361 "--\n"
362 "\n"
363 "Hexadecimal representation of binary data.\n"
364 "\n"
365 " sep\n"
366 " An optional single character or byte to separate hex bytes.\n"
367 " bytes_per_sep\n"
368 " How many bytes between separators. Positive values count from the\n"
369 " right, negative values count from the left.\n"
370 "\n"
371 "The return value is a bytes object. This function is also\n"
372 "available as \"hexlify()\".\n"
373 "\n"
374 "Example:\n"
375 ">>> binascii.b2a_hex(b\'\\xb9\\x01\\xef\')\n"
376 "b\'b901ef\'\n"
377 ">>> binascii.hexlify(b\'\\xb9\\x01\\xef\', \':\')\n"
378 "b\'b9:01:ef\'\n"
379 ">>> binascii.b2a_hex(b\'\\xb9\\x01\\xef\', b\'_\', 2)\n"
380 "b\'b9_01ef\'");
381
382 #define BINASCII_B2A_HEX_METHODDEF \
383 {"b2a_hex", _PyCFunction_CAST(binascii_b2a_hex), METH_FASTCALL|METH_KEYWORDS, binascii_b2a_hex__doc__},
384
385 static PyObject *
386 binascii_b2a_hex_impl(PyObject *module, Py_buffer *data, PyObject *sep,
387 int bytes_per_sep);
388
389 static PyObject *
390 binascii_b2a_hex(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
391 {
392 PyObject *return_value = NULL;
393 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
394
395 #define NUM_KEYWORDS 3
396 static struct {
397 PyGC_Head _this_is_not_used;
398 PyObject_VAR_HEAD
399 Py_hash_t ob_hash;
400 PyObject *ob_item[NUM_KEYWORDS];
401 } _kwtuple = {
402 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
403 .ob_hash = -1,
404 .ob_item = { &_Py_ID(data), &_Py_ID(sep), &_Py_ID(bytes_per_sep), },
405 };
406 #undef NUM_KEYWORDS
407 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
408
409 #else // !Py_BUILD_CORE
410 # define KWTUPLE NULL
411 #endif // !Py_BUILD_CORE
412
413 static const char * const _keywords[] = {"data", "sep", "bytes_per_sep", NULL};
414 static _PyArg_Parser _parser = {
415 .keywords = _keywords,
416 .fname = "b2a_hex",
417 .kwtuple = KWTUPLE,
418 };
419 #undef KWTUPLE
420 PyObject *argsbuf[3];
421 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
422 Py_buffer data = {NULL, NULL};
423 PyObject *sep = NULL;
424 int bytes_per_sep = 1;
425
426 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
427 /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
428 if (!args) {
429 goto exit;
430 }
431 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
432 goto exit;
433 }
434 if (!noptargs) {
435 goto skip_optional_pos;
436 }
437 if (args[1]) {
438 sep = args[1];
439 if (!--noptargs) {
440 goto skip_optional_pos;
441 }
442 }
443 bytes_per_sep = PyLong_AsInt(args[2]);
444 if (bytes_per_sep == -1 && PyErr_Occurred()) {
445 goto exit;
446 }
447 skip_optional_pos:
448 return_value = binascii_b2a_hex_impl(module, &data, sep, bytes_per_sep);
449
450 exit:
451 /* Cleanup for data */
452 if (data.obj) {
453 PyBuffer_Release(&data);
454 }
455
456 return return_value;
457 }
458
459 PyDoc_STRVAR(binascii_hexlify__doc__,
460 "hexlify($module, /, data, sep=<unrepresentable>, bytes_per_sep=1)\n"
461 "--\n"
462 "\n"
463 "Hexadecimal representation of binary data.\n"
464 "\n"
465 " sep\n"
466 " An optional single character or byte to separate hex bytes.\n"
467 " bytes_per_sep\n"
468 " How many bytes between separators. Positive values count from the\n"
469 " right, negative values count from the left.\n"
470 "\n"
471 "The return value is a bytes object. This function is also\n"
472 "available as \"b2a_hex()\".");
473
474 #define BINASCII_HEXLIFY_METHODDEF \
475 {"hexlify", _PyCFunction_CAST(binascii_hexlify), METH_FASTCALL|METH_KEYWORDS, binascii_hexlify__doc__},
476
477 static PyObject *
478 binascii_hexlify_impl(PyObject *module, Py_buffer *data, PyObject *sep,
479 int bytes_per_sep);
480
481 static PyObject *
482 binascii_hexlify(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
483 {
484 PyObject *return_value = NULL;
485 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
486
487 #define NUM_KEYWORDS 3
488 static struct {
489 PyGC_Head _this_is_not_used;
490 PyObject_VAR_HEAD
491 Py_hash_t ob_hash;
492 PyObject *ob_item[NUM_KEYWORDS];
493 } _kwtuple = {
494 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
495 .ob_hash = -1,
496 .ob_item = { &_Py_ID(data), &_Py_ID(sep), &_Py_ID(bytes_per_sep), },
497 };
498 #undef NUM_KEYWORDS
499 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
500
501 #else // !Py_BUILD_CORE
502 # define KWTUPLE NULL
503 #endif // !Py_BUILD_CORE
504
505 static const char * const _keywords[] = {"data", "sep", "bytes_per_sep", NULL};
506 static _PyArg_Parser _parser = {
507 .keywords = _keywords,
508 .fname = "hexlify",
509 .kwtuple = KWTUPLE,
510 };
511 #undef KWTUPLE
512 PyObject *argsbuf[3];
513 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
514 Py_buffer data = {NULL, NULL};
515 PyObject *sep = NULL;
516 int bytes_per_sep = 1;
517
518 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
519 /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
520 if (!args) {
521 goto exit;
522 }
523 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
524 goto exit;
525 }
526 if (!noptargs) {
527 goto skip_optional_pos;
528 }
529 if (args[1]) {
530 sep = args[1];
531 if (!--noptargs) {
532 goto skip_optional_pos;
533 }
534 }
535 bytes_per_sep = PyLong_AsInt(args[2]);
536 if (bytes_per_sep == -1 && PyErr_Occurred()) {
537 goto exit;
538 }
539 skip_optional_pos:
540 return_value = binascii_hexlify_impl(module, &data, sep, bytes_per_sep);
541
542 exit:
543 /* Cleanup for data */
544 if (data.obj) {
545 PyBuffer_Release(&data);
546 }
547
548 return return_value;
549 }
550
551 PyDoc_STRVAR(binascii_a2b_hex__doc__,
552 "a2b_hex($module, hexstr, /)\n"
553 "--\n"
554 "\n"
555 "Binary data of hexadecimal representation.\n"
556 "\n"
557 "hexstr must contain an even number of hex digits (upper or lower case).\n"
558 "This function is also available as \"unhexlify()\".");
559
560 #define BINASCII_A2B_HEX_METHODDEF \
561 {"a2b_hex", (PyCFunction)binascii_a2b_hex, METH_O, binascii_a2b_hex__doc__},
562
563 static PyObject *
564 binascii_a2b_hex_impl(PyObject *module, Py_buffer *hexstr);
565
566 static PyObject *
567 binascii_a2b_hex(PyObject *module, PyObject *arg)
568 {
569 PyObject *return_value = NULL;
570 Py_buffer hexstr = {NULL, NULL};
571
572 if (!ascii_buffer_converter(arg, &hexstr)) {
573 goto exit;
574 }
575 return_value = binascii_a2b_hex_impl(module, &hexstr);
576
577 exit:
578 /* Cleanup for hexstr */
579 if (hexstr.obj)
580 PyBuffer_Release(&hexstr);
581
582 return return_value;
583 }
584
585 PyDoc_STRVAR(binascii_unhexlify__doc__,
586 "unhexlify($module, hexstr, /)\n"
587 "--\n"
588 "\n"
589 "Binary data of hexadecimal representation.\n"
590 "\n"
591 "hexstr must contain an even number of hex digits (upper or lower case).");
592
593 #define BINASCII_UNHEXLIFY_METHODDEF \
594 {"unhexlify", (PyCFunction)binascii_unhexlify, METH_O, binascii_unhexlify__doc__},
595
596 static PyObject *
597 binascii_unhexlify_impl(PyObject *module, Py_buffer *hexstr);
598
599 static PyObject *
600 binascii_unhexlify(PyObject *module, PyObject *arg)
601 {
602 PyObject *return_value = NULL;
603 Py_buffer hexstr = {NULL, NULL};
604
605 if (!ascii_buffer_converter(arg, &hexstr)) {
606 goto exit;
607 }
608 return_value = binascii_unhexlify_impl(module, &hexstr);
609
610 exit:
611 /* Cleanup for hexstr */
612 if (hexstr.obj)
613 PyBuffer_Release(&hexstr);
614
615 return return_value;
616 }
617
618 PyDoc_STRVAR(binascii_a2b_qp__doc__,
619 "a2b_qp($module, /, data, header=False)\n"
620 "--\n"
621 "\n"
622 "Decode a string of qp-encoded data.");
623
624 #define BINASCII_A2B_QP_METHODDEF \
625 {"a2b_qp", _PyCFunction_CAST(binascii_a2b_qp), METH_FASTCALL|METH_KEYWORDS, binascii_a2b_qp__doc__},
626
627 static PyObject *
628 binascii_a2b_qp_impl(PyObject *module, Py_buffer *data, int header);
629
630 static PyObject *
631 binascii_a2b_qp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
632 {
633 PyObject *return_value = NULL;
634 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
635
636 #define NUM_KEYWORDS 2
637 static struct {
638 PyGC_Head _this_is_not_used;
639 PyObject_VAR_HEAD
640 Py_hash_t ob_hash;
641 PyObject *ob_item[NUM_KEYWORDS];
642 } _kwtuple = {
643 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
644 .ob_hash = -1,
645 .ob_item = { &_Py_ID(data), &_Py_ID(header), },
646 };
647 #undef NUM_KEYWORDS
648 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
649
650 #else // !Py_BUILD_CORE
651 # define KWTUPLE NULL
652 #endif // !Py_BUILD_CORE
653
654 static const char * const _keywords[] = {"data", "header", NULL};
655 static _PyArg_Parser _parser = {
656 .keywords = _keywords,
657 .fname = "a2b_qp",
658 .kwtuple = KWTUPLE,
659 };
660 #undef KWTUPLE
661 PyObject *argsbuf[2];
662 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
663 Py_buffer data = {NULL, NULL};
664 int header = 0;
665
666 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
667 /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
668 if (!args) {
669 goto exit;
670 }
671 if (!ascii_buffer_converter(args[0], &data)) {
672 goto exit;
673 }
674 if (!noptargs) {
675 goto skip_optional_pos;
676 }
677 header = PyObject_IsTrue(args[1]);
678 if (header < 0) {
679 goto exit;
680 }
681 skip_optional_pos:
682 return_value = binascii_a2b_qp_impl(module, &data, header);
683
684 exit:
685 /* Cleanup for data */
686 if (data.obj)
687 PyBuffer_Release(&data);
688
689 return return_value;
690 }
691
692 PyDoc_STRVAR(binascii_b2a_qp__doc__,
693 "b2a_qp($module, /, data, quotetabs=False, istext=True, header=False)\n"
694 "--\n"
695 "\n"
696 "Encode a string using quoted-printable encoding.\n"
697 "\n"
698 "On encoding, when istext is set, newlines are not encoded, and white\n"
699 "space at end of lines is. When istext is not set, \\r and \\n (CR/LF)\n"
700 "are both encoded. When quotetabs is set, space and tabs are encoded.");
701
702 #define BINASCII_B2A_QP_METHODDEF \
703 {"b2a_qp", _PyCFunction_CAST(binascii_b2a_qp), METH_FASTCALL|METH_KEYWORDS, binascii_b2a_qp__doc__},
704
705 static PyObject *
706 binascii_b2a_qp_impl(PyObject *module, Py_buffer *data, int quotetabs,
707 int istext, int header);
708
709 static PyObject *
710 binascii_b2a_qp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
711 {
712 PyObject *return_value = NULL;
713 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
714
715 #define NUM_KEYWORDS 4
716 static struct {
717 PyGC_Head _this_is_not_used;
718 PyObject_VAR_HEAD
719 Py_hash_t ob_hash;
720 PyObject *ob_item[NUM_KEYWORDS];
721 } _kwtuple = {
722 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
723 .ob_hash = -1,
724 .ob_item = { &_Py_ID(data), &_Py_ID(quotetabs), &_Py_ID(istext), &_Py_ID(header), },
725 };
726 #undef NUM_KEYWORDS
727 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
728
729 #else // !Py_BUILD_CORE
730 # define KWTUPLE NULL
731 #endif // !Py_BUILD_CORE
732
733 static const char * const _keywords[] = {"data", "quotetabs", "istext", "header", NULL};
734 static _PyArg_Parser _parser = {
735 .keywords = _keywords,
736 .fname = "b2a_qp",
737 .kwtuple = KWTUPLE,
738 };
739 #undef KWTUPLE
740 PyObject *argsbuf[4];
741 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
742 Py_buffer data = {NULL, NULL};
743 int quotetabs = 0;
744 int istext = 1;
745 int header = 0;
746
747 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
748 /*minpos*/ 1, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
749 if (!args) {
750 goto exit;
751 }
752 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
753 goto exit;
754 }
755 if (!noptargs) {
756 goto skip_optional_pos;
757 }
758 if (args[1]) {
759 quotetabs = PyObject_IsTrue(args[1]);
760 if (quotetabs < 0) {
761 goto exit;
762 }
763 if (!--noptargs) {
764 goto skip_optional_pos;
765 }
766 }
767 if (args[2]) {
768 istext = PyObject_IsTrue(args[2]);
769 if (istext < 0) {
770 goto exit;
771 }
772 if (!--noptargs) {
773 goto skip_optional_pos;
774 }
775 }
776 header = PyObject_IsTrue(args[3]);
777 if (header < 0) {
778 goto exit;
779 }
780 skip_optional_pos:
781 return_value = binascii_b2a_qp_impl(module, &data, quotetabs, istext, header);
782
783 exit:
784 /* Cleanup for data */
785 if (data.obj) {
786 PyBuffer_Release(&data);
787 }
788
789 return return_value;
790 }
791 /*[clinic end generated code: output=adb855a2797c3cad input=a9049054013a1b77]*/