graph: use codecs.open

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

authorJulien Cristau <julien.cristau@logilab.fr>
changesetd40ffc71c1e9
branchstable
phasedraft
hiddenyes
parent revision#5a8fb4b4a7f5 [modutils] fix python3.3 crash on file_from_modpath. Closes #137244
child revision<not specified>
files modified by this revision
graph.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1371573931 -7200
# Tue Jun 18 18:45:31 2013 +0200
# Branch stable
# Node ID d40ffc71c1e9c0e26e0b261996f35cec393ee1d3
# Parent 5a8fb4b4a7f567b65b8f935282316be0b1f9018e
graph: use codecs.open

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

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