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

py2/py3: str.decode('base64') and bytes.encode('base64') don't exist in Python 3.

parent fe8749a8
......@@ -29,6 +29,8 @@
import urllib2
from lxml import etree
from erp5.component.document.Document import ConversionError
import base64
from Products.ERP5Type.Utils import bytes2str
SVG_DEFAULT_NAMESPACE = "http://www.w3.org/2000/svg"
......@@ -38,7 +40,7 @@ def getDataURI(url):
except Exception as e:
raise ConversionError("Error to transform url (%s) into data uri. ERROR = %s" % (url, Exception(e)))
return 'data:%s;base64,%s' % (data.info()["content-type"],
data.read().encode("base64").replace('\n', ""))
bytes2str(base64.b64encode(data.read())).replace('\n', ""))
def transformUrlToDataURI(content):
if content is None or len(content) == 0:
......
......@@ -104,7 +104,7 @@
<draw:frame draw:style-name="fr1" draw:name="Image1" text:anchor-type="as-char" svg:width="3in" draw:z-index="0"
tal:attributes="draw:name python:'embedded_erp5_image_%s' % image.getId();
svg:height python: '%1.1fin' % (3.0 * image.getHeight() / (image.getWidth() or 1.0))">
<draw:image><office:binary-data tal:content="python:str(image.convert(format='png')[1]).encode('base64')" /></draw:image>
<draw:image><office:binary-data tal:content="python:modules['base64'].b64encode(image.convert(format='png')[1])" /></draw:image>
</draw:frame>
</text:p>
</tal:block>
......
......@@ -29,6 +29,7 @@
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from erp5.component.test.testDms import makeFileUpload
from time import time
import base64
class TestRunMyDoc(ERP5TypeTestCase):
"""
......@@ -132,7 +133,7 @@ class TestRunMyDoc(ERP5TypeTestCase):
self.tic()
# The right image were updated.
image_upload.seek(0)
self.assertEqual(image_page_2.getData(), image_upload.read().decode("base64"))
self.assertEqual(image_page_2.getData(), base64.b64decode(image_upload.read()))
self.assertEqual(image_page_2.getFilename(), image_reference + '.png')
self.assertEqual(image_page.getData(), '')
......
import base64
portal = context.getPortalObject()
# Update Photos
......@@ -9,7 +10,7 @@ for record in portal.expense_record_module.objectValues(portal_type="Expense Rec
if ticket.getReference():
photo_data = photo_data.split(",")[1]
image = portal.portal_contributions.newContent(
data = photo_data.decode('base64'),
data = base64.b64decode(photo_data),
reference=ticket.getReference()+ "-justificatif",
title = ticket.getReference() + " Justificatif",
description = ticket.getDescription(),
......
import base64
import json
portal = context.getPortalObject()
record = context
......@@ -80,7 +81,7 @@ if photo_data:
if "application/pdf" in photo_type:
filename="tmp.pdf"
image = portal.portal_contributions.newContent(
data = photo_data.decode('base64'),
data = base64.b64decode(photo_data),
reference=ticket.getReference()+ "-justificatif",
title = ticket.getReference() + " Justificatif",
description = ticket.getDescription(),
......
"""
Upload a screenshot taken by the test to ERP5
"""
import base64
data_uri = context.REQUEST.form.get('data_uri', 'default')
image_module = getattr(context, "image_module", None)
......@@ -16,7 +17,7 @@ if image is None or image.getPortalType() != "Image":
image.setContentType('image/png')
data_text = data_uri.read()
data = data_text.decode('base64')
data = base64.b64decode(data_text)
image.edit(data=data,
filename=str(image_reference) + '.png',
......
......@@ -30,6 +30,7 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import \
ERP5TypeTestCase, immediateCompilation
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
from runUnitTest import tests_home
import base64
import glob
import shutil
import os
......@@ -280,9 +281,9 @@ class TestBusinessTemplateTwoFileExport(ERP5TypeTestCase):
self.assertEqual(image_page.getProperty(property_id), property_value)
png_data = """iVBORw0KGgoAAAANSUhEUgAAAAUA
png_data = base64.b64decode(b"""iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==""".decode("base64")
9TXL0Y4OHwAAAABJRU5ErkJggg==""")
def test_twoFileImportExportForImageIdentifyingTypeByContent(self):
"""
......
......@@ -7,6 +7,7 @@ from six.moves import cStringIO as StringIO
from json import dumps
from Acquisition import aq_base
from six.moves.urllib.parse import urljoin
import base64
class GadgetWidget(Widget.Widget):
"""
......@@ -150,7 +151,7 @@ class GadgetFieldValidator(Validator.Validator):
if value is not None:
if field.get_value('data_url'):
value=value.split(",")[1]
return StringIO(value.decode('base64'))
return StringIO(base64.b64decode(value))
return value
......
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