• 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     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 PyObject *
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 
341     if (!_PyArg_CheckPositional("crc_hqx", nargs, 2, 2)) {
342         goto exit;
343     }
344     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
345         goto exit;
346     }
347     if (!PyBuffer_IsContiguous(&data, 'C')) {
348         _PyArg_BadArgument("crc_hqx", "argument 1", "contiguous buffer", args[0]);
349         goto exit;
350     }
351     if (PyFloat_Check(args[1])) {
352         PyErr_SetString(PyExc_TypeError,
353                         "integer argument expected, got float" );
354         goto exit;
355     }
356     crc = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
357     if (crc == (unsigned int)-1 && PyErr_Occurred()) {
358         goto exit;
359     }
360     return_value = binascii_crc_hqx_impl(module, &data, crc);
361 
362 exit:
363     /* Cleanup for data */
364     if (data.obj) {
365        PyBuffer_Release(&data);
366     }
367 
368     return return_value;
369 }
370 
371 PyDoc_STRVAR(binascii_crc32__doc__,
372 "crc32($module, data, crc=0, /)\n"
373 "--\n"
374 "\n"
375 "Compute CRC-32 incrementally.");
376 
377 #define BINASCII_CRC32_METHODDEF    \
378     {"crc32", (PyCFunction)(void(*)(void))binascii_crc32, METH_FASTCALL, binascii_crc32__doc__},
379 
380 static unsigned int
381 binascii_crc32_impl(PyObject *module, Py_buffer *data, unsigned int crc);
382 
383 static PyObject *
binascii_crc32(PyObject * module,PyObject * const * args,Py_ssize_t nargs)384 binascii_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
385 {
386     PyObject *return_value = NULL;
387     Py_buffer data = {NULL, NULL};
388     unsigned int crc = 0;
389     unsigned int _return_value;
390 
391     if (!_PyArg_CheckPositional("crc32", nargs, 1, 2)) {
392         goto exit;
393     }
394     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
395         goto exit;
396     }
397     if (!PyBuffer_IsContiguous(&data, 'C')) {
398         _PyArg_BadArgument("crc32", "argument 1", "contiguous buffer", args[0]);
399         goto exit;
400     }
401     if (nargs < 2) {
402         goto skip_optional;
403     }
404     if (PyFloat_Check(args[1])) {
405         PyErr_SetString(PyExc_TypeError,
406                         "integer argument expected, got float" );
407         goto exit;
408     }
409     crc = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
410     if (crc == (unsigned int)-1 && PyErr_Occurred()) {
411         goto exit;
412     }
413 skip_optional:
414     _return_value = binascii_crc32_impl(module, &data, crc);
415     if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
416         goto exit;
417     }
418     return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
419 
420 exit:
421     /* Cleanup for data */
422     if (data.obj) {
423        PyBuffer_Release(&data);
424     }
425 
426     return return_value;
427 }
428 
429 PyDoc_STRVAR(binascii_b2a_hex__doc__,
430 "b2a_hex($module, /, data, sep=<unrepresentable>, bytes_per_sep=1)\n"
431 "--\n"
432 "\n"
433 "Hexadecimal representation of binary data.\n"
434 "\n"
435 "  sep\n"
436 "    An optional single character or byte to separate hex bytes.\n"
437 "  bytes_per_sep\n"
438 "    How many bytes between separators.  Positive values count from the\n"
439 "    right, negative values count from the left.\n"
440 "\n"
441 "The return value is a bytes object.  This function is also\n"
442 "available as \"hexlify()\".\n"
443 "\n"
444 "Example:\n"
445 ">>> binascii.b2a_hex(b\'\\xb9\\x01\\xef\')\n"
446 "b\'b901ef\'\n"
447 ">>> binascii.hexlify(b\'\\xb9\\x01\\xef\', \':\')\n"
448 "b\'b9:01:ef\'\n"
449 ">>> binascii.b2a_hex(b\'\\xb9\\x01\\xef\', b\'_\', 2)\n"
450 "b\'b9_01ef\'");
451 
452 #define BINASCII_B2A_HEX_METHODDEF    \
453     {"b2a_hex", (PyCFunction)(void(*)(void))binascii_b2a_hex, METH_FASTCALL|METH_KEYWORDS, binascii_b2a_hex__doc__},
454 
455 static PyObject *
456 binascii_b2a_hex_impl(PyObject *module, Py_buffer *data, PyObject *sep,
457                       int bytes_per_sep);
458 
459 static PyObject *
binascii_b2a_hex(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)460 binascii_b2a_hex(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
461 {
462     PyObject *return_value = NULL;
463     static const char * const _keywords[] = {"data", "sep", "bytes_per_sep", NULL};
464     static _PyArg_Parser _parser = {NULL, _keywords, "b2a_hex", 0};
465     PyObject *argsbuf[3];
466     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
467     Py_buffer data = {NULL, NULL};
468     PyObject *sep = NULL;
469     int bytes_per_sep = 1;
470 
471     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
472     if (!args) {
473         goto exit;
474     }
475     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
476         goto exit;
477     }
478     if (!PyBuffer_IsContiguous(&data, 'C')) {
479         _PyArg_BadArgument("b2a_hex", "argument 'data'", "contiguous buffer", args[0]);
480         goto exit;
481     }
482     if (!noptargs) {
483         goto skip_optional_pos;
484     }
485     if (args[1]) {
486         sep = args[1];
487         if (!--noptargs) {
488             goto skip_optional_pos;
489         }
490     }
491     if (PyFloat_Check(args[2])) {
492         PyErr_SetString(PyExc_TypeError,
493                         "integer argument expected, got float" );
494         goto exit;
495     }
496     bytes_per_sep = _PyLong_AsInt(args[2]);
497     if (bytes_per_sep == -1 && PyErr_Occurred()) {
498         goto exit;
499     }
500 skip_optional_pos:
501     return_value = binascii_b2a_hex_impl(module, &data, sep, bytes_per_sep);
502 
503 exit:
504     /* Cleanup for data */
505     if (data.obj) {
506        PyBuffer_Release(&data);
507     }
508 
509     return return_value;
510 }
511 
512 PyDoc_STRVAR(binascii_hexlify__doc__,
513 "hexlify($module, /, data, sep=<unrepresentable>, bytes_per_sep=1)\n"
514 "--\n"
515 "\n"
516 "Hexadecimal representation of binary data.\n"
517 "\n"
518 "  sep\n"
519 "    An optional single character or byte to separate hex bytes.\n"
520 "  bytes_per_sep\n"
521 "    How many bytes between separators.  Positive values count from the\n"
522 "    right, negative values count from the left.\n"
523 "\n"
524 "The return value is a bytes object.  This function is also\n"
525 "available as \"b2a_hex()\".");
526 
527 #define BINASCII_HEXLIFY_METHODDEF    \
528     {"hexlify", (PyCFunction)(void(*)(void))binascii_hexlify, METH_FASTCALL|METH_KEYWORDS, binascii_hexlify__doc__},
529 
530 static PyObject *
531 binascii_hexlify_impl(PyObject *module, Py_buffer *data, PyObject *sep,
532                       int bytes_per_sep);
533 
534 static PyObject *
binascii_hexlify(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)535 binascii_hexlify(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
536 {
537     PyObject *return_value = NULL;
538     static const char * const _keywords[] = {"data", "sep", "bytes_per_sep", NULL};
539     static _PyArg_Parser _parser = {NULL, _keywords, "hexlify", 0};
540     PyObject *argsbuf[3];
541     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
542     Py_buffer data = {NULL, NULL};
543     PyObject *sep = NULL;
544     int bytes_per_sep = 1;
545 
546     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
547     if (!args) {
548         goto exit;
549     }
550     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
551         goto exit;
552     }
553     if (!PyBuffer_IsContiguous(&data, 'C')) {
554         _PyArg_BadArgument("hexlify", "argument 'data'", "contiguous buffer", args[0]);
555         goto exit;
556     }
557     if (!noptargs) {
558         goto skip_optional_pos;
559     }
560     if (args[1]) {
561         sep = args[1];
562         if (!--noptargs) {
563             goto skip_optional_pos;
564         }
565     }
566     if (PyFloat_Check(args[2])) {
567         PyErr_SetString(PyExc_TypeError,
568                         "integer argument expected, got float" );
569         goto exit;
570     }
571     bytes_per_sep = _PyLong_AsInt(args[2]);
572     if (bytes_per_sep == -1 && PyErr_Occurred()) {
573         goto exit;
574     }
575 skip_optional_pos:
576     return_value = binascii_hexlify_impl(module, &data, sep, bytes_per_sep);
577 
578 exit:
579     /* Cleanup for data */
580     if (data.obj) {
581        PyBuffer_Release(&data);
582     }
583 
584     return return_value;
585 }
586 
587 PyDoc_STRVAR(binascii_a2b_hex__doc__,
588 "a2b_hex($module, hexstr, /)\n"
589 "--\n"
590 "\n"
591 "Binary data of hexadecimal representation.\n"
592 "\n"
593 "hexstr must contain an even number of hex digits (upper or lower case).\n"
594 "This function is also available as \"unhexlify()\".");
595 
596 #define BINASCII_A2B_HEX_METHODDEF    \
597     {"a2b_hex", (PyCFunction)binascii_a2b_hex, METH_O, binascii_a2b_hex__doc__},
598 
599 static PyObject *
600 binascii_a2b_hex_impl(PyObject *module, Py_buffer *hexstr);
601 
602 static PyObject *
binascii_a2b_hex(PyObject * module,PyObject * arg)603 binascii_a2b_hex(PyObject *module, PyObject *arg)
604 {
605     PyObject *return_value = NULL;
606     Py_buffer hexstr = {NULL, NULL};
607 
608     if (!ascii_buffer_converter(arg, &hexstr)) {
609         goto exit;
610     }
611     return_value = binascii_a2b_hex_impl(module, &hexstr);
612 
613 exit:
614     /* Cleanup for hexstr */
615     if (hexstr.obj)
616        PyBuffer_Release(&hexstr);
617 
618     return return_value;
619 }
620 
621 PyDoc_STRVAR(binascii_unhexlify__doc__,
622 "unhexlify($module, hexstr, /)\n"
623 "--\n"
624 "\n"
625 "Binary data of hexadecimal representation.\n"
626 "\n"
627 "hexstr must contain an even number of hex digits (upper or lower case).");
628 
629 #define BINASCII_UNHEXLIFY_METHODDEF    \
630     {"unhexlify", (PyCFunction)binascii_unhexlify, METH_O, binascii_unhexlify__doc__},
631 
632 static PyObject *
633 binascii_unhexlify_impl(PyObject *module, Py_buffer *hexstr);
634 
635 static PyObject *
binascii_unhexlify(PyObject * module,PyObject * arg)636 binascii_unhexlify(PyObject *module, PyObject *arg)
637 {
638     PyObject *return_value = NULL;
639     Py_buffer hexstr = {NULL, NULL};
640 
641     if (!ascii_buffer_converter(arg, &hexstr)) {
642         goto exit;
643     }
644     return_value = binascii_unhexlify_impl(module, &hexstr);
645 
646 exit:
647     /* Cleanup for hexstr */
648     if (hexstr.obj)
649        PyBuffer_Release(&hexstr);
650 
651     return return_value;
652 }
653 
654 PyDoc_STRVAR(binascii_a2b_qp__doc__,
655 "a2b_qp($module, /, data, header=False)\n"
656 "--\n"
657 "\n"
658 "Decode a string of qp-encoded data.");
659 
660 #define BINASCII_A2B_QP_METHODDEF    \
661     {"a2b_qp", (PyCFunction)(void(*)(void))binascii_a2b_qp, METH_FASTCALL|METH_KEYWORDS, binascii_a2b_qp__doc__},
662 
663 static PyObject *
664 binascii_a2b_qp_impl(PyObject *module, Py_buffer *data, int header);
665 
666 static PyObject *
binascii_a2b_qp(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)667 binascii_a2b_qp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
668 {
669     PyObject *return_value = NULL;
670     static const char * const _keywords[] = {"data", "header", NULL};
671     static _PyArg_Parser _parser = {NULL, _keywords, "a2b_qp", 0};
672     PyObject *argsbuf[2];
673     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
674     Py_buffer data = {NULL, NULL};
675     int header = 0;
676 
677     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
678     if (!args) {
679         goto exit;
680     }
681     if (!ascii_buffer_converter(args[0], &data)) {
682         goto exit;
683     }
684     if (!noptargs) {
685         goto skip_optional_pos;
686     }
687     if (PyFloat_Check(args[1])) {
688         PyErr_SetString(PyExc_TypeError,
689                         "integer argument expected, got float" );
690         goto exit;
691     }
692     header = _PyLong_AsInt(args[1]);
693     if (header == -1 && PyErr_Occurred()) {
694         goto exit;
695     }
696 skip_optional_pos:
697     return_value = binascii_a2b_qp_impl(module, &data, header);
698 
699 exit:
700     /* Cleanup for data */
701     if (data.obj)
702        PyBuffer_Release(&data);
703 
704     return return_value;
705 }
706 
707 PyDoc_STRVAR(binascii_b2a_qp__doc__,
708 "b2a_qp($module, /, data, quotetabs=False, istext=True, header=False)\n"
709 "--\n"
710 "\n"
711 "Encode a string using quoted-printable encoding.\n"
712 "\n"
713 "On encoding, when istext is set, newlines are not encoded, and white\n"
714 "space at end of lines is.  When istext is not set, \\r and \\n (CR/LF)\n"
715 "are both encoded.  When quotetabs is set, space and tabs are encoded.");
716 
717 #define BINASCII_B2A_QP_METHODDEF    \
718     {"b2a_qp", (PyCFunction)(void(*)(void))binascii_b2a_qp, METH_FASTCALL|METH_KEYWORDS, binascii_b2a_qp__doc__},
719 
720 static PyObject *
721 binascii_b2a_qp_impl(PyObject *module, Py_buffer *data, int quotetabs,
722                      int istext, int header);
723 
724 static PyObject *
binascii_b2a_qp(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)725 binascii_b2a_qp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
726 {
727     PyObject *return_value = NULL;
728     static const char * const _keywords[] = {"data", "quotetabs", "istext", "header", NULL};
729     static _PyArg_Parser _parser = {NULL, _keywords, "b2a_qp", 0};
730     PyObject *argsbuf[4];
731     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
732     Py_buffer data = {NULL, NULL};
733     int quotetabs = 0;
734     int istext = 1;
735     int header = 0;
736 
737     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 4, 0, argsbuf);
738     if (!args) {
739         goto exit;
740     }
741     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
742         goto exit;
743     }
744     if (!PyBuffer_IsContiguous(&data, 'C')) {
745         _PyArg_BadArgument("b2a_qp", "argument 'data'", "contiguous buffer", args[0]);
746         goto exit;
747     }
748     if (!noptargs) {
749         goto skip_optional_pos;
750     }
751     if (args[1]) {
752         if (PyFloat_Check(args[1])) {
753             PyErr_SetString(PyExc_TypeError,
754                             "integer argument expected, got float" );
755             goto exit;
756         }
757         quotetabs = _PyLong_AsInt(args[1]);
758         if (quotetabs == -1 && PyErr_Occurred()) {
759             goto exit;
760         }
761         if (!--noptargs) {
762             goto skip_optional_pos;
763         }
764     }
765     if (args[2]) {
766         if (PyFloat_Check(args[2])) {
767             PyErr_SetString(PyExc_TypeError,
768                             "integer argument expected, got float" );
769             goto exit;
770         }
771         istext = _PyLong_AsInt(args[2]);
772         if (istext == -1 && PyErr_Occurred()) {
773             goto exit;
774         }
775         if (!--noptargs) {
776             goto skip_optional_pos;
777         }
778     }
779     if (PyFloat_Check(args[3])) {
780         PyErr_SetString(PyExc_TypeError,
781                         "integer argument expected, got float" );
782         goto exit;
783     }
784     header = _PyLong_AsInt(args[3]);
785     if (header == -1 && PyErr_Occurred()) {
786         goto exit;
787     }
788 skip_optional_pos:
789     return_value = binascii_b2a_qp_impl(module, &data, quotetabs, istext, header);
790 
791 exit:
792     /* Cleanup for data */
793     if (data.obj) {
794        PyBuffer_Release(&data);
795     }
796 
797     return return_value;
798 }
799 /*[clinic end generated code: output=a1e878d3963b615e input=a9049054013a1b77]*/
800