graph: use codecs.open. Closes #155138

Makes python3 happier (can't write utf8 data to a file opened without an encoding)

authorJulien Cristau <julien.cristau@logilab.fr>
changeset9e4eb6f9c594
branchstable
phasepublic
hiddenno
parent revision#49aeb5521e29 testlib: fix for python 3.3
child revision#03abf06e88d7 update Changelog
files modified by this revision
graph.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1371731258 -7200
# Thu Jun 20 14:27:38 2013 +0200
# Branch stable
# Node ID 9e4eb6f9c594d6e4c1541cd0d16c0d44a3c080bb
# Parent 49aeb5521e2962fce18f5d02323ac8668dfd88b3
graph: use codecs.open. Closes #155138

Makes python3 happier (can't write utf8 data to a file opened without an
encoding)

diff --git a/graph.py b/graph.py
@@ -26,11 +26,11 @@
1 
2  import os.path as osp
3  import os
4  import sys
5  import tempfile
6 -from logilab.common.compat import str_encode
7 +import codecs
8 
9  def escape(value):
10      """Make <value> usable in a dot file."""
11      lines = [line.replace('"', '\\"') for line in value.split('\n')]
12      data = '\\l'.join(lines)
@@ -104,12 +104,12 @@
13              target = 'png'
14              pdot, dot_sourcepath = tempfile.mkstemp(".dot", name)
15              ppng, outputfile = tempfile.mkstemp(".png", name)
16              os.close(pdot)
17              os.close(ppng)
18 -        pdot = open(dot_sourcepath, 'w')
19 -        pdot.write(str_encode(self.source, 'utf8'))
20 +        pdot = codecs.open(dot_sourcepath, 'w', encoding='utf8')
21 +        pdot.write(self.source)
22          pdot.close()
23          if target != 'dot':
24              if sys.platform == 'win32':
25                  use_shell = True
26              else: