123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798 |
- /*[clinic input]
- preserve
- [clinic start generated code]*/
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- # include "pycore_gc.h" // PyGC_Head
- # include "pycore_runtime.h" // _Py_ID()
- #endif
- PyDoc_STRVAR(binascii_a2b_uu__doc__,
- "a2b_uu($module, data, /)\n"
- "--\n"
- "\n"
- "Decode a line of uuencoded data.");
- #define BINASCII_A2B_UU_METHODDEF \
- {"a2b_uu", (PyCFunction)binascii_a2b_uu, METH_O, binascii_a2b_uu__doc__},
- static PyObject *
- binascii_a2b_uu_impl(PyObject *module, Py_buffer *data);
- static PyObject *
- binascii_a2b_uu(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- Py_buffer data = {NULL, NULL};
- if (!ascii_buffer_converter(arg, &data)) {
- goto exit;
- }
- return_value = binascii_a2b_uu_impl(module, &data);
- exit:
- /* Cleanup for data */
- if (data.obj)
- PyBuffer_Release(&data);
- return return_value;
- }
- PyDoc_STRVAR(binascii_b2a_uu__doc__,
- "b2a_uu($module, data, /, *, backtick=False)\n"
- "--\n"
- "\n"
- "Uuencode line of data.");
- #define BINASCII_B2A_UU_METHODDEF \
- {"b2a_uu", _PyCFunction_CAST(binascii_b2a_uu), METH_FASTCALL|METH_KEYWORDS, binascii_b2a_uu__doc__},
- static PyObject *
- binascii_b2a_uu_impl(PyObject *module, Py_buffer *data, int backtick);
- static PyObject *
- binascii_b2a_uu(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(backtick), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"", "backtick", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "b2a_uu",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- Py_buffer data = {NULL, NULL};
- int backtick = 0;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
- goto exit;
- }
- if (!PyBuffer_IsContiguous(&data, 'C')) {
- _PyArg_BadArgument("b2a_uu", "argument 1", "contiguous buffer", args[0]);
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- backtick = PyObject_IsTrue(args[1]);
- if (backtick < 0) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = binascii_b2a_uu_impl(module, &data, backtick);
- exit:
- /* Cleanup for data */
- if (data.obj) {
- PyBuffer_Release(&data);
- }
- return return_value;
- }
- PyDoc_STRVAR(binascii_a2b_base64__doc__,
- "a2b_base64($module, data, /, *, strict_mode=False)\n"
- "--\n"
- "\n"
- "Decode a line of base64 data.\n"
- "\n"
- " strict_mode\n"
- " When set to True, bytes that are not part of the base64 standard are not allowed.\n"
- " The same applies to excess data after padding (= / ==).");
- #define BINASCII_A2B_BASE64_METHODDEF \
- {"a2b_base64", _PyCFunction_CAST(binascii_a2b_base64), METH_FASTCALL|METH_KEYWORDS, binascii_a2b_base64__doc__},
- static PyObject *
- binascii_a2b_base64_impl(PyObject *module, Py_buffer *data, int strict_mode);
- static PyObject *
- binascii_a2b_base64(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(strict_mode), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"", "strict_mode", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "a2b_base64",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- Py_buffer data = {NULL, NULL};
- int strict_mode = 0;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!ascii_buffer_converter(args[0], &data)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- strict_mode = PyObject_IsTrue(args[1]);
- if (strict_mode < 0) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = binascii_a2b_base64_impl(module, &data, strict_mode);
- exit:
- /* Cleanup for data */
- if (data.obj)
- PyBuffer_Release(&data);
- return return_value;
- }
- PyDoc_STRVAR(binascii_b2a_base64__doc__,
- "b2a_base64($module, data, /, *, newline=True)\n"
- "--\n"
- "\n"
- "Base64-code line of data.");
- #define BINASCII_B2A_BASE64_METHODDEF \
- {"b2a_base64", _PyCFunction_CAST(binascii_b2a_base64), METH_FASTCALL|METH_KEYWORDS, binascii_b2a_base64__doc__},
- static PyObject *
- binascii_b2a_base64_impl(PyObject *module, Py_buffer *data, int newline);
- static PyObject *
- binascii_b2a_base64(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(newline), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"", "newline", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "b2a_base64",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- Py_buffer data = {NULL, NULL};
- int newline = 1;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
- goto exit;
- }
- if (!PyBuffer_IsContiguous(&data, 'C')) {
- _PyArg_BadArgument("b2a_base64", "argument 1", "contiguous buffer", args[0]);
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- newline = PyObject_IsTrue(args[1]);
- if (newline < 0) {
- goto exit;
- }
- skip_optional_kwonly:
- return_value = binascii_b2a_base64_impl(module, &data, newline);
- exit:
- /* Cleanup for data */
- if (data.obj) {
- PyBuffer_Release(&data);
- }
- return return_value;
- }
- PyDoc_STRVAR(binascii_crc_hqx__doc__,
- "crc_hqx($module, data, crc, /)\n"
- "--\n"
- "\n"
- "Compute CRC-CCITT incrementally.");
- #define BINASCII_CRC_HQX_METHODDEF \
- {"crc_hqx", _PyCFunction_CAST(binascii_crc_hqx), METH_FASTCALL, binascii_crc_hqx__doc__},
- static PyObject *
- binascii_crc_hqx_impl(PyObject *module, Py_buffer *data, unsigned int crc);
- static PyObject *
- binascii_crc_hqx(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- Py_buffer data = {NULL, NULL};
- unsigned int crc;
- if (!_PyArg_CheckPositional("crc_hqx", nargs, 2, 2)) {
- goto exit;
- }
- if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
- goto exit;
- }
- if (!PyBuffer_IsContiguous(&data, 'C')) {
- _PyArg_BadArgument("crc_hqx", "argument 1", "contiguous buffer", args[0]);
- goto exit;
- }
- crc = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
- if (crc == (unsigned int)-1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = binascii_crc_hqx_impl(module, &data, crc);
- exit:
- /* Cleanup for data */
- if (data.obj) {
- PyBuffer_Release(&data);
- }
- return return_value;
- }
- PyDoc_STRVAR(binascii_crc32__doc__,
- "crc32($module, data, crc=0, /)\n"
- "--\n"
- "\n"
- "Compute CRC-32 incrementally.");
- #define BINASCII_CRC32_METHODDEF \
- {"crc32", _PyCFunction_CAST(binascii_crc32), METH_FASTCALL, binascii_crc32__doc__},
- static unsigned int
- binascii_crc32_impl(PyObject *module, Py_buffer *data, unsigned int crc);
- static PyObject *
- binascii_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
- {
- PyObject *return_value = NULL;
- Py_buffer data = {NULL, NULL};
- unsigned int crc = 0;
- unsigned int _return_value;
- if (!_PyArg_CheckPositional("crc32", nargs, 1, 2)) {
- goto exit;
- }
- if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
- goto exit;
- }
- if (!PyBuffer_IsContiguous(&data, 'C')) {
- _PyArg_BadArgument("crc32", "argument 1", "contiguous buffer", args[0]);
- goto exit;
- }
- if (nargs < 2) {
- goto skip_optional;
- }
- crc = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
- if (crc == (unsigned int)-1 && PyErr_Occurred()) {
- goto exit;
- }
- skip_optional:
- _return_value = binascii_crc32_impl(module, &data, crc);
- if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
- goto exit;
- }
- return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
- exit:
- /* Cleanup for data */
- if (data.obj) {
- PyBuffer_Release(&data);
- }
- return return_value;
- }
- PyDoc_STRVAR(binascii_b2a_hex__doc__,
- "b2a_hex($module, /, data, sep=<unrepresentable>, bytes_per_sep=1)\n"
- "--\n"
- "\n"
- "Hexadecimal representation of binary data.\n"
- "\n"
- " sep\n"
- " An optional single character or byte to separate hex bytes.\n"
- " bytes_per_sep\n"
- " How many bytes between separators. Positive values count from the\n"
- " right, negative values count from the left.\n"
- "\n"
- "The return value is a bytes object. This function is also\n"
- "available as \"hexlify()\".\n"
- "\n"
- "Example:\n"
- ">>> binascii.b2a_hex(b\'\\xb9\\x01\\xef\')\n"
- "b\'b901ef\'\n"
- ">>> binascii.hexlify(b\'\\xb9\\x01\\xef\', \':\')\n"
- "b\'b9:01:ef\'\n"
- ">>> binascii.b2a_hex(b\'\\xb9\\x01\\xef\', b\'_\', 2)\n"
- "b\'b9_01ef\'");
- #define BINASCII_B2A_HEX_METHODDEF \
- {"b2a_hex", _PyCFunction_CAST(binascii_b2a_hex), METH_FASTCALL|METH_KEYWORDS, binascii_b2a_hex__doc__},
- static PyObject *
- binascii_b2a_hex_impl(PyObject *module, Py_buffer *data, PyObject *sep,
- int bytes_per_sep);
- static PyObject *
- binascii_b2a_hex(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 3
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(data), &_Py_ID(sep), &_Py_ID(bytes_per_sep), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"data", "sep", "bytes_per_sep", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "b2a_hex",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[3];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- Py_buffer data = {NULL, NULL};
- PyObject *sep = NULL;
- int bytes_per_sep = 1;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
- goto exit;
- }
- if (!PyBuffer_IsContiguous(&data, 'C')) {
- _PyArg_BadArgument("b2a_hex", "argument 'data'", "contiguous buffer", args[0]);
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- if (args[1]) {
- sep = args[1];
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- bytes_per_sep = _PyLong_AsInt(args[2]);
- if (bytes_per_sep == -1 && PyErr_Occurred()) {
- goto exit;
- }
- skip_optional_pos:
- return_value = binascii_b2a_hex_impl(module, &data, sep, bytes_per_sep);
- exit:
- /* Cleanup for data */
- if (data.obj) {
- PyBuffer_Release(&data);
- }
- return return_value;
- }
- PyDoc_STRVAR(binascii_hexlify__doc__,
- "hexlify($module, /, data, sep=<unrepresentable>, bytes_per_sep=1)\n"
- "--\n"
- "\n"
- "Hexadecimal representation of binary data.\n"
- "\n"
- " sep\n"
- " An optional single character or byte to separate hex bytes.\n"
- " bytes_per_sep\n"
- " How many bytes between separators. Positive values count from the\n"
- " right, negative values count from the left.\n"
- "\n"
- "The return value is a bytes object. This function is also\n"
- "available as \"b2a_hex()\".");
- #define BINASCII_HEXLIFY_METHODDEF \
- {"hexlify", _PyCFunction_CAST(binascii_hexlify), METH_FASTCALL|METH_KEYWORDS, binascii_hexlify__doc__},
- static PyObject *
- binascii_hexlify_impl(PyObject *module, Py_buffer *data, PyObject *sep,
- int bytes_per_sep);
- static PyObject *
- binascii_hexlify(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 3
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(data), &_Py_ID(sep), &_Py_ID(bytes_per_sep), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"data", "sep", "bytes_per_sep", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "hexlify",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[3];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- Py_buffer data = {NULL, NULL};
- PyObject *sep = NULL;
- int bytes_per_sep = 1;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
- goto exit;
- }
- if (!PyBuffer_IsContiguous(&data, 'C')) {
- _PyArg_BadArgument("hexlify", "argument 'data'", "contiguous buffer", args[0]);
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- if (args[1]) {
- sep = args[1];
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- bytes_per_sep = _PyLong_AsInt(args[2]);
- if (bytes_per_sep == -1 && PyErr_Occurred()) {
- goto exit;
- }
- skip_optional_pos:
- return_value = binascii_hexlify_impl(module, &data, sep, bytes_per_sep);
- exit:
- /* Cleanup for data */
- if (data.obj) {
- PyBuffer_Release(&data);
- }
- return return_value;
- }
- PyDoc_STRVAR(binascii_a2b_hex__doc__,
- "a2b_hex($module, hexstr, /)\n"
- "--\n"
- "\n"
- "Binary data of hexadecimal representation.\n"
- "\n"
- "hexstr must contain an even number of hex digits (upper or lower case).\n"
- "This function is also available as \"unhexlify()\".");
- #define BINASCII_A2B_HEX_METHODDEF \
- {"a2b_hex", (PyCFunction)binascii_a2b_hex, METH_O, binascii_a2b_hex__doc__},
- static PyObject *
- binascii_a2b_hex_impl(PyObject *module, Py_buffer *hexstr);
- static PyObject *
- binascii_a2b_hex(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- Py_buffer hexstr = {NULL, NULL};
- if (!ascii_buffer_converter(arg, &hexstr)) {
- goto exit;
- }
- return_value = binascii_a2b_hex_impl(module, &hexstr);
- exit:
- /* Cleanup for hexstr */
- if (hexstr.obj)
- PyBuffer_Release(&hexstr);
- return return_value;
- }
- PyDoc_STRVAR(binascii_unhexlify__doc__,
- "unhexlify($module, hexstr, /)\n"
- "--\n"
- "\n"
- "Binary data of hexadecimal representation.\n"
- "\n"
- "hexstr must contain an even number of hex digits (upper or lower case).");
- #define BINASCII_UNHEXLIFY_METHODDEF \
- {"unhexlify", (PyCFunction)binascii_unhexlify, METH_O, binascii_unhexlify__doc__},
- static PyObject *
- binascii_unhexlify_impl(PyObject *module, Py_buffer *hexstr);
- static PyObject *
- binascii_unhexlify(PyObject *module, PyObject *arg)
- {
- PyObject *return_value = NULL;
- Py_buffer hexstr = {NULL, NULL};
- if (!ascii_buffer_converter(arg, &hexstr)) {
- goto exit;
- }
- return_value = binascii_unhexlify_impl(module, &hexstr);
- exit:
- /* Cleanup for hexstr */
- if (hexstr.obj)
- PyBuffer_Release(&hexstr);
- return return_value;
- }
- PyDoc_STRVAR(binascii_a2b_qp__doc__,
- "a2b_qp($module, /, data, header=False)\n"
- "--\n"
- "\n"
- "Decode a string of qp-encoded data.");
- #define BINASCII_A2B_QP_METHODDEF \
- {"a2b_qp", _PyCFunction_CAST(binascii_a2b_qp), METH_FASTCALL|METH_KEYWORDS, binascii_a2b_qp__doc__},
- static PyObject *
- binascii_a2b_qp_impl(PyObject *module, Py_buffer *data, int header);
- static PyObject *
- binascii_a2b_qp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 2
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(data), &_Py_ID(header), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"data", "header", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "a2b_qp",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[2];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- Py_buffer data = {NULL, NULL};
- int header = 0;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!ascii_buffer_converter(args[0], &data)) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- header = PyObject_IsTrue(args[1]);
- if (header < 0) {
- goto exit;
- }
- skip_optional_pos:
- return_value = binascii_a2b_qp_impl(module, &data, header);
- exit:
- /* Cleanup for data */
- if (data.obj)
- PyBuffer_Release(&data);
- return return_value;
- }
- PyDoc_STRVAR(binascii_b2a_qp__doc__,
- "b2a_qp($module, /, data, quotetabs=False, istext=True, header=False)\n"
- "--\n"
- "\n"
- "Encode a string using quoted-printable encoding.\n"
- "\n"
- "On encoding, when istext is set, newlines are not encoded, and white\n"
- "space at end of lines is. When istext is not set, \\r and \\n (CR/LF)\n"
- "are both encoded. When quotetabs is set, space and tabs are encoded.");
- #define BINASCII_B2A_QP_METHODDEF \
- {"b2a_qp", _PyCFunction_CAST(binascii_b2a_qp), METH_FASTCALL|METH_KEYWORDS, binascii_b2a_qp__doc__},
- static PyObject *
- binascii_b2a_qp_impl(PyObject *module, Py_buffer *data, int quotetabs,
- int istext, int header);
- static PyObject *
- binascii_b2a_qp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
- {
- PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 4
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(data), &_Py_ID(quotetabs), &_Py_ID(istext), &_Py_ID(header), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"data", "quotetabs", "istext", "header", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "b2a_qp",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[4];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- Py_buffer data = {NULL, NULL};
- int quotetabs = 0;
- int istext = 1;
- int header = 0;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 4, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
- goto exit;
- }
- if (!PyBuffer_IsContiguous(&data, 'C')) {
- _PyArg_BadArgument("b2a_qp", "argument 'data'", "contiguous buffer", args[0]);
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- if (args[1]) {
- quotetabs = PyObject_IsTrue(args[1]);
- if (quotetabs < 0) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- if (args[2]) {
- istext = PyObject_IsTrue(args[2]);
- if (istext < 0) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_pos;
- }
- }
- header = PyObject_IsTrue(args[3]);
- if (header < 0) {
- goto exit;
- }
- skip_optional_pos:
- return_value = binascii_b2a_qp_impl(module, &data, quotetabs, istext, header);
- exit:
- /* Cleanup for data */
- if (data.obj) {
- PyBuffer_Release(&data);
- }
- return return_value;
- }
- /*[clinic end generated code: output=ab156917c9db79d2 input=a9049054013a1b77]*/
|