Line data Source code
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 *
18 200 : binascii_a2b_uu(PyObject *module, PyObject *arg)
19 : {
20 200 : PyObject *return_value = NULL;
21 200 : Py_buffer data = {NULL, NULL};
22 :
23 200 : if (!ascii_buffer_converter(arg, &data)) {
24 4 : goto exit;
25 : }
26 196 : return_value = binascii_a2b_uu_impl(module, &data);
27 :
28 200 : exit:
29 : /* Cleanup for data */
30 200 : if (data.obj)
31 192 : PyBuffer_Release(&data);
32 :
33 200 : 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 *
49 138 : binascii_b2a_uu(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
50 : {
51 138 : 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 138 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
56 138 : Py_buffer data = {NULL, NULL};
57 138 : int backtick = 0;
58 :
59 138 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
60 138 : if (!args) {
61 8 : goto exit;
62 : }
63 130 : if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
64 4 : goto exit;
65 : }
66 126 : if (!PyBuffer_IsContiguous(&data, 'C')) {
67 0 : _PyArg_BadArgument("b2a_uu", "argument 1", "contiguous buffer", args[0]);
68 0 : goto exit;
69 : }
70 126 : if (!noptargs) {
71 40 : goto skip_optional_kwonly;
72 : }
73 86 : backtick = _PyLong_AsInt(args[1]);
74 86 : if (backtick == -1 && PyErr_Occurred()) {
75 0 : goto exit;
76 : }
77 86 : skip_optional_kwonly:
78 126 : return_value = binascii_b2a_uu_impl(module, &data, backtick);
79 :
80 138 : exit:
81 : /* Cleanup for data */
82 138 : if (data.obj) {
83 126 : PyBuffer_Release(&data);
84 : }
85 :
86 138 : 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 *
106 1011 : binascii_a2b_base64(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
107 : {
108 1011 : 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 1011 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
113 1011 : Py_buffer data = {NULL, NULL};
114 1011 : int strict_mode = 0;
115 :
116 1011 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
117 1011 : if (!args) {
118 4 : goto exit;
119 : }
120 1007 : if (!ascii_buffer_converter(args[0], &data)) {
121 4 : goto exit;
122 : }
123 1003 : if (!noptargs) {
124 669 : goto skip_optional_kwonly;
125 : }
126 334 : strict_mode = _PyLong_AsInt(args[1]);
127 334 : if (strict_mode == -1 && PyErr_Occurred()) {
128 0 : goto exit;
129 : }
130 334 : skip_optional_kwonly:
131 1003 : return_value = binascii_a2b_base64_impl(module, &data, strict_mode);
132 :
133 1011 : exit:
134 : /* Cleanup for data */
135 1011 : if (data.obj)
136 999 : PyBuffer_Release(&data);
137 :
138 1011 : 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 *
154 4535 : binascii_b2a_base64(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
155 : {
156 4535 : 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 4535 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
161 4535 : Py_buffer data = {NULL, NULL};
162 4535 : int newline = 1;
163 :
164 4535 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
165 4535 : if (!args) {
166 4 : goto exit;
167 : }
168 4531 : if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
169 14 : goto exit;
170 : }
171 4517 : if (!PyBuffer_IsContiguous(&data, 'C')) {
172 0 : _PyArg_BadArgument("b2a_base64", "argument 1", "contiguous buffer", args[0]);
173 0 : goto exit;
174 : }
175 4517 : if (!noptargs) {
176 4203 : goto skip_optional_kwonly;
177 : }
178 314 : newline = _PyLong_AsInt(args[1]);
179 314 : if (newline == -1 && PyErr_Occurred()) {
180 0 : goto exit;
181 : }
182 314 : skip_optional_kwonly:
183 4517 : return_value = binascii_b2a_base64_impl(module, &data, newline);
184 :
185 4535 : exit:
186 : /* Cleanup for data */
187 4535 : if (data.obj) {
188 4517 : PyBuffer_Release(&data);
189 : }
190 :
191 4535 : 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 *
207 60 : binascii_crc_hqx(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
208 : {
209 60 : PyObject *return_value = NULL;
210 60 : Py_buffer data = {NULL, NULL};
211 : unsigned int crc;
212 :
213 60 : if (!_PyArg_CheckPositional("crc_hqx", nargs, 2, 2)) {
214 16 : goto exit;
215 : }
216 44 : if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
217 4 : goto exit;
218 : }
219 40 : if (!PyBuffer_IsContiguous(&data, 'C')) {
220 0 : _PyArg_BadArgument("crc_hqx", "argument 1", "contiguous buffer", args[0]);
221 0 : goto exit;
222 : }
223 40 : crc = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
224 40 : if (crc == (unsigned int)-1 && PyErr_Occurred()) {
225 0 : goto exit;
226 : }
227 40 : return_value = binascii_crc_hqx_impl(module, &data, crc);
228 :
229 60 : exit:
230 : /* Cleanup for data */
231 60 : if (data.obj) {
232 40 : PyBuffer_Release(&data);
233 : }
234 :
235 60 : 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 *
251 30 : binascii_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
252 : {
253 30 : PyObject *return_value = NULL;
254 30 : Py_buffer data = {NULL, NULL};
255 30 : unsigned int crc = 0;
256 : unsigned int _return_value;
257 :
258 30 : if (!_PyArg_CheckPositional("crc32", nargs, 1, 2)) {
259 8 : goto exit;
260 : }
261 22 : if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
262 4 : goto exit;
263 : }
264 18 : if (!PyBuffer_IsContiguous(&data, 'C')) {
265 0 : _PyArg_BadArgument("crc32", "argument 1", "contiguous buffer", args[0]);
266 0 : goto exit;
267 : }
268 18 : if (nargs < 2) {
269 14 : goto skip_optional;
270 : }
271 4 : crc = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
272 4 : if (crc == (unsigned int)-1 && PyErr_Occurred()) {
273 0 : goto exit;
274 : }
275 4 : skip_optional:
276 18 : _return_value = binascii_crc32_impl(module, &data, crc);
277 18 : if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
278 0 : goto exit;
279 : }
280 18 : return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
281 :
282 30 : exit:
283 : /* Cleanup for data */
284 30 : if (data.obj) {
285 18 : PyBuffer_Release(&data);
286 : }
287 :
288 30 : 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 *
322 40 : binascii_b2a_hex(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
323 : {
324 40 : 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 40 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
329 40 : Py_buffer data = {NULL, NULL};
330 40 : PyObject *sep = NULL;
331 40 : int bytes_per_sep = 1;
332 :
333 40 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
334 40 : if (!args) {
335 4 : goto exit;
336 : }
337 36 : if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
338 5 : goto exit;
339 : }
340 31 : if (!PyBuffer_IsContiguous(&data, 'C')) {
341 0 : _PyArg_BadArgument("b2a_hex", "argument 'data'", "contiguous buffer", args[0]);
342 0 : goto exit;
343 : }
344 31 : if (!noptargs) {
345 27 : goto skip_optional_pos;
346 : }
347 4 : if (args[1]) {
348 4 : sep = args[1];
349 4 : if (!--noptargs) {
350 4 : goto skip_optional_pos;
351 : }
352 : }
353 0 : bytes_per_sep = _PyLong_AsInt(args[2]);
354 0 : if (bytes_per_sep == -1 && PyErr_Occurred()) {
355 0 : goto exit;
356 : }
357 0 : skip_optional_pos:
358 31 : return_value = binascii_b2a_hex_impl(module, &data, sep, bytes_per_sep);
359 :
360 40 : exit:
361 : /* Cleanup for data */
362 40 : if (data.obj) {
363 31 : PyBuffer_Release(&data);
364 : }
365 :
366 40 : 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 *
392 246 : binascii_hexlify(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
393 : {
394 246 : 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 246 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
399 246 : Py_buffer data = {NULL, NULL};
400 246 : PyObject *sep = NULL;
401 246 : int bytes_per_sep = 1;
402 :
403 246 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
404 246 : if (!args) {
405 4 : goto exit;
406 : }
407 242 : if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
408 6 : goto exit;
409 : }
410 236 : if (!PyBuffer_IsContiguous(&data, 'C')) {
411 0 : _PyArg_BadArgument("hexlify", "argument 'data'", "contiguous buffer", args[0]);
412 0 : goto exit;
413 : }
414 236 : if (!noptargs) {
415 232 : goto skip_optional_pos;
416 : }
417 4 : if (args[1]) {
418 4 : sep = args[1];
419 4 : if (!--noptargs) {
420 0 : goto skip_optional_pos;
421 : }
422 : }
423 4 : bytes_per_sep = _PyLong_AsInt(args[2]);
424 4 : if (bytes_per_sep == -1 && PyErr_Occurred()) {
425 0 : goto exit;
426 : }
427 4 : skip_optional_pos:
428 236 : return_value = binascii_hexlify_impl(module, &data, sep, bytes_per_sep);
429 :
430 246 : exit:
431 : /* Cleanup for data */
432 246 : if (data.obj) {
433 236 : PyBuffer_Release(&data);
434 : }
435 :
436 246 : 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 *
455 58 : binascii_a2b_hex(PyObject *module, PyObject *arg)
456 : {
457 58 : PyObject *return_value = NULL;
458 58 : Py_buffer hexstr = {NULL, NULL};
459 :
460 58 : if (!ascii_buffer_converter(arg, &hexstr)) {
461 4 : goto exit;
462 : }
463 54 : return_value = binascii_a2b_hex_impl(module, &hexstr);
464 :
465 58 : exit:
466 : /* Cleanup for hexstr */
467 58 : if (hexstr.obj)
468 50 : PyBuffer_Release(&hexstr);
469 :
470 58 : 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 *
488 17235 : binascii_unhexlify(PyObject *module, PyObject *arg)
489 : {
490 17235 : PyObject *return_value = NULL;
491 17235 : Py_buffer hexstr = {NULL, NULL};
492 :
493 17235 : if (!ascii_buffer_converter(arg, &hexstr)) {
494 4 : goto exit;
495 : }
496 17231 : return_value = binascii_unhexlify_impl(module, &hexstr);
497 :
498 17235 : exit:
499 : /* Cleanup for hexstr */
500 17235 : if (hexstr.obj)
501 16881 : PyBuffer_Release(&hexstr);
502 :
503 17235 : 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 *
519 166 : binascii_a2b_qp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
520 : {
521 166 : 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 166 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
526 166 : Py_buffer data = {NULL, NULL};
527 166 : int header = 0;
528 :
529 166 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
530 166 : if (!args) {
531 4 : goto exit;
532 : }
533 162 : if (!ascii_buffer_converter(args[0], &data)) {
534 4 : goto exit;
535 : }
536 158 : if (!noptargs) {
537 72 : goto skip_optional_pos;
538 : }
539 86 : header = _PyLong_AsInt(args[1]);
540 86 : if (header == -1 && PyErr_Occurred()) {
541 0 : goto exit;
542 : }
543 86 : skip_optional_pos:
544 158 : return_value = binascii_a2b_qp_impl(module, &data, header);
545 :
546 166 : exit:
547 : /* Cleanup for data */
548 166 : if (data.obj)
549 154 : PyBuffer_Release(&data);
550 :
551 166 : 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 *
572 246 : binascii_b2a_qp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
573 : {
574 246 : 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 246 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
579 246 : Py_buffer data = {NULL, NULL};
580 246 : int quotetabs = 0;
581 246 : int istext = 1;
582 246 : int header = 0;
583 :
584 246 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 4, 0, argsbuf);
585 246 : if (!args) {
586 8 : goto exit;
587 : }
588 238 : if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
589 4 : goto exit;
590 : }
591 234 : if (!PyBuffer_IsContiguous(&data, 'C')) {
592 0 : _PyArg_BadArgument("b2a_qp", "argument 'data'", "contiguous buffer", args[0]);
593 0 : goto exit;
594 : }
595 234 : if (!noptargs) {
596 112 : goto skip_optional_pos;
597 : }
598 122 : if (args[1]) {
599 82 : quotetabs = _PyLong_AsInt(args[1]);
600 82 : if (quotetabs == -1 && PyErr_Occurred()) {
601 0 : goto exit;
602 : }
603 82 : if (!--noptargs) {
604 28 : goto skip_optional_pos;
605 : }
606 : }
607 94 : if (args[2]) {
608 25 : istext = _PyLong_AsInt(args[2]);
609 25 : if (istext == -1 && PyErr_Occurred()) {
610 0 : goto exit;
611 : }
612 25 : if (!--noptargs) {
613 24 : goto skip_optional_pos;
614 : }
615 : }
616 70 : header = _PyLong_AsInt(args[3]);
617 70 : if (header == -1 && PyErr_Occurred()) {
618 0 : goto exit;
619 : }
620 70 : skip_optional_pos:
621 234 : return_value = binascii_b2a_qp_impl(module, &data, quotetabs, istext, header);
622 :
623 246 : exit:
624 : /* Cleanup for data */
625 246 : if (data.obj) {
626 234 : PyBuffer_Release(&data);
627 : }
628 :
629 246 : return return_value;
630 : }
631 : /*[clinic end generated code: output=ba9ed7b810b8762d input=a9049054013a1b77]*/
|