mirror of
https://github.com/python/cpython
synced 2026-09-29 11:30:29 +03:00
bpo-36297: remove "unicode_internal" codec (GH-12342)
This commit is contained in:
parent
6fb544d8bc
commit
6a16b18224
12 changed files with 40 additions and 529 deletions
|
|
@ -21,8 +21,7 @@
|
|||
(Unicode object, bytes consumed)
|
||||
|
||||
These <encoding>s are available: utf_8, unicode_escape,
|
||||
raw_unicode_escape, unicode_internal, latin_1, ascii (7-bit),
|
||||
mbcs (on win32).
|
||||
raw_unicode_escape, latin_1, ascii (7-bit), mbcs (on win32).
|
||||
|
||||
|
||||
Written by Marc-Andre Lemburg (mal@lemburg.com).
|
||||
|
|
@ -250,38 +249,6 @@ _codecs_escape_encode_impl(PyObject *module, PyObject *data,
|
|||
}
|
||||
|
||||
/* --- Decoder ------------------------------------------------------------ */
|
||||
/*[clinic input]
|
||||
_codecs.unicode_internal_decode
|
||||
obj: object
|
||||
errors: str(accept={str, NoneType}) = NULL
|
||||
/
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_codecs_unicode_internal_decode_impl(PyObject *module, PyObject *obj,
|
||||
const char *errors)
|
||||
/*[clinic end generated code: output=edbfe175e09eff9a input=8d57930aeda170c6]*/
|
||||
{
|
||||
if (PyUnicode_Check(obj)) {
|
||||
if (PyUnicode_READY(obj) < 0)
|
||||
return NULL;
|
||||
Py_INCREF(obj);
|
||||
return codec_tuple(obj, PyUnicode_GET_LENGTH(obj));
|
||||
}
|
||||
else {
|
||||
Py_buffer view;
|
||||
PyObject *result;
|
||||
if (PyObject_GetBuffer(obj, &view, PyBUF_SIMPLE) != 0)
|
||||
return NULL;
|
||||
|
||||
result = codec_tuple(
|
||||
_PyUnicode_DecodeUnicodeInternal(view.buf, view.len, errors),
|
||||
view.len);
|
||||
PyBuffer_Release(&view);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_codecs.utf_7_decode
|
||||
data: Py_buffer
|
||||
|
|
@ -686,51 +653,6 @@ _codecs_readbuffer_encode_impl(PyObject *module, Py_buffer *data,
|
|||
return codec_tuple(result, data->len);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_codecs.unicode_internal_encode
|
||||
obj: object
|
||||
errors: str(accept={str, NoneType}) = NULL
|
||||
/
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_codecs_unicode_internal_encode_impl(PyObject *module, PyObject *obj,
|
||||
const char *errors)
|
||||
/*[clinic end generated code: output=a72507dde4ea558f input=8628f0280cf5ba61]*/
|
||||
{
|
||||
if (PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||
"unicode_internal codec has been deprecated",
|
||||
1))
|
||||
return NULL;
|
||||
|
||||
if (PyUnicode_Check(obj)) {
|
||||
Py_UNICODE *u;
|
||||
Py_ssize_t len, size;
|
||||
|
||||
if (PyUnicode_READY(obj) < 0)
|
||||
return NULL;
|
||||
|
||||
u = PyUnicode_AsUnicodeAndSize(obj, &len);
|
||||
if (u == NULL)
|
||||
return NULL;
|
||||
if ((size_t)len > (size_t)PY_SSIZE_T_MAX / sizeof(Py_UNICODE))
|
||||
return PyErr_NoMemory();
|
||||
size = len * sizeof(Py_UNICODE);
|
||||
return codec_tuple(PyBytes_FromStringAndSize((const char*)u, size),
|
||||
PyUnicode_GET_LENGTH(obj));
|
||||
}
|
||||
else {
|
||||
Py_buffer view;
|
||||
PyObject *result;
|
||||
if (PyObject_GetBuffer(obj, &view, PyBUF_SIMPLE) != 0)
|
||||
return NULL;
|
||||
result = codec_tuple(PyBytes_FromStringAndSize(view.buf, view.len),
|
||||
view.len);
|
||||
PyBuffer_Release(&view);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_codecs.utf_7_encode
|
||||
str: unicode
|
||||
|
|
@ -1095,8 +1017,6 @@ static PyMethodDef _codecs_functions[] = {
|
|||
_CODECS_UTF_32_EX_DECODE_METHODDEF
|
||||
_CODECS_UNICODE_ESCAPE_ENCODE_METHODDEF
|
||||
_CODECS_UNICODE_ESCAPE_DECODE_METHODDEF
|
||||
_CODECS_UNICODE_INTERNAL_ENCODE_METHODDEF
|
||||
_CODECS_UNICODE_INTERNAL_DECODE_METHODDEF
|
||||
_CODECS_RAW_UNICODE_ESCAPE_ENCODE_METHODDEF
|
||||
_CODECS_RAW_UNICODE_ESCAPE_DECODE_METHODDEF
|
||||
_CODECS_LATIN_1_ENCODE_METHODDEF
|
||||
|
|
|
|||
104
Modules/clinic/_codecsmodule.c.h
generated
104
Modules/clinic/_codecsmodule.c.h
generated
|
|
@ -370,57 +370,6 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_codecs_unicode_internal_decode__doc__,
|
||||
"unicode_internal_decode($module, obj, errors=None, /)\n"
|
||||
"--\n"
|
||||
"\n");
|
||||
|
||||
#define _CODECS_UNICODE_INTERNAL_DECODE_METHODDEF \
|
||||
{"unicode_internal_decode", (PyCFunction)(void(*)(void))_codecs_unicode_internal_decode, METH_FASTCALL, _codecs_unicode_internal_decode__doc__},
|
||||
|
||||
static PyObject *
|
||||
_codecs_unicode_internal_decode_impl(PyObject *module, PyObject *obj,
|
||||
const char *errors);
|
||||
|
||||
static PyObject *
|
||||
_codecs_unicode_internal_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *obj;
|
||||
const char *errors = NULL;
|
||||
|
||||
if (!_PyArg_CheckPositional("unicode_internal_decode", nargs, 1, 2)) {
|
||||
goto exit;
|
||||
}
|
||||
obj = args[0];
|
||||
if (nargs < 2) {
|
||||
goto skip_optional;
|
||||
}
|
||||
if (args[1] == Py_None) {
|
||||
errors = NULL;
|
||||
}
|
||||
else if (PyUnicode_Check(args[1])) {
|
||||
Py_ssize_t errors_length;
|
||||
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
|
||||
if (errors == NULL) {
|
||||
goto exit;
|
||||
}
|
||||
if (strlen(errors) != (size_t)errors_length) {
|
||||
PyErr_SetString(PyExc_ValueError, "embedded null character");
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
else {
|
||||
_PyArg_BadArgument("unicode_internal_decode", 2, "str or None", args[1]);
|
||||
goto exit;
|
||||
}
|
||||
skip_optional:
|
||||
return_value = _codecs_unicode_internal_decode_impl(module, obj, errors);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_codecs_utf_7_decode__doc__,
|
||||
"utf_7_decode($module, data, errors=None, final=False, /)\n"
|
||||
"--\n"
|
||||
|
|
@ -1853,57 +1802,6 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_codecs_unicode_internal_encode__doc__,
|
||||
"unicode_internal_encode($module, obj, errors=None, /)\n"
|
||||
"--\n"
|
||||
"\n");
|
||||
|
||||
#define _CODECS_UNICODE_INTERNAL_ENCODE_METHODDEF \
|
||||
{"unicode_internal_encode", (PyCFunction)(void(*)(void))_codecs_unicode_internal_encode, METH_FASTCALL, _codecs_unicode_internal_encode__doc__},
|
||||
|
||||
static PyObject *
|
||||
_codecs_unicode_internal_encode_impl(PyObject *module, PyObject *obj,
|
||||
const char *errors);
|
||||
|
||||
static PyObject *
|
||||
_codecs_unicode_internal_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *obj;
|
||||
const char *errors = NULL;
|
||||
|
||||
if (!_PyArg_CheckPositional("unicode_internal_encode", nargs, 1, 2)) {
|
||||
goto exit;
|
||||
}
|
||||
obj = args[0];
|
||||
if (nargs < 2) {
|
||||
goto skip_optional;
|
||||
}
|
||||
if (args[1] == Py_None) {
|
||||
errors = NULL;
|
||||
}
|
||||
else if (PyUnicode_Check(args[1])) {
|
||||
Py_ssize_t errors_length;
|
||||
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
|
||||
if (errors == NULL) {
|
||||
goto exit;
|
||||
}
|
||||
if (strlen(errors) != (size_t)errors_length) {
|
||||
PyErr_SetString(PyExc_ValueError, "embedded null character");
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
else {
|
||||
_PyArg_BadArgument("unicode_internal_encode", 2, "str or None", args[1]);
|
||||
goto exit;
|
||||
}
|
||||
skip_optional:
|
||||
return_value = _codecs_unicode_internal_encode_impl(module, obj, errors);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_codecs_utf_7_encode__doc__,
|
||||
"utf_7_encode($module, str, errors=None, /)\n"
|
||||
"--\n"
|
||||
|
|
@ -3024,4 +2922,4 @@ exit:
|
|||
#ifndef _CODECS_CODE_PAGE_ENCODE_METHODDEF
|
||||
#define _CODECS_CODE_PAGE_ENCODE_METHODDEF
|
||||
#endif /* !defined(_CODECS_CODE_PAGE_ENCODE_METHODDEF) */
|
||||
/*[clinic end generated code: output=02bd0f0cf9a28150 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=da3c47709a55a05e input=a9049054013a1b77]*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue