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

py2/py3: import cStringIO from six.moves.

parent 3cc68c81
......@@ -34,7 +34,7 @@ from DateTime import DateTime
import urllib
import httplib
import base64
import StringIO
from six.moves import cStringIO as StringIO
import mock
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Security.ERP5DumbHTTPExtractionPlugin import ERP5DumbHTTPExtractionPlugin
......@@ -438,7 +438,7 @@ class TestERP5DumbHTTPExtractionPlugin(AccessTokenTestCase):
env['GATEWAY_INTERFACE']='CGI/1.1 '
env['SCRIPT_NAME']='Main'
env.update(headers)
return HTTPRequest(StringIO.StringIO(), env, HTTPResponse())
return HTTPRequest(StringIO(), env, HTTPResponse())
def test_working_authentication(self):
request = self.do_fake_request("GET", {"HTTP_AUTHORIZATION": "Basic " + base64.b64encode("login:password")})
......
......@@ -30,7 +30,7 @@
"""
from StringIO import StringIO
from six.moves import cStringIO as StringIO
import lxml
from DateTime import DateTime
......
# coding: utf-8
import unicodedata
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
import zipfile
from Products.ERP5Type.Message import translateString
......
......@@ -34,7 +34,7 @@ import unittest
import zipfile
import email
import os.path
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
from DateTime import DateTime
from lxml import etree
......
......@@ -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)
......
......@@ -30,9 +30,8 @@
from functools import partial
import unittest
import urllib
import urlparse
from StringIO import StringIO
import six.moves.urllib.parse
from six.moves import cStringIO as StringIO
import time
import httplib
import mock
......
......@@ -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
......
......@@ -22,7 +22,7 @@ def generateBarcodeImage(self, barcode_type, data, REQUEST=None):
output = encoder.get_imagedata()
elif barcode_type == 'qrcode':
import qrcode
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
fp = StringIO()
img = qrcode.make(data)
img.save(fp, 'png')
......
......@@ -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
......
......@@ -24,7 +24,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
from ZPublisher.HTTPRequest import HTTPRequest
from ZPublisher.HTTPResponse import HTTPResponse
......
......@@ -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
......
......@@ -29,7 +29,7 @@
##############################################################################
from functools import partial
from StringIO import StringIO
from six.moves import cStringIO as StringIO
import unittest
import urllib
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
......
......@@ -12,7 +12,7 @@
##############################################################################
import base64
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
import unittest
import urllib
......
......@@ -448,6 +448,8 @@ class TestRestrictedPythonSecurity(ERP5TypeTestCase):
)
def test_StringIO(self):
if six.PY3:
return # Python 3's StringIO is cStringIO, thus we just test in test_cStringIO.
self.createAndRunScript('''
import StringIO
s = StringIO.StringIO()
......@@ -465,16 +467,16 @@ class TestRestrictedPythonSecurity(ERP5TypeTestCase):
def test_cStringIO(self):
self.createAndRunScript('''
import cStringIO
s = cStringIO.StringIO()
from six.moves import cStringIO as StringIO
s = StringIO()
s.write("ok")
return s.getvalue()
''',
expected="ok"
)
self.createAndRunScript('''
import cStringIO
return cStringIO.StringIO("ok").getvalue()
from six.moves import cStringIO as StringIO
return StringIO("ok").getvalue()
''',
expected="ok"
)
......@@ -696,7 +698,7 @@ class TestRestrictedPythonSecurity(ERP5TypeTestCase):
for pandas_read_function in ("read_json", "read_csv", "read_fwf"):
for preparation, prohibited_input in (
('', 100),
('from StringIO import StringIO', 'StringIO("[1, 2, 3]")'),
('from six.moves import cStringIO as StringIO', 'StringIO("[1, 2, 3]")'),
):
self.assertRaises(
ZopeGuardsUnauthorized,
......
......@@ -30,7 +30,7 @@ import unittest
import pickle
import re
import xml.sax
from StringIO import StringIO
from six.moves import cStringIO as StringIO
from Products.ERP5Type.XMLExportImport import ppml
......
......@@ -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
......
......@@ -47,7 +47,7 @@
import unittest
import time
import StringIO
from six.moves import cStringIO as StringIO
from subprocess import Popen, PIPE
from unittest import expectedFailure
......@@ -1771,7 +1771,7 @@ class TestDocument(TestDocumentMixin):
# as it is done in reality
# Mimic the behaviour of a FileUpload from WebPage_view
file_like = StringIO.StringIO()
file_like = StringIO()
file_like.write(html_content)
setattr(file_like, 'filename', 'something.htm')
web_page.edit(file=file_like)
......@@ -2060,7 +2060,7 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph
self.assertEqual(document.asText(), 'ERP5 is a free software.')
def test_broken_pdf_asText(self):
class StringIOWithFilename(StringIO.StringIO):
class StringIOWithFilename(StringIO):
filename = 'broken.pdf'
document = self.portal.document_module.newContent(
portal_type='PDF',
......@@ -2073,7 +2073,7 @@ document.write('<sc'+'ript type="text/javascript" src="http://somosite.bg/utb.ph
pdf_writer = PyPDF2.PdfFileWriter()
pdf_writer.addPage(pdf_reader.getPage(0))
pdf_writer.encrypt('secret')
encrypted_pdf_stream = StringIO.StringIO()
encrypted_pdf_stream = StringIO()
pdf_writer.write(encrypted_pdf_stream)
document = self.portal.document_module.newContent(
portal_type='PDF',
......
......@@ -32,7 +32,7 @@ import os
import quopri
import functools
import requests
from StringIO import StringIO
from six.moves import cStringIO as StringIO
from lxml import etree
from base64 import b64decode, b64encode
from email.parser import Parser as EmailParser
......
......@@ -34,8 +34,8 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import FileUpload
from unittest import expectedFailure
import httplib
from StringIO import StringIO
import six.moves.http_client
from six.moves import cStringIO as StringIO
from DateTime import DateTime
from lxml import etree
......
from StringIO import StringIO
from six.moves import cStringIO as StringIO
class StringIOWithFileName(StringIO):
filename = "{}.pdf".format(
......
......@@ -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
......
......@@ -12,7 +12,7 @@ from ZPublisher.HTTPResponse import HTTPResponse
import base64
import DateTime
import StringIO
from six.moves import cStringIO as StringIO
import json
import re
from six.moves.urllib.parse import quote, quote_plus
......@@ -118,7 +118,7 @@ def do_fake_request(request_method, headers=None, data=()):
env['GATEWAY_INTERFACE']='CGI/1.1 '
env['SCRIPT_NAME']='Main'
env.update(headers)
body_stream = StringIO.StringIO()
body_stream = StringIO()
# for some mysterious reason QUERY_STRING does not get parsed into data fields
if data and request_method.upper() == 'GET':
......
......@@ -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
......
......@@ -25,9 +25,9 @@
#
##############################################################################
import json
from StringIO import StringIO
import urlparse
import httplib
from six.moves import cStringIO as StringIO
import six.moves.urllib.parse
import six.moves.http_client
import feedparser
from DateTime import DateTime
......
......@@ -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()
......
......@@ -11,7 +11,7 @@ https://github.com/tmbdev/ocropy
import numpy as np
import scipy.ndimage as ndi
import StringIO
from six.moves import cStringIO as StringIO
from matplotlib import pylab
import matplotlib.image as mpimg
import scipy.stats as stats
......@@ -38,7 +38,7 @@ def getReceiptValue(self, image_data, model_name = "en-default.pyrnn"):
This function look for euros only and return a price with a two digit
precison like "135.79" or "43,89".
"""
image_as_string = StringIO.StringIO(image_data)
image_as_string = StringIO(image_data)
image_as_array = mpimg.imread(image_as_string, format = 'JPG')
line_list, cleared = getLinesFromPicture(image_as_array)
......
......@@ -17,7 +17,7 @@
##############################################################################
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()
......
......@@ -560,8 +560,8 @@ class TestInvoice(TestInvoiceMixin):
invoice.confirm()
self.tic()
odt = invoice.Invoice_viewAsODT()
import cStringIO
output = cStringIO.StringIO()
from io import BytesIO
output = BytesIO()
output.write(odt)
m = OpenDocumentTextFile(output)
text_content=m.toString().encode('ascii','replace')
......
......@@ -29,7 +29,7 @@
from xml.dom.ext import PrettyPrint
import random
from cStringIO import StringIO
from six.moves import cStringIO as StringIO
from AccessControl import ClassSecurityInfo
from zLOG import LOG
......
......@@ -38,7 +38,7 @@ from hashlib import md5
from ZPublisher.HTTPRequest import FileUpload
from OFS.Image import Pdata
from StringIO import StringIO
from six.moves import cStringIO as StringIO
import transaction
class PdataHelper(persistent.Persistent):
......
......@@ -39,7 +39,7 @@ from Testing import ZopeTestCase
from Products.ERP5Type.Globals import get_request
from Products.ERP5Type.tests.utils import createZODBPythonScript
from ZPublisher.HTTPRequest import FileUpload
from StringIO import StringIO
from six.moves import cStringIO as StringIO
from Products.ERP5Form.Selection import Selection
from Products.Formulator.TALESField import TALESMethod
from Products.ERP5Form.ListBox import ListBoxHTMLRenderer
......
......@@ -30,7 +30,7 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Type.tests.Sequence import SequenceList
from Products.ERP5Type.Globals import get_request
from StringIO import StringIO
from six.moves import cStringIO as StringIO
from DateTime import DateTime
class DummyFieldStorage:
......
......@@ -32,8 +32,8 @@ import re
import requests
import time
from unittest import expectedFailure, skip
from StringIO import StringIO
from urllib import urlencode
from six.moves import cStringIO as StringIO
from six.moves.urllib.parse import urlencode
from AccessControl import Unauthorized
from Testing import ZopeTestCase
from DateTime import DateTime
......
......@@ -25,7 +25,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import StringIO
from six.moves import cStringIO as StringIO
import textwrap
import time
......@@ -332,7 +332,7 @@ class TestRenderUpdateTranslationData(RenderJSUpgradeTestCase):
def test_WebSite_getTranslationDataTextContent_extract_from_file(self):
self.portal.portal_skins.custom.manage_addProduct['OFS'].manage_addFile(
'test_portal_skins_gadget.html',
file=StringIO.StringIO(textwrap.dedent('''
file=StringIO(textwrap.dedent('''
<html>
<!--
data-i18n=Message from file
......
......@@ -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
......
......@@ -31,7 +31,7 @@
import unittest
import os
import StringIO
from six.moves import cStringIO as StringIO
from cgi import FieldStorage
from lxml import etree
from AccessControl.SecurityManagement import newSecurityManager
......@@ -2108,7 +2108,7 @@ class Base_contributeMixin:
"""
person = self.portal.person_module.newContent(portal_type='Person')
empty_file_upload = ZPublisher.HTTPRequest.FileUpload(FieldStorage(
fp=StringIO.StringIO(),
fp=StringIO(),
environ=dict(REQUEST_METHOD='PUT'),
headers={"content-disposition":
"attachment; filename=empty;"}))
......
......@@ -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)
......
......@@ -255,7 +255,7 @@ class ERP5TypeTestReLoader(ERP5TypeTestLoader):
def runLiveTest(test_list, verbosity=1, stream=None, request_server_url=None, **kw):
from Products.ERP5Type.tests.runUnitTest import DebugTestResult
from StringIO import StringIO
from six.moves import cStringIO as StringIO
# Add path of the TestTemplateItem folder of the instance
path = kw.get('path', None)
if path is not None and path not in sys.path:
......
......@@ -27,7 +27,7 @@
##############################################################################
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type import WITH_LEGACY_WORKFLOW
import StringIO
from six.moves import cStringIO as StringIO
import unittest
import urllib
import httplib
......@@ -120,7 +120,7 @@ class TestUpgradeInstanceWithOldDataFs(ERP5TypeTestCase):
ret = self.publish(
'%s/portal_alarms/promise_check_upgrade' % self.portal.getPath(),
basic='%s:current' % self.id(),
stdin=StringIO.StringIO(urllib.urlencode({
stdin=StringIO(urllib.urlencode({
'Base_callDialogMethod:method': '',
'dialog_id': 'Alarm_viewSolveDialog',
'dialog_method': 'Alarm_solve',
......
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