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