Commit 4a38b80d authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Jérome Perrin

py2/py3: import cStringIO from six.moves.

parent 9252c0db
# coding: utf-8 # coding: utf-8
import unicodedata import unicodedata
from cStringIO import StringIO from six.moves import cStringIO as StringIO
import zipfile import zipfile
from Products.ERP5Type.Message import translateString from Products.ERP5Type.Message import translateString
......
...@@ -20,7 +20,7 @@ zipfile (bool) ...@@ -20,7 +20,7 @@ zipfile (bool)
When true, the result is a zip file containing profiling result along with the python code (and, when not possible, the disassembled bytecode) of all files which appear in the profiling result. When true, the result is a zip file containing profiling result along with the python code (and, when not possible, the disassembled bytecode) of all files which appear in the profiling result.
When false, the result is a bare profiling result (cachegrind file format). When false, the result is a bare profiling result (cachegrind file format).
""" """
from StringIO import StringIO from six.moves import cStringIO as StringIO
portal = context.getPortalObject() portal = context.getPortalObject()
if statistic: if statistic:
profiler, retriever = portal.ERP5Site_getStatisticalProfilerAndThread(single=True) profiler, retriever = portal.ERP5Site_getStatisticalProfilerAndThread(single=True)
......
...@@ -18,7 +18,7 @@ zipfile (bool) ...@@ -18,7 +18,7 @@ zipfile (bool)
When false, the result is a bare profiling result (cachegrind file format). When false, the result is a bare profiling result (cachegrind file format).
""" """
from time import sleep from time import sleep
from StringIO import StringIO from six.moves import cStringIO as StringIO
profiler, thread = context.ERP5Site_getStatisticalProfilerAndThread(single=False) profiler, thread = context.ERP5Site_getStatisticalProfilerAndThread(single=False)
with thread: with thread:
sleep(duration) sleep(duration)
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
import os import os
import subprocess import subprocess
from cStringIO import StringIO from six.moves import cStringIO as StringIO
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Acquisition import aq_base from Acquisition import aq_base
......
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
# #
############################################################################## ##############################################################################
import re, zipfile, cStringIO import re, zipfile
from six.moves import cStringIO as StringIO
from warnings import warn from warnings import warn
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from OFS.Image import Pdata from OFS.Image import Pdata
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
# #
############################################################################## ##############################################################################
from cStringIO import StringIO from six.moves import cStringIO as StringIO
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.Base import removeIContentishInterface from Products.ERP5Type.Base import removeIContentishInterface
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
############################################################################## ##############################################################################
import zope.interface import zope.interface
from StringIO import StringIO from six.moves import cStringIO as StringIO
from Acquisition import aq_base from Acquisition import aq_base
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
......
...@@ -30,17 +30,17 @@ ...@@ -30,17 +30,17 @@
# This extension should be replaced by a clever parser provided by # This extension should be replaced by a clever parser provided by
# ERP5OOo or probably by CloudOOo itself. # ERP5OOo or probably by CloudOOo itself.
import StringIO from io import BytesIO
def read(self, filename, data): def read(self, filename, data):
""" """
Return a OOCalc as a StringIO Return a OOCalc as a BytesIO
""" """
if data is None: if data is None:
oo_template_file = getattr(self, filename) oo_template_file = getattr(self, filename)
fp = StringIO.StringIO(oo_template_file) fp = BytesIO(oo_template_file)
else: else:
fp = StringIO.StringIO(data) fp = BytesIO(data)
fp.filename = filename fp.filename = filename
return fp return fp
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
from matplotlib.figure import Figure from matplotlib.figure import Figure
from IPython.core.display import DisplayObject from IPython.core.display import DisplayObject
from IPython.lib.display import IFrame from IPython.lib.display import IFrame
from cStringIO import StringIO from six.moves import cStringIO as StringIO
from erp5.portal_type import Image from erp5.portal_type import Image
from types import ModuleType from types import ModuleType
from ZODB.serialize import ObjectWriter from ZODB.serialize import ObjectWriter
......
from StringIO import StringIO from io import BytesIO
class StringIOWithFileName(StringIO): class BytesIOWithFileName(BytesIO):
filename = "{}.pdf".format( filename = "{}.pdf".format(
kw.get("title") or DateTime().strftime('%d-%m-%Y_%Hh%M')) kw.get("title") or DateTime().strftime('%d-%m-%Y_%Hh%M'))
...@@ -9,7 +9,7 @@ active_process = portal.restrictedTraverse(str(active_process_url)) ...@@ -9,7 +9,7 @@ active_process = portal.restrictedTraverse(str(active_process_url))
pdf_data_list = context.Base_getTempImageList(active_process, image_list) pdf_data_list = context.Base_getTempImageList(active_process, image_list)
pdf_data = context.ERP5Site_mergePDFList(pdf_data_list=pdf_data_list) pdf_data = context.ERP5Site_mergePDFList(pdf_data_list=pdf_data_list)
file_object = StringIOWithFileName(pdf_data) file_object = BytesIOWithFileName(pdf_data)
context.Base_contribute( context.Base_contribute(
file=file_object, file=file_object,
......
...@@ -53,7 +53,7 @@ def getActionTitleListFromAllActionProvider(portal): ...@@ -53,7 +53,7 @@ def getActionTitleListFromAllActionProvider(portal):
return result return result
from StringIO import StringIO from six.moves import cStringIO as StringIO
from zope.tal.htmltalparser import HTMLTALParser from zope.tal.htmltalparser import HTMLTALParser
from zope.tal.talparser import TALParser from zope.tal.talparser import TALParser
from zope.tal.talgenerator import TALGenerator from zope.tal.talgenerator import TALGenerator
......
...@@ -60,7 +60,7 @@ if not zip_file: ...@@ -60,7 +60,7 @@ if not zip_file:
rejectSoftwarePublication(software_publication) rejectSoftwarePublication(software_publication)
return return
from cStringIO import StringIO from six.moves import cStringIO as StringIO
import zipfile import zipfile
from zipfile import BadZipfile from zipfile import BadZipfile
......
...@@ -35,7 +35,7 @@ def mergePDFList(self, pdf_data_list, start_on_recto=False): ...@@ -35,7 +35,7 @@ def mergePDFList(self, pdf_data_list, start_on_recto=False):
to have each PDF as the recto page. This is useful if you have to print the to have each PDF as the recto page. This is useful if you have to print the
merged pdf in recto/verso mode. merged pdf in recto/verso mode.
""" """
from StringIO import StringIO from six.moves import cStringIO as StringIO
from PyPDF2 import PdfFileWriter, PdfFileReader from PyPDF2 import PdfFileWriter, PdfFileReader
output = PdfFileWriter() output = PdfFileWriter()
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
from __future__ import print_function from __future__ import print_function
import os, sys, shutil, tempfile import os, sys, shutil, tempfile
from cStringIO import StringIO from six.moves import cStringIO as StringIO
from zLOG import LOG,ERROR,INFO,WARNING from zLOG import LOG,ERROR,INFO,WARNING
from OFS.Image import File, Image from OFS.Image import File, Image
import os, transaction import os, transaction
......
#from Products.ERP5.Document.TileImageTransformed import TileImageTransformed #from Products.ERP5.Document.TileImageTransformed import TileImageTransformed
#from cStringIO import StringIO #from six.moves import cStringIO as StringIO
portal = context.getPortalObject() portal = context.getPortalObject()
......
...@@ -332,7 +332,7 @@ class CSVBenchmarkResult(BenchmarkResult): ...@@ -332,7 +332,7 @@ class CSVBenchmarkResult(BenchmarkResult):
self.logger.error(logged_msg) self.logger.error(logged_msg)
raise RuntimeError(msg) raise RuntimeError(msg)
from cStringIO import StringIO from six.moves import cStringIO as StringIO
from six.moves import xmlrpc_client as xmlrpclib from six.moves import xmlrpc_client as xmlrpclib
import datetime import datetime
......
...@@ -37,10 +37,7 @@ from pandas import * ...@@ -37,10 +37,7 @@ from pandas import *
import six as _six import six as _six
from AccessControl.ZopeGuards import Unauthorized as _ZopeGuardsUnauthorized from AccessControl.ZopeGuards import Unauthorized as _ZopeGuardsUnauthorized
if _six.PY2: from six.moves import cStringIO as _StringIO
from StringIO import StringIO as _StringIO
else:
from io import StringIO as _StringIO
def _addRestrictedPandasReadFunction(function_name): def _addRestrictedPandasReadFunction(function_name):
......
...@@ -29,9 +29,8 @@ ...@@ -29,9 +29,8 @@
# Install openers # Install openers
# -> testTemplateTool.TestTemplateTool.test_getBusinessTemplateUrl # -> testTemplateTool.TestTemplateTool.test_getBusinessTemplateUrl
import urllib import six.moves.urllib.request, six.moves.urllib.parse, six.moves.urllib.error
import urllib2 from six.moves import cStringIO as StringIO
import cStringIO
import socket import socket
import os import os
import dircache import dircache
...@@ -61,7 +60,7 @@ class DirectoryFileHandler(urllib2.FileHandler): ...@@ -61,7 +60,7 @@ class DirectoryFileHandler(urllib2.FileHandler):
size = stats.st_size size = stats.st_size
modified = formatdate(stats.st_mtime, usegmt=True) modified = formatdate(stats.st_mtime, usegmt=True)
mtype = mimetypes.guess_type(file)[0] mtype = mimetypes.guess_type(file)[0]
headers = mimetools.Message(cStringIO.StringIO( headers = mimetools.Message(StringIO(
'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' % 'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' %
(mtype or 'text/plain', size, modified))) (mtype or 'text/plain', size, modified)))
if host: if host:
...@@ -70,14 +69,14 @@ class DirectoryFileHandler(urllib2.FileHandler): ...@@ -70,14 +69,14 @@ class DirectoryFileHandler(urllib2.FileHandler):
(not port and socket.gethostbyname(host) in self.get_names()): (not port and socket.gethostbyname(host) in self.get_names()):
try: try:
file_list = dircache.listdir(localfile) file_list = dircache.listdir(localfile)
s = cStringIO.StringIO() s = StringIO()
s.write('<html><head><base href="%s"/></head><body>' % ('file:' + file)) s.write('<html><head><base href="%s"/></head><body>' % ('file:' + file))
s.write('<p>Directory Content:</p>') s.write('<p>Directory Content:</p>')
for f in file_list: for f in file_list:
s.write('<p><a href="%s">%s</a></p>\n' % (urllib.quote(f), f)) s.write('<p><a href="%s">%s</a></p>\n' % (urllib.quote(f), f))
s.write('</body></html>') s.write('</body></html>')
s.seek(0) s.seek(0)
headers = mimetools.Message(cStringIO.StringIO( headers = mimetools.Message(StringIO(
'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' % 'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' %
('text/html', size, modified))) ('text/html', size, modified)))
return urllib2.addinfourl(s, headers, 'file:' + file) return urllib2.addinfourl(s, headers, 'file:' + file)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment