Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
2fb885cc
Commit
2fb885cc
authored
Oct 01, 2016
by
Berker Peksag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #28228: imghdr now supports pathlib
parent
1ffee9a0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
1 deletion
+15
-1
Doc/library/imghdr.rst
Doc/library/imghdr.rst
+3
-0
Lib/imghdr.py
Lib/imghdr.py
+3
-1
Lib/test/test_imghdr.py
Lib/test/test_imghdr.py
+7
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/imghdr.rst
View file @
2fb885cc
...
...
@@ -20,6 +20,9 @@ The :mod:`imghdr` module defines the following function:
string describing the image type. If optional *h* is provided, the *filename*
is ignored and *h* is assumed to contain the byte stream to test.
.. versionchanged:: 3.6
Accepts a :term:`path-like object`.
The following image types are recognized, as listed below with the return value
from :func:`what`:
...
...
Lib/imghdr.py
View file @
2fb885cc
"""Recognize image file formats based on their first few bytes."""
from
os
import
PathLike
__all__
=
[
"what"
]
#-------------------------#
...
...
@@ -10,7 +12,7 @@ def what(file, h=None):
f
=
None
try
:
if
h
is
None
:
if
isinstance
(
file
,
str
):
if
isinstance
(
file
,
(
str
,
PathLike
)
):
f
=
open
(
file
,
'rb'
)
h
=
f
.
read
(
32
)
else
:
...
...
Lib/test/test_imghdr.py
View file @
2fb885cc
import
imghdr
import
io
import
os
import
pathlib
import
unittest
import
warnings
from
test.support
import
findfile
,
TESTFN
,
unlink
...
...
@@ -49,6 +50,12 @@ class TestImghdr(unittest.TestCase):
self
.
assertEqual
(
imghdr
.
what
(
None
,
data
),
expected
)
self
.
assertEqual
(
imghdr
.
what
(
None
,
bytearray
(
data
)),
expected
)
def
test_pathlike_filename
(
self
):
for
filename
,
expected
in
TEST_FILES
:
with
self
.
subTest
(
filename
=
filename
):
filename
=
findfile
(
filename
,
subdir
=
'imghdrdata'
)
self
.
assertEqual
(
imghdr
.
what
(
pathlib
.
Path
(
filename
)),
expected
)
def
test_register_test
(
self
):
def
test_jumbo
(
h
,
file
):
if
h
.
startswith
(
b'eggs'
):
...
...
Misc/NEWS
View file @
2fb885cc
...
...
@@ -46,6 +46,8 @@ Core and Builtins
Library
-------
- Issue #28228: imghdr now supports pathlib.
- Issue #28226: compileall now supports pathlib.
- Issue #28314: Fix function declaration (C flags) for the getiterator() method
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment