SF.net SVN: docutils:[9915] trunk/docutils/docutils/writers/html4css1/ __init__.py

milde--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9915
          http://sourceforge.net/p/docutils/code/9915
Author:   milde
Date:     2024-08-21 13:45:18 +0000 (Wed, 21 Aug 2024)
Log Message:
-----------
HTML4 writer: catch/report errors when reading image file.

The html writers read image files when
embedding an image or scaling an image without size options.

Catch errors from converting the image URI to a file system path.
Report errors as warning.

Modified Paths:
--------------
    trunk/docutils/docutils/writers/html4css1/__init__.py

Modified: trunk/docutils/docutils/writers/html4css1/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/html4css1/__init__.py	2024-08-21 13:45:08 UTC (rev 9914)
+++ trunk/docutils/docutils/writers/html4css1/__init__.py	2024-08-21 13:45:18 UTC (rev 9915)
@@ -571,12 +571,13 @@
         if 'scale' in node:
             if (PIL and ('width' not in node or 'height' not in node)
                 and self.settings.file_insertion_enabled):
-                imagepath = self.uri2imagepath(uri)
                 try:
+                    imagepath = self.uri2imagepath(uri)
                     with PIL.Image.open(imagepath) as img:
                         img_size = img.size
-                except (OSError, UnicodeEncodeError):
-                    pass  # TODO: warn/info?
+                except (ValueError, OSError, UnicodeEncodeError) as e:
+                    self.document.reporter.warning(
+                        f'Problem reading image file: {e}')
                 else:
                     self.settings.record_dependencies.add(
                         imagepath.replace('\\', '/'))

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.