• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)(void(*)(void))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, /)\n"
91 "--\n"
92 "\n"
93 "Decode a line of base64 data.");
94 
95 #define BINASCII_A2B_BASE64_METHODDEF    \
96     {"a2b_base64", (PyCFunction)binascii_a2b_base64, METH_O, binascii_a2b_base64__doc__},
97 
98 static PyObject *
99 binascii_a2b_base64_impl(PyObject *module, Py_buffer *data);
100 
101 static PyObject *
binascii_a2b_base64(PyObject * module,PyObject * arg)102 binascii_a2b_base64(PyObject *module, PyObject *arg)
103 {
104     PyObject *return_value = NULL;
105     Py_buffer data = {NULL, NULL};
106 
107     if (!ascii_buffer_converter(arg, &data)) {
108         goto exit;
109     }
110     return_value = binascii_a2b_base64_impl(module, &data);
111 
112 exit:
113     /* Cleanup for data */
114     if (data.obj)
115        PyBuffer_Release(&data);
116 
117     return return_value;
118 }
119 
120 PyDoc_STRVAR(binascii_b2a_base64__doc__,
121 "b2a_base64($module, data, /, *, newline=True)\n"
122 "--\n"
123 "\n"
124 "Base64-code line of data.");
125 
126 #define BINASCII_B2A_BASE64_METHODDEF    \
127     {"b2a_base64", (PyCFunction)(void(*)(void))binascii_b2a_base64, METH_FASTCALL|METH_KEYWORDS, binascii_b2a_base64__doc__},
128 
129 static PyObject *
130 binascii_b2a_base64_impl(PyObject *module, Py_buffer *data, int newline);
131 
132 static PyObject *
binascii_b2a_base64(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)133 binascii_b2a_base64(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
134 {
135     PyObject *return_value = NULL;
136     static const char * const _keywords[] = {"", "newline", NULL};
137     static _PyArg_Parser _parser = {NULL, _keywords, "b2a_base64", 0};
138     PyObject *argsbuf[2];
139     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
140     Py_buffer data = {NULL, NULL};
141     int newline = 1;
142 
143     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
144     if (!args) {
145         goto exit;
146     }
147     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
148         goto exit;
149     }
150     if (!PyBuffer_IsContiguous(&data, 'C')) {
151         _PyArg_BadArgument("b2a_base64", "argument 1", "contiguous buffer", args[0]);
152         goto exit;
153     }
154     if (!noptargs) {
155         goto skip_optional_kwonly;
156     }
157     newline = _PyLong_AsInt(args[1]);
158     if (newline == -1 && PyErr_Occurred()) {
159         goto exit;
160     }
161 skip_optional_kwonly:
162     return_value = binascii_b2a_base64_impl(module, &data, newline);
163 
164 exit:
165     /* Cleanup for data */
166     if (data.obj) {
167        PyBuffer_Release(&data);
168     }
169 
170     return return_value;
171 }
172 
173 PyDoc_STRVAR(binascii_a2b_hqx__doc__,
174 "a2b_hqx($module, data, /)\n"
175 "--\n"
176 "\n"
177 "Decode .hqx coding.");
178 
179 #define BINASCII_A2B_HQX_METHODDEF    \
180     {"a2b_hqx", (PyCFunction)binascii_a2b_hqx, METH_O, binascii_a2b_hqx__doc__},
181 
182 static PyObject *
183 binascii_a2b_hqx_impl(PyObject *module, Py_buffer *data);
184 
185 static PyObject *
binascii_a2b_hqx(PyObject * module,PyObject * arg)186 binascii_a2b_hqx(PyObject *module, PyObject *arg)
187 {
188     PyObject *return_value = NULL;
189     Py_buffer data = {NULL, NULL};
190 
191     if (!ascii_buffer_converter(arg, &data)) {
192         goto exit;
193     }
194     return_value = binascii_a2b_hqx_impl(module, &data);
195 
196 exit:
197     /* Cleanup for data */
198     if (data.obj)
199        PyBuffer_Release(&data);
200 
201     return return_value;
202 }
203 
204 PyDoc_STRVAR(binascii_rlecode_hqx__doc__,
205 "rlecode_hqx($module, data, /)\n"
206 "--\n"
207 "\n"
208 "Binhex RLE-code binary data.");
209 
210 #define BINASCII_RLECODE_HQX_METHODDEF    \
211     {"rlecode_hqx", (PyCFunction)binascii_rlecode_hqx, METH_O, binascii_rlecode_hqx__doc__},
212 
213 static PyObject *
214 binascii_rlecode_hqx_impl(PyObject *module, Py_buffer *data);
215 
216 static PyObject *
binascii_rlecode_hqx(PyObject * module,PyObject * arg)217 binascii_rlecode_hqx(PyObject *module, PyObject *arg)
218 {
219     PyObject *return_value = NULL;
220     Py_buffer data = {NULL, NULL};
221 
222     if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
223         goto exit;
224     }
225     if (!PyBuffer_IsContiguous(&data, 'C')) {
226         _PyArg_BadArgument("rlecode_hqx", "argument", "contiguous buffer", arg);
227         goto exit;
228     }
229     return_value = binascii_rlecode_hqx_impl(module, &data);
230 
231 exit:
232     /* Cleanup for data */
233     if (data.obj) {
234        PyBuffer_Release(&data);
235     }
236 
237     return return_value;
238 }
239 
240 PyDoc_STRVAR(binascii_b2a_hqx__doc__,
241 "b2a_hqx($module, data, /)\n"
242 "--\n"
243 "\n"
244 "Encode .hqx data.");
245 
246 #define BINASCII_B2A_HQX_METHODDEF    \
247     {"b2a_hqx", (PyCFunction)binascii_b2a_hqx, METH_O, binascii_b2a_hqx__doc__},
248 
249 static PyObject *
250 binascii_b2a_hqx_impl(PyObject *module, Py_buffer *data);
251 
252 static PyObject *
binascii_b2a_hqx(PyObject * module,PyObject * arg)253 binascii_b2a_hqx(PyObject *module, PyObject *arg)
254 {
255     PyObject *return_value = NULL;
256     Py_buffer data = {NULL, NULL};
257 
258     if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
259         goto exit;
260     }
261     if (!PyBuffer_IsContiguous(&data, 'C')) {
262         _PyArg_BadArgument("b2a_hqx", "argument", "contiguous buffer", arg);
263         goto exit;
264     }
265     return_value = binascii_b2a_hqx_impl(module, &data);
266 
267 exit:
268     /* Cleanup for data */
269     if (data.obj) {
270        PyBuffer_Release(&data);
271     }
272 
273     return return_value;
274 }
275 
276 PyDoc_STRVAR(binascii_rledecode_hqx__doc__,
277 "rledecode_hqx($module, data, /)\n"
278 "--\n"
279 "\n"
280 "Decode hexbin RLE-coded string.");
281 
282 #define BINASCII_RLEDECODE_HQX_METHODDEF    \
283     {"rledecode_hqx", (PyCFunction)binascii_rledecode_hqx, METH_O, binascii_rledecode_hqx__doc__},
284 
285 static PyObject *
286 binascii_rledecode_hqx_impl(PyObject *module, Py_buffer *data);
287 
288 static PyObject *
binascii_rledecode_hqx(PyObject * module,PyObject * arg)289 binascii_rledecode_hqx(PyObject *module, PyObject *arg)
290 {
291     PyObject *return_value = NULL;
292     Py_buffer data = {NULL, NULL};
293 
294     if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
295         goto exit;
296     }
297     if (!PyBuffer_IsContiguous(&data, 'C')) {
298         _PyArg_BadArgument("rledecode_hqx", "argument", "contiguous buffer", arg);
299         goto exit;
300     }
301     return_value = binascii_rledecode_hqx_impl(module, &data);
302 
303 exit:
304     /* Cleanup for data */
305     if (data.obj) {
306        PyBuffer_Release(&data);
307     }
308 
309     return return_value;
310 }
311 
312 PyDoc_STRVAR(binascii_crc_hqx__doc__,
313 "crc_hqx($module, data, crc, /)\n"
314 "--\n"
315 "\n"
316 "Compute CRC-CCITT incrementally.");
317 
318 #define BINASCII_CRC_HQX_METHODDEF    \
319     {"crc_hqx", (PyCFunction)(void(*)(void))binascii_crc_hqx, METH_FASTCALL, binascii_crc_hqx__doc__},
320 
321 static PyObject *
322 binascii_crc_hqx_impl(PyObject *module, Py_buffer *data, unsigned int crc);
323 
324 static PyObject *
binascii_crc_hqx(PyObject * module,PyObject * const * args,Py_ssize_t nargs)325 binascii_crc_hqx(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
326 {
327     PyObject *return_value = NULL;
328     Py_buffer data = {NULL, NULL};
329     unsigned int crc;
330 
331     if (!_PyArg_CheckPositional("crc_hqx", nargs, 2, 2)) {
332         goto exit;
333     }
334     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
335         goto exit;
336     }
337     if (!PyBuffer_IsContiguous(&data, 'C')) {
338         _PyArg_BadArgument("crc_hqx", "argument 1", "contiguous buffer", args[0]);
339         goto exit;
340     }
341     crc = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
342     if (crc == (unsigned int)-1 && PyErr_Occurred()) {
343         goto exit;
344     }
345     return_value = binascii_crc_hqx_impl(module, &data, crc);
346 
347 exit:
348     /* Cleanup for data */
349     if (data.obj) {
350        PyBuffer_Release(&data);
351     }
352 
353     return return_value;
354 }
355 
356 PyDoc_STRVAR(binascii_crc32__doc__,
357 "crc32($module, data, crc=0, /)\n"
358 "--\n"
359 "\n"
360 "Compute CRC-32 incrementally.");
361 
362 #define BINASCII_CRC32_METHODDEF    \
363     {"crc32", (PyCFunction)(void(*)(void))binascii_crc32, METH_FASTCALL, binascii_crc32__doc__},
364 
365 static unsigned int
366 binascii_crc32_impl(PyObject *module, Py_buffer *data, unsigned int crc);
367 
368 static PyObject *
binascii_crc32(PyObject * module,PyObject * const * args,Py_ssize_t nargs)369 binascii_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
370 {
371     PyObject *return_value = NULL;
372     Py_buffer data = {NULL, NULL};
373     unsigned int crc = 0;
374     unsigned int _return_value;
375 
376     if (!_PyArg_CheckPositional("crc32", nargs, 1, 2)) {
377         goto exit;
378     }
379     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
380         goto exit;
381     }
382     if (!PyBuffer_IsContiguous(&data, 'C')) {
383         _PyArg_BadArgument("crc32", "argument 1", "contiguous buffer", args[0]);
384         goto exit;
385     }
386     if (nargs < 2) {
387         goto skip_optional;
388     }
389     crc = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
390     if (crc == (unsigned int)-1 && PyErr_Occurred()) {
391         goto exit;
392     }
393 skip_optional:
394     _return_value = binascii_crc32_impl(module, &data, crc);
395     if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
396         goto exit;
397     }
398     return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
399 
400 exit:
401     /* Cleanup for data */
402     if (data.obj) {
403        PyBuffer_Release(&data);
404     }
405 
406     return return_value;
407 }
408 
409 PyDoc_STRVAR(binascii_b2a_hex__doc__,
410 "b2a_hex($module, /, data, sep=<unrepresentable>, bytes_per_sep=1)\n"
411 "--\n"
412 "\n"
413 "Hexadecimal representation of binary data.\n"
414 "\n"
415 "  sep\n"
416 "    An optional single character or byte to separate hex bytes.\n"
417 "  bytes_per_sep\n"
418 "    How many bytes between separators.  Positive values count from the\n"
419 "    right, negative values count from the left.\n"
420 "\n"
421 "The return value is a bytes object.  This function is also\n"
422 "available as \"hexlify()\".\n"
423 "\n"
424 "Example:\n"
425 ">>> binascii.b2a_hex(b\'\\xb9\\x01\\xef\')\n"
426 "b\'b901ef\'\n"
427 ">>> binascii.hexlify(b\'\\xb9\\x01\\xef\', \':\')\n"
428 "b\'b9:01:ef\'\n"
429 ">>> binascii.b2a_hex(b\'\\xb9\\x01\\xef\', b\'_\', 2)\n"
430 "b\'b9_01ef\'");
431 
432 #define BINASCII_B2A_HEX_METHODDEF    \
433     {"b2a_hex", (PyCFunction)(void(*)(void))binascii_b2a_hex, METH_FASTCALL|METH_KEYWORDS, binascii_b2a_hex__doc__},
434 
435 static PyObject *
436 binascii_b2a_hex_impl(PyObject *module, Py_buffer *data, PyObject *sep,
437                       int bytes_per_sep);
438 
439 static PyObject *
binascii_b2a_hex(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)440 binascii_b2a_hex(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
441 {
442     PyObject *return_value = NULL;
443     static const char * const _keywords[] = {"data", "sep", "bytes_per_sep", NULL};
444     static _PyArg_Parser _parser = {NULL, _keywords, "b2a_hex", 0};
445     PyObject *argsbuf[3];
446     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
447     Py_buffer data = {NULL, NULL};
448     PyObject *sep = NULL;
449     int bytes_per_sep = 1;
450 
451     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
452     if (!args) {
453         goto exit;
454     }
455     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
456         goto exit;
457     }
458     if (!PyBuffer_IsContiguous(&data, 'C')) {
459         _PyArg_BadArgument("b2a_hex", "argument 'data'", "contiguous buffer", args[0]);
460         goto exit;
461     }
462     if (!noptargs) {
463         goto skip_optional_pos;
464     }
465     if (args[1]) {
466         sep = args[1];
467         if (!--noptargs) {
468             goto skip_optional_pos;
469         }
470     }
471     bytes_per_sep = _PyLong_AsInt(args[2]);
472     if (bytes_per_sep == -1 && PyErr_Occurred()) {
473         goto exit;
474     }
475 skip_optional_pos:
476     return_value = binascii_b2a_hex_impl(module, &data, sep, bytes_per_sep);
477 
478 exit:
479     /* Cleanup for data */
480     if (data.obj) {
481        PyBuffer_Release(&data);
482     }
483 
484     return return_value;
485 }
486 
487 PyDoc_STRVAR(binascii_hexlify__doc__,
488 "hexlify($module, /, data, sep=<unrepresentable>, bytes_per_sep=1)\n"
489 "--\n"
490 "\n"
491 "Hexadecimal representation of binary data.\n"
492 "\n"
493 "  sep\n"
494 "    An optional single character or byte to separate hex bytes.\n"
495 "  bytes_per_sep\n"
496 "    How many bytes between separators.  Positive values count from the\n"
497 "    right, negative values count from the left.\n"
498 "\n"
499 "The return value is a bytes object.  This function is also\n"
500 "available as \"b2a_hex()\".");
501 
502 #define BINASCII_HEXLIFY_METHODDEF    \
503     {"hexlify", (PyCFunction)(void(*)(void))binascii_hexlify, METH_FASTCALL|METH_KEYWORDS, binascii_hexlify__doc__},
504 
505 static PyObject *
506 binascii_hexlify_impl(PyObject *module, Py_buffer *data, PyObject *sep,
507                       int bytes_per_sep);
508 
509 static PyObject *
binascii_hexlify(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)510 binascii_hexlify(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
511 {
512     PyObject *return_value = NULL;
513     static const char * const _keywords[] = {"data", "sep", "bytes_per_sep", NULL};
514     static _PyArg_Parser _parser = {NULL, _keywords, "hexlify", 0};
515     PyObject *argsbuf[3];
516     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
517     Py_buffer data = {NULL, NULL};
518     PyObject *sep = NULL;
519     int bytes_per_sep = 1;
520 
521     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
522     if (!args) {
523         goto exit;
524     }
525     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
526         goto exit;
527     }
528     if (!PyBuffer_IsContiguous(&data, 'C')) {
529         _PyArg_BadArgument("hexlify", "argument 'data'", "contiguous buffer", args[0]);
530         goto exit;
531     }
532     if (!noptargs) {
533         goto skip_optional_pos;
534     }
535     if (args[1]) {
536         sep = args[1];
537         if (!--noptargs) {
538             goto skip_optional_pos;
539         }
540     }
541     bytes_per_sep = _PyLong_AsInt(args[2]);
542     if (bytes_per_sep == -1 && PyErr_Occurred()) {
543         goto exit;
544     }
545 skip_optional_pos:
546     return_value = binascii_hexlify_impl(module, &data, sep, bytes_per_sep);
547 
548 exit:
549     /* Cleanup for data */
550     if (data.obj) {
551        PyBuffer_Release(&data);
552     }
553 
554     return return_value;
555 }
556 
557 PyDoc_STRVAR(binascii_a2b_hex__doc__,
558 "a2b_hex($module, hexstr, /)\n"
559 "--\n"
560 "\n"
561 "Binary data of hexadecimal representation.\n"
562 "\n"
563 "hexstr must contain an even number of hex digits (upper or lower case).\n"
564 "This function is also available as \"unhexlify()\".");
565 
566 #define BINASCII_A2B_HEX_METHODDEF    \
567     {"a2b_hex", (PyCFunction)binascii_a2b_hex, METH_O, binascii_a2b_hex__doc__},
568 
569 static PyObject *
570 binascii_a2b_hex_impl(PyObject *module, Py_buffer *hexstr);
571 
572 static PyObject *
binascii_a2b_hex(PyObject * module,PyObject * arg)573 binascii_a2b_hex(PyObject *module, PyObject *arg)
574 {
575     PyObject *return_value = NULL;
576     Py_buffer hexstr = {NULL, NULL};
577 
578     if (!ascii_buffer_converter(arg, &hexstr)) {
579         goto exit;
580     }
581     return_value = binascii_a2b_hex_impl(module, &hexstr);
582 
583 exit:
584     /* Cleanup for hexstr */
585     if (hexstr.obj)
586        PyBuffer_Release(&hexstr);
587 
588     return return_value;
589 }
590 
591 PyDoc_STRVAR(binascii_unhexlify__doc__,
592 "unhexlify($module, hexstr, /)\n"
593 "--\n"
594 "\n"
595 "Binary data of hexadecimal representation.\n"
596 "\n"
597 "hexstr must contain an even number of hex digits (upper or lower case).");
598 
599 #define BINASCII_UNHEXLIFY_METHODDEF    \
600     {"unhexlify", (PyCFunction)binascii_unhexlify, METH_O, binascii_unhexlify__doc__},
601 
602 static PyObject *
603 binascii_unhexlify_impl(PyObject *module, Py_buffer *hexstr);
604 
605 static PyObject *
binascii_unhexlify(PyObject * module,PyObject * arg)606 binascii_unhexlify(PyObject *module, PyObject *arg)
607 {
608     PyObject *return_value = NULL;
609     Py_buffer hexstr = {NULL, NULL};
610 
611     if (!ascii_buffer_converter(arg, &hexstr)) {
612         goto exit;
613     }
614     return_value = binascii_unhexlify_impl(module, &hexstr);
615 
616 exit:
617     /* Cleanup for hexstr */
618     if (hexstr.obj)
619        PyBuffer_Release(&hexstr);
620 
621     return return_value;
622 }
623 
624 PyDoc_STRVAR(binascii_a2b_qp__doc__,
625 "a2b_qp($module, /, data, header=False)\n"
626 "--\n"
627 "\n"
628 "Decode a string of qp-encoded data.");
629 
630 #define BINASCII_A2B_QP_METHODDEF    \
631     {"a2b_qp", (PyCFunction)(void(*)(void))binascii_a2b_qp, METH_FASTCALL|METH_KEYWORDS, binascii_a2b_qp__doc__},
632 
633 static PyObject *
634 binascii_a2b_qp_impl(PyObject *module, Py_buffer *data, int header);
635 
636 static PyObject *
binascii_a2b_qp(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)637 binascii_a2b_qp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
638 {
639     PyObject *return_value = NULL;
640     static const char * const _keywords[] = {"data", "header", NULL};
641     static _PyArg_Parser _parser = {NULL, _keywords, "a2b_qp", 0};
642     PyObject *argsbuf[2];
643     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
644     Py_buffer data = {NULL, NULL};
645     int header = 0;
646 
647     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
648     if (!args) {
649         goto exit;
650     }
651     if (!ascii_buffer_converter(args[0], &data)) {
652         goto exit;
653     }
654     if (!noptargs) {
655         goto skip_optional_pos;
656     }
657     header = _PyLong_AsInt(args[1]);
658     if (header == -1 && PyErr_Occurred()) {
659         goto exit;
660     }
661 skip_optional_pos:
662     return_value = binascii_a2b_qp_impl(module, &data, header);
663 
664 exit:
665     /* Cleanup for data */
666     if (data.obj)
667        PyBuffer_Release(&data);
668 
669     return return_value;
670 }
671 
672 PyDoc_STRVAR(binascii_b2a_qp__doc__,
673 "b2a_qp($module, /, data, quotetabs=False, istext=True, header=False)\n"
674 "--\n"
675 "\n"
676 "Encode a string using quoted-printable encoding.\n"
677 "\n"
678 "On encoding, when istext is set, newlines are not encoded, and white\n"
679 "space at end of lines is.  When istext is not set, \\r and \\n (CR/LF)\n"
680 "are both encoded.  When quotetabs is set, space and tabs are encoded.");
681 
682 #define BINASCII_B2A_QP_METHODDEF    \
683     {"b2a_qp", (PyCFunction)(void(*)(void))binascii_b2a_qp, METH_FASTCALL|METH_KEYWORDS, binascii_b2a_qp__doc__},
684 
685 static PyObject *
686 binascii_b2a_qp_impl(PyObject *module, Py_buffer *data, int quotetabs,
687                      int istext, int header);
688 
689 static PyObject *
binascii_b2a_qp(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)690 binascii_b2a_qp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
691 {
692     PyObject *return_value = NULL;
693     static const char * const _keywords[] = {"data", "quotetabs", "istext", "header", NULL};
694     static _PyArg_Parser _parser = {NULL, _keywords, "b2a_qp", 0};
695     PyObject *argsbuf[4];
696     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
697     Py_buffer data = {NULL, NULL};
698     int quotetabs = 0;
699     int istext = 1;
700     int header = 0;
701 
702     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 4, 0, argsbuf);
703     if (!args) {
704         goto exit;
705     }
706     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
707         goto exit;
708     }
709     if (!PyBuffer_IsContiguous(&data, 'C')) {
710         _PyArg_BadArgument("b2a_qp", "argument 'data'", "contiguous buffer", args[0]);
711         goto exit;
712     }
713     if (!noptargs) {
714         goto skip_optional_pos;
715     }
716     if (args[1]) {
717         quotetabs = _PyLong_AsInt(args[1]);
718         if (quotetabs == -1 && PyErr_Occurred()) {
719             goto exit;
720         }
721         if (!--noptargs) {
722             goto skip_optional_pos;
723         }
724     }
725     if (args[2]) {
726         istext = _PyLong_AsInt(args[2]);
727         if (istext == -1 && PyErr_Occurred()) {
728             goto exit;
729         }
730         if (!--noptargs) {
731             goto skip_optional_pos;
732         }
733     }
734     header = _PyLong_AsInt(args[3]);
735     if (header == -1 && PyErr_Occurred()) {
736         goto exit;
737     }
738 skip_optional_pos:
739     return_value = binascii_b2a_qp_impl(module, &data, quotetabs, istext, header);
740 
741 exit:
742     /* Cleanup for data */
743     if (data.obj) {
744        PyBuffer_Release(&data);
745     }
746 
747     return return_value;
748 }
749 /*[clinic end generated code: output=95a0178f30801b89 input=a9049054013a1b77]*/
750