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