Bug 481786 - pydot does not support unicode :)
pydot does not support unicode :)
Product: Fedora
Classification: Fedora
Component: pydot (Show other bugs)
All Linux
low Severity medium
: ---
: ---
Assigned To: Tom "spot" Callaway
Fedora Extras Quality Assurance
Depends On:
  Show dependency treegraph
Reported: 2009-01-27 11:22 EST by Pierre-YvesChibon
Modified: 2009-08-31 12:59 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2009-08-31 12:59:59 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Pierre-YvesChibon 2009-01-27 11:22:18 EST
Description of problem:

#-*- coding: UTF-8 -*-

import pydot
n1 = u"Thérèse Doe"
n2 = u"Jean-Pierre Toué"

# Does not work
g = pydot.Dot()
g.add_edge(pydot.Edge(n1, n2))

# Work :)
g = pydot.Dot()
g.add_edge(pydot.Edge(n1.encode('UTF-8'), n2.encode('UTF-8')))

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1.run the code given above
Actual results:

Expected results:
See part two of the code :)

Additional info:
Not that I foreseen
Comment 1 Tom "spot" Callaway 2009-02-03 15:27:34 EST
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:
Comment 2 Pierre-YvesChibon 2009-02-03 15:35:50 EST
I've had quite some headache trying to understand it :)

Thanks for reporting it.
Comment 3 Toshio Ernie Kuratomi 2009-05-29 03:26:44 EDT
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:

g.add_edge(pydot.Edge('Th\xe9r\xe8se Doe'))

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.
Comment 4 Tom "spot" Callaway 2009-08-31 12:59:59 EDT
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.

Note You need to log in before you can comment on or make changes to this bug.