[Python-checkins] r64373 - in doctools/trunk/sphinx: builder.py environment.py

georg.brandl python-checkins at python.org
Wed Jun 18 12:06:23 CEST 2008


Author: georg.brandl
Date: Wed Jun 18 12:06:22 2008
New Revision: 64373

Log:
Fix image handling.


Modified:
   doctools/trunk/sphinx/builder.py
   doctools/trunk/sphinx/environment.py

Modified: doctools/trunk/sphinx/builder.py
==============================================================================
--- doctools/trunk/sphinx/builder.py	(original)
+++ doctools/trunk/sphinx/builder.py	Wed Jun 18 12:06:22 2008
@@ -128,20 +128,19 @@
         Pick the best candidate for all image URIs.
         """
         for node in doctree.traverse(nodes.image):
-            uri = node['candidates'].get('*', None)
-            if not uri:
+            if '*' not in node['candidates']:
                 for imgtype in self.supported_image_types:
-                    uri = node['candidates'].get(imgtype, None)
-                    if uri:
-                        node['uri'] = uri
+                    candidate = node['candidates'].get(imgtype, None)
+                    if candidate:
                         break
                 else:
-                    self.warn('%s:%s: %s' %
-                              (node.source, node.lineno,
-                               'No matching candidate for uri: %(uri)s' % node))
+                    self.warn('%s:%s: no matching candidate for image URI %r' %
+                              (node.source, node.lineno, node['uri']))
                     continue
-            if uri in self.env.images:
-                self.images[uri] = self.env.images[uri][1]
+                node['uri'] = candidate
+            else:
+                candidate = node['uri']
+            self.images[candidate] = self.env.images[candidate][1]
 
     # build methods
 

Modified: doctools/trunk/sphinx/environment.py
==============================================================================
--- doctools/trunk/sphinx/environment.py	(original)
+++ doctools/trunk/sphinx/environment.py	Wed Jun 18 12:06:22 2008
@@ -63,7 +63,7 @@
 
 # This is increased every time an environment attribute is added
 # or changed to properly invalidate pickle files.
-ENV_VERSION = 23
+ENV_VERSION = 24
 
 
 default_substitutions = set([
@@ -535,6 +535,7 @@
                 candidates['*'] = imguri
                 continue
             imgpath = path.normpath(path.join(docdir, imguri))
+            node['uri'] = imgpath
             if imgpath.endswith(os.extsep + '*'):
                 for filename in glob(imgpath):
                     basename, ext = os.path.splitext(filename)
@@ -543,7 +544,11 @@
                     elif ext == '.svg':
                         candidates['image/svg+xml'] = filename
                     else:
-                        imgtype = imghdr.what(filename)
+                        f = open(filename, 'rb')
+                        try:
+                            imgtype = imghdr.what(f)
+                        finally:
+                            f.close()
                         if imgtype:
                             candidates['image/' + imgtype] = filename
             else:


More information about the Python-checkins mailing list