Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop use of imghdr #443

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

drop use of imghdr #443

wants to merge 1 commit into from

Conversation

dkg
Copy link
Contributor

@dkg dkg commented Jun 14, 2023

imghdr is deprecated and will be removed in python 3.13 (see https://peps.python.org/pep-0594/#imghdr)

The relevant code in imghdr is just:

def test_jpeg(h, f):
    """JPEG data with JFIF or Exif markers; and raw JPEG"""
    if h[6:10] in (b'JFIF', b'Exif'):
        return 'jpeg'
    elif h[:4] == b'\xff\xd8\xff\xdb':
        return 'jpeg'

So we transplant it directly

imghdr is deprecated and will be removed in python 3.13 (see https://peps.python.org/pep-0594/#imghdr)

The relevant code in imghdr is just:

```
def test_jpeg(h, f):
    """JPEG data with JFIF or Exif markers; and raw JPEG"""
    if h[6:10] in (b'JFIF', b'Exif'):
        return 'jpeg'
    elif h[:4] == b'\xff\xd8\xff\xdb':
        return 'jpeg'
```

So we transplant it directly
@jbkkd
Copy link

jbkkd commented Sep 18, 2023

Any chance this could get merged in the near future?

@ktdreyer
Copy link

ktdreyer commented Oct 24, 2023

@Commod0re would you please merge this PR and ship a new release to PyPI?

I've confirmed that the implementation here matches test_jpeg() in /usr/lib64/python3.11/imghdr.py. Also, I tested this conditional on a random JPG image and imagebytes[6:10] is indeed b'JFIF'.

@etzelc
Copy link

etzelc commented Oct 15, 2024

Python 3.13 was released last week, and the imghdr module has been removed. https://www.python.org/downloads/release/python-3130/.

Are there any remaining blockers for this PR?

@sshishov
Copy link

We cannot move to Python3.13 because of this blocker.

But instead of copy-pasting the code, maybe we can try to use some alternatives proposed in PEP-0594?

These are the alternatives proposed there:

Hope that the issue will be resolved, either by "hardcoding" the old implementation or replacing with "supported" libraries.

@jenstroeger
Copy link

jenstroeger commented Feb 24, 2025

@dkg @sshishov I’ve been using python-magic for a while, and would recommend that:

>>> import magic
>>> 
>>> magic.from_buffer(imagebytes, mime=True)
'image/jpeg'

so the code in this PR could be changed to

if magic.from_buffer(imagebytes, mime=True) == 'image/jpeg':
    ...

Any chance to move this PR forward and support Python 3.13 soon?

Also, you may want to consider changing this line

PGPy/setup.cfg

Line 46 in 30a7571

python_requires = >=3.6
to exclude 3.14

python_requires = >=3.6,<3.14

to avoid future breakage.

@sshishov
Copy link

sshishov commented Feb 25, 2025

Hi @jenstroeger,

Unfortunately I am on the same boat as you. I am just the consumer/user of this repository and maintainer or contributor at least. Therefore we should find the person who has right access to this repo and ask him for this favor.

Best regards, Sergei

@sshishov
Copy link

@Commod0re , I can see that you have merged the latest MR to this repo. Could you please help us out here and move this repo to support latest Python please?

n-oden added a commit to memory/python-dpkg that referenced this pull request Feb 27, 2025
- drop support for python 3.8, which is EOLed
- add official support for python 3.13
- ...which sadly requires using a fork of PGPy; see discussion at:
    - SecurityInnovation/PGPy#462
    - SecurityInnovation/PGPy#443
- update zstandard library, addressing #21
- update other libraries:
    - cryptography
    - ruff
    - mypy
- remove use of [email protected] from the macos/darwin tooling in the Makefile
- include type hints (#20); thank you @tim25651!
memory added a commit to memory/python-dpkg that referenced this pull request Feb 27, 2025
- drop support for python 3.8, which is EOLed
- add official support for python 3.13
- ...which sadly requires using a fork of PGPy; see discussion at:
    - SecurityInnovation/PGPy#462
    - SecurityInnovation/PGPy#443
- update zstandard library, addressing #21
- update other libraries:
    - cryptography
    - ruff
    - mypy
- remove use of [email protected] from the macos/darwin tooling in the Makefile
- include type hints (#20); thank you @tim25651!

Co-authored-by: Nathan J. Mehl <[email protected]>
@memory
Copy link

memory commented Mar 2, 2025

@sshishov While we're waiting for this project to start moving forward again, I've made a (hopefully temporary) fork available on pypi that has this PR merged and also fixes the cryptography version requirement: https://pypi.org/project/PGPy13/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants