Red Hat Bugzilla – Bug 481786
pydot does not support unicode :)
Last modified: 2009-08-31 12:59:59 EDT
Description of problem:
#-*- coding: UTF-8 -*-
n1 = u"Thérèse Doe"
n2 = u"Jean-Pierre Toué"
# Does not work
g = pydot.Dot()
# Work :)
g = pydot.Dot()
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1.run the code given above
See part two of the code :)
Not that I foreseen
Unicode in python gives me a headache. All my attempts to fix this just made it worse. Hopefully upstream will have better luck than I did.
Filed upstream here:
I've had quite some headache trying to understand it :)
Thanks for reporting it.
This one looks like it isn't a bug to me. Rather, it's a request for an API change.
Right now, pydot accepts str type. It does not accept unicode type. So the user is forced to change the unicode strings that they have into byte strings before sending it into a pydot function. That's why n1.encode('UTF-8') is necessary.
This makes some sense as pydot must interact with the world outside of python in the form of the /usr/bin/dot command. pydot communicates with that command by writing the information for /usr/bin/dot to a temporary file and then having /usr/bin/dot operate on that file. In order to create the temporary file, pydot must deal in byte strings (str). In the current code, the user gives pydot byte strings and pydot writes those out directly to the file. The user performs the conversion from unicode type to utf-8 encoded byte string.
In order for pydot to handle unicode strings instead of byte strings, it would need to make the conversion that the user is currently doing. That shouldn't be too hard as /usr/bin/dot will accept utf-8 and all unicode strings can be encoded to utf-8. However, for sanity of the pydot upstream, pydot probably should stop accepting byte strings when it makes this switch. So end-user code similar to this will start to fail:
If pydot upstream chooses to accept both byte strings and unicode type, it will have to take into account what happens when the user provides byte strings that are not valid utf-8 and also unicode strings. If they aren't careful, pydot will get confused about what it needs to do in this situation and either crash or output garbage.
Making this sort of API change should only be done by upstream.
This is filed upstream, but upstream seems to be gone. :/
Since I agree with Toshio, we won't be doing a one-off fix here, especially since it breaks API, I'm closing this ticket out.