[issue4874] decoding functions in _codecs module accept str arguments

Marc-Andre Lemburg report at bugs.python.org
Thu Jan 8 10:29:21 CET 2009


Marc-Andre Lemburg <mal at egenix.com> added the comment:

On 2009-01-08 01:59, STINNER Victor wrote:
> STINNER Victor <victor.stinner at haypocalc.com> added the comment:
> 
> Patch replacing "s*" parsing format by "y*" for:
>  - utf_7_decode()
>  - utf_8_decode()
>  - utf_16_decode()
>  - utf_16_le_decode()
>  - utf_16_be_decode()
>  - utf_16_ex_decode()
>  - utf_32_decode()
>  - utf_32_le_decode()
>  - utf_32_be_decode()
>  - utf_32_ex_decode()
>  - latin_1_decode()
>  - ascii_decode()
>  - charmap_decode()
>  - mbcs_decode()

These are fine.

>  - unicode_escape_decode()
>  - raw_unicode_escape_decode()

These changes are in line with their C API codec interfaces as well,
but those particular codecs could well also be made to work on Unicode
input, since unescaping can well be applied to Unicode as well.

I'll probably open a new item for this.

> Using run_tests.sh, all tests are ok (with 19 skipped tests). I guess 
> that there is not tests for all these functions :-/

The mbcs codec is only available on Windows.

All others are tested by test_codecs.py.

Which ones are skipped in your case ?

> Note: codecs documentation was already correct:
> 
> .. method:: Codec.decode(input[, errors])
>    (...)
>    *input* must be a bytes object or one which provides the read-only 
> character
>    buffer interface -- for example, buffer objects and memory mapped 
> files.

That's not entirely correct: codecs are allowed to accept any
object type and can also return any object type. It up to them
to decide, e.g. a codec may accept both bytes and Unicode input
and always generate Unicode output when decoding.

I guess I have to review those doc changes...

----------
nosy: +lemburg

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4874>
_______________________________________


More information about the Python-bugs-list mailing list