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

py2/py3: import cStringIO from six.moves.

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