From 8eb0181f2bf933623f15a8b3c745c832b99ad7ef Mon Sep 17 00:00:00 2001 From: milde Date: Thu, 3 May 2012 10:55:30 +0000 Subject: [PATCH] odtwriter: import the PIL Image module via ``import PIL``. * Unify the PIL.Image import (images.py and the HTML writer changed already in Dec 2011, Pygments in May 2010). * starting with PIL 1.2, "PIL lives in the PIL namespace only" (http://mail.python.org/pipermail/image-sig/2011-January/006650.html) git-svn-id: https://docutils.svn.sourceforge.net/svnroot/docutils/trunk/docutils@7422 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- HISTORY.txt | 4 ++++ docutils/writers/odf_odt/__init__.py | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/HISTORY.txt b/HISTORY.txt index 885024944..3d55f1fc6 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -25,8 +25,12 @@ Release 0.9 (2012-05-02) - New reStructuredText "code" role and directive and "code" option of the "include" directive with syntax highlighting by Pygments_. - Fix parse_option_marker for option arguments containing ``=``. + - Fix [ 2993756 ]: import Python Imaging Library's Image module + via ``import PIL`` as starting with PIL 1.2, + "PIL lives in the PIL namespace only" (announcement__). .. _Pygments: http://pygments.org/ +__ http://mail.python.org/pipermail/image-sig/2011-January/006650.html * setup.py diff --git a/docutils/writers/odf_odt/__init__.py b/docutils/writers/odf_odt/__init__.py index 6dcc17b00..81f84b10b 100644 --- a/docutils/writers/odf_odt/__init__.py +++ b/docutils/writers/odf_odt/__init__.py @@ -64,12 +64,15 @@ try: except ImportError, exp: pygments = None -# -# Is the PIL imaging library installed? -try: - import Image -except ImportError, exp: - Image = None +try: # check for the Python Imaging Library + import PIL +except ImportError: + try: # sometimes PIL modules are put in PYTHONPATH's root + import Image + class PIL(object): pass # dummy wrapper + PIL.Image = Image + except ImportError: + PIL = None ## import warnings ## warnings.warn('importing IPShellEmbed', UserWarning) @@ -2123,9 +2126,9 @@ class ODFTranslator(nodes.GenericNodeVisitor): height = self.get_image_width_height(node, 'height') dpi = (72, 72) - if Image is not None and source in self.image_dict: + if PIL is not None and source in self.image_dict: filename, destination = self.image_dict[source] - imageobj = Image.open(filename, 'r') + imageobj = PIL.Image.open(filename, 'r') dpi = imageobj.info.get('dpi', dpi) # dpi information can be (xdpi, ydpi) or xydpi try: iter(dpi) -- 2.11.4.GIT