[MERGE] Forward-port latest 7.0 bugfixes, up to f8671cb
authorOlivier Dony <odo@openerp.com>
Thu, 22 May 2014 14:44:33 +0000 (16:44 +0200)
committerOlivier Dony <odo@openerp.com>
Thu, 22 May 2014 14:44:33 +0000 (16:44 +0200)
1  2 
addons/account_budget/account_budget.py
addons/report_webkit/webkit_report.py
openerp/report/render/rml2pdf/trml2pdf.py

@@@ -168,25 -117,15 +168,15 @@@ class WebKitParser(report_sxw)
          # default to UTF-8 encoding.  Use <meta charset="latin-1"> to override.
          command.extend(['--encoding', 'utf-8'])
          if header :
-             head_file = file( os.path.join(
-                                   tmp_dir,
-                                   str(time.time()) + '.head.html'
-                                  ),
-                                 'w'
-                             )
-             head_file.write(self._sanitize_html(header.encode('utf-8')))
-             head_file.close()
+             with tempfile.NamedTemporaryFile(suffix=".head.html",
+                                              delete=False) as head_file:
 -                head_file.write(self._sanitize_html(header))
++                head_file.write(self._sanitize_html(header.encode('utf-8')))
              file_to_del.append(head_file.name)
              command.extend(['--header-html', head_file.name])
          if footer :
-             foot_file = file(  os.path.join(
-                                   tmp_dir,
-                                   str(time.time()) + '.foot.html'
-                                  ),
-                                 'w'
-                             )
-             foot_file.write(self._sanitize_html(footer.encode('utf-8')))
-             foot_file.close()
+             with tempfile.NamedTemporaryFile(suffix=".foot.html",
+                                              delete=False) as foot_file:
 -                foot_file.write(self._sanitize_html(footer))
++                foot_file.write(self._sanitize_html(footer.encode('utf-8')))
              file_to_del.append(foot_file.name)
              command.extend(['--footer-html', foot_file.name])
  
              command.extend(['--page-size', str(webkit_header.format).replace(',', '.')])
          count = 0
          for html in html_list :
-             html_file = file(os.path.join(tmp_dir, str(time.time()) + str(count) +'.body.html'), 'w')
-             count += 1
-             html_file.write(self._sanitize_html(html.encode('utf-8')))
-             html_file.close()
+             with tempfile.NamedTemporaryFile(suffix="%d.body.html" %count,
+                                              delete=False) as html_file:
+                 count += 1
 -                html_file.write(self._sanitize_html(html))
++                html_file.write(self._sanitize_html(html.encode('utf-8')))
              file_to_del.append(html_file.name)
              command.append(html_file.name)
          command.append(out_filename)