Commits

shim...@gmail.com  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

  • Participants
  • Parent commits 82a166b

Comments (0)

Files changed (2)

File 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():

File 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