google-code-export / pydot

Automatically exported from code.google.com/p/pydot
MIT License
1 stars 0 forks source link

problem generation label from unicode string #55

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
2.
3.
#!/usr/bin/env python
# -*- coding: cp1251 -*-
import pydot as p
G = p.Dot(graph_type='digraph',charset='utf8')
a=p.Node(u'Мама')
G.add_node(a)
b=p.Node('bbb')
G.add_node(b)
G.add_edge(p.Edge(a,b))
G.write_png("aaa.png")

expected aaa.png

got 

Traceback (most recent call last):
  File "a.py", line 10, in <module>
    G.write_png("aaa.png")
  File "C:\PROJECTS\mc2py\mc2lib\pyd\pydot-1.0.25\pydot.py", line 1794, in <lambda>
    lambda path, f=frmt, prog=self.prog : self.write(path, format=f, prog=prog))
  File "C:\PROJECTS\mc2py\mc2lib\pyd\pydot-1.0.25\pydot.py", line 1884, in write
    dot_fd.write(self.create(prog, format))
  File "C:\PROJECTS\mc2py\mc2lib\pyd\pydot-1.0.25\pydot.py", line 1940, in create
    self.write(tmp_name)
  File "C:\PROJECTS\mc2py\mc2lib\pyd\pydot-1.0.25\pydot.py", line 1882, in write
    dot_fd.write(self.to_string())
UnicodeEncodeError: 'ascii' codec can't encode characters in position 27-30: 
ordinal not in range(128)

OS
windows XP, pydot-1.0.25

can be corrected if in pydot.py line 1882 
        if format == 'raw':
            dot_fd.write(self.to_string())
        else:
replace by
        if format == 'raw':
            dot_fd.write((self.to_string()).encode('utf8'))
        else:

Please provide any additional information below.

Original issue reported on code.google.com by doza...@mail.ru on 11 Aug 2011 at 7:22

GoogleCodeExporter commented 9 years ago
fixed in revision 28

Original comment by ero.carr...@gmail.com on 2 Jan 2012 at 11:53