Reading of layer name with UTF-8 encoding in summary failled

Bug #642571 reported by François Bianco
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
JessyInk
Fix Released
Medium
Hannes Hochreiner

Bug Description

To get this bug, just name a tag with non ascii character and open summary :

Traceback (most recent call last):
  File "/usr/share/inkscape/extensions/jessyInk_summary.py", line 195, in <module>
    effect.affect()
  File "/usr/share/inkscape/extensions/inkex.py", line 207, in affect
    self.effect()
  File "/usr/share/inkscape/extensions/jessyInk_summary.py", line 90, in effect
    self.describeNode(slide, "\t", str(slideCounter), str(len(slides)), slide.get("{" + inkex.NSS["inkscape"] + "}label"))
  File "/usr/share/inkscape/extensions/jessyInk_summary.py", line 94, in describeNode
    inkex.errormsg(_("{0}Layer name: {1}").format(prefix, node.get("{" + inkex.NSS["inkscape"] + "}label")))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 6: ordinal not in range(128)

Revision history for this message
Hannes Hochreiner (hannes-hochreiner) wrote :

This seems to be an encoding problem similar to the one that was fixed with the transition extension recently. I'll get to it asap.

Changed in jessyink:
milestone: none → 1.5.3
assignee: nobody → Hannes Hochreiner (hannes-hochreiner)
importance: Undecided → Medium
status: New → In Progress
Revision history for this message
François Bianco (fbianco) wrote :

I just found a solution to this problem. Please find a patch attached.

By correcting it, I also had to make a change in inkex.py, apparently also corrected upstream, but in a (less safer ?) way. I let you judge it :

--- inkex.py.ori 2010-09-22 15:47:14.198637824 +0200
+++ inkex.py 2010-09-22 18:03:43.178171056 +0200
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+# -*- coding: utf-8 -*-
 """
 inkex.py
 A helper module for creating Inkscape extensions
@@ -66,7 +67,7 @@
     sys.exit(_('The fantastic lxml wrapper for libxml2 is required by inkex.py and therefore this extension. Please download and install the latest version from http://cheeseshop.python.org/pypi/lxml/, or install it through your package manager by a command like: sudo apt-get install python-lxml'))

 def debug(what):
- sys.stderr.write(str(what) + "\n")
+ sys.stderr.write(unicode(what,'utf-8','replace') + "\n").encode("UTF-8"))
     return what

 def errormsg(msg):
@@ -83,7 +84,7 @@
          ...
          inkex.errormsg(_("This extension requires two selected paths."))
     """
- sys.stderr.write((str(msg) + "\n").encode("UTF-8"))
+ sys.stderr.write((unicode(msg,'utf-8','replace') + "\n").encode("UTF-8"))

 def check_inkbool(option, opt, value):
     if str(value).capitalize() == 'True':

Revision history for this message
Hannes Hochreiner (hannes-hochreiner) wrote :

Hi François,

thanks for the patch! I suppose, I still should change the string handling in the JessyInk extension as well. As for the changes in "inkex.py", I try and figure out what the status is upstream and if I don't commit the patch myself, I'll forward it to the good people working on the Inkscape extension system.

Cheers,
Hannes

Revision history for this message
Hannes Hochreiner (hannes-hochreiner) wrote :

I had a look at the patch, but it did not solve the problem for me.

If I understand the problem correctly, "sys.stderr" expects an ascii encoded string. Re-encoding the message string in UTF-8 therefore did not help. I guess we either have to re-encode the string in ascii (accepting possible losses) or switch "sys.stderr" to "utf-8".

It would be interesting to know whether the encoding of "sys.stderr" is different on different systems.

Revision history for this message
Hannes Hochreiner (hannes-hochreiner) wrote :

After having another look at the problem, it seems to me that the format function is causing the trouble. Therefore, the simplest way to fix the problem seems to be to change the string that is being formated to a unicode string by pre-pending a "u".

=== modified file 'inkscapeExtensions/jessyInk_summary.py'
--- inkscapeExtensions/jessyInk_summary.py 2010-06-07 20:02:58 +0000
+++ inkscapeExtensions/jessyInk_summary.py 2010-10-23 18:28:49 +0000
@@ -91,7 +91,7 @@
    slideCounter += 1

  def describeNode(self, node, prefix, slideNumber, numberOfSlides, slideTitle):
- inkex.errormsg(_("{0}Layer name: {1}").format(prefix, node.get("{" + inkex.NSS["inkscape"] + "}label")))
+ inkex.errormsg(_(u"{0}Layer name: {1}").format(prefix, node.get("{" + inkex.NSS["inkscape"] + "}label")))

   # Display information about transitions.
   transitionInAttribute = node.get("{" + inkex.NSS["jessyink"] + "}transitionIn")

Changed in jessyink:
status: In Progress → Fix Committed
Changed in jessyink:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.