Package: python-docutils / 0.12+dfsg-1

python3-pil-no-bytestrings.diff Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Description: Python 3: don't pass byte strings to PIL.Image.open()
 With Python 3.X, pass Unicode strings (rather than byte strings) to
 PIL.Image.open().
 .
 This is to work around a PIL bug: http://bugs.debian.org/708449
Author: Jakub Wilk <jwilk@debian.org>
Forwarded: no
Bug-Debian: http://bugs.debian.org/708159
Last-Update: 2013-08-03

--- a/docutils/parsers/rst/directives/images.py
+++ b/docutils/parsers/rst/directives/images.py
@@ -127,8 +127,11 @@
             if PIL and self.state.document.settings.file_insertion_enabled:
                 imagepath = urllib.url2pathname(image_node['uri'])
                 try:
-                    img = PIL.Image.open(
-                            imagepath.encode(sys.getfilesystemencoding()))
+                    if isinstance(imagepath, str):
+                        imagepath_str = imagepath
+                    else:
+                        imagepath_str = imagepath.encode(sys.getfilesystemencoding())
+                    img = PIL.Image.open(imagepath_str)
                 except (IOError, UnicodeEncodeError):
                     pass # TODO: warn?
                 else:
--- a/docutils/writers/html4css1/__init__.py
+++ b/docutils/writers/html4css1/__init__.py
@@ -1039,8 +1039,11 @@
                 and self.settings.file_insertion_enabled):
                 imagepath = urllib.url2pathname(uri)
                 try:
-                    img = PIL.Image.open(
-                            imagepath.encode(sys.getfilesystemencoding()))
+                    if isinstance(imagepath, str):
+                        imagepath_str = imagepath
+                    else:
+                        imagepath_str = imagepath.encode(sys.getfilesystemencoding())
+                    img = PIL.Image.open(imagepath_str)
                 except (IOError, UnicodeEncodeError):
                     pass # TODO: warn?
                 else: