[issue19997] imghdr.what doesn't accept bytes paths

Claudiu.Popa report at bugs.python.org
Mon Dec 16 13:48:13 CET 2013


New submission from Claudiu.Popa:

imghdr.what check explicitly for string path, while `open` happily accepts bytes paths, as seen below:

>>> x
b'\xc2\xba'
>>> imghdr.what(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tank/libs/cpython/Lib/imghdr.py", line 15, in what
    location = file.tell()
AttributeError: 'bytes' object has no attribute 'tell'
>>> open(x)
<_io.TextIOWrapper name=b'\xc2\xba' mode='r' encoding='UTF-8'>

A reason why this should be supported can be found in this message: http://bugs.python.org/msg191691.
The following patch fixes this. Also, it depends on issue19990 (where test_imghdr.py was added).

----------
components: Library (Lib)
files: imghdr_bytes.patch
keywords: patch
messages: 206299
nosy: Claudiu.Popa
priority: normal
severity: normal
status: open
title: imghdr.what doesn't accept bytes paths
type: behavior
versions: Python 3.5
Added file: http://bugs.python.org/file33164/imghdr_bytes.patch

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


More information about the Python-bugs-list mailing list