From c5923d87f2b087e54b759c920cdbea041e8ab3ba Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Mon, 5 Jan 2009 22:02:40 +0100 Subject: [PATCH] [IMP] Use cStringIO bzr revid: stephane@tinyerp.com-20090105210240-nkg2vm08dwhz2xtq --- bin/addons/__init__.py | 4 ++-- .../base/module/wizard/wizard_export_lang.py | 4 ++-- .../base/module/wizard/wizard_module_import.py | 4 ++-- .../module/wizard/wizard_update_translations.py | 4 ++-- bin/report/custom.py | 11 ++++++----- bin/report/print_xml.py | 5 +++-- bin/report/render/rml2html/rml2html.py | 4 ++-- bin/report/render/rml2pdf/trml2pdf.py | 16 ++++++++-------- bin/report/render/simple.py | 2 +- bin/report/report_sxw.py | 4 ++-- bin/service/web_services.py | 2 +- bin/tools/convert.py | 9 ++++++--- bin/tools/misc.py | 4 ++-- 13 files changed, 39 insertions(+), 34 deletions(-) diff --git a/bin/addons/__init__.py b/bin/addons/__init__.py index 4ab55d6a6bc..9a43513f0d5 100644 --- a/bin/addons/__init__.py +++ b/bin/addons/__init__.py @@ -41,7 +41,7 @@ import release import re import base64 from zipfile import PyZipFile, ZIP_DEFLATED -import StringIO +import cStringIO logger = netsvc.Logger() @@ -198,7 +198,7 @@ def get_module_as_zip(modulename, b64enc=True, src=True): if os.path.isfile(ap + '.zip'): val = file(ap + '.zip', 'rb').read() else: - archname = StringIO.StringIO('wb') + archname = cStringIO.StringIO('wb') archive = PyZipFile(archname, "w", ZIP_DEFLATED) archive.writepy(ap) _zippy(archive, ap, src=src) diff --git a/bin/addons/base/module/wizard/wizard_export_lang.py b/bin/addons/base/module/wizard/wizard_export_lang.py index 718464a5c76..e4ed0523b92 100644 --- a/bin/addons/base/module/wizard/wizard_export_lang.py +++ b/bin/addons/base/module/wizard/wizard_export_lang.py @@ -23,7 +23,7 @@ import wizard import tools import base64 -import StringIO +import cStringIO import csv import pooler from osv import fields,osv @@ -49,7 +49,7 @@ class wizard_export_lang(osv.osv_memory): this = self.browse(cr, uid, ids)[0] mods = map(lambda m: m.name, this.modules) or ['all'] mods.sort() - buf=StringIO.StringIO() + buf=cStringIO.StringIO() tools.trans_export(this.lang, mods, buf, this.format, dbname=cr.dbname) if this.format == 'csv': this.advice = _("Save this document to a .CSV file and open it with your favourite spreadsheet software. The file encoding is UTF-8. You have to translate the latest column before reimporting it.") diff --git a/bin/addons/base/module/wizard/wizard_module_import.py b/bin/addons/base/module/wizard/wizard_module_import.py index c166761b275..e686fa856e2 100644 --- a/bin/addons/base/module/wizard/wizard_module_import.py +++ b/bin/addons/base/module/wizard/wizard_module_import.py @@ -28,7 +28,7 @@ import os import tools import zipfile -import StringIO +import cStringIO import base64 finish_form =''' @@ -55,7 +55,7 @@ class move_module_wizard(wizard.interface): module_data = data['form']['module_file'] val =base64.decodestring(module_data) - fp = StringIO.StringIO(val) + fp = cStringIO.StringIO(val) fdata = zipfile.ZipFile(fp, 'r') fname = fdata.namelist()[0] module_name = os.path.split(fname)[0] diff --git a/bin/addons/base/module/wizard/wizard_update_translations.py b/bin/addons/base/module/wizard/wizard_update_translations.py index e2a8512a8b3..d12ca6f6981 100644 --- a/bin/addons/base/module/wizard/wizard_update_translations.py +++ b/bin/addons/base/module/wizard/wizard_update_translations.py @@ -23,7 +23,7 @@ from osv import osv, fields import tools import pooler -import StringIO +import cStringIO class update_translations(osv.osv_memory): def _get_languages(self, cr, uid, context): @@ -45,7 +45,7 @@ class update_translations(osv.osv_memory): def act_update(self, cr, uid, ids, context=None): this = self.browse(cr, uid, ids)[0] lang_name = self._get_lang_name(cr, uid, this.lang) - buf=StringIO.StringIO() + buf=cStringIO.StringIO() tools.trans_export(this.lang, ['all'], buf, 'csv', dbname=cr.dbname) tools.trans_load_data(cr.dbname, buf, 'csv', this.lang, lang_name=lang_name) buf.close() diff --git a/bin/report/custom.py b/bin/report/custom.py index 80889255962..0823457ddce 100644 --- a/bin/report/custom.py +++ b/bin/report/custom.py @@ -20,7 +20,8 @@ # ############################################################################## -import os, time +import os +import time import netsvc import tools @@ -37,7 +38,7 @@ import libxml2 import libxslt from pychart import * import misc -import StringIO +import cStringIO class external_pdf(render.render): def __init__(self, pdf): @@ -358,7 +359,7 @@ class report_custom(report_int): def _create_lines(self, cr, uid, ids, report, fields, results, context): service = netsvc.LocalService("object_proxy") - pdf_string = StringIO.StringIO() + pdf_string = cStringIO.StringIO() can = canvas.init(fname=pdf_string, format='pdf') can.show(80,380,'/16/H'+report['title']) @@ -461,7 +462,7 @@ class report_custom(report_int): def _create_bars(self, cr, uid, ids, report, fields, results, context): service = netsvc.LocalService("object_proxy") - pdf_string = StringIO.StringIO() + pdf_string = cStringIO.StringIO() can = canvas.init(fname=pdf_string, format='pdf') can.show(80,380,'/16/H'+report['title']) @@ -558,7 +559,7 @@ class report_custom(report_int): return True def _create_pie(self, cr, uid, ids, report, fields, results, context): - pdf_string = StringIO.StringIO() + pdf_string = cStringIO.StringIO() can = canvas.init(fname=pdf_string, format='pdf') ar = area.T(size=(350,350), legend=legend.T(), x_grid_style = None, y_grid_style = None) diff --git a/bin/report/print_xml.py b/bin/report/print_xml.py index 8ed5dd18012..972beb7252e 100644 --- a/bin/report/print_xml.py +++ b/bin/report/print_xml.py @@ -162,9 +162,10 @@ class document(object): fname = str(datas['datas_fname']) ext = fname.split('.')[-1].lower() if ext in ('jpg','jpeg', 'png'): - import base64, StringIO + import base64 + import cStringIO dt = base64.decodestring(datas['datas']) - fp = StringIO.StringIO(dt) + fp = cStringIO.StringIO(dt) i = str(len(self.bin_datas)) self.bin_datas[i] = fp diff --git a/bin/report/render/rml2html/rml2html.py b/bin/report/render/rml2html/rml2html.py index c5321b0f2e5..5d005cc45a6 100644 --- a/bin/report/render/rml2html/rml2html.py +++ b/bin/report/render/rml2html/rml2html.py @@ -37,7 +37,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import sys -import StringIO +import cStringIO import xml.dom.minidom import copy @@ -365,7 +365,7 @@ def parseString(data, fout=None): fp.close() return fout else: - fp = StringIO.StringIO() + fp = cStringIO.StringIO() r.render(fp) return fp.getvalue() diff --git a/bin/report/render/rml2pdf/trml2pdf.py b/bin/report/render/rml2pdf/trml2pdf.py index 92aba87f372..ddd014b7bfa 100644 --- a/bin/report/render/rml2pdf/trml2pdf.py +++ b/bin/report/render/rml2pdf/trml2pdf.py @@ -40,7 +40,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import sys -import StringIO +import cStringIO import xml.dom.minidom import copy @@ -355,22 +355,22 @@ class _rml_canvas(object): if node.hasAttribute('name'): image_data = self.images[node.getAttribute('name')] - s = StringIO.StringIO(image_data) + s = cStringIO.StringIO(image_data) else: import base64 image_data = base64.decodestring(node.firstChild.nodeValue) if not image_data: return False - s = StringIO.StringIO(image_data) + s = cStringIO.StringIO(image_data) else: if node.getAttribute('file') in self.images: - s = StringIO.StringIO(self.images[node.getAttribute('file')]) + s = cStringIO.StringIO(self.images[node.getAttribute('file')]) else: try: u = urllib.urlopen(str(node.getAttribute('file'))) - s = StringIO.StringIO(u.read()) + s = cStringIO.StringIO(u.read()) except: u = file(os.path.join(self.path,str(node.getAttribute('file'))), 'rb') - s = StringIO.StringIO(u.read()) + s = cStringIO.StringIO(u.read()) img = ImageReader(s) (sx,sy) = img.getSize() @@ -639,7 +639,7 @@ class _rml_flowable(object): else: import base64 image_data = base64.decodestring(node.firstChild.nodeValue) - image = StringIO.StringIO(image_data) + image = cStringIO.StringIO(image_data) return platypus.Image(image, mask=(250,255,250,255,250,255), **(utils.attr_get(node, ['width','height']))) else: return platypus.Image(node.getAttribute('file'), mask=(250,255,250,255,250,255), **(utils.attr_get(node, ['width','height']))) @@ -794,7 +794,7 @@ def parseString(data, fout=None, images={}, path='.',title=None): fp.close() return fout else: - fp = StringIO.StringIO() + fp = cStringIO.StringIO() r.render(fp) return fp.getvalue() diff --git a/bin/report/render/simple.py b/bin/report/render/simple.py index 6b52c49b718..72f27e147d8 100644 --- a/bin/report/render/simple.py +++ b/bin/report/render/simple.py @@ -22,7 +22,7 @@ import render -from StringIO import StringIO +from cStringIO import StringIO import xml.dom.minidom from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table diff --git a/bin/report/report_sxw.py b/bin/report/report_sxw.py index c4f10212b5a..e202a9a275b 100644 --- a/bin/report/report_sxw.py +++ b/bin/report/report_sxw.py @@ -21,7 +21,7 @@ ############################################################################## from interface import report_rml -import StringIO +import cStringIO import base64 import copy import ir @@ -618,7 +618,7 @@ class report_sxw(report_rml): if report_type in ['sxw','odt'] and report_xml: context['parents'] = sxw_parents - sxw_io = StringIO.StringIO(report_xml.report_sxw_content) + sxw_io = cStringIO.StringIO(report_xml.report_sxw_content) sxw_z = zipfile.ZipFile(sxw_io, mode='r') rml = sxw_z.read('content.xml') meta = sxw_z.read('meta.xml') diff --git a/bin/service/web_services.py b/bin/service/web_services.py index b97e8a81fa7..dfcf7272d63 100644 --- a/bin/service/web_services.py +++ b/bin/service/web_services.py @@ -105,7 +105,7 @@ class db(netsvc.Service): except Exception, e: serv.actions[id]['clean'] = False serv.actions[id]['exception'] = e - from StringIO import StringIO + from cStringIO import StringIO import traceback e_str = StringIO() traceback.print_exc(file=e_str) diff --git a/bin/tools/convert.py b/bin/tools/convert.py index 089316e9797..7c4ad731b5c 100644 --- a/bin/tools/convert.py +++ b/bin/tools/convert.py @@ -20,8 +20,11 @@ # ############################################################################## import re -import StringIO,xml.dom.minidom -import osv,ir,pooler +import cStringIO +import xml.dom.minidom +import osv +import ir +import pooler import csv import os.path @@ -804,7 +807,7 @@ def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init', pool = pooler.get_pool(cr.dbname) - input = StringIO.StringIO(csvcontent) + input = cStringIO.StringIO(csvcontent) reader = csv.reader(input, quotechar='"', delimiter=',') fields = reader.next() fname_partial = "" diff --git a/bin/tools/misc.py b/bin/tools/misc.py index d27191616aa..1803de2ae9d 100644 --- a/bin/tools/misc.py +++ b/bin/tools/misc.py @@ -224,10 +224,10 @@ def file_open(name, mode="r", subdir='addons', pathinfo=False): else: zipname = tail if zipfile.is_zipfile(head+'.zip'): - import StringIO + import cStringIO zfile = zipfile.ZipFile(head+'.zip') try: - fo = StringIO.StringIO(zfile.read(os.path.join( + fo = cStringIO.StringIO(zfile.read(os.path.join( os.path.basename(head), zipname).replace( os.sep, '/')))