Anonymous avatar Anonymous committed 71444a5

fix debug2 UnicodeEncodeError issue caused by docutils Element.__repr__() return unicode object if Element['names'] contain unicode object.

This is maybe docutils issue: https://sourceforge.net/tracker/?func=detail&aid=3601607&group_id=38414&atid=422030

Comments (0)

Files changed (2)

sphinx/application.py

             event.pop(listener_id, None)
 
     def emit(self, event, *args):
-        args_repr = repr(map(unicode, args))[:100]
-        self.debug2('[app] emitting event: %s%s', event, args_repr)
+        self.debug2('[app] emitting event: %r%s', event, repr(args)[:100])
         results = []
         if event in self._listeners:
             for _, callback in self._listeners[event].iteritems():

sphinx/util/nodes.py

     return self.__class__(self.rawsource, **self.attributes)
 
 nodes.Element.copy = _new_copy
+
+# monkey-patch Element.__repr__ to return str if include unicode.
+# sf.net/tracker/?func=detail&aid=3601607&group_id=38414&atid=422030
+import sys
+if sys.version_info < (3,):
+    _element_repr_orig = nodes.Element.__repr__
+    
+    def _repr(self):
+        s = _element_repr_orig(self)
+        if isinstance(s, unicode):
+            return s.encode('utf-8')
+        return s
+    
+    nodes.Element.__repr__ = _repr
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.