| 1 |
/*[clinic input] |
| 2 |
preserve |
| 3 |
[clinic start generated code]*/ |
| 4 |
|
| 5 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 6 |
# include "pycore_gc.h" // PyGC_Head |
| 7 |
# include "pycore_runtime.h" // _Py_ID() |
| 8 |
#endif |
| 9 |
#include "pycore_modsupport.h" // _PyArg_BadArgument() |
| 10 |
|
| 11 |
PyDoc_STRVAR(_codecs_register__doc__, |
| 12 |
"register($module, search_function, /)\n" |
| 13 |
"--\n" |
| 14 |
"\n" |
| 15 |
"Register a codec search function.\n" |
| 16 |
"\n" |
| 17 |
"Search functions are expected to take one argument, the encoding\n" |
| 18 |
"name in all lower case letters, and either return None, or a tuple\n" |
| 19 |
"of functions (encoder, decoder, stream_reader, stream_writer) (or\n" |
| 20 |
"a CodecInfo object)."); |
| 21 |
|
| 22 |
#define _CODECS_REGISTER_METHODDEF \ |
| 23 |
{"register", (PyCFunction)_codecs_register, METH_O, _codecs_register__doc__}, |
| 24 |
|
| 25 |
PyDoc_STRVAR(_codecs_unregister__doc__, |
| 26 |
"unregister($module, search_function, /)\n" |
| 27 |
"--\n" |
| 28 |
"\n" |
| 29 |
"Unregister a codec search function and clear the registry\'s cache.\n" |
| 30 |
"\n" |
| 31 |
"If the search function is not registered, do nothing."); |
| 32 |
|
| 33 |
#define _CODECS_UNREGISTER_METHODDEF \ |
| 34 |
{"unregister", (PyCFunction)_codecs_unregister, METH_O, _codecs_unregister__doc__}, |
| 35 |
|
| 36 |
PyDoc_STRVAR(_codecs_lookup__doc__, |
| 37 |
"lookup($module, encoding, /)\n" |
| 38 |
"--\n" |
| 39 |
"\n" |
| 40 |
"Looks up a codec tuple in the Python codec registry and returns a CodecInfo object."); |
| 41 |
|
| 42 |
#define _CODECS_LOOKUP_METHODDEF \ |
| 43 |
{"lookup", (PyCFunction)_codecs_lookup, METH_O, _codecs_lookup__doc__}, |
| 44 |
|
| 45 |
static PyObject * |
| 46 |
_codecs_lookup_impl(PyObject *module, const char *encoding); |
| 47 |
|
| 48 |
static PyObject * |
| 49 |
_codecs_lookup(PyObject *module, PyObject *arg) |
| 50 |
{ |
| 51 |
PyObject *return_value = NULL; |
| 52 |
const char *encoding; |
| 53 |
|
| 54 |
if (!PyUnicode_Check(arg)) { |
| 55 |
_PyArg_BadArgument("lookup", "argument", "str", arg); |
| 56 |
goto exit; |
| 57 |
} |
| 58 |
Py_ssize_t encoding_length; |
| 59 |
encoding = PyUnicode_AsUTF8AndSize(arg, &encoding_length); |
| 60 |
if (encoding == NULL) { |
| 61 |
goto exit; |
| 62 |
} |
| 63 |
if (strlen(encoding) != (size_t)encoding_length) { |
| 64 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 65 |
goto exit; |
| 66 |
} |
| 67 |
return_value = _codecs_lookup_impl(module, encoding); |
| 68 |
|
| 69 |
exit: |
| 70 |
return return_value; |
| 71 |
} |
| 72 |
|
| 73 |
PyDoc_STRVAR(_codecs_encode__doc__, |
| 74 |
"encode($module, /, obj, encoding=\'utf-8\', errors=\'strict\')\n" |
| 75 |
"--\n" |
| 76 |
"\n" |
| 77 |
"Encodes obj using the codec registered for encoding.\n" |
| 78 |
"\n" |
| 79 |
"The default encoding is \'utf-8\'. errors may be given to set a\n" |
| 80 |
"different error handling scheme. Default is \'strict\' meaning that\n" |
| 81 |
"encoding errors raise a ValueError. Other possible values are \'ignore\',\n" |
| 82 |
"\'replace\' and \'backslashreplace\' as well as any other name registered\n" |
| 83 |
"with codecs.register_error that can handle ValueErrors."); |
| 84 |
|
| 85 |
#define _CODECS_ENCODE_METHODDEF \ |
| 86 |
{"encode", _PyCFunction_CAST(_codecs_encode), METH_FASTCALL|METH_KEYWORDS, _codecs_encode__doc__}, |
| 87 |
|
| 88 |
static PyObject * |
| 89 |
_codecs_encode_impl(PyObject *module, PyObject *obj, const char *encoding, |
| 90 |
const char *errors); |
| 91 |
|
| 92 |
static PyObject * |
| 93 |
_codecs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 94 |
{ |
| 95 |
PyObject *return_value = NULL; |
| 96 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 97 |
|
| 98 |
#define NUM_KEYWORDS 3 |
| 99 |
static struct { |
| 100 |
PyGC_Head _this_is_not_used; |
| 101 |
PyObject_VAR_HEAD |
| 102 |
Py_hash_t ob_hash; |
| 103 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 104 |
} _kwtuple = { |
| 105 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 106 |
.ob_hash = -1, |
| 107 |
.ob_item = { &_Py_ID(obj), &_Py_ID(encoding), &_Py_ID(errors), }, |
| 108 |
}; |
| 109 |
#undef NUM_KEYWORDS |
| 110 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 111 |
|
| 112 |
#else // !Py_BUILD_CORE |
| 113 |
# define KWTUPLE NULL |
| 114 |
#endif // !Py_BUILD_CORE |
| 115 |
|
| 116 |
static const char * const _keywords[] = {"obj", "encoding", "errors", NULL}; |
| 117 |
static _PyArg_Parser _parser = { |
| 118 |
.keywords = _keywords, |
| 119 |
.fname = "encode", |
| 120 |
.kwtuple = KWTUPLE, |
| 121 |
}; |
| 122 |
#undef KWTUPLE |
| 123 |
PyObject *argsbuf[3]; |
| 124 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
| 125 |
PyObject *obj; |
| 126 |
const char *encoding = NULL; |
| 127 |
const char *errors = NULL; |
| 128 |
|
| 129 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 130 |
/*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 131 |
if (!args) { |
| 132 |
goto exit; |
| 133 |
} |
| 134 |
obj = args[0]; |
| 135 |
if (!noptargs) { |
| 136 |
goto skip_optional_pos; |
| 137 |
} |
| 138 |
if (args[1]) { |
| 139 |
if (!PyUnicode_Check(args[1])) { |
| 140 |
_PyArg_BadArgument("encode", "argument 'encoding'", "str", args[1]); |
| 141 |
goto exit; |
| 142 |
} |
| 143 |
Py_ssize_t encoding_length; |
| 144 |
encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length); |
| 145 |
if (encoding == NULL) { |
| 146 |
goto exit; |
| 147 |
} |
| 148 |
if (strlen(encoding) != (size_t)encoding_length) { |
| 149 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 150 |
goto exit; |
| 151 |
} |
| 152 |
if (!--noptargs) { |
| 153 |
goto skip_optional_pos; |
| 154 |
} |
| 155 |
} |
| 156 |
if (!PyUnicode_Check(args[2])) { |
| 157 |
_PyArg_BadArgument("encode", "argument 'errors'", "str", args[2]); |
| 158 |
goto exit; |
| 159 |
} |
| 160 |
Py_ssize_t errors_length; |
| 161 |
errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length); |
| 162 |
if (errors == NULL) { |
| 163 |
goto exit; |
| 164 |
} |
| 165 |
if (strlen(errors) != (size_t)errors_length) { |
| 166 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 167 |
goto exit; |
| 168 |
} |
| 169 |
skip_optional_pos: |
| 170 |
return_value = _codecs_encode_impl(module, obj, encoding, errors); |
| 171 |
|
| 172 |
exit: |
| 173 |
return return_value; |
| 174 |
} |
| 175 |
|
| 176 |
PyDoc_STRVAR(_codecs_decode__doc__, |
| 177 |
"decode($module, /, obj, encoding=\'utf-8\', errors=\'strict\')\n" |
| 178 |
"--\n" |
| 179 |
"\n" |
| 180 |
"Decodes obj using the codec registered for encoding.\n" |
| 181 |
"\n" |
| 182 |
"Default encoding is \'utf-8\'. errors may be given to set a\n" |
| 183 |
"different error handling scheme. Default is \'strict\' meaning that\n" |
| 184 |
"encoding errors raise a ValueError. Other possible values are \'ignore\',\n" |
| 185 |
"\'replace\' and \'backslashreplace\' as well as any other name registered\n" |
| 186 |
"with codecs.register_error that can handle ValueErrors."); |
| 187 |
|
| 188 |
#define _CODECS_DECODE_METHODDEF \ |
| 189 |
{"decode", _PyCFunction_CAST(_codecs_decode), METH_FASTCALL|METH_KEYWORDS, _codecs_decode__doc__}, |
| 190 |
|
| 191 |
static PyObject * |
| 192 |
_codecs_decode_impl(PyObject *module, PyObject *obj, const char *encoding, |
| 193 |
const char *errors); |
| 194 |
|
| 195 |
static PyObject * |
| 196 |
_codecs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 197 |
{ |
| 198 |
PyObject *return_value = NULL; |
| 199 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 200 |
|
| 201 |
#define NUM_KEYWORDS 3 |
| 202 |
static struct { |
| 203 |
PyGC_Head _this_is_not_used; |
| 204 |
PyObject_VAR_HEAD |
| 205 |
Py_hash_t ob_hash; |
| 206 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 207 |
} _kwtuple = { |
| 208 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 209 |
.ob_hash = -1, |
| 210 |
.ob_item = { &_Py_ID(obj), &_Py_ID(encoding), &_Py_ID(errors), }, |
| 211 |
}; |
| 212 |
#undef NUM_KEYWORDS |
| 213 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 214 |
|
| 215 |
#else // !Py_BUILD_CORE |
| 216 |
# define KWTUPLE NULL |
| 217 |
#endif // !Py_BUILD_CORE |
| 218 |
|
| 219 |
static const char * const _keywords[] = {"obj", "encoding", "errors", NULL}; |
| 220 |
static _PyArg_Parser _parser = { |
| 221 |
.keywords = _keywords, |
| 222 |
.fname = "decode", |
| 223 |
.kwtuple = KWTUPLE, |
| 224 |
}; |
| 225 |
#undef KWTUPLE |
| 226 |
PyObject *argsbuf[3]; |
| 227 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
| 228 |
PyObject *obj; |
| 229 |
const char *encoding = NULL; |
| 230 |
const char *errors = NULL; |
| 231 |
|
| 232 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 233 |
/*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 234 |
if (!args) { |
| 235 |
goto exit; |
| 236 |
} |
| 237 |
obj = args[0]; |
| 238 |
if (!noptargs) { |
| 239 |
goto skip_optional_pos; |
| 240 |
} |
| 241 |
if (args[1]) { |
| 242 |
if (!PyUnicode_Check(args[1])) { |
| 243 |
_PyArg_BadArgument("decode", "argument 'encoding'", "str", args[1]); |
| 244 |
goto exit; |
| 245 |
} |
| 246 |
Py_ssize_t encoding_length; |
| 247 |
encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length); |
| 248 |
if (encoding == NULL) { |
| 249 |
goto exit; |
| 250 |
} |
| 251 |
if (strlen(encoding) != (size_t)encoding_length) { |
| 252 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 253 |
goto exit; |
| 254 |
} |
| 255 |
if (!--noptargs) { |
| 256 |
goto skip_optional_pos; |
| 257 |
} |
| 258 |
} |
| 259 |
if (!PyUnicode_Check(args[2])) { |
| 260 |
_PyArg_BadArgument("decode", "argument 'errors'", "str", args[2]); |
| 261 |
goto exit; |
| 262 |
} |
| 263 |
Py_ssize_t errors_length; |
| 264 |
errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length); |
| 265 |
if (errors == NULL) { |
| 266 |
goto exit; |
| 267 |
} |
| 268 |
if (strlen(errors) != (size_t)errors_length) { |
| 269 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 270 |
goto exit; |
| 271 |
} |
| 272 |
skip_optional_pos: |
| 273 |
return_value = _codecs_decode_impl(module, obj, encoding, errors); |
| 274 |
|
| 275 |
exit: |
| 276 |
return return_value; |
| 277 |
} |
| 278 |
|
| 279 |
PyDoc_STRVAR(_codecs_escape_decode__doc__, |
| 280 |
"escape_decode($module, data, errors=None, /)\n" |
| 281 |
"--\n" |
| 282 |
"\n"); |
| 283 |
|
| 284 |
#define _CODECS_ESCAPE_DECODE_METHODDEF \ |
| 285 |
{"escape_decode", _PyCFunction_CAST(_codecs_escape_decode), METH_FASTCALL, _codecs_escape_decode__doc__}, |
| 286 |
|
| 287 |
static PyObject * |
| 288 |
_codecs_escape_decode_impl(PyObject *module, Py_buffer *data, |
| 289 |
const char *errors); |
| 290 |
|
| 291 |
static PyObject * |
| 292 |
_codecs_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 293 |
{ |
| 294 |
PyObject *return_value = NULL; |
| 295 |
Py_buffer data = {NULL, NULL}; |
| 296 |
const char *errors = NULL; |
| 297 |
|
| 298 |
if (!_PyArg_CheckPositional("escape_decode", nargs, 1, 2)) { |
| 299 |
goto exit; |
| 300 |
} |
| 301 |
if (PyUnicode_Check(args[0])) { |
| 302 |
Py_ssize_t len; |
| 303 |
const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len); |
| 304 |
if (ptr == NULL) { |
| 305 |
goto exit; |
| 306 |
} |
| 307 |
if (PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, PyBUF_SIMPLE) < 0) { |
| 308 |
goto exit; |
| 309 |
} |
| 310 |
} |
| 311 |
else { /* any bytes-like object */ |
| 312 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 313 |
goto exit; |
| 314 |
} |
| 315 |
} |
| 316 |
if (nargs < 2) { |
| 317 |
goto skip_optional; |
| 318 |
} |
| 319 |
if (args[1] == Py_None) { |
| 320 |
errors = NULL; |
| 321 |
} |
| 322 |
else if (PyUnicode_Check(args[1])) { |
| 323 |
Py_ssize_t errors_length; |
| 324 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 325 |
if (errors == NULL) { |
| 326 |
goto exit; |
| 327 |
} |
| 328 |
if (strlen(errors) != (size_t)errors_length) { |
| 329 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 330 |
goto exit; |
| 331 |
} |
| 332 |
} |
| 333 |
else { |
| 334 |
_PyArg_BadArgument("escape_decode", "argument 2", "str or None", args[1]); |
| 335 |
goto exit; |
| 336 |
} |
| 337 |
skip_optional: |
| 338 |
return_value = _codecs_escape_decode_impl(module, &data, errors); |
| 339 |
|
| 340 |
exit: |
| 341 |
/* Cleanup for data */ |
| 342 |
if (data.obj) { |
| 343 |
PyBuffer_Release(&data); |
| 344 |
} |
| 345 |
|
| 346 |
return return_value; |
| 347 |
} |
| 348 |
|
| 349 |
PyDoc_STRVAR(_codecs_escape_encode__doc__, |
| 350 |
"escape_encode($module, data, errors=None, /)\n" |
| 351 |
"--\n" |
| 352 |
"\n"); |
| 353 |
|
| 354 |
#define _CODECS_ESCAPE_ENCODE_METHODDEF \ |
| 355 |
{"escape_encode", _PyCFunction_CAST(_codecs_escape_encode), METH_FASTCALL, _codecs_escape_encode__doc__}, |
| 356 |
|
| 357 |
static PyObject * |
| 358 |
_codecs_escape_encode_impl(PyObject *module, PyObject *data, |
| 359 |
const char *errors); |
| 360 |
|
| 361 |
static PyObject * |
| 362 |
_codecs_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 363 |
{ |
| 364 |
PyObject *return_value = NULL; |
| 365 |
PyObject *data; |
| 366 |
const char *errors = NULL; |
| 367 |
|
| 368 |
if (!_PyArg_CheckPositional("escape_encode", nargs, 1, 2)) { |
| 369 |
goto exit; |
| 370 |
} |
| 371 |
if (!PyBytes_Check(args[0])) { |
| 372 |
_PyArg_BadArgument("escape_encode", "argument 1", "bytes", args[0]); |
| 373 |
goto exit; |
| 374 |
} |
| 375 |
data = args[0]; |
| 376 |
if (nargs < 2) { |
| 377 |
goto skip_optional; |
| 378 |
} |
| 379 |
if (args[1] == Py_None) { |
| 380 |
errors = NULL; |
| 381 |
} |
| 382 |
else if (PyUnicode_Check(args[1])) { |
| 383 |
Py_ssize_t errors_length; |
| 384 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 385 |
if (errors == NULL) { |
| 386 |
goto exit; |
| 387 |
} |
| 388 |
if (strlen(errors) != (size_t)errors_length) { |
| 389 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 390 |
goto exit; |
| 391 |
} |
| 392 |
} |
| 393 |
else { |
| 394 |
_PyArg_BadArgument("escape_encode", "argument 2", "str or None", args[1]); |
| 395 |
goto exit; |
| 396 |
} |
| 397 |
skip_optional: |
| 398 |
return_value = _codecs_escape_encode_impl(module, data, errors); |
| 399 |
|
| 400 |
exit: |
| 401 |
return return_value; |
| 402 |
} |
| 403 |
|
| 404 |
PyDoc_STRVAR(_codecs_utf_7_decode__doc__, |
| 405 |
"utf_7_decode($module, data, errors=None, final=False, /)\n" |
| 406 |
"--\n" |
| 407 |
"\n"); |
| 408 |
|
| 409 |
#define _CODECS_UTF_7_DECODE_METHODDEF \ |
| 410 |
{"utf_7_decode", _PyCFunction_CAST(_codecs_utf_7_decode), METH_FASTCALL, _codecs_utf_7_decode__doc__}, |
| 411 |
|
| 412 |
static PyObject * |
| 413 |
_codecs_utf_7_decode_impl(PyObject *module, Py_buffer *data, |
| 414 |
const char *errors, int final); |
| 415 |
|
| 416 |
static PyObject * |
| 417 |
_codecs_utf_7_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 418 |
{ |
| 419 |
PyObject *return_value = NULL; |
| 420 |
Py_buffer data = {NULL, NULL}; |
| 421 |
const char *errors = NULL; |
| 422 |
int final = 0; |
| 423 |
|
| 424 |
if (!_PyArg_CheckPositional("utf_7_decode", nargs, 1, 3)) { |
| 425 |
goto exit; |
| 426 |
} |
| 427 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 428 |
goto exit; |
| 429 |
} |
| 430 |
if (nargs < 2) { |
| 431 |
goto skip_optional; |
| 432 |
} |
| 433 |
if (args[1] == Py_None) { |
| 434 |
errors = NULL; |
| 435 |
} |
| 436 |
else if (PyUnicode_Check(args[1])) { |
| 437 |
Py_ssize_t errors_length; |
| 438 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 439 |
if (errors == NULL) { |
| 440 |
goto exit; |
| 441 |
} |
| 442 |
if (strlen(errors) != (size_t)errors_length) { |
| 443 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 444 |
goto exit; |
| 445 |
} |
| 446 |
} |
| 447 |
else { |
| 448 |
_PyArg_BadArgument("utf_7_decode", "argument 2", "str or None", args[1]); |
| 449 |
goto exit; |
| 450 |
} |
| 451 |
if (nargs < 3) { |
| 452 |
goto skip_optional; |
| 453 |
} |
| 454 |
final = PyObject_IsTrue(args[2]); |
| 455 |
if (final < 0) { |
| 456 |
goto exit; |
| 457 |
} |
| 458 |
skip_optional: |
| 459 |
return_value = _codecs_utf_7_decode_impl(module, &data, errors, final); |
| 460 |
|
| 461 |
exit: |
| 462 |
/* Cleanup for data */ |
| 463 |
if (data.obj) { |
| 464 |
PyBuffer_Release(&data); |
| 465 |
} |
| 466 |
|
| 467 |
return return_value; |
| 468 |
} |
| 469 |
|
| 470 |
PyDoc_STRVAR(_codecs_utf_8_decode__doc__, |
| 471 |
"utf_8_decode($module, data, errors=None, final=False, /)\n" |
| 472 |
"--\n" |
| 473 |
"\n"); |
| 474 |
|
| 475 |
#define _CODECS_UTF_8_DECODE_METHODDEF \ |
| 476 |
{"utf_8_decode", _PyCFunction_CAST(_codecs_utf_8_decode), METH_FASTCALL, _codecs_utf_8_decode__doc__}, |
| 477 |
|
| 478 |
static PyObject * |
| 479 |
_codecs_utf_8_decode_impl(PyObject *module, Py_buffer *data, |
| 480 |
const char *errors, int final); |
| 481 |
|
| 482 |
static PyObject * |
| 483 |
_codecs_utf_8_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 484 |
{ |
| 485 |
PyObject *return_value = NULL; |
| 486 |
Py_buffer data = {NULL, NULL}; |
| 487 |
const char *errors = NULL; |
| 488 |
int final = 0; |
| 489 |
|
| 490 |
if (!_PyArg_CheckPositional("utf_8_decode", nargs, 1, 3)) { |
| 491 |
goto exit; |
| 492 |
} |
| 493 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 494 |
goto exit; |
| 495 |
} |
| 496 |
if (nargs < 2) { |
| 497 |
goto skip_optional; |
| 498 |
} |
| 499 |
if (args[1] == Py_None) { |
| 500 |
errors = NULL; |
| 501 |
} |
| 502 |
else if (PyUnicode_Check(args[1])) { |
| 503 |
Py_ssize_t errors_length; |
| 504 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 505 |
if (errors == NULL) { |
| 506 |
goto exit; |
| 507 |
} |
| 508 |
if (strlen(errors) != (size_t)errors_length) { |
| 509 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 510 |
goto exit; |
| 511 |
} |
| 512 |
} |
| 513 |
else { |
| 514 |
_PyArg_BadArgument("utf_8_decode", "argument 2", "str or None", args[1]); |
| 515 |
goto exit; |
| 516 |
} |
| 517 |
if (nargs < 3) { |
| 518 |
goto skip_optional; |
| 519 |
} |
| 520 |
final = PyObject_IsTrue(args[2]); |
| 521 |
if (final < 0) { |
| 522 |
goto exit; |
| 523 |
} |
| 524 |
skip_optional: |
| 525 |
return_value = _codecs_utf_8_decode_impl(module, &data, errors, final); |
| 526 |
|
| 527 |
exit: |
| 528 |
/* Cleanup for data */ |
| 529 |
if (data.obj) { |
| 530 |
PyBuffer_Release(&data); |
| 531 |
} |
| 532 |
|
| 533 |
return return_value; |
| 534 |
} |
| 535 |
|
| 536 |
PyDoc_STRVAR(_codecs_utf_16_decode__doc__, |
| 537 |
"utf_16_decode($module, data, errors=None, final=False, /)\n" |
| 538 |
"--\n" |
| 539 |
"\n"); |
| 540 |
|
| 541 |
#define _CODECS_UTF_16_DECODE_METHODDEF \ |
| 542 |
{"utf_16_decode", _PyCFunction_CAST(_codecs_utf_16_decode), METH_FASTCALL, _codecs_utf_16_decode__doc__}, |
| 543 |
|
| 544 |
static PyObject * |
| 545 |
_codecs_utf_16_decode_impl(PyObject *module, Py_buffer *data, |
| 546 |
const char *errors, int final); |
| 547 |
|
| 548 |
static PyObject * |
| 549 |
_codecs_utf_16_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 550 |
{ |
| 551 |
PyObject *return_value = NULL; |
| 552 |
Py_buffer data = {NULL, NULL}; |
| 553 |
const char *errors = NULL; |
| 554 |
int final = 0; |
| 555 |
|
| 556 |
if (!_PyArg_CheckPositional("utf_16_decode", nargs, 1, 3)) { |
| 557 |
goto exit; |
| 558 |
} |
| 559 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 560 |
goto exit; |
| 561 |
} |
| 562 |
if (nargs < 2) { |
| 563 |
goto skip_optional; |
| 564 |
} |
| 565 |
if (args[1] == Py_None) { |
| 566 |
errors = NULL; |
| 567 |
} |
| 568 |
else if (PyUnicode_Check(args[1])) { |
| 569 |
Py_ssize_t errors_length; |
| 570 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 571 |
if (errors == NULL) { |
| 572 |
goto exit; |
| 573 |
} |
| 574 |
if (strlen(errors) != (size_t)errors_length) { |
| 575 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 576 |
goto exit; |
| 577 |
} |
| 578 |
} |
| 579 |
else { |
| 580 |
_PyArg_BadArgument("utf_16_decode", "argument 2", "str or None", args[1]); |
| 581 |
goto exit; |
| 582 |
} |
| 583 |
if (nargs < 3) { |
| 584 |
goto skip_optional; |
| 585 |
} |
| 586 |
final = PyObject_IsTrue(args[2]); |
| 587 |
if (final < 0) { |
| 588 |
goto exit; |
| 589 |
} |
| 590 |
skip_optional: |
| 591 |
return_value = _codecs_utf_16_decode_impl(module, &data, errors, final); |
| 592 |
|
| 593 |
exit: |
| 594 |
/* Cleanup for data */ |
| 595 |
if (data.obj) { |
| 596 |
PyBuffer_Release(&data); |
| 597 |
} |
| 598 |
|
| 599 |
return return_value; |
| 600 |
} |
| 601 |
|
| 602 |
PyDoc_STRVAR(_codecs_utf_16_le_decode__doc__, |
| 603 |
"utf_16_le_decode($module, data, errors=None, final=False, /)\n" |
| 604 |
"--\n" |
| 605 |
"\n"); |
| 606 |
|
| 607 |
#define _CODECS_UTF_16_LE_DECODE_METHODDEF \ |
| 608 |
{"utf_16_le_decode", _PyCFunction_CAST(_codecs_utf_16_le_decode), METH_FASTCALL, _codecs_utf_16_le_decode__doc__}, |
| 609 |
|
| 610 |
static PyObject * |
| 611 |
_codecs_utf_16_le_decode_impl(PyObject *module, Py_buffer *data, |
| 612 |
const char *errors, int final); |
| 613 |
|
| 614 |
static PyObject * |
| 615 |
_codecs_utf_16_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 616 |
{ |
| 617 |
PyObject *return_value = NULL; |
| 618 |
Py_buffer data = {NULL, NULL}; |
| 619 |
const char *errors = NULL; |
| 620 |
int final = 0; |
| 621 |
|
| 622 |
if (!_PyArg_CheckPositional("utf_16_le_decode", nargs, 1, 3)) { |
| 623 |
goto exit; |
| 624 |
} |
| 625 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 626 |
goto exit; |
| 627 |
} |
| 628 |
if (nargs < 2) { |
| 629 |
goto skip_optional; |
| 630 |
} |
| 631 |
if (args[1] == Py_None) { |
| 632 |
errors = NULL; |
| 633 |
} |
| 634 |
else if (PyUnicode_Check(args[1])) { |
| 635 |
Py_ssize_t errors_length; |
| 636 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 637 |
if (errors == NULL) { |
| 638 |
goto exit; |
| 639 |
} |
| 640 |
if (strlen(errors) != (size_t)errors_length) { |
| 641 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 642 |
goto exit; |
| 643 |
} |
| 644 |
} |
| 645 |
else { |
| 646 |
_PyArg_BadArgument("utf_16_le_decode", "argument 2", "str or None", args[1]); |
| 647 |
goto exit; |
| 648 |
} |
| 649 |
if (nargs < 3) { |
| 650 |
goto skip_optional; |
| 651 |
} |
| 652 |
final = PyObject_IsTrue(args[2]); |
| 653 |
if (final < 0) { |
| 654 |
goto exit; |
| 655 |
} |
| 656 |
skip_optional: |
| 657 |
return_value = _codecs_utf_16_le_decode_impl(module, &data, errors, final); |
| 658 |
|
| 659 |
exit: |
| 660 |
/* Cleanup for data */ |
| 661 |
if (data.obj) { |
| 662 |
PyBuffer_Release(&data); |
| 663 |
} |
| 664 |
|
| 665 |
return return_value; |
| 666 |
} |
| 667 |
|
| 668 |
PyDoc_STRVAR(_codecs_utf_16_be_decode__doc__, |
| 669 |
"utf_16_be_decode($module, data, errors=None, final=False, /)\n" |
| 670 |
"--\n" |
| 671 |
"\n"); |
| 672 |
|
| 673 |
#define _CODECS_UTF_16_BE_DECODE_METHODDEF \ |
| 674 |
{"utf_16_be_decode", _PyCFunction_CAST(_codecs_utf_16_be_decode), METH_FASTCALL, _codecs_utf_16_be_decode__doc__}, |
| 675 |
|
| 676 |
static PyObject * |
| 677 |
_codecs_utf_16_be_decode_impl(PyObject *module, Py_buffer *data, |
| 678 |
const char *errors, int final); |
| 679 |
|
| 680 |
static PyObject * |
| 681 |
_codecs_utf_16_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 682 |
{ |
| 683 |
PyObject *return_value = NULL; |
| 684 |
Py_buffer data = {NULL, NULL}; |
| 685 |
const char *errors = NULL; |
| 686 |
int final = 0; |
| 687 |
|
| 688 |
if (!_PyArg_CheckPositional("utf_16_be_decode", nargs, 1, 3)) { |
| 689 |
goto exit; |
| 690 |
} |
| 691 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 692 |
goto exit; |
| 693 |
} |
| 694 |
if (nargs < 2) { |
| 695 |
goto skip_optional; |
| 696 |
} |
| 697 |
if (args[1] == Py_None) { |
| 698 |
errors = NULL; |
| 699 |
} |
| 700 |
else if (PyUnicode_Check(args[1])) { |
| 701 |
Py_ssize_t errors_length; |
| 702 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 703 |
if (errors == NULL) { |
| 704 |
goto exit; |
| 705 |
} |
| 706 |
if (strlen(errors) != (size_t)errors_length) { |
| 707 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 708 |
goto exit; |
| 709 |
} |
| 710 |
} |
| 711 |
else { |
| 712 |
_PyArg_BadArgument("utf_16_be_decode", "argument 2", "str or None", args[1]); |
| 713 |
goto exit; |
| 714 |
} |
| 715 |
if (nargs < 3) { |
| 716 |
goto skip_optional; |
| 717 |
} |
| 718 |
final = PyObject_IsTrue(args[2]); |
| 719 |
if (final < 0) { |
| 720 |
goto exit; |
| 721 |
} |
| 722 |
skip_optional: |
| 723 |
return_value = _codecs_utf_16_be_decode_impl(module, &data, errors, final); |
| 724 |
|
| 725 |
exit: |
| 726 |
/* Cleanup for data */ |
| 727 |
if (data.obj) { |
| 728 |
PyBuffer_Release(&data); |
| 729 |
} |
| 730 |
|
| 731 |
return return_value; |
| 732 |
} |
| 733 |
|
| 734 |
PyDoc_STRVAR(_codecs_utf_16_ex_decode__doc__, |
| 735 |
"utf_16_ex_decode($module, data, errors=None, byteorder=0, final=False,\n" |
| 736 |
" /)\n" |
| 737 |
"--\n" |
| 738 |
"\n"); |
| 739 |
|
| 740 |
#define _CODECS_UTF_16_EX_DECODE_METHODDEF \ |
| 741 |
{"utf_16_ex_decode", _PyCFunction_CAST(_codecs_utf_16_ex_decode), METH_FASTCALL, _codecs_utf_16_ex_decode__doc__}, |
| 742 |
|
| 743 |
static PyObject * |
| 744 |
_codecs_utf_16_ex_decode_impl(PyObject *module, Py_buffer *data, |
| 745 |
const char *errors, int byteorder, int final); |
| 746 |
|
| 747 |
static PyObject * |
| 748 |
_codecs_utf_16_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 749 |
{ |
| 750 |
PyObject *return_value = NULL; |
| 751 |
Py_buffer data = {NULL, NULL}; |
| 752 |
const char *errors = NULL; |
| 753 |
int byteorder = 0; |
| 754 |
int final = 0; |
| 755 |
|
| 756 |
if (!_PyArg_CheckPositional("utf_16_ex_decode", nargs, 1, 4)) { |
| 757 |
goto exit; |
| 758 |
} |
| 759 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 760 |
goto exit; |
| 761 |
} |
| 762 |
if (nargs < 2) { |
| 763 |
goto skip_optional; |
| 764 |
} |
| 765 |
if (args[1] == Py_None) { |
| 766 |
errors = NULL; |
| 767 |
} |
| 768 |
else if (PyUnicode_Check(args[1])) { |
| 769 |
Py_ssize_t errors_length; |
| 770 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 771 |
if (errors == NULL) { |
| 772 |
goto exit; |
| 773 |
} |
| 774 |
if (strlen(errors) != (size_t)errors_length) { |
| 775 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 776 |
goto exit; |
| 777 |
} |
| 778 |
} |
| 779 |
else { |
| 780 |
_PyArg_BadArgument("utf_16_ex_decode", "argument 2", "str or None", args[1]); |
| 781 |
goto exit; |
| 782 |
} |
| 783 |
if (nargs < 3) { |
| 784 |
goto skip_optional; |
| 785 |
} |
| 786 |
byteorder = PyLong_AsInt(args[2]); |
| 787 |
if (byteorder == -1 && PyErr_Occurred()) { |
| 788 |
goto exit; |
| 789 |
} |
| 790 |
if (nargs < 4) { |
| 791 |
goto skip_optional; |
| 792 |
} |
| 793 |
final = PyObject_IsTrue(args[3]); |
| 794 |
if (final < 0) { |
| 795 |
goto exit; |
| 796 |
} |
| 797 |
skip_optional: |
| 798 |
return_value = _codecs_utf_16_ex_decode_impl(module, &data, errors, byteorder, final); |
| 799 |
|
| 800 |
exit: |
| 801 |
/* Cleanup for data */ |
| 802 |
if (data.obj) { |
| 803 |
PyBuffer_Release(&data); |
| 804 |
} |
| 805 |
|
| 806 |
return return_value; |
| 807 |
} |
| 808 |
|
| 809 |
PyDoc_STRVAR(_codecs_utf_32_decode__doc__, |
| 810 |
"utf_32_decode($module, data, errors=None, final=False, /)\n" |
| 811 |
"--\n" |
| 812 |
"\n"); |
| 813 |
|
| 814 |
#define _CODECS_UTF_32_DECODE_METHODDEF \ |
| 815 |
{"utf_32_decode", _PyCFunction_CAST(_codecs_utf_32_decode), METH_FASTCALL, _codecs_utf_32_decode__doc__}, |
| 816 |
|
| 817 |
static PyObject * |
| 818 |
_codecs_utf_32_decode_impl(PyObject *module, Py_buffer *data, |
| 819 |
const char *errors, int final); |
| 820 |
|
| 821 |
static PyObject * |
| 822 |
_codecs_utf_32_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 823 |
{ |
| 824 |
PyObject *return_value = NULL; |
| 825 |
Py_buffer data = {NULL, NULL}; |
| 826 |
const char *errors = NULL; |
| 827 |
int final = 0; |
| 828 |
|
| 829 |
if (!_PyArg_CheckPositional("utf_32_decode", nargs, 1, 3)) { |
| 830 |
goto exit; |
| 831 |
} |
| 832 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 833 |
goto exit; |
| 834 |
} |
| 835 |
if (nargs < 2) { |
| 836 |
goto skip_optional; |
| 837 |
} |
| 838 |
if (args[1] == Py_None) { |
| 839 |
errors = NULL; |
| 840 |
} |
| 841 |
else if (PyUnicode_Check(args[1])) { |
| 842 |
Py_ssize_t errors_length; |
| 843 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 844 |
if (errors == NULL) { |
| 845 |
goto exit; |
| 846 |
} |
| 847 |
if (strlen(errors) != (size_t)errors_length) { |
| 848 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 849 |
goto exit; |
| 850 |
} |
| 851 |
} |
| 852 |
else { |
| 853 |
_PyArg_BadArgument("utf_32_decode", "argument 2", "str or None", args[1]); |
| 854 |
goto exit; |
| 855 |
} |
| 856 |
if (nargs < 3) { |
| 857 |
goto skip_optional; |
| 858 |
} |
| 859 |
final = PyObject_IsTrue(args[2]); |
| 860 |
if (final < 0) { |
| 861 |
goto exit; |
| 862 |
} |
| 863 |
skip_optional: |
| 864 |
return_value = _codecs_utf_32_decode_impl(module, &data, errors, final); |
| 865 |
|
| 866 |
exit: |
| 867 |
/* Cleanup for data */ |
| 868 |
if (data.obj) { |
| 869 |
PyBuffer_Release(&data); |
| 870 |
} |
| 871 |
|
| 872 |
return return_value; |
| 873 |
} |
| 874 |
|
| 875 |
PyDoc_STRVAR(_codecs_utf_32_le_decode__doc__, |
| 876 |
"utf_32_le_decode($module, data, errors=None, final=False, /)\n" |
| 877 |
"--\n" |
| 878 |
"\n"); |
| 879 |
|
| 880 |
#define _CODECS_UTF_32_LE_DECODE_METHODDEF \ |
| 881 |
{"utf_32_le_decode", _PyCFunction_CAST(_codecs_utf_32_le_decode), METH_FASTCALL, _codecs_utf_32_le_decode__doc__}, |
| 882 |
|
| 883 |
static PyObject * |
| 884 |
_codecs_utf_32_le_decode_impl(PyObject *module, Py_buffer *data, |
| 885 |
const char *errors, int final); |
| 886 |
|
| 887 |
static PyObject * |
| 888 |
_codecs_utf_32_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 889 |
{ |
| 890 |
PyObject *return_value = NULL; |
| 891 |
Py_buffer data = {NULL, NULL}; |
| 892 |
const char *errors = NULL; |
| 893 |
int final = 0; |
| 894 |
|
| 895 |
if (!_PyArg_CheckPositional("utf_32_le_decode", nargs, 1, 3)) { |
| 896 |
goto exit; |
| 897 |
} |
| 898 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 899 |
goto exit; |
| 900 |
} |
| 901 |
if (nargs < 2) { |
| 902 |
goto skip_optional; |
| 903 |
} |
| 904 |
if (args[1] == Py_None) { |
| 905 |
errors = NULL; |
| 906 |
} |
| 907 |
else if (PyUnicode_Check(args[1])) { |
| 908 |
Py_ssize_t errors_length; |
| 909 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 910 |
if (errors == NULL) { |
| 911 |
goto exit; |
| 912 |
} |
| 913 |
if (strlen(errors) != (size_t)errors_length) { |
| 914 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 915 |
goto exit; |
| 916 |
} |
| 917 |
} |
| 918 |
else { |
| 919 |
_PyArg_BadArgument("utf_32_le_decode", "argument 2", "str or None", args[1]); |
| 920 |
goto exit; |
| 921 |
} |
| 922 |
if (nargs < 3) { |
| 923 |
goto skip_optional; |
| 924 |
} |
| 925 |
final = PyObject_IsTrue(args[2]); |
| 926 |
if (final < 0) { |
| 927 |
goto exit; |
| 928 |
} |
| 929 |
skip_optional: |
| 930 |
return_value = _codecs_utf_32_le_decode_impl(module, &data, errors, final); |
| 931 |
|
| 932 |
exit: |
| 933 |
/* Cleanup for data */ |
| 934 |
if (data.obj) { |
| 935 |
PyBuffer_Release(&data); |
| 936 |
} |
| 937 |
|
| 938 |
return return_value; |
| 939 |
} |
| 940 |
|
| 941 |
PyDoc_STRVAR(_codecs_utf_32_be_decode__doc__, |
| 942 |
"utf_32_be_decode($module, data, errors=None, final=False, /)\n" |
| 943 |
"--\n" |
| 944 |
"\n"); |
| 945 |
|
| 946 |
#define _CODECS_UTF_32_BE_DECODE_METHODDEF \ |
| 947 |
{"utf_32_be_decode", _PyCFunction_CAST(_codecs_utf_32_be_decode), METH_FASTCALL, _codecs_utf_32_be_decode__doc__}, |
| 948 |
|
| 949 |
static PyObject * |
| 950 |
_codecs_utf_32_be_decode_impl(PyObject *module, Py_buffer *data, |
| 951 |
const char *errors, int final); |
| 952 |
|
| 953 |
static PyObject * |
| 954 |
_codecs_utf_32_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 955 |
{ |
| 956 |
PyObject *return_value = NULL; |
| 957 |
Py_buffer data = {NULL, NULL}; |
| 958 |
const char *errors = NULL; |
| 959 |
int final = 0; |
| 960 |
|
| 961 |
if (!_PyArg_CheckPositional("utf_32_be_decode", nargs, 1, 3)) { |
| 962 |
goto exit; |
| 963 |
} |
| 964 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 965 |
goto exit; |
| 966 |
} |
| 967 |
if (nargs < 2) { |
| 968 |
goto skip_optional; |
| 969 |
} |
| 970 |
if (args[1] == Py_None) { |
| 971 |
errors = NULL; |
| 972 |
} |
| 973 |
else if (PyUnicode_Check(args[1])) { |
| 974 |
Py_ssize_t errors_length; |
| 975 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 976 |
if (errors == NULL) { |
| 977 |
goto exit; |
| 978 |
} |
| 979 |
if (strlen(errors) != (size_t)errors_length) { |
| 980 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 981 |
goto exit; |
| 982 |
} |
| 983 |
} |
| 984 |
else { |
| 985 |
_PyArg_BadArgument("utf_32_be_decode", "argument 2", "str or None", args[1]); |
| 986 |
goto exit; |
| 987 |
} |
| 988 |
if (nargs < 3) { |
| 989 |
goto skip_optional; |
| 990 |
} |
| 991 |
final = PyObject_IsTrue(args[2]); |
| 992 |
if (final < 0) { |
| 993 |
goto exit; |
| 994 |
} |
| 995 |
skip_optional: |
| 996 |
return_value = _codecs_utf_32_be_decode_impl(module, &data, errors, final); |
| 997 |
|
| 998 |
exit: |
| 999 |
/* Cleanup for data */ |
| 1000 |
if (data.obj) { |
| 1001 |
PyBuffer_Release(&data); |
| 1002 |
} |
| 1003 |
|
| 1004 |
return return_value; |
| 1005 |
} |
| 1006 |
|
| 1007 |
PyDoc_STRVAR(_codecs_utf_32_ex_decode__doc__, |
| 1008 |
"utf_32_ex_decode($module, data, errors=None, byteorder=0, final=False,\n" |
| 1009 |
" /)\n" |
| 1010 |
"--\n" |
| 1011 |
"\n"); |
| 1012 |
|
| 1013 |
#define _CODECS_UTF_32_EX_DECODE_METHODDEF \ |
| 1014 |
{"utf_32_ex_decode", _PyCFunction_CAST(_codecs_utf_32_ex_decode), METH_FASTCALL, _codecs_utf_32_ex_decode__doc__}, |
| 1015 |
|
| 1016 |
static PyObject * |
| 1017 |
_codecs_utf_32_ex_decode_impl(PyObject *module, Py_buffer *data, |
| 1018 |
const char *errors, int byteorder, int final); |
| 1019 |
|
| 1020 |
static PyObject * |
| 1021 |
_codecs_utf_32_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1022 |
{ |
| 1023 |
PyObject *return_value = NULL; |
| 1024 |
Py_buffer data = {NULL, NULL}; |
| 1025 |
const char *errors = NULL; |
| 1026 |
int byteorder = 0; |
| 1027 |
int final = 0; |
| 1028 |
|
| 1029 |
if (!_PyArg_CheckPositional("utf_32_ex_decode", nargs, 1, 4)) { |
| 1030 |
goto exit; |
| 1031 |
} |
| 1032 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 1033 |
goto exit; |
| 1034 |
} |
| 1035 |
if (nargs < 2) { |
| 1036 |
goto skip_optional; |
| 1037 |
} |
| 1038 |
if (args[1] == Py_None) { |
| 1039 |
errors = NULL; |
| 1040 |
} |
| 1041 |
else if (PyUnicode_Check(args[1])) { |
| 1042 |
Py_ssize_t errors_length; |
| 1043 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 1044 |
if (errors == NULL) { |
| 1045 |
goto exit; |
| 1046 |
} |
| 1047 |
if (strlen(errors) != (size_t)errors_length) { |
| 1048 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 1049 |
goto exit; |
| 1050 |
} |
| 1051 |
} |
| 1052 |
else { |
| 1053 |
_PyArg_BadArgument("utf_32_ex_decode", "argument 2", "str or None", args[1]); |
| 1054 |
goto exit; |
| 1055 |
} |
| 1056 |
if (nargs < 3) { |
| 1057 |
goto skip_optional; |
| 1058 |
} |
| 1059 |
byteorder = PyLong_AsInt(args[2]); |
| 1060 |
if (byteorder == -1 && PyErr_Occurred()) { |
| 1061 |
goto exit; |
| 1062 |
} |
| 1063 |
if (nargs < 4) { |
| 1064 |
goto skip_optional; |
| 1065 |
} |
| 1066 |
final = PyObject_IsTrue(args[3]); |
| 1067 |
if (final < 0) { |
| 1068 |
goto exit; |
| 1069 |
} |
| 1070 |
skip_optional: |
| 1071 |
return_value = _codecs_utf_32_ex_decode_impl(module, &data, errors, byteorder, final); |
| 1072 |
|
| 1073 |
exit: |
| 1074 |
/* Cleanup for data */ |
| 1075 |
if (data.obj) { |
| 1076 |
PyBuffer_Release(&data); |
| 1077 |
} |
| 1078 |
|
| 1079 |
return return_value; |
| 1080 |
} |
| 1081 |
|
| 1082 |
PyDoc_STRVAR(_codecs_unicode_escape_decode__doc__, |
| 1083 |
"unicode_escape_decode($module, data, errors=None, final=True, /)\n" |
| 1084 |
"--\n" |
| 1085 |
"\n"); |
| 1086 |
|
| 1087 |
#define _CODECS_UNICODE_ESCAPE_DECODE_METHODDEF \ |
| 1088 |
{"unicode_escape_decode", _PyCFunction_CAST(_codecs_unicode_escape_decode), METH_FASTCALL, _codecs_unicode_escape_decode__doc__}, |
| 1089 |
|
| 1090 |
static PyObject * |
| 1091 |
_codecs_unicode_escape_decode_impl(PyObject *module, Py_buffer *data, |
| 1092 |
const char *errors, int final); |
| 1093 |
|
| 1094 |
static PyObject * |
| 1095 |
_codecs_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1096 |
{ |
| 1097 |
PyObject *return_value = NULL; |
| 1098 |
Py_buffer data = {NULL, NULL}; |
| 1099 |
const char *errors = NULL; |
| 1100 |
int final = 1; |
| 1101 |
|
| 1102 |
if (!_PyArg_CheckPositional("unicode_escape_decode", nargs, 1, 3)) { |
| 1103 |
goto exit; |
| 1104 |
} |
| 1105 |
if (PyUnicode_Check(args[0])) { |
| 1106 |
Py_ssize_t len; |
| 1107 |
const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len); |
| 1108 |
if (ptr == NULL) { |
| 1109 |
goto exit; |
| 1110 |
} |
| 1111 |
if (PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, PyBUF_SIMPLE) < 0) { |
| 1112 |
goto exit; |
| 1113 |
} |
| 1114 |
} |
| 1115 |
else { /* any bytes-like object */ |
| 1116 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 1117 |
goto exit; |
| 1118 |
} |
| 1119 |
} |
| 1120 |
if (nargs < 2) { |
| 1121 |
goto skip_optional; |
| 1122 |
} |
| 1123 |
if (args[1] == Py_None) { |
| 1124 |
errors = NULL; |
| 1125 |
} |
| 1126 |
else if (PyUnicode_Check(args[1])) { |
| 1127 |
Py_ssize_t errors_length; |
| 1128 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 1129 |
if (errors == NULL) { |
| 1130 |
goto exit; |
| 1131 |
} |
| 1132 |
if (strlen(errors) != (size_t)errors_length) { |
| 1133 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 1134 |
goto exit; |
| 1135 |
} |
| 1136 |
} |
| 1137 |
else { |
| 1138 |
_PyArg_BadArgument("unicode_escape_decode", "argument 2", "str or None", args[1]); |
| 1139 |
goto exit; |
| 1140 |
} |
| 1141 |
if (nargs < 3) { |
| 1142 |
goto skip_optional; |
| 1143 |
} |
| 1144 |
final = PyObject_IsTrue(args[2]); |
| 1145 |
if (final < 0) { |
| 1146 |
goto exit; |
| 1147 |
} |
| 1148 |
skip_optional: |
| 1149 |
return_value = _codecs_unicode_escape_decode_impl(module, &data, errors, final); |
| 1150 |
|
| 1151 |
exit: |
| 1152 |
/* Cleanup for data */ |
| 1153 |
if (data.obj) { |
| 1154 |
PyBuffer_Release(&data); |
| 1155 |
} |
| 1156 |
|
| 1157 |
return return_value; |
| 1158 |
} |
| 1159 |
|
| 1160 |
PyDoc_STRVAR(_codecs_raw_unicode_escape_decode__doc__, |
| 1161 |
"raw_unicode_escape_decode($module, data, errors=None, final=True, /)\n" |
| 1162 |
"--\n" |
| 1163 |
"\n"); |
| 1164 |
|
| 1165 |
#define _CODECS_RAW_UNICODE_ESCAPE_DECODE_METHODDEF \ |
| 1166 |
{"raw_unicode_escape_decode", _PyCFunction_CAST(_codecs_raw_unicode_escape_decode), METH_FASTCALL, _codecs_raw_unicode_escape_decode__doc__}, |
| 1167 |
|
| 1168 |
static PyObject * |
| 1169 |
_codecs_raw_unicode_escape_decode_impl(PyObject *module, Py_buffer *data, |
| 1170 |
const char *errors, int final); |
| 1171 |
|
| 1172 |
static PyObject * |
| 1173 |
_codecs_raw_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1174 |
{ |
| 1175 |
PyObject *return_value = NULL; |
| 1176 |
Py_buffer data = {NULL, NULL}; |
| 1177 |
const char *errors = NULL; |
| 1178 |
int final = 1; |
| 1179 |
|
| 1180 |
if (!_PyArg_CheckPositional("raw_unicode_escape_decode", nargs, 1, 3)) { |
| 1181 |
goto exit; |
| 1182 |
} |
| 1183 |
if (PyUnicode_Check(args[0])) { |
| 1184 |
Py_ssize_t len; |
| 1185 |
const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len); |
| 1186 |
if (ptr == NULL) { |
| 1187 |
goto exit; |
| 1188 |
} |
| 1189 |
if (PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, PyBUF_SIMPLE) < 0) { |
| 1190 |
goto exit; |
| 1191 |
} |
| 1192 |
} |
| 1193 |
else { /* any bytes-like object */ |
| 1194 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 1195 |
goto exit; |
| 1196 |
} |
| 1197 |
} |
| 1198 |
if (nargs < 2) { |
| 1199 |
goto skip_optional; |
| 1200 |
} |
| 1201 |
if (args[1] == Py_None) { |
| 1202 |
errors = NULL; |
| 1203 |
} |
| 1204 |
else if (PyUnicode_Check(args[1])) { |
| 1205 |
Py_ssize_t errors_length; |
| 1206 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 1207 |
if (errors == NULL) { |
| 1208 |
goto exit; |
| 1209 |
} |
| 1210 |
if (strlen(errors) != (size_t)errors_length) { |
| 1211 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 1212 |
goto exit; |
| 1213 |
} |
| 1214 |
} |
| 1215 |
else { |
| 1216 |
_PyArg_BadArgument("raw_unicode_escape_decode", "argument 2", "str or None", args[1]); |
| 1217 |
goto exit; |
| 1218 |
} |
| 1219 |
if (nargs < 3) { |
| 1220 |
goto skip_optional; |
| 1221 |
} |
| 1222 |
final = PyObject_IsTrue(args[2]); |
| 1223 |
if (final < 0) { |
| 1224 |
goto exit; |
| 1225 |
} |
| 1226 |
skip_optional: |
| 1227 |
return_value = _codecs_raw_unicode_escape_decode_impl(module, &data, errors, final); |
| 1228 |
|
| 1229 |
exit: |
| 1230 |
/* Cleanup for data */ |
| 1231 |
if (data.obj) { |
| 1232 |
PyBuffer_Release(&data); |
| 1233 |
} |
| 1234 |
|
| 1235 |
return return_value; |
| 1236 |
} |
| 1237 |
|
| 1238 |
PyDoc_STRVAR(_codecs_latin_1_decode__doc__, |
| 1239 |
"latin_1_decode($module, data, errors=None, /)\n" |
| 1240 |
"--\n" |
| 1241 |
"\n"); |
| 1242 |
|
| 1243 |
#define _CODECS_LATIN_1_DECODE_METHODDEF \ |
| 1244 |
{"latin_1_decode", _PyCFunction_CAST(_codecs_latin_1_decode), METH_FASTCALL, _codecs_latin_1_decode__doc__}, |
| 1245 |
|
| 1246 |
static PyObject * |
| 1247 |
_codecs_latin_1_decode_impl(PyObject *module, Py_buffer *data, |
| 1248 |
const char *errors); |
| 1249 |
|
| 1250 |
static PyObject * |
| 1251 |
_codecs_latin_1_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1252 |
{ |
| 1253 |
PyObject *return_value = NULL; |
| 1254 |
Py_buffer data = {NULL, NULL}; |
| 1255 |
const char *errors = NULL; |
| 1256 |
|
| 1257 |
if (!_PyArg_CheckPositional("latin_1_decode", nargs, 1, 2)) { |
| 1258 |
goto exit; |
| 1259 |
} |
| 1260 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 1261 |
goto exit; |
| 1262 |
} |
| 1263 |
if (nargs < 2) { |
| 1264 |
goto skip_optional; |
| 1265 |
} |
| 1266 |
if (args[1] == Py_None) { |
| 1267 |
errors = NULL; |
| 1268 |
} |
| 1269 |
else if (PyUnicode_Check(args[1])) { |
| 1270 |
Py_ssize_t errors_length; |
| 1271 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 1272 |
if (errors == NULL) { |
| 1273 |
goto exit; |
| 1274 |
} |
| 1275 |
if (strlen(errors) != (size_t)errors_length) { |
| 1276 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 1277 |
goto exit; |
| 1278 |
} |
| 1279 |
} |
| 1280 |
else { |
| 1281 |
_PyArg_BadArgument("latin_1_decode", "argument 2", "str or None", args[1]); |
| 1282 |
goto exit; |
| 1283 |
} |
| 1284 |
skip_optional: |
| 1285 |
return_value = _codecs_latin_1_decode_impl(module, &data, errors); |
| 1286 |
|
| 1287 |
exit: |
| 1288 |
/* Cleanup for data */ |
| 1289 |
if (data.obj) { |
| 1290 |
PyBuffer_Release(&data); |
| 1291 |
} |
| 1292 |
|
| 1293 |
return return_value; |
| 1294 |
} |
| 1295 |
|
| 1296 |
PyDoc_STRVAR(_codecs_ascii_decode__doc__, |
| 1297 |
"ascii_decode($module, data, errors=None, /)\n" |
| 1298 |
"--\n" |
| 1299 |
"\n"); |
| 1300 |
|
| 1301 |
#define _CODECS_ASCII_DECODE_METHODDEF \ |
| 1302 |
{"ascii_decode", _PyCFunction_CAST(_codecs_ascii_decode), METH_FASTCALL, _codecs_ascii_decode__doc__}, |
| 1303 |
|
| 1304 |
static PyObject * |
| 1305 |
_codecs_ascii_decode_impl(PyObject *module, Py_buffer *data, |
| 1306 |
const char *errors); |
| 1307 |
|
| 1308 |
static PyObject * |
| 1309 |
_codecs_ascii_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1310 |
{ |
| 1311 |
PyObject *return_value = NULL; |
| 1312 |
Py_buffer data = {NULL, NULL}; |
| 1313 |
const char *errors = NULL; |
| 1314 |
|
| 1315 |
if (!_PyArg_CheckPositional("ascii_decode", nargs, 1, 2)) { |
| 1316 |
goto exit; |
| 1317 |
} |
| 1318 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 1319 |
goto exit; |
| 1320 |
} |
| 1321 |
if (nargs < 2) { |
| 1322 |
goto skip_optional; |
| 1323 |
} |
| 1324 |
if (args[1] == Py_None) { |
| 1325 |
errors = NULL; |
| 1326 |
} |
| 1327 |
else if (PyUnicode_Check(args[1])) { |
| 1328 |
Py_ssize_t errors_length; |
| 1329 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 1330 |
if (errors == NULL) { |
| 1331 |
goto exit; |
| 1332 |
} |
| 1333 |
if (strlen(errors) != (size_t)errors_length) { |
| 1334 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 1335 |
goto exit; |
| 1336 |
} |
| 1337 |
} |
| 1338 |
else { |
| 1339 |
_PyArg_BadArgument("ascii_decode", "argument 2", "str or None", args[1]); |
| 1340 |
goto exit; |
| 1341 |
} |
| 1342 |
skip_optional: |
| 1343 |
return_value = _codecs_ascii_decode_impl(module, &data, errors); |
| 1344 |
|
| 1345 |
exit: |
| 1346 |
/* Cleanup for data */ |
| 1347 |
if (data.obj) { |
| 1348 |
PyBuffer_Release(&data); |
| 1349 |
} |
| 1350 |
|
| 1351 |
return return_value; |
| 1352 |
} |
| 1353 |
|
| 1354 |
PyDoc_STRVAR(_codecs_charmap_decode__doc__, |
| 1355 |
"charmap_decode($module, data, errors=None, mapping=None, /)\n" |
| 1356 |
"--\n" |
| 1357 |
"\n"); |
| 1358 |
|
| 1359 |
#define _CODECS_CHARMAP_DECODE_METHODDEF \ |
| 1360 |
{"charmap_decode", _PyCFunction_CAST(_codecs_charmap_decode), METH_FASTCALL, _codecs_charmap_decode__doc__}, |
| 1361 |
|
| 1362 |
static PyObject * |
| 1363 |
_codecs_charmap_decode_impl(PyObject *module, Py_buffer *data, |
| 1364 |
const char *errors, PyObject *mapping); |
| 1365 |
|
| 1366 |
static PyObject * |
| 1367 |
_codecs_charmap_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1368 |
{ |
| 1369 |
PyObject *return_value = NULL; |
| 1370 |
Py_buffer data = {NULL, NULL}; |
| 1371 |
const char *errors = NULL; |
| 1372 |
PyObject *mapping = Py_None; |
| 1373 |
|
| 1374 |
if (!_PyArg_CheckPositional("charmap_decode", nargs, 1, 3)) { |
| 1375 |
goto exit; |
| 1376 |
} |
| 1377 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 1378 |
goto exit; |
| 1379 |
} |
| 1380 |
if (nargs < 2) { |
| 1381 |
goto skip_optional; |
| 1382 |
} |
| 1383 |
if (args[1] == Py_None) { |
| 1384 |
errors = NULL; |
| 1385 |
} |
| 1386 |
else if (PyUnicode_Check(args[1])) { |
| 1387 |
Py_ssize_t errors_length; |
| 1388 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 1389 |
if (errors == NULL) { |
| 1390 |
goto exit; |
| 1391 |
} |
| 1392 |
if (strlen(errors) != (size_t)errors_length) { |
| 1393 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 1394 |
goto exit; |
| 1395 |
} |
| 1396 |
} |
| 1397 |
else { |
| 1398 |
_PyArg_BadArgument("charmap_decode", "argument 2", "str or None", args[1]); |
| 1399 |
goto exit; |
| 1400 |
} |
| 1401 |
if (nargs < 3) { |
| 1402 |
goto skip_optional; |
| 1403 |
} |
| 1404 |
mapping = args[2]; |
| 1405 |
skip_optional: |
| 1406 |
return_value = _codecs_charmap_decode_impl(module, &data, errors, mapping); |
| 1407 |
|
| 1408 |
exit: |
| 1409 |
/* Cleanup for data */ |
| 1410 |
if (data.obj) { |
| 1411 |
PyBuffer_Release(&data); |
| 1412 |
} |
| 1413 |
|
| 1414 |
return return_value; |
| 1415 |
} |
| 1416 |
|
| 1417 |
#if defined(MS_WINDOWS) |
| 1418 |
|
| 1419 |
PyDoc_STRVAR(_codecs_mbcs_decode__doc__, |
| 1420 |
"mbcs_decode($module, data, errors=None, final=False, /)\n" |
| 1421 |
"--\n" |
| 1422 |
"\n"); |
| 1423 |
|
| 1424 |
#define _CODECS_MBCS_DECODE_METHODDEF \ |
| 1425 |
{"mbcs_decode", _PyCFunction_CAST(_codecs_mbcs_decode), METH_FASTCALL, _codecs_mbcs_decode__doc__}, |
| 1426 |
|
| 1427 |
static PyObject * |
| 1428 |
_codecs_mbcs_decode_impl(PyObject *module, Py_buffer *data, |
| 1429 |
const char *errors, int final); |
| 1430 |
|
| 1431 |
static PyObject * |
| 1432 |
_codecs_mbcs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1433 |
{ |
| 1434 |
PyObject *return_value = NULL; |
| 1435 |
Py_buffer data = {NULL, NULL}; |
| 1436 |
const char *errors = NULL; |
| 1437 |
int final = 0; |
| 1438 |
|
| 1439 |
if (!_PyArg_CheckPositional("mbcs_decode", nargs, 1, 3)) { |
| 1440 |
goto exit; |
| 1441 |
} |
| 1442 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 1443 |
goto exit; |
| 1444 |
} |
| 1445 |
if (nargs < 2) { |
| 1446 |
goto skip_optional; |
| 1447 |
} |
| 1448 |
if (args[1] == Py_None) { |
| 1449 |
errors = NULL; |
| 1450 |
} |
| 1451 |
else if (PyUnicode_Check(args[1])) { |
| 1452 |
Py_ssize_t errors_length; |
| 1453 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 1454 |
if (errors == NULL) { |
| 1455 |
goto exit; |
| 1456 |
} |
| 1457 |
if (strlen(errors) != (size_t)errors_length) { |
| 1458 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 1459 |
goto exit; |
| 1460 |
} |
| 1461 |
} |
| 1462 |
else { |
| 1463 |
_PyArg_BadArgument("mbcs_decode", "argument 2", "str or None", args[1]); |
| 1464 |
goto exit; |
| 1465 |
} |
| 1466 |
if (nargs < 3) { |
| 1467 |
goto skip_optional; |
| 1468 |
} |
| 1469 |
final = PyObject_IsTrue(args[2]); |
| 1470 |
if (final < 0) { |
| 1471 |
goto exit; |
| 1472 |
} |
| 1473 |
skip_optional: |
| 1474 |
return_value = _codecs_mbcs_decode_impl(module, &data, errors, final); |
| 1475 |
|
| 1476 |
exit: |
| 1477 |
/* Cleanup for data */ |
| 1478 |
if (data.obj) { |
| 1479 |
PyBuffer_Release(&data); |
| 1480 |
} |
| 1481 |
|
| 1482 |
return return_value; |
| 1483 |
} |
| 1484 |
|
| 1485 |
#endif /* defined(MS_WINDOWS) */ |
| 1486 |
|
| 1487 |
#if defined(MS_WINDOWS) |
| 1488 |
|
| 1489 |
PyDoc_STRVAR(_codecs_oem_decode__doc__, |
| 1490 |
"oem_decode($module, data, errors=None, final=False, /)\n" |
| 1491 |
"--\n" |
| 1492 |
"\n"); |
| 1493 |
|
| 1494 |
#define _CODECS_OEM_DECODE_METHODDEF \ |
| 1495 |
{"oem_decode", _PyCFunction_CAST(_codecs_oem_decode), METH_FASTCALL, _codecs_oem_decode__doc__}, |
| 1496 |
|
| 1497 |
static PyObject * |
| 1498 |
_codecs_oem_decode_impl(PyObject *module, Py_buffer *data, |
| 1499 |
const char *errors, int final); |
| 1500 |
|
| 1501 |
static PyObject * |
| 1502 |
_codecs_oem_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1503 |
{ |
| 1504 |
PyObject *return_value = NULL; |
| 1505 |
Py_buffer data = {NULL, NULL}; |
| 1506 |
const char *errors = NULL; |
| 1507 |
int final = 0; |
| 1508 |
|
| 1509 |
if (!_PyArg_CheckPositional("oem_decode", nargs, 1, 3)) { |
| 1510 |
goto exit; |
| 1511 |
} |
| 1512 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 1513 |
goto exit; |
| 1514 |
} |
| 1515 |
if (nargs < 2) { |
| 1516 |
goto skip_optional; |
| 1517 |
} |
| 1518 |
if (args[1] == Py_None) { |
| 1519 |
errors = NULL; |
| 1520 |
} |
| 1521 |
else if (PyUnicode_Check(args[1])) { |
| 1522 |
Py_ssize_t errors_length; |
| 1523 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 1524 |
if (errors == NULL) { |
| 1525 |
goto exit; |
| 1526 |
} |
| 1527 |
if (strlen(errors) != (size_t)errors_length) { |
| 1528 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 1529 |
goto exit; |
| 1530 |
} |
| 1531 |
} |
| 1532 |
else { |
| 1533 |
_PyArg_BadArgument("oem_decode", "argument 2", "str or None", args[1]); |
| 1534 |
goto exit; |
| 1535 |
} |
| 1536 |
if (nargs < 3) { |
| 1537 |
goto skip_optional; |
| 1538 |
} |
| 1539 |
final = PyObject_IsTrue(args[2]); |
| 1540 |
if (final < 0) { |
| 1541 |
goto exit; |
| 1542 |
} |
| 1543 |
skip_optional: |
| 1544 |
return_value = _codecs_oem_decode_impl(module, &data, errors, final); |
| 1545 |
|
| 1546 |
exit: |
| 1547 |
/* Cleanup for data */ |
| 1548 |
if (data.obj) { |
| 1549 |
PyBuffer_Release(&data); |
| 1550 |
} |
| 1551 |
|
| 1552 |
return return_value; |
| 1553 |
} |
| 1554 |
|
| 1555 |
#endif /* defined(MS_WINDOWS) */ |
| 1556 |
|
| 1557 |
#if defined(MS_WINDOWS) |
| 1558 |
|
| 1559 |
PyDoc_STRVAR(_codecs_code_page_decode__doc__, |
| 1560 |
"code_page_decode($module, codepage, data, errors=None, final=False, /)\n" |
| 1561 |
"--\n" |
| 1562 |
"\n"); |
| 1563 |
|
| 1564 |
#define _CODECS_CODE_PAGE_DECODE_METHODDEF \ |
| 1565 |
{"code_page_decode", _PyCFunction_CAST(_codecs_code_page_decode), METH_FASTCALL, _codecs_code_page_decode__doc__}, |
| 1566 |
|
| 1567 |
static PyObject * |
| 1568 |
_codecs_code_page_decode_impl(PyObject *module, int codepage, |
| 1569 |
Py_buffer *data, const char *errors, int final); |
| 1570 |
|
| 1571 |
static PyObject * |
| 1572 |
_codecs_code_page_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1573 |
{ |
| 1574 |
PyObject *return_value = NULL; |
| 1575 |
int codepage; |
| 1576 |
Py_buffer data = {NULL, NULL}; |
| 1577 |
const char *errors = NULL; |
| 1578 |
int final = 0; |
| 1579 |
|
| 1580 |
if (!_PyArg_CheckPositional("code_page_decode", nargs, 2, 4)) { |
| 1581 |
goto exit; |
| 1582 |
} |
| 1583 |
codepage = PyLong_AsInt(args[0]); |
| 1584 |
if (codepage == -1 && PyErr_Occurred()) { |
| 1585 |
goto exit; |
| 1586 |
} |
| 1587 |
if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) { |
| 1588 |
goto exit; |
| 1589 |
} |
| 1590 |
if (nargs < 3) { |
| 1591 |
goto skip_optional; |
| 1592 |
} |
| 1593 |
if (args[2] == Py_None) { |
| 1594 |
errors = NULL; |
| 1595 |
} |
| 1596 |
else if (PyUnicode_Check(args[2])) { |
| 1597 |
Py_ssize_t errors_length; |
| 1598 |
errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length); |
| 1599 |
if (errors == NULL) { |
| 1600 |
goto exit; |
| 1601 |
} |
| 1602 |
if (strlen(errors) != (size_t)errors_length) { |
| 1603 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 1604 |
goto exit; |
| 1605 |
} |
| 1606 |
} |
| 1607 |
else { |
| 1608 |
_PyArg_BadArgument("code_page_decode", "argument 3", "str or None", args[2]); |
| 1609 |
goto exit; |
| 1610 |
} |
| 1611 |
if (nargs < 4) { |
| 1612 |
goto skip_optional; |
| 1613 |
} |
| 1614 |
final = PyObject_IsTrue(args[3]); |
| 1615 |
if (final < 0) { |
| 1616 |
goto exit; |
| 1617 |
} |
| 1618 |
skip_optional: |
| 1619 |
return_value = _codecs_code_page_decode_impl(module, codepage, &data, errors, final); |
| 1620 |
|
| 1621 |
exit: |
| 1622 |
/* Cleanup for data */ |
| 1623 |
if (data.obj) { |
| 1624 |
PyBuffer_Release(&data); |
| 1625 |
} |
| 1626 |
|
| 1627 |
return return_value; |
| 1628 |
} |
| 1629 |
|
| 1630 |
#endif /* defined(MS_WINDOWS) */ |
| 1631 |
|
| 1632 |
PyDoc_STRVAR(_codecs_readbuffer_encode__doc__, |
| 1633 |
"readbuffer_encode($module, data, errors=None, /)\n" |
| 1634 |
"--\n" |
| 1635 |
"\n"); |
| 1636 |
|
| 1637 |
#define _CODECS_READBUFFER_ENCODE_METHODDEF \ |
| 1638 |
{"readbuffer_encode", _PyCFunction_CAST(_codecs_readbuffer_encode), METH_FASTCALL, _codecs_readbuffer_encode__doc__}, |
| 1639 |
|
| 1640 |
static PyObject * |
| 1641 |
_codecs_readbuffer_encode_impl(PyObject *module, Py_buffer *data, |
| 1642 |
const char *errors); |
| 1643 |
|
| 1644 |
static PyObject * |
| 1645 |
_codecs_readbuffer_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1646 |
{ |
| 1647 |
PyObject *return_value = NULL; |
| 1648 |
Py_buffer data = {NULL, NULL}; |
| 1649 |
const char *errors = NULL; |
| 1650 |
|
| 1651 |
if (!_PyArg_CheckPositional("readbuffer_encode", nargs, 1, 2)) { |
| 1652 |
goto exit; |
| 1653 |
} |
| 1654 |
if (PyUnicode_Check(args[0])) { |
| 1655 |
Py_ssize_t len; |
| 1656 |
const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len); |
| 1657 |
if (ptr == NULL) { |
| 1658 |
goto exit; |
| 1659 |
} |
| 1660 |
if (PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, PyBUF_SIMPLE) < 0) { |
| 1661 |
goto exit; |
| 1662 |
} |
| 1663 |
} |
| 1664 |
else { /* any bytes-like object */ |
| 1665 |
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
| 1666 |
goto exit; |
| 1667 |
} |
| 1668 |
} |
| 1669 |
if (nargs < 2) { |
| 1670 |
goto skip_optional; |
| 1671 |
} |
| 1672 |
if (args[1] == Py_None) { |
| 1673 |
errors = NULL; |
| 1674 |
} |
| 1675 |
else if (PyUnicode_Check(args[1])) { |
| 1676 |
Py_ssize_t errors_length; |
| 1677 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 1678 |
if (errors == NULL) { |
| 1679 |
goto exit; |
| 1680 |
} |
| 1681 |
if (strlen(errors) != (size_t)errors_length) { |
| 1682 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 1683 |
goto exit; |
| 1684 |
} |
| 1685 |
} |
| 1686 |
else { |
| 1687 |
_PyArg_BadArgument("readbuffer_encode", "argument 2", "str or None", args[1]); |
| 1688 |
goto exit; |
| 1689 |
} |
| 1690 |
skip_optional: |
| 1691 |
return_value = _codecs_readbuffer_encode_impl(module, &data, errors); |
| 1692 |
|
| 1693 |
exit: |
| 1694 |
/* Cleanup for data */ |
| 1695 |
if (data.obj) { |
| 1696 |
PyBuffer_Release(&data); |
| 1697 |
} |
| 1698 |
|
| 1699 |
return return_value; |
| 1700 |
} |
| 1701 |
|
| 1702 |
PyDoc_STRVAR(_codecs_utf_7_encode__doc__, |
| 1703 |
"utf_7_encode($module, str, errors=None, /)\n" |
| 1704 |
"--\n" |
| 1705 |
"\n"); |
| 1706 |
|
| 1707 |
#define _CODECS_UTF_7_ENCODE_METHODDEF \ |
| 1708 |
{"utf_7_encode", _PyCFunction_CAST(_codecs_utf_7_encode), METH_FASTCALL, _codecs_utf_7_encode__doc__}, |
| 1709 |
|
| 1710 |
static PyObject * |
| 1711 |
_codecs_utf_7_encode_impl(PyObject *module, PyObject *str, |
| 1712 |
const char *errors); |
| 1713 |
|
| 1714 |
static PyObject * |
| 1715 |
_codecs_utf_7_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1716 |
{ |
| 1717 |
PyObject *return_value = NULL; |
| 1718 |
PyObject *str; |
| 1719 |
const char *errors = NULL; |
| 1720 |
|
| 1721 |
if (!_PyArg_CheckPositional("utf_7_encode", nargs, 1, 2)) { |
| 1722 |
goto exit; |
| 1723 |
} |
| 1724 |
if (!PyUnicode_Check(args[0])) { |
| 1725 |
_PyArg_BadArgument("utf_7_encode", "argument 1", "str", args[0]); |
| 1726 |
goto exit; |
| 1727 |
} |
| 1728 |
str = args[0]; |
| 1729 |
if (nargs < 2) { |
| 1730 |
goto skip_optional; |
| 1731 |
} |
| 1732 |
if (args[1] == Py_None) { |
| 1733 |
errors = NULL; |
| 1734 |
} |
| 1735 |
else if (PyUnicode_Check(args[1])) { |
| 1736 |
Py_ssize_t errors_length; |
| 1737 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 1738 |
if (errors == NULL) { |
| 1739 |
goto exit; |
| 1740 |
} |
| 1741 |
if (strlen(errors) != (size_t)errors_length) { |
| 1742 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 1743 |
goto exit; |
| 1744 |
} |
| 1745 |
} |
| 1746 |
else { |
| 1747 |
_PyArg_BadArgument("utf_7_encode", "argument 2", "str or None", args[1]); |
| 1748 |
goto exit; |
| 1749 |
} |
| 1750 |
skip_optional: |
| 1751 |
return_value = _codecs_utf_7_encode_impl(module, str, errors); |
| 1752 |
|
| 1753 |
exit: |
| 1754 |
return return_value; |
| 1755 |
} |
| 1756 |
|
| 1757 |
PyDoc_STRVAR(_codecs_utf_8_encode__doc__, |
| 1758 |
"utf_8_encode($module, str, errors=None, /)\n" |
| 1759 |
"--\n" |
| 1760 |
"\n"); |
| 1761 |
|
| 1762 |
#define _CODECS_UTF_8_ENCODE_METHODDEF \ |
| 1763 |
{"utf_8_encode", _PyCFunction_CAST(_codecs_utf_8_encode), METH_FASTCALL, _codecs_utf_8_encode__doc__}, |
| 1764 |
|
| 1765 |
static PyObject * |
| 1766 |
_codecs_utf_8_encode_impl(PyObject *module, PyObject *str, |
| 1767 |
const char *errors); |
| 1768 |
|
| 1769 |
static PyObject * |
| 1770 |
_codecs_utf_8_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1771 |
{ |
| 1772 |
PyObject *return_value = NULL; |
| 1773 |
PyObject *str; |
| 1774 |
const char *errors = NULL; |
| 1775 |
|
| 1776 |
if (!_PyArg_CheckPositional("utf_8_encode", nargs, 1, 2)) { |
| 1777 |
goto exit; |
| 1778 |
} |
| 1779 |
if (!PyUnicode_Check(args[0])) { |
| 1780 |
_PyArg_BadArgument("utf_8_encode", "argument 1", "str", args[0]); |
| 1781 |
goto exit; |
| 1782 |
} |
| 1783 |
str = args[0]; |
| 1784 |
if (nargs < 2) { |
| 1785 |
goto skip_optional; |
| 1786 |
} |
| 1787 |
if (args[1] == Py_None) { |
| 1788 |
errors = NULL; |
| 1789 |
} |
| 1790 |
else if (PyUnicode_Check(args[1])) { |
| 1791 |
Py_ssize_t errors_length; |
| 1792 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 1793 |
if (errors == NULL) { |
| 1794 |
goto exit; |
| 1795 |
} |
| 1796 |
if (strlen(errors) != (size_t)errors_length) { |
| 1797 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 1798 |
goto exit; |
| 1799 |
} |
| 1800 |
} |
| 1801 |
else { |
| 1802 |
_PyArg_BadArgument("utf_8_encode", "argument 2", "str or None", args[1]); |
| 1803 |
goto exit; |
| 1804 |
} |
| 1805 |
skip_optional: |
| 1806 |
return_value = _codecs_utf_8_encode_impl(module, str, errors); |
| 1807 |
|
| 1808 |
exit: |
| 1809 |
return return_value; |
| 1810 |
} |
| 1811 |
|
| 1812 |
PyDoc_STRVAR(_codecs_utf_16_encode__doc__, |
| 1813 |
"utf_16_encode($module, str, errors=None, byteorder=0, /)\n" |
| 1814 |
"--\n" |
| 1815 |
"\n"); |
| 1816 |
|
| 1817 |
#define _CODECS_UTF_16_ENCODE_METHODDEF \ |
| 1818 |
{"utf_16_encode", _PyCFunction_CAST(_codecs_utf_16_encode), METH_FASTCALL, _codecs_utf_16_encode__doc__}, |
| 1819 |
|
| 1820 |
static PyObject * |
| 1821 |
_codecs_utf_16_encode_impl(PyObject *module, PyObject *str, |
| 1822 |
const char *errors, int byteorder); |
| 1823 |
|
| 1824 |
static PyObject * |
| 1825 |
_codecs_utf_16_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1826 |
{ |
| 1827 |
PyObject *return_value = NULL; |
| 1828 |
PyObject *str; |
| 1829 |
const char *errors = NULL; |
| 1830 |
int byteorder = 0; |
| 1831 |
|
| 1832 |
if (!_PyArg_CheckPositional("utf_16_encode", nargs, 1, 3)) { |
| 1833 |
goto exit; |
| 1834 |
} |
| 1835 |
if (!PyUnicode_Check(args[0])) { |
| 1836 |
_PyArg_BadArgument("utf_16_encode", "argument 1", "str", args[0]); |
| 1837 |
goto exit; |
| 1838 |
} |
| 1839 |
str = args[0]; |
| 1840 |
if (nargs < 2) { |
| 1841 |
goto skip_optional; |
| 1842 |
} |
| 1843 |
if (args[1] == Py_None) { |
| 1844 |
errors = NULL; |
| 1845 |
} |
| 1846 |
else if (PyUnicode_Check(args[1])) { |
| 1847 |
Py_ssize_t errors_length; |
| 1848 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 1849 |
if (errors == NULL) { |
| 1850 |
goto exit; |
| 1851 |
} |
| 1852 |
if (strlen(errors) != (size_t)errors_length) { |
| 1853 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 1854 |
goto exit; |
| 1855 |
} |
| 1856 |
} |
| 1857 |
else { |
| 1858 |
_PyArg_BadArgument("utf_16_encode", "argument 2", "str or None", args[1]); |
| 1859 |
goto exit; |
| 1860 |
} |
| 1861 |
if (nargs < 3) { |
| 1862 |
goto skip_optional; |
| 1863 |
} |
| 1864 |
byteorder = PyLong_AsInt(args[2]); |
| 1865 |
if (byteorder == -1 && PyErr_Occurred()) { |
| 1866 |
goto exit; |
| 1867 |
} |
| 1868 |
skip_optional: |
| 1869 |
return_value = _codecs_utf_16_encode_impl(module, str, errors, byteorder); |
| 1870 |
|
| 1871 |
exit: |
| 1872 |
return return_value; |
| 1873 |
} |
| 1874 |
|
| 1875 |
PyDoc_STRVAR(_codecs_utf_16_le_encode__doc__, |
| 1876 |
"utf_16_le_encode($module, str, errors=None, /)\n" |
| 1877 |
"--\n" |
| 1878 |
"\n"); |
| 1879 |
|
| 1880 |
#define _CODECS_UTF_16_LE_ENCODE_METHODDEF \ |
| 1881 |
{"utf_16_le_encode", _PyCFunction_CAST(_codecs_utf_16_le_encode), METH_FASTCALL, _codecs_utf_16_le_encode__doc__}, |
| 1882 |
|
| 1883 |
static PyObject * |
| 1884 |
_codecs_utf_16_le_encode_impl(PyObject *module, PyObject *str, |
| 1885 |
const char *errors); |
| 1886 |
|
| 1887 |
static PyObject * |
| 1888 |
_codecs_utf_16_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1889 |
{ |
| 1890 |
PyObject *return_value = NULL; |
| 1891 |
PyObject *str; |
| 1892 |
const char *errors = NULL; |
| 1893 |
|
| 1894 |
if (!_PyArg_CheckPositional("utf_16_le_encode", nargs, 1, 2)) { |
| 1895 |
goto exit; |
| 1896 |
} |
| 1897 |
if (!PyUnicode_Check(args[0])) { |
| 1898 |
_PyArg_BadArgument("utf_16_le_encode", "argument 1", "str", args[0]); |
| 1899 |
goto exit; |
| 1900 |
} |
| 1901 |
str = args[0]; |
| 1902 |
if (nargs < 2) { |
| 1903 |
goto skip_optional; |
| 1904 |
} |
| 1905 |
if (args[1] == Py_None) { |
| 1906 |
errors = NULL; |
| 1907 |
} |
| 1908 |
else if (PyUnicode_Check(args[1])) { |
| 1909 |
Py_ssize_t errors_length; |
| 1910 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 1911 |
if (errors == NULL) { |
| 1912 |
goto exit; |
| 1913 |
} |
| 1914 |
if (strlen(errors) != (size_t)errors_length) { |
| 1915 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 1916 |
goto exit; |
| 1917 |
} |
| 1918 |
} |
| 1919 |
else { |
| 1920 |
_PyArg_BadArgument("utf_16_le_encode", "argument 2", "str or None", args[1]); |
| 1921 |
goto exit; |
| 1922 |
} |
| 1923 |
skip_optional: |
| 1924 |
return_value = _codecs_utf_16_le_encode_impl(module, str, errors); |
| 1925 |
|
| 1926 |
exit: |
| 1927 |
return return_value; |
| 1928 |
} |
| 1929 |
|
| 1930 |
PyDoc_STRVAR(_codecs_utf_16_be_encode__doc__, |
| 1931 |
"utf_16_be_encode($module, str, errors=None, /)\n" |
| 1932 |
"--\n" |
| 1933 |
"\n"); |
| 1934 |
|
| 1935 |
#define _CODECS_UTF_16_BE_ENCODE_METHODDEF \ |
| 1936 |
{"utf_16_be_encode", _PyCFunction_CAST(_codecs_utf_16_be_encode), METH_FASTCALL, _codecs_utf_16_be_encode__doc__}, |
| 1937 |
|
| 1938 |
static PyObject * |
| 1939 |
_codecs_utf_16_be_encode_impl(PyObject *module, PyObject *str, |
| 1940 |
const char *errors); |
| 1941 |
|
| 1942 |
static PyObject * |
| 1943 |
_codecs_utf_16_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1944 |
{ |
| 1945 |
PyObject *return_value = NULL; |
| 1946 |
PyObject *str; |
| 1947 |
const char *errors = NULL; |
| 1948 |
|
| 1949 |
if (!_PyArg_CheckPositional("utf_16_be_encode", nargs, 1, 2)) { |
| 1950 |
goto exit; |
| 1951 |
} |
| 1952 |
if (!PyUnicode_Check(args[0])) { |
| 1953 |
_PyArg_BadArgument("utf_16_be_encode", "argument 1", "str", args[0]); |
| 1954 |
goto exit; |
| 1955 |
} |
| 1956 |
str = args[0]; |
| 1957 |
if (nargs < 2) { |
| 1958 |
goto skip_optional; |
| 1959 |
} |
| 1960 |
if (args[1] == Py_None) { |
| 1961 |
errors = NULL; |
| 1962 |
} |
| 1963 |
else if (PyUnicode_Check(args[1])) { |
| 1964 |
Py_ssize_t errors_length; |
| 1965 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 1966 |
if (errors == NULL) { |
| 1967 |
goto exit; |
| 1968 |
} |
| 1969 |
if (strlen(errors) != (size_t)errors_length) { |
| 1970 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 1971 |
goto exit; |
| 1972 |
} |
| 1973 |
} |
| 1974 |
else { |
| 1975 |
_PyArg_BadArgument("utf_16_be_encode", "argument 2", "str or None", args[1]); |
| 1976 |
goto exit; |
| 1977 |
} |
| 1978 |
skip_optional: |
| 1979 |
return_value = _codecs_utf_16_be_encode_impl(module, str, errors); |
| 1980 |
|
| 1981 |
exit: |
| 1982 |
return return_value; |
| 1983 |
} |
| 1984 |
|
| 1985 |
PyDoc_STRVAR(_codecs_utf_32_encode__doc__, |
| 1986 |
"utf_32_encode($module, str, errors=None, byteorder=0, /)\n" |
| 1987 |
"--\n" |
| 1988 |
"\n"); |
| 1989 |
|
| 1990 |
#define _CODECS_UTF_32_ENCODE_METHODDEF \ |
| 1991 |
{"utf_32_encode", _PyCFunction_CAST(_codecs_utf_32_encode), METH_FASTCALL, _codecs_utf_32_encode__doc__}, |
| 1992 |
|
| 1993 |
static PyObject * |
| 1994 |
_codecs_utf_32_encode_impl(PyObject *module, PyObject *str, |
| 1995 |
const char *errors, int byteorder); |
| 1996 |
|
| 1997 |
static PyObject * |
| 1998 |
_codecs_utf_32_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1999 |
{ |
| 2000 |
PyObject *return_value = NULL; |
| 2001 |
PyObject *str; |
| 2002 |
const char *errors = NULL; |
| 2003 |
int byteorder = 0; |
| 2004 |
|
| 2005 |
if (!_PyArg_CheckPositional("utf_32_encode", nargs, 1, 3)) { |
| 2006 |
goto exit; |
| 2007 |
} |
| 2008 |
if (!PyUnicode_Check(args[0])) { |
| 2009 |
_PyArg_BadArgument("utf_32_encode", "argument 1", "str", args[0]); |
| 2010 |
goto exit; |
| 2011 |
} |
| 2012 |
str = args[0]; |
| 2013 |
if (nargs < 2) { |
| 2014 |
goto skip_optional; |
| 2015 |
} |
| 2016 |
if (args[1] == Py_None) { |
| 2017 |
errors = NULL; |
| 2018 |
} |
| 2019 |
else if (PyUnicode_Check(args[1])) { |
| 2020 |
Py_ssize_t errors_length; |
| 2021 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 2022 |
if (errors == NULL) { |
| 2023 |
goto exit; |
| 2024 |
} |
| 2025 |
if (strlen(errors) != (size_t)errors_length) { |
| 2026 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 2027 |
goto exit; |
| 2028 |
} |
| 2029 |
} |
| 2030 |
else { |
| 2031 |
_PyArg_BadArgument("utf_32_encode", "argument 2", "str or None", args[1]); |
| 2032 |
goto exit; |
| 2033 |
} |
| 2034 |
if (nargs < 3) { |
| 2035 |
goto skip_optional; |
| 2036 |
} |
| 2037 |
byteorder = PyLong_AsInt(args[2]); |
| 2038 |
if (byteorder == -1 && PyErr_Occurred()) { |
| 2039 |
goto exit; |
| 2040 |
} |
| 2041 |
skip_optional: |
| 2042 |
return_value = _codecs_utf_32_encode_impl(module, str, errors, byteorder); |
| 2043 |
|
| 2044 |
exit: |
| 2045 |
return return_value; |
| 2046 |
} |
| 2047 |
|
| 2048 |
PyDoc_STRVAR(_codecs_utf_32_le_encode__doc__, |
| 2049 |
"utf_32_le_encode($module, str, errors=None, /)\n" |
| 2050 |
"--\n" |
| 2051 |
"\n"); |
| 2052 |
|
| 2053 |
#define _CODECS_UTF_32_LE_ENCODE_METHODDEF \ |
| 2054 |
{"utf_32_le_encode", _PyCFunction_CAST(_codecs_utf_32_le_encode), METH_FASTCALL, _codecs_utf_32_le_encode__doc__}, |
| 2055 |
|
| 2056 |
static PyObject * |
| 2057 |
_codecs_utf_32_le_encode_impl(PyObject *module, PyObject *str, |
| 2058 |
const char *errors); |
| 2059 |
|
| 2060 |
static PyObject * |
| 2061 |
_codecs_utf_32_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 2062 |
{ |
| 2063 |
PyObject *return_value = NULL; |
| 2064 |
PyObject *str; |
| 2065 |
const char *errors = NULL; |
| 2066 |
|
| 2067 |
if (!_PyArg_CheckPositional("utf_32_le_encode", nargs, 1, 2)) { |
| 2068 |
goto exit; |
| 2069 |
} |
| 2070 |
if (!PyUnicode_Check(args[0])) { |
| 2071 |
_PyArg_BadArgument("utf_32_le_encode", "argument 1", "str", args[0]); |
| 2072 |
goto exit; |
| 2073 |
} |
| 2074 |
str = args[0]; |
| 2075 |
if (nargs < 2) { |
| 2076 |
goto skip_optional; |
| 2077 |
} |
| 2078 |
if (args[1] == Py_None) { |
| 2079 |
errors = NULL; |
| 2080 |
} |
| 2081 |
else if (PyUnicode_Check(args[1])) { |
| 2082 |
Py_ssize_t errors_length; |
| 2083 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 2084 |
if (errors == NULL) { |
| 2085 |
goto exit; |
| 2086 |
} |
| 2087 |
if (strlen(errors) != (size_t)errors_length) { |
| 2088 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 2089 |
goto exit; |
| 2090 |
} |
| 2091 |
} |
| 2092 |
else { |
| 2093 |
_PyArg_BadArgument("utf_32_le_encode", "argument 2", "str or None", args[1]); |
| 2094 |
goto exit; |
| 2095 |
} |
| 2096 |
skip_optional: |
| 2097 |
return_value = _codecs_utf_32_le_encode_impl(module, str, errors); |
| 2098 |
|
| 2099 |
exit: |
| 2100 |
return return_value; |
| 2101 |
} |
| 2102 |
|
| 2103 |
PyDoc_STRVAR(_codecs_utf_32_be_encode__doc__, |
| 2104 |
"utf_32_be_encode($module, str, errors=None, /)\n" |
| 2105 |
"--\n" |
| 2106 |
"\n"); |
| 2107 |
|
| 2108 |
#define _CODECS_UTF_32_BE_ENCODE_METHODDEF \ |
| 2109 |
{"utf_32_be_encode", _PyCFunction_CAST(_codecs_utf_32_be_encode), METH_FASTCALL, _codecs_utf_32_be_encode__doc__}, |
| 2110 |
|
| 2111 |
static PyObject * |
| 2112 |
_codecs_utf_32_be_encode_impl(PyObject *module, PyObject *str, |
| 2113 |
const char *errors); |
| 2114 |
|
| 2115 |
static PyObject * |
| 2116 |
_codecs_utf_32_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 2117 |
{ |
| 2118 |
PyObject *return_value = NULL; |
| 2119 |
PyObject *str; |
| 2120 |
const char *errors = NULL; |
| 2121 |
|
| 2122 |
if (!_PyArg_CheckPositional("utf_32_be_encode", nargs, 1, 2)) { |
| 2123 |
goto exit; |
| 2124 |
} |
| 2125 |
if (!PyUnicode_Check(args[0])) { |
| 2126 |
_PyArg_BadArgument("utf_32_be_encode", "argument 1", "str", args[0]); |
| 2127 |
goto exit; |
| 2128 |
} |
| 2129 |
str = args[0]; |
| 2130 |
if (nargs < 2) { |
| 2131 |
goto skip_optional; |
| 2132 |
} |
| 2133 |
if (args[1] == Py_None) { |
| 2134 |
errors = NULL; |
| 2135 |
} |
| 2136 |
else if (PyUnicode_Check(args[1])) { |
| 2137 |
Py_ssize_t errors_length; |
| 2138 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 2139 |
if (errors == NULL) { |
| 2140 |
goto exit; |
| 2141 |
} |
| 2142 |
if (strlen(errors) != (size_t)errors_length) { |
| 2143 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 2144 |
goto exit; |
| 2145 |
} |
| 2146 |
} |
| 2147 |
else { |
| 2148 |
_PyArg_BadArgument("utf_32_be_encode", "argument 2", "str or None", args[1]); |
| 2149 |
goto exit; |
| 2150 |
} |
| 2151 |
skip_optional: |
| 2152 |
return_value = _codecs_utf_32_be_encode_impl(module, str, errors); |
| 2153 |
|
| 2154 |
exit: |
| 2155 |
return return_value; |
| 2156 |
} |
| 2157 |
|
| 2158 |
PyDoc_STRVAR(_codecs_unicode_escape_encode__doc__, |
| 2159 |
"unicode_escape_encode($module, str, errors=None, /)\n" |
| 2160 |
"--\n" |
| 2161 |
"\n"); |
| 2162 |
|
| 2163 |
#define _CODECS_UNICODE_ESCAPE_ENCODE_METHODDEF \ |
| 2164 |
{"unicode_escape_encode", _PyCFunction_CAST(_codecs_unicode_escape_encode), METH_FASTCALL, _codecs_unicode_escape_encode__doc__}, |
| 2165 |
|
| 2166 |
static PyObject * |
| 2167 |
_codecs_unicode_escape_encode_impl(PyObject *module, PyObject *str, |
| 2168 |
const char *errors); |
| 2169 |
|
| 2170 |
static PyObject * |
| 2171 |
_codecs_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 2172 |
{ |
| 2173 |
PyObject *return_value = NULL; |
| 2174 |
PyObject *str; |
| 2175 |
const char *errors = NULL; |
| 2176 |
|
| 2177 |
if (!_PyArg_CheckPositional("unicode_escape_encode", nargs, 1, 2)) { |
| 2178 |
goto exit; |
| 2179 |
} |
| 2180 |
if (!PyUnicode_Check(args[0])) { |
| 2181 |
_PyArg_BadArgument("unicode_escape_encode", "argument 1", "str", args[0]); |
| 2182 |
goto exit; |
| 2183 |
} |
| 2184 |
str = args[0]; |
| 2185 |
if (nargs < 2) { |
| 2186 |
goto skip_optional; |
| 2187 |
} |
| 2188 |
if (args[1] == Py_None) { |
| 2189 |
errors = NULL; |
| 2190 |
} |
| 2191 |
else if (PyUnicode_Check(args[1])) { |
| 2192 |
Py_ssize_t errors_length; |
| 2193 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 2194 |
if (errors == NULL) { |
| 2195 |
goto exit; |
| 2196 |
} |
| 2197 |
if (strlen(errors) != (size_t)errors_length) { |
| 2198 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 2199 |
goto exit; |
| 2200 |
} |
| 2201 |
} |
| 2202 |
else { |
| 2203 |
_PyArg_BadArgument("unicode_escape_encode", "argument 2", "str or None", args[1]); |
| 2204 |
goto exit; |
| 2205 |
} |
| 2206 |
skip_optional: |
| 2207 |
return_value = _codecs_unicode_escape_encode_impl(module, str, errors); |
| 2208 |
|
| 2209 |
exit: |
| 2210 |
return return_value; |
| 2211 |
} |
| 2212 |
|
| 2213 |
PyDoc_STRVAR(_codecs_raw_unicode_escape_encode__doc__, |
| 2214 |
"raw_unicode_escape_encode($module, str, errors=None, /)\n" |
| 2215 |
"--\n" |
| 2216 |
"\n"); |
| 2217 |
|
| 2218 |
#define _CODECS_RAW_UNICODE_ESCAPE_ENCODE_METHODDEF \ |
| 2219 |
{"raw_unicode_escape_encode", _PyCFunction_CAST(_codecs_raw_unicode_escape_encode), METH_FASTCALL, _codecs_raw_unicode_escape_encode__doc__}, |
| 2220 |
|
| 2221 |
static PyObject * |
| 2222 |
_codecs_raw_unicode_escape_encode_impl(PyObject *module, PyObject *str, |
| 2223 |
const char *errors); |
| 2224 |
|
| 2225 |
static PyObject * |
| 2226 |
_codecs_raw_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 2227 |
{ |
| 2228 |
PyObject *return_value = NULL; |
| 2229 |
PyObject *str; |
| 2230 |
const char *errors = NULL; |
| 2231 |
|
| 2232 |
if (!_PyArg_CheckPositional("raw_unicode_escape_encode", nargs, 1, 2)) { |
| 2233 |
goto exit; |
| 2234 |
} |
| 2235 |
if (!PyUnicode_Check(args[0])) { |
| 2236 |
_PyArg_BadArgument("raw_unicode_escape_encode", "argument 1", "str", args[0]); |
| 2237 |
goto exit; |
| 2238 |
} |
| 2239 |
str = args[0]; |
| 2240 |
if (nargs < 2) { |
| 2241 |
goto skip_optional; |
| 2242 |
} |
| 2243 |
if (args[1] == Py_None) { |
| 2244 |
errors = NULL; |
| 2245 |
} |
| 2246 |
else if (PyUnicode_Check(args[1])) { |
| 2247 |
Py_ssize_t errors_length; |
| 2248 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 2249 |
if (errors == NULL) { |
| 2250 |
goto exit; |
| 2251 |
} |
| 2252 |
if (strlen(errors) != (size_t)errors_length) { |
| 2253 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 2254 |
goto exit; |
| 2255 |
} |
| 2256 |
} |
| 2257 |
else { |
| 2258 |
_PyArg_BadArgument("raw_unicode_escape_encode", "argument 2", "str or None", args[1]); |
| 2259 |
goto exit; |
| 2260 |
} |
| 2261 |
skip_optional: |
| 2262 |
return_value = _codecs_raw_unicode_escape_encode_impl(module, str, errors); |
| 2263 |
|
| 2264 |
exit: |
| 2265 |
return return_value; |
| 2266 |
} |
| 2267 |
|
| 2268 |
PyDoc_STRVAR(_codecs_latin_1_encode__doc__, |
| 2269 |
"latin_1_encode($module, str, errors=None, /)\n" |
| 2270 |
"--\n" |
| 2271 |
"\n"); |
| 2272 |
|
| 2273 |
#define _CODECS_LATIN_1_ENCODE_METHODDEF \ |
| 2274 |
{"latin_1_encode", _PyCFunction_CAST(_codecs_latin_1_encode), METH_FASTCALL, _codecs_latin_1_encode__doc__}, |
| 2275 |
|
| 2276 |
static PyObject * |
| 2277 |
_codecs_latin_1_encode_impl(PyObject *module, PyObject *str, |
| 2278 |
const char *errors); |
| 2279 |
|
| 2280 |
static PyObject * |
| 2281 |
_codecs_latin_1_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 2282 |
{ |
| 2283 |
PyObject *return_value = NULL; |
| 2284 |
PyObject *str; |
| 2285 |
const char *errors = NULL; |
| 2286 |
|
| 2287 |
if (!_PyArg_CheckPositional("latin_1_encode", nargs, 1, 2)) { |
| 2288 |
goto exit; |
| 2289 |
} |
| 2290 |
if (!PyUnicode_Check(args[0])) { |
| 2291 |
_PyArg_BadArgument("latin_1_encode", "argument 1", "str", args[0]); |
| 2292 |
goto exit; |
| 2293 |
} |
| 2294 |
str = args[0]; |
| 2295 |
if (nargs < 2) { |
| 2296 |
goto skip_optional; |
| 2297 |
} |
| 2298 |
if (args[1] == Py_None) { |
| 2299 |
errors = NULL; |
| 2300 |
} |
| 2301 |
else if (PyUnicode_Check(args[1])) { |
| 2302 |
Py_ssize_t errors_length; |
| 2303 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 2304 |
if (errors == NULL) { |
| 2305 |
goto exit; |
| 2306 |
} |
| 2307 |
if (strlen(errors) != (size_t)errors_length) { |
| 2308 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 2309 |
goto exit; |
| 2310 |
} |
| 2311 |
} |
| 2312 |
else { |
| 2313 |
_PyArg_BadArgument("latin_1_encode", "argument 2", "str or None", args[1]); |
| 2314 |
goto exit; |
| 2315 |
} |
| 2316 |
skip_optional: |
| 2317 |
return_value = _codecs_latin_1_encode_impl(module, str, errors); |
| 2318 |
|
| 2319 |
exit: |
| 2320 |
return return_value; |
| 2321 |
} |
| 2322 |
|
| 2323 |
PyDoc_STRVAR(_codecs_ascii_encode__doc__, |
| 2324 |
"ascii_encode($module, str, errors=None, /)\n" |
| 2325 |
"--\n" |
| 2326 |
"\n"); |
| 2327 |
|
| 2328 |
#define _CODECS_ASCII_ENCODE_METHODDEF \ |
| 2329 |
{"ascii_encode", _PyCFunction_CAST(_codecs_ascii_encode), METH_FASTCALL, _codecs_ascii_encode__doc__}, |
| 2330 |
|
| 2331 |
static PyObject * |
| 2332 |
_codecs_ascii_encode_impl(PyObject *module, PyObject *str, |
| 2333 |
const char *errors); |
| 2334 |
|
| 2335 |
static PyObject * |
| 2336 |
_codecs_ascii_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 2337 |
{ |
| 2338 |
PyObject *return_value = NULL; |
| 2339 |
PyObject *str; |
| 2340 |
const char *errors = NULL; |
| 2341 |
|
| 2342 |
if (!_PyArg_CheckPositional("ascii_encode", nargs, 1, 2)) { |
| 2343 |
goto exit; |
| 2344 |
} |
| 2345 |
if (!PyUnicode_Check(args[0])) { |
| 2346 |
_PyArg_BadArgument("ascii_encode", "argument 1", "str", args[0]); |
| 2347 |
goto exit; |
| 2348 |
} |
| 2349 |
str = args[0]; |
| 2350 |
if (nargs < 2) { |
| 2351 |
goto skip_optional; |
| 2352 |
} |
| 2353 |
if (args[1] == Py_None) { |
| 2354 |
errors = NULL; |
| 2355 |
} |
| 2356 |
else if (PyUnicode_Check(args[1])) { |
| 2357 |
Py_ssize_t errors_length; |
| 2358 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 2359 |
if (errors == NULL) { |
| 2360 |
goto exit; |
| 2361 |
} |
| 2362 |
if (strlen(errors) != (size_t)errors_length) { |
| 2363 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 2364 |
goto exit; |
| 2365 |
} |
| 2366 |
} |
| 2367 |
else { |
| 2368 |
_PyArg_BadArgument("ascii_encode", "argument 2", "str or None", args[1]); |
| 2369 |
goto exit; |
| 2370 |
} |
| 2371 |
skip_optional: |
| 2372 |
return_value = _codecs_ascii_encode_impl(module, str, errors); |
| 2373 |
|
| 2374 |
exit: |
| 2375 |
return return_value; |
| 2376 |
} |
| 2377 |
|
| 2378 |
PyDoc_STRVAR(_codecs_charmap_encode__doc__, |
| 2379 |
"charmap_encode($module, str, errors=None, mapping=None, /)\n" |
| 2380 |
"--\n" |
| 2381 |
"\n"); |
| 2382 |
|
| 2383 |
#define _CODECS_CHARMAP_ENCODE_METHODDEF \ |
| 2384 |
{"charmap_encode", _PyCFunction_CAST(_codecs_charmap_encode), METH_FASTCALL, _codecs_charmap_encode__doc__}, |
| 2385 |
|
| 2386 |
static PyObject * |
| 2387 |
_codecs_charmap_encode_impl(PyObject *module, PyObject *str, |
| 2388 |
const char *errors, PyObject *mapping); |
| 2389 |
|
| 2390 |
static PyObject * |
| 2391 |
_codecs_charmap_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 2392 |
{ |
| 2393 |
PyObject *return_value = NULL; |
| 2394 |
PyObject *str; |
| 2395 |
const char *errors = NULL; |
| 2396 |
PyObject *mapping = Py_None; |
| 2397 |
|
| 2398 |
if (!_PyArg_CheckPositional("charmap_encode", nargs, 1, 3)) { |
| 2399 |
goto exit; |
| 2400 |
} |
| 2401 |
if (!PyUnicode_Check(args[0])) { |
| 2402 |
_PyArg_BadArgument("charmap_encode", "argument 1", "str", args[0]); |
| 2403 |
goto exit; |
| 2404 |
} |
| 2405 |
str = args[0]; |
| 2406 |
if (nargs < 2) { |
| 2407 |
goto skip_optional; |
| 2408 |
} |
| 2409 |
if (args[1] == Py_None) { |
| 2410 |
errors = NULL; |
| 2411 |
} |
| 2412 |
else if (PyUnicode_Check(args[1])) { |
| 2413 |
Py_ssize_t errors_length; |
| 2414 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 2415 |
if (errors == NULL) { |
| 2416 |
goto exit; |
| 2417 |
} |
| 2418 |
if (strlen(errors) != (size_t)errors_length) { |
| 2419 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 2420 |
goto exit; |
| 2421 |
} |
| 2422 |
} |
| 2423 |
else { |
| 2424 |
_PyArg_BadArgument("charmap_encode", "argument 2", "str or None", args[1]); |
| 2425 |
goto exit; |
| 2426 |
} |
| 2427 |
if (nargs < 3) { |
| 2428 |
goto skip_optional; |
| 2429 |
} |
| 2430 |
mapping = args[2]; |
| 2431 |
skip_optional: |
| 2432 |
return_value = _codecs_charmap_encode_impl(module, str, errors, mapping); |
| 2433 |
|
| 2434 |
exit: |
| 2435 |
return return_value; |
| 2436 |
} |
| 2437 |
|
| 2438 |
PyDoc_STRVAR(_codecs_charmap_build__doc__, |
| 2439 |
"charmap_build($module, map, /)\n" |
| 2440 |
"--\n" |
| 2441 |
"\n"); |
| 2442 |
|
| 2443 |
#define _CODECS_CHARMAP_BUILD_METHODDEF \ |
| 2444 |
{"charmap_build", (PyCFunction)_codecs_charmap_build, METH_O, _codecs_charmap_build__doc__}, |
| 2445 |
|
| 2446 |
static PyObject * |
| 2447 |
_codecs_charmap_build_impl(PyObject *module, PyObject *map); |
| 2448 |
|
| 2449 |
static PyObject * |
| 2450 |
_codecs_charmap_build(PyObject *module, PyObject *arg) |
| 2451 |
{ |
| 2452 |
PyObject *return_value = NULL; |
| 2453 |
PyObject *map; |
| 2454 |
|
| 2455 |
if (!PyUnicode_Check(arg)) { |
| 2456 |
_PyArg_BadArgument("charmap_build", "argument", "str", arg); |
| 2457 |
goto exit; |
| 2458 |
} |
| 2459 |
map = arg; |
| 2460 |
return_value = _codecs_charmap_build_impl(module, map); |
| 2461 |
|
| 2462 |
exit: |
| 2463 |
return return_value; |
| 2464 |
} |
| 2465 |
|
| 2466 |
#if defined(MS_WINDOWS) |
| 2467 |
|
| 2468 |
PyDoc_STRVAR(_codecs_mbcs_encode__doc__, |
| 2469 |
"mbcs_encode($module, str, errors=None, /)\n" |
| 2470 |
"--\n" |
| 2471 |
"\n"); |
| 2472 |
|
| 2473 |
#define _CODECS_MBCS_ENCODE_METHODDEF \ |
| 2474 |
{"mbcs_encode", _PyCFunction_CAST(_codecs_mbcs_encode), METH_FASTCALL, _codecs_mbcs_encode__doc__}, |
| 2475 |
|
| 2476 |
static PyObject * |
| 2477 |
_codecs_mbcs_encode_impl(PyObject *module, PyObject *str, const char *errors); |
| 2478 |
|
| 2479 |
static PyObject * |
| 2480 |
_codecs_mbcs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 2481 |
{ |
| 2482 |
PyObject *return_value = NULL; |
| 2483 |
PyObject *str; |
| 2484 |
const char *errors = NULL; |
| 2485 |
|
| 2486 |
if (!_PyArg_CheckPositional("mbcs_encode", nargs, 1, 2)) { |
| 2487 |
goto exit; |
| 2488 |
} |
| 2489 |
if (!PyUnicode_Check(args[0])) { |
| 2490 |
_PyArg_BadArgument("mbcs_encode", "argument 1", "str", args[0]); |
| 2491 |
goto exit; |
| 2492 |
} |
| 2493 |
str = args[0]; |
| 2494 |
if (nargs < 2) { |
| 2495 |
goto skip_optional; |
| 2496 |
} |
| 2497 |
if (args[1] == Py_None) { |
| 2498 |
errors = NULL; |
| 2499 |
} |
| 2500 |
else if (PyUnicode_Check(args[1])) { |
| 2501 |
Py_ssize_t errors_length; |
| 2502 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 2503 |
if (errors == NULL) { |
| 2504 |
goto exit; |
| 2505 |
} |
| 2506 |
if (strlen(errors) != (size_t)errors_length) { |
| 2507 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 2508 |
goto exit; |
| 2509 |
} |
| 2510 |
} |
| 2511 |
else { |
| 2512 |
_PyArg_BadArgument("mbcs_encode", "argument 2", "str or None", args[1]); |
| 2513 |
goto exit; |
| 2514 |
} |
| 2515 |
skip_optional: |
| 2516 |
return_value = _codecs_mbcs_encode_impl(module, str, errors); |
| 2517 |
|
| 2518 |
exit: |
| 2519 |
return return_value; |
| 2520 |
} |
| 2521 |
|
| 2522 |
#endif /* defined(MS_WINDOWS) */ |
| 2523 |
|
| 2524 |
#if defined(MS_WINDOWS) |
| 2525 |
|
| 2526 |
PyDoc_STRVAR(_codecs_oem_encode__doc__, |
| 2527 |
"oem_encode($module, str, errors=None, /)\n" |
| 2528 |
"--\n" |
| 2529 |
"\n"); |
| 2530 |
|
| 2531 |
#define _CODECS_OEM_ENCODE_METHODDEF \ |
| 2532 |
{"oem_encode", _PyCFunction_CAST(_codecs_oem_encode), METH_FASTCALL, _codecs_oem_encode__doc__}, |
| 2533 |
|
| 2534 |
static PyObject * |
| 2535 |
_codecs_oem_encode_impl(PyObject *module, PyObject *str, const char *errors); |
| 2536 |
|
| 2537 |
static PyObject * |
| 2538 |
_codecs_oem_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 2539 |
{ |
| 2540 |
PyObject *return_value = NULL; |
| 2541 |
PyObject *str; |
| 2542 |
const char *errors = NULL; |
| 2543 |
|
| 2544 |
if (!_PyArg_CheckPositional("oem_encode", nargs, 1, 2)) { |
| 2545 |
goto exit; |
| 2546 |
} |
| 2547 |
if (!PyUnicode_Check(args[0])) { |
| 2548 |
_PyArg_BadArgument("oem_encode", "argument 1", "str", args[0]); |
| 2549 |
goto exit; |
| 2550 |
} |
| 2551 |
str = args[0]; |
| 2552 |
if (nargs < 2) { |
| 2553 |
goto skip_optional; |
| 2554 |
} |
| 2555 |
if (args[1] == Py_None) { |
| 2556 |
errors = NULL; |
| 2557 |
} |
| 2558 |
else if (PyUnicode_Check(args[1])) { |
| 2559 |
Py_ssize_t errors_length; |
| 2560 |
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 2561 |
if (errors == NULL) { |
| 2562 |
goto exit; |
| 2563 |
} |
| 2564 |
if (strlen(errors) != (size_t)errors_length) { |
| 2565 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 2566 |
goto exit; |
| 2567 |
} |
| 2568 |
} |
| 2569 |
else { |
| 2570 |
_PyArg_BadArgument("oem_encode", "argument 2", "str or None", args[1]); |
| 2571 |
goto exit; |
| 2572 |
} |
| 2573 |
skip_optional: |
| 2574 |
return_value = _codecs_oem_encode_impl(module, str, errors); |
| 2575 |
|
| 2576 |
exit: |
| 2577 |
return return_value; |
| 2578 |
} |
| 2579 |
|
| 2580 |
#endif /* defined(MS_WINDOWS) */ |
| 2581 |
|
| 2582 |
#if defined(MS_WINDOWS) |
| 2583 |
|
| 2584 |
PyDoc_STRVAR(_codecs_code_page_encode__doc__, |
| 2585 |
"code_page_encode($module, code_page, str, errors=None, /)\n" |
| 2586 |
"--\n" |
| 2587 |
"\n"); |
| 2588 |
|
| 2589 |
#define _CODECS_CODE_PAGE_ENCODE_METHODDEF \ |
| 2590 |
{"code_page_encode", _PyCFunction_CAST(_codecs_code_page_encode), METH_FASTCALL, _codecs_code_page_encode__doc__}, |
| 2591 |
|
| 2592 |
static PyObject * |
| 2593 |
_codecs_code_page_encode_impl(PyObject *module, int code_page, PyObject *str, |
| 2594 |
const char *errors); |
| 2595 |
|
| 2596 |
static PyObject * |
| 2597 |
_codecs_code_page_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 2598 |
{ |
| 2599 |
PyObject *return_value = NULL; |
| 2600 |
int code_page; |
| 2601 |
PyObject *str; |
| 2602 |
const char *errors = NULL; |
| 2603 |
|
| 2604 |
if (!_PyArg_CheckPositional("code_page_encode", nargs, 2, 3)) { |
| 2605 |
goto exit; |
| 2606 |
} |
| 2607 |
code_page = PyLong_AsInt(args[0]); |
| 2608 |
if (code_page == -1 && PyErr_Occurred()) { |
| 2609 |
goto exit; |
| 2610 |
} |
| 2611 |
if (!PyUnicode_Check(args[1])) { |
| 2612 |
_PyArg_BadArgument("code_page_encode", "argument 2", "str", args[1]); |
| 2613 |
goto exit; |
| 2614 |
} |
| 2615 |
str = args[1]; |
| 2616 |
if (nargs < 3) { |
| 2617 |
goto skip_optional; |
| 2618 |
} |
| 2619 |
if (args[2] == Py_None) { |
| 2620 |
errors = NULL; |
| 2621 |
} |
| 2622 |
else if (PyUnicode_Check(args[2])) { |
| 2623 |
Py_ssize_t errors_length; |
| 2624 |
errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length); |
| 2625 |
if (errors == NULL) { |
| 2626 |
goto exit; |
| 2627 |
} |
| 2628 |
if (strlen(errors) != (size_t)errors_length) { |
| 2629 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 2630 |
goto exit; |
| 2631 |
} |
| 2632 |
} |
| 2633 |
else { |
| 2634 |
_PyArg_BadArgument("code_page_encode", "argument 3", "str or None", args[2]); |
| 2635 |
goto exit; |
| 2636 |
} |
| 2637 |
skip_optional: |
| 2638 |
return_value = _codecs_code_page_encode_impl(module, code_page, str, errors); |
| 2639 |
|
| 2640 |
exit: |
| 2641 |
return return_value; |
| 2642 |
} |
| 2643 |
|
| 2644 |
#endif /* defined(MS_WINDOWS) */ |
| 2645 |
|
| 2646 |
PyDoc_STRVAR(_codecs_register_error__doc__, |
| 2647 |
"register_error($module, errors, handler, /)\n" |
| 2648 |
"--\n" |
| 2649 |
"\n" |
| 2650 |
"Register the specified error handler under the name errors.\n" |
| 2651 |
"\n" |
| 2652 |
"handler must be a callable object, that will be called with an exception\n" |
| 2653 |
"instance containing information about the location of the\n" |
| 2654 |
"encoding/decoding error and must return a (replacement, new position)\n" |
| 2655 |
"tuple."); |
| 2656 |
|
| 2657 |
#define _CODECS_REGISTER_ERROR_METHODDEF \ |
| 2658 |
{"register_error", _PyCFunction_CAST(_codecs_register_error), METH_FASTCALL, _codecs_register_error__doc__}, |
| 2659 |
|
| 2660 |
static PyObject * |
| 2661 |
_codecs_register_error_impl(PyObject *module, const char *errors, |
| 2662 |
PyObject *handler); |
| 2663 |
|
| 2664 |
static PyObject * |
| 2665 |
_codecs_register_error(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 2666 |
{ |
| 2667 |
PyObject *return_value = NULL; |
| 2668 |
const char *errors; |
| 2669 |
PyObject *handler; |
| 2670 |
|
| 2671 |
if (!_PyArg_CheckPositional("register_error", nargs, 2, 2)) { |
| 2672 |
goto exit; |
| 2673 |
} |
| 2674 |
if (!PyUnicode_Check(args[0])) { |
| 2675 |
_PyArg_BadArgument("register_error", "argument 1", "str", args[0]); |
| 2676 |
goto exit; |
| 2677 |
} |
| 2678 |
Py_ssize_t errors_length; |
| 2679 |
errors = PyUnicode_AsUTF8AndSize(args[0], &errors_length); |
| 2680 |
if (errors == NULL) { |
| 2681 |
goto exit; |
| 2682 |
} |
| 2683 |
if (strlen(errors) != (size_t)errors_length) { |
| 2684 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 2685 |
goto exit; |
| 2686 |
} |
| 2687 |
handler = args[1]; |
| 2688 |
return_value = _codecs_register_error_impl(module, errors, handler); |
| 2689 |
|
| 2690 |
exit: |
| 2691 |
return return_value; |
| 2692 |
} |
| 2693 |
|
| 2694 |
PyDoc_STRVAR(_codecs__unregister_error__doc__, |
| 2695 |
"_unregister_error($module, errors, /)\n" |
| 2696 |
"--\n" |
| 2697 |
"\n" |
| 2698 |
"Un-register the specified error handler for the error handling `errors\'.\n" |
| 2699 |
"\n" |
| 2700 |
"Only custom error handlers can be un-registered. An exception is raised\n" |
| 2701 |
"if the error handling is a built-in one (e.g., \'strict\'), or if an error\n" |
| 2702 |
"occurs.\n" |
| 2703 |
"\n" |
| 2704 |
"Otherwise, this returns True if a custom handler has been successfully\n" |
| 2705 |
"un-registered, and False if no custom handler for the specified error\n" |
| 2706 |
"handling exists."); |
| 2707 |
|
| 2708 |
#define _CODECS__UNREGISTER_ERROR_METHODDEF \ |
| 2709 |
{"_unregister_error", (PyCFunction)_codecs__unregister_error, METH_O, _codecs__unregister_error__doc__}, |
| 2710 |
|
| 2711 |
static int |
| 2712 |
_codecs__unregister_error_impl(PyObject *module, const char *errors); |
| 2713 |
|
| 2714 |
static PyObject * |
| 2715 |
_codecs__unregister_error(PyObject *module, PyObject *arg) |
| 2716 |
{ |
| 2717 |
PyObject *return_value = NULL; |
| 2718 |
const char *errors; |
| 2719 |
int _return_value; |
| 2720 |
|
| 2721 |
if (!PyUnicode_Check(arg)) { |
| 2722 |
_PyArg_BadArgument("_unregister_error", "argument", "str", arg); |
| 2723 |
goto exit; |
| 2724 |
} |
| 2725 |
Py_ssize_t errors_length; |
| 2726 |
errors = PyUnicode_AsUTF8AndSize(arg, &errors_length); |
| 2727 |
if (errors == NULL) { |
| 2728 |
goto exit; |
| 2729 |
} |
| 2730 |
if (strlen(errors) != (size_t)errors_length) { |
| 2731 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 2732 |
goto exit; |
| 2733 |
} |
| 2734 |
_return_value = _codecs__unregister_error_impl(module, errors); |
| 2735 |
if ((_return_value == -1) && PyErr_Occurred()) { |
| 2736 |
goto exit; |
| 2737 |
} |
| 2738 |
return_value = PyBool_FromLong((long)_return_value); |
| 2739 |
|
| 2740 |
exit: |
| 2741 |
return return_value; |
| 2742 |
} |
| 2743 |
|
| 2744 |
PyDoc_STRVAR(_codecs_lookup_error__doc__, |
| 2745 |
"lookup_error($module, name, /)\n" |
| 2746 |
"--\n" |
| 2747 |
"\n" |
| 2748 |
"lookup_error(errors) -> handler\n" |
| 2749 |
"\n" |
| 2750 |
"Return the error handler for the specified error handling name or raise\n" |
| 2751 |
"a LookupError, if no handler exists under this name."); |
| 2752 |
|
| 2753 |
#define _CODECS_LOOKUP_ERROR_METHODDEF \ |
| 2754 |
{"lookup_error", (PyCFunction)_codecs_lookup_error, METH_O, _codecs_lookup_error__doc__}, |
| 2755 |
|
| 2756 |
static PyObject * |
| 2757 |
_codecs_lookup_error_impl(PyObject *module, const char *name); |
| 2758 |
|
| 2759 |
static PyObject * |
| 2760 |
_codecs_lookup_error(PyObject *module, PyObject *arg) |
| 2761 |
{ |
| 2762 |
PyObject *return_value = NULL; |
| 2763 |
const char *name; |
| 2764 |
|
| 2765 |
if (!PyUnicode_Check(arg)) { |
| 2766 |
_PyArg_BadArgument("lookup_error", "argument", "str", arg); |
| 2767 |
goto exit; |
| 2768 |
} |
| 2769 |
Py_ssize_t name_length; |
| 2770 |
name = PyUnicode_AsUTF8AndSize(arg, &name_length); |
| 2771 |
if (name == NULL) { |
| 2772 |
goto exit; |
| 2773 |
} |
| 2774 |
if (strlen(name) != (size_t)name_length) { |
| 2775 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 2776 |
goto exit; |
| 2777 |
} |
| 2778 |
return_value = _codecs_lookup_error_impl(module, name); |
| 2779 |
|
| 2780 |
exit: |
| 2781 |
return return_value; |
| 2782 |
} |
| 2783 |
|
| 2784 |
#ifndef _CODECS_MBCS_DECODE_METHODDEF |
| 2785 |
#define _CODECS_MBCS_DECODE_METHODDEF |
| 2786 |
#endif /* !defined(_CODECS_MBCS_DECODE_METHODDEF) */ |
| 2787 |
|
| 2788 |
#ifndef _CODECS_OEM_DECODE_METHODDEF |
| 2789 |
#define _CODECS_OEM_DECODE_METHODDEF |
| 2790 |
#endif /* !defined(_CODECS_OEM_DECODE_METHODDEF) */ |
| 2791 |
|
| 2792 |
#ifndef _CODECS_CODE_PAGE_DECODE_METHODDEF |
| 2793 |
#define _CODECS_CODE_PAGE_DECODE_METHODDEF |
| 2794 |
#endif /* !defined(_CODECS_CODE_PAGE_DECODE_METHODDEF) */ |
| 2795 |
|
| 2796 |
#ifndef _CODECS_MBCS_ENCODE_METHODDEF |
| 2797 |
#define _CODECS_MBCS_ENCODE_METHODDEF |
| 2798 |
#endif /* !defined(_CODECS_MBCS_ENCODE_METHODDEF) */ |
| 2799 |
|
| 2800 |
#ifndef _CODECS_OEM_ENCODE_METHODDEF |
| 2801 |
#define _CODECS_OEM_ENCODE_METHODDEF |
| 2802 |
#endif /* !defined(_CODECS_OEM_ENCODE_METHODDEF) */ |
| 2803 |
|
| 2804 |
#ifndef _CODECS_CODE_PAGE_ENCODE_METHODDEF |
| 2805 |
#define _CODECS_CODE_PAGE_ENCODE_METHODDEF |
| 2806 |
#endif /* !defined(_CODECS_CODE_PAGE_ENCODE_METHODDEF) */ |
| 2807 |
/*[clinic end generated code: output=eb221ef27f132476 input=a9049054013a1b77]*/ |