Skip to content

Replace imghdr with filetype and add unit tests for image_to_html#26

Open
mamico wants to merge 4 commits intomainfrom
deprecated_imghdr
Open

Replace imghdr with filetype and add unit tests for image_to_html#26
mamico wants to merge 4 commits intomainfrom
deprecated_imghdr

Conversation

@mamico
Copy link
Copy Markdown
Member

@mamico mamico commented Apr 13, 2026

Motivation

imghdr is stato rimosso dalla standard library a partire da Python 3.13 (deprecato in 3.11 eliminato in 3.13). La sostituzione con filetype garantisce compatibilità con le versioni recenti di Python senza dipendere da moduli deprecati.

Changes

  • browser/export_view.py: sostituito imghdr.what() con filetype.guess(). Usato img.format (rilevato da PIL dopo Image.open()) per il salvataggio, e kind.mime per il data URL nell' tag. Questo corregge anche un bug silente: il vecchio
    codice produceva data:jpeg;base64,... invece del MIME type corretto data:image/jpeg;base64,....
  • setup.py: aggiunto filetype a install_requires; aggiunto classifier Python :: 3.12 e 3.13
  • tests/test_pdf_csv_export.py: aggiunta classe TestImageToHtml con 5 unit test per image_to_html (input vuoto, SVG, bytes non riconoscibili, PNG valido, JPEG valido). I test non richiedono il layer Plone.

@mamico mamico requested a review from cekk April 13, 2026 12:35
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.

1 participant