summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-09-02 10:10:08 (GMT)
committerGitHub <noreply@github.com>2021-09-02 10:10:08 (GMT)
commita8066087054417885db0a2dbdce2ddb2ac498247 (patch)
tree9715670a690514e50d8439085787181157a56ef0 /Modules
parentd589a7e7eb56196c05337d37417479375878b127 (diff)
downloadcpython-a8066087054417885db0a2dbdce2ddb2ac498247.zip
cpython-a8066087054417885db0a2dbdce2ddb2ac498247.tar.gz
cpython-a8066087054417885db0a2dbdce2ddb2ac498247.tar.bz2
bpo-45085: Remove the binhex module (GH-28117)
The binhex module, deprecated in Python 3.9, is now removed. The following binascii functions, deprecated in Python 3.9, are now also removed: * a2b_hqx(), b2a_hqx(); * rlecode_hqx(), rledecode_hqx(). The binascii.crc_hqx() function remains available.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/binascii.c418
-rw-r--r--Modules/clinic/binascii.c.h141
2 files changed, 1 insertions, 558 deletions
diff --git a/Modules/binascii.c b/Modules/binascii.c
index e80eb2a..db960dc 100644
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -72,69 +72,6 @@ get_binascii_state(PyObject *module)
return (binascii_state *)PyModule_GetState(module);
}
-/*
-** hqx lookup table, ascii->binary.
-*/
-
-#define RUNCHAR 0x90
-
-#define DONE 0x7F
-#define SKIP 0x7E
-#define FAIL 0x7D
-
-static const unsigned char table_a2b_hqx[256] = {
-/* ^@ ^A ^B ^C ^D ^E ^F ^G */
-/* 0*/ FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
-/* \b \t \n ^K ^L \r ^N ^O */
-/* 1*/ FAIL, FAIL, SKIP, FAIL, FAIL, SKIP, FAIL, FAIL,
-/* ^P ^Q ^R ^S ^T ^U ^V ^W */
-/* 2*/ FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
-/* ^X ^Y ^Z ^[ ^\ ^] ^^ ^_ */
-/* 3*/ FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
-/* ! " # $ % & ' */
-/* 4*/ FAIL, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
-/* ( ) * + , - . / */
-/* 5*/ 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, FAIL, FAIL,
-/* 0 1 2 3 4 5 6 7 */
-/* 6*/ 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, FAIL,
-/* 8 9 : ; < = > ? */
-/* 7*/ 0x14, 0x15, DONE, FAIL, FAIL, FAIL, FAIL, FAIL,
-/* @ A B C D E F G */
-/* 8*/ 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D,
-/* H I J K L M N O */
-/* 9*/ 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, FAIL,
-/* P Q R S T U V W */
-/*10*/ 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, FAIL,
-/* X Y Z [ \ ] ^ _ */
-/*11*/ 0x2C, 0x2D, 0x2E, 0x2F, FAIL, FAIL, FAIL, FAIL,
-/* ` a b c d e f g */
-/*12*/ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, FAIL,
-/* h i j k l m n o */
-/*13*/ 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, FAIL, FAIL,
-/* p q r s t u v w */
-/*14*/ 0x3D, 0x3E, 0x3F, FAIL, FAIL, FAIL, FAIL, FAIL,
-/* x y z { | } ~ ^? */
-/*15*/ FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
-/*16*/ FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
- FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
- FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
- FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
- FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
- FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
- FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
- FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
- FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
- FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
- FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
- FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
- FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
- FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
- FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
- FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,
-};
-
-static const unsigned char table_b2a_hqx[] =
-"!\"#$%&'()*+,-012345689@ABCDEFGHIJKLMNPQRSTUVXYZ[`abcdefhijklmpqr";
static const unsigned char table_a2b_base64[] = {
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
@@ -165,7 +102,6 @@ static const unsigned char table_b2a_base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
static const unsigned short crctab_hqx[256] = {
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
@@ -649,356 +585,6 @@ binascii_b2a_base64_impl(PyObject *module, Py_buffer *data, int newline)
return _PyBytesWriter_Finish(&writer, ascii_data);
}
-/*[clinic input]
-binascii.a2b_hqx
-
- data: ascii_buffer
- /
-
-Decode .hqx coding.
-[clinic start generated code]*/
-
-static PyObject *
-binascii_a2b_hqx_impl(PyObject *module, Py_buffer *data)
-/*[clinic end generated code: output=4d6d8c54d54ea1c1 input=0d914c680e0eed55]*/
-{
- if (PyErr_WarnEx(PyExc_DeprecationWarning,
- "binascii.a2b_hqx() is deprecated", 1) < 0) {
- return NULL;
- }
-
- const unsigned char *ascii_data;
- unsigned char *bin_data;
- int leftbits = 0;
- unsigned char this_ch;
- unsigned int leftchar = 0;
- PyObject *res;
- Py_ssize_t len;
- int done = 0;
- _PyBytesWriter writer;
- binascii_state *state;
-
- ascii_data = data->buf;
- len = data->len;
- _PyBytesWriter_Init(&writer);
-
- assert(len >= 0);
-
- if (len > PY_SSIZE_T_MAX - 2)
- return PyErr_NoMemory();
-
- /* Allocate a string that is too big (fixed later)
- Add two to the initial length to prevent interning which
- would preclude subsequent resizing. */
- bin_data = _PyBytesWriter_Alloc(&writer, len + 2);
- if (bin_data == NULL)
- return NULL;
-
- for( ; len > 0 ; len--, ascii_data++ ) {
- /* Get the byte and look it up */
- this_ch = table_a2b_hqx[*ascii_data];
- if ( this_ch == SKIP )
- continue;
- if ( this_ch == FAIL ) {
- state = get_binascii_state(module);
- if (state == NULL) {
- return NULL;
- }
- PyErr_SetString(state->Error, "Illegal char");
- _PyBytesWriter_Dealloc(&writer);
- return NULL;
- }
- if ( this_ch == DONE ) {
- /* The terminating colon */
- done = 1;
- break;
- }
-
- /* Shift it into the buffer and see if any bytes are ready */
- leftchar = (leftchar << 6) | (this_ch);
- leftbits += 6;
- if ( leftbits >= 8 ) {
- leftbits -= 8;
- *bin_data++ = (leftchar >> leftbits) & 0xff;
- leftchar &= ((1 << leftbits) - 1);
- }
- }
-
- if ( leftbits && !done ) {
- state = get_binascii_state(module);
- if (state == NULL) {
- return NULL;
- }
- PyErr_SetString(state->Incomplete,
- "String has incomplete number of bytes");
- _PyBytesWriter_Dealloc(&writer);
- return NULL;
- }
-
- res = _PyBytesWriter_Finish(&writer, bin_data);
- if (res == NULL)
- return NULL;
- return Py_BuildValue("Ni", res, done);
-}
-
-
-/*[clinic input]
-binascii.rlecode_hqx
-
- data: Py_buffer
- /
-
-Binhex RLE-code binary data.
-[clinic start generated code]*/
-
-static PyObject *
-binascii_rlecode_hqx_impl(PyObject *module, Py_buffer *data)
-/*[clinic end generated code: output=393d79338f5f5629 input=e1f1712447a82b09]*/
-{
- if (PyErr_WarnEx(PyExc_DeprecationWarning,
- "binascii.rlecode_hqx() is deprecated", 1) < 0) {
- return NULL;
- }
-
- const unsigned char *in_data;
- unsigned char *out_data;
- unsigned char ch;
- Py_ssize_t in, inend, len;
- _PyBytesWriter writer;
-
- _PyBytesWriter_Init(&writer);
- in_data = data->buf;
- len = data->len;
-
- assert(len >= 0);
-
- if (len > PY_SSIZE_T_MAX / 2 - 2)
- return PyErr_NoMemory();
-
- /* Worst case: output is twice as big as input (fixed later) */
- out_data = _PyBytesWriter_Alloc(&writer, len * 2 + 2);
- if (out_data == NULL)
- return NULL;
-
- for( in=0; in<len; in++) {
- ch = in_data[in];
- if ( ch == RUNCHAR ) {
- /* RUNCHAR. Escape it. */
- *out_data++ = RUNCHAR;
- *out_data++ = 0;
- } else {
- /* Check how many following are the same */
- for(inend=in+1;
- inend<len && in_data[inend] == ch &&
- inend < in+255;
- inend++) ;
- if ( inend - in > 3 ) {
- /* More than 3 in a row. Output RLE. */
- *out_data++ = ch;
- *out_data++ = RUNCHAR;
- *out_data++ = (unsigned char) (inend-in);
- in = inend-1;
- } else {
- /* Less than 3. Output the byte itself */
- *out_data++ = ch;
- }
- }
- }
-
- return _PyBytesWriter_Finish(&writer, out_data);
-}
-
-
-/*[clinic input]
-binascii.b2a_hqx
-
- data: Py_buffer
- /
-
-Encode .hqx data.
-[clinic start generated code]*/
-
-static PyObject *
-binascii_b2a_hqx_impl(PyObject *module, Py_buffer *data)
-/*[clinic end generated code: output=d0aa5a704bc9f7de input=9596ebe019fe12ba]*/
-{
- if (PyErr_WarnEx(PyExc_DeprecationWarning,
- "binascii.b2a_hqx() is deprecated", 1) < 0) {
- return NULL;
- }
-
- unsigned char *ascii_data;
- const unsigned char *bin_data;
- int leftbits = 0;
- unsigned char this_ch;
- unsigned int leftchar = 0;
- Py_ssize_t len;
- _PyBytesWriter writer;
-
- bin_data = data->buf;
- len = data->len;
- _PyBytesWriter_Init(&writer);
-
- assert(len >= 0);
-
- if (len > PY_SSIZE_T_MAX / 2 - 2)
- return PyErr_NoMemory();
-
- /* Allocate a buffer that is at least large enough */
- ascii_data = _PyBytesWriter_Alloc(&writer, len * 2 + 2);
- if (ascii_data == NULL)
- return NULL;
-
- for( ; len > 0 ; len--, bin_data++ ) {
- /* Shift into our buffer, and output any 6bits ready */
- leftchar = (leftchar << 8) | *bin_data;
- leftbits += 8;
- while ( leftbits >= 6 ) {
- this_ch = (leftchar >> (leftbits-6)) & 0x3f;
- leftbits -= 6;
- *ascii_data++ = table_b2a_hqx[this_ch];
- }
- }
- /* Output a possible runt byte */
- if ( leftbits ) {
- leftchar <<= (6-leftbits);
- *ascii_data++ = table_b2a_hqx[leftchar & 0x3f];
- }
-
- return _PyBytesWriter_Finish(&writer, ascii_data);
-}
-
-
-/*[clinic input]
-binascii.rledecode_hqx
-
- data: Py_buffer
- /
-
-Decode hexbin RLE-coded string.
-[clinic start generated code]*/
-
-static PyObject *
-binascii_rledecode_hqx_impl(PyObject *module, Py_buffer *data)
-/*[clinic end generated code: output=9826619565de1c6c input=54cdd49fc014402c]*/
-{
- if (PyErr_WarnEx(PyExc_DeprecationWarning,
- "binascii.rledecode_hqx() is deprecated", 1) < 0) {
- return NULL;
- }
-
- const unsigned char *in_data;
- unsigned char *out_data;
- unsigned char in_byte, in_repeat;
- Py_ssize_t in_len;
- _PyBytesWriter writer;
-
- in_data = data->buf;
- in_len = data->len;
- _PyBytesWriter_Init(&writer);
- binascii_state *state;
-
- assert(in_len >= 0);
-
- /* Empty string is a special case */
- if ( in_len == 0 )
- return PyBytes_FromStringAndSize("", 0);
- else if (in_len > PY_SSIZE_T_MAX / 2)
- return PyErr_NoMemory();
-
- /* Allocate a buffer of reasonable size. Resized when needed */
- out_data = _PyBytesWriter_Alloc(&writer, in_len);
- if (out_data == NULL)
- return NULL;
-
- /* Use overallocation */
- writer.overallocate = 1;
-
- /*
- ** We need two macros here to get/put bytes and handle
- ** end-of-buffer for input and output strings.
- */
-#define INBYTE(b) \
- do { \
- if ( --in_len < 0 ) { \
- state = get_binascii_state(module); \
- if (state == NULL) { \
- return NULL; \
- } \
- PyErr_SetString(state->Incomplete, ""); \
- goto error; \
- } \
- b = *in_data++; \
- } while(0)
-
- /*
- ** Handle first byte separately (since we have to get angry
- ** in case of an orphaned RLE code).
- */
- INBYTE(in_byte);
-
- if (in_byte == RUNCHAR) {
- INBYTE(in_repeat);
- /* only 1 byte will be written, but 2 bytes were preallocated:
- subtract 1 byte to prevent overallocation */
- writer.min_size--;
-
- if (in_repeat != 0) {
- /* Note Error, not Incomplete (which is at the end
- ** of the string only). This is a programmer error.
- */
- state = get_binascii_state(module);
- if (state == NULL) {
- return NULL;
- }
- PyErr_SetString(state->Error, "Orphaned RLE code at start");
- goto error;
- }
- *out_data++ = RUNCHAR;
- } else {
- *out_data++ = in_byte;
- }
-
- while( in_len > 0 ) {
- INBYTE(in_byte);
-
- if (in_byte == RUNCHAR) {
- INBYTE(in_repeat);
- /* only 1 byte will be written, but 2 bytes were preallocated:
- subtract 1 byte to prevent overallocation */
- writer.min_size--;
-
- if ( in_repeat == 0 ) {
- /* Just an escaped RUNCHAR value */
- *out_data++ = RUNCHAR;
- } else {
- /* Pick up value and output a sequence of it */
- in_byte = out_data[-1];
-
- /* enlarge the buffer if needed */
- if (in_repeat > 1) {
- /* -1 because we already preallocated 1 byte */
- out_data = _PyBytesWriter_Prepare(&writer, out_data,
- in_repeat - 1);
- if (out_data == NULL)
- goto error;
- }
-
- while ( --in_repeat > 0 )
- *out_data++ = in_byte;
- }
- } else {
- /* Normal byte */
- *out_data++ = in_byte;
- }
- }
- return _PyBytesWriter_Finish(&writer, out_data);
-
-error:
- _PyBytesWriter_Dealloc(&writer);
- return NULL;
-}
-
/*[clinic input]
binascii.crc_hqx
@@ -1629,14 +1215,10 @@ static struct PyMethodDef binascii_module_methods[] = {
BINASCII_B2A_UU_METHODDEF
BINASCII_A2B_BASE64_METHODDEF
BINASCII_B2A_BASE64_METHODDEF
- BINASCII_A2B_HQX_METHODDEF
- BINASCII_B2A_HQX_METHODDEF
BINASCII_A2B_HEX_METHODDEF
BINASCII_B2A_HEX_METHODDEF
BINASCII_HEXLIFY_METHODDEF
BINASCII_UNHEXLIFY_METHODDEF
- BINASCII_RLECODE_HQX_METHODDEF
- BINASCII_RLEDECODE_HQX_METHODDEF
BINASCII_CRC_HQX_METHODDEF
BINASCII_CRC32_METHODDEF
BINASCII_A2B_QP_METHODDEF
diff --git a/Modules/clinic/binascii.c.h b/Modules/clinic/binascii.c.h
index a924004..a0ca6d6 100644
--- a/Modules/clinic/binascii.c.h
+++ b/Modules/clinic/binascii.c.h
@@ -191,145 +191,6 @@ exit:
return return_value;
}
-PyDoc_STRVAR(binascii_a2b_hqx__doc__,
-"a2b_hqx($module, data, /)\n"
-"--\n"
-"\n"
-"Decode .hqx coding.");
-
-#define BINASCII_A2B_HQX_METHODDEF \
- {"a2b_hqx", (PyCFunction)binascii_a2b_hqx, METH_O, binascii_a2b_hqx__doc__},
-
-static PyObject *
-binascii_a2b_hqx_impl(PyObject *module, Py_buffer *data);
-
-static PyObject *
-binascii_a2b_hqx(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_hqx_impl(module, &data);
-
-exit:
- /* Cleanup for data */
- if (data.obj)
- PyBuffer_Release(&data);
-
- return return_value;
-}
-
-PyDoc_STRVAR(binascii_rlecode_hqx__doc__,
-"rlecode_hqx($module, data, /)\n"
-"--\n"
-"\n"
-"Binhex RLE-code binary data.");
-
-#define BINASCII_RLECODE_HQX_METHODDEF \
- {"rlecode_hqx", (PyCFunction)binascii_rlecode_hqx, METH_O, binascii_rlecode_hqx__doc__},
-
-static PyObject *
-binascii_rlecode_hqx_impl(PyObject *module, Py_buffer *data);
-
-static PyObject *
-binascii_rlecode_hqx(PyObject *module, PyObject *arg)
-{
- PyObject *return_value = NULL;
- Py_buffer data = {NULL, NULL};
-
- if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
- goto exit;
- }
- if (!PyBuffer_IsContiguous(&data, 'C')) {
- _PyArg_BadArgument("rlecode_hqx", "argument", "contiguous buffer", arg);
- goto exit;
- }
- return_value = binascii_rlecode_hqx_impl(module, &data);
-
-exit:
- /* Cleanup for data */
- if (data.obj) {
- PyBuffer_Release(&data);
- }
-
- return return_value;
-}
-
-PyDoc_STRVAR(binascii_b2a_hqx__doc__,
-"b2a_hqx($module, data, /)\n"
-"--\n"
-"\n"
-"Encode .hqx data.");
-
-#define BINASCII_B2A_HQX_METHODDEF \
- {"b2a_hqx", (PyCFunction)binascii_b2a_hqx, METH_O, binascii_b2a_hqx__doc__},
-
-static PyObject *
-binascii_b2a_hqx_impl(PyObject *module, Py_buffer *data);
-
-static PyObject *
-binascii_b2a_hqx(PyObject *module, PyObject *arg)
-{
- PyObject *return_value = NULL;
- Py_buffer data = {NULL, NULL};
-
- if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
- goto exit;
- }
- if (!PyBuffer_IsContiguous(&data, 'C')) {
- _PyArg_BadArgument("b2a_hqx", "argument", "contiguous buffer", arg);
- goto exit;
- }
- return_value = binascii_b2a_hqx_impl(module, &data);
-
-exit:
- /* Cleanup for data */
- if (data.obj) {
- PyBuffer_Release(&data);
- }
-
- return return_value;
-}
-
-PyDoc_STRVAR(binascii_rledecode_hqx__doc__,
-"rledecode_hqx($module, data, /)\n"
-"--\n"
-"\n"
-"Decode hexbin RLE-coded string.");
-
-#define BINASCII_RLEDECODE_HQX_METHODDEF \
- {"rledecode_hqx", (PyCFunction)binascii_rledecode_hqx, METH_O, binascii_rledecode_hqx__doc__},
-
-static PyObject *
-binascii_rledecode_hqx_impl(PyObject *module, Py_buffer *data);
-
-static PyObject *
-binascii_rledecode_hqx(PyObject *module, PyObject *arg)
-{
- PyObject *return_value = NULL;
- Py_buffer data = {NULL, NULL};
-
- if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
- goto exit;
- }
- if (!PyBuffer_IsContiguous(&data, 'C')) {
- _PyArg_BadArgument("rledecode_hqx", "argument", "contiguous buffer", arg);
- goto exit;
- }
- return_value = binascii_rledecode_hqx_impl(module, &data);
-
-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"
@@ -767,4 +628,4 @@ exit:
return return_value;
}
-/*[clinic end generated code: output=0f261ee49971f5ca input=a9049054013a1b77]*/
+/*[clinic end generated code: output=4162d08536697182 input=a9049054013a1b77]*/