(
errors, encoding, reason, input, startinpos, endinpos, decode=True
)
| 1365 | |
| 1366 | |
| 1367 | def unicode_call_errorhandler( |
| 1368 | errors, encoding, reason, input, startinpos, endinpos, decode=True |
| 1369 | ): |
| 1370 | errorHandler = lookup_error(errors) |
| 1371 | if decode: |
| 1372 | exceptionObject = UnicodeDecodeError( |
| 1373 | encoding, input, startinpos, endinpos, reason |
| 1374 | ) |
| 1375 | else: |
| 1376 | exceptionObject = UnicodeEncodeError( |
| 1377 | encoding, input, startinpos, endinpos, reason |
| 1378 | ) |
| 1379 | res = errorHandler(exceptionObject) |
| 1380 | if ( |
| 1381 | isinstance(res, tuple) |
| 1382 | and isinstance(res[0], (str, bytes)) |
| 1383 | and isinstance(res[1], int) |
| 1384 | ): |
| 1385 | newpos = res[1] |
| 1386 | if newpos < 0: |
| 1387 | newpos = len(input) + newpos |
| 1388 | if newpos < 0 or newpos > len(input): |
| 1389 | raise IndexError("position %d from error handler out of bounds" % newpos) |
| 1390 | return res[0], newpos |
| 1391 | else: |
| 1392 | raise TypeError( |
| 1393 | "encoding error handler must return (unicode, int) tuple, not %s" |
| 1394 | % repr(res) |
| 1395 | ) |
| 1396 | |
| 1397 | |
| 1398 | # /* --- Latin-1 Codec ------------------------------------------------------ */ |
no test coverage detected