Commit c25900c7 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

py2/py3: import cStringIO from six.moves.

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