Commit 319b0c4e authored by Jérome Perrin's avatar Jérome Perrin

*: fix python2 compatibility with base64.encodebytes

parent 76de408d
......@@ -4,13 +4,17 @@ from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject
import hashlib
from zLOG import LOG, WARNING
import base64
import datetime
import os
import time
import requests
from Products.ERP5Type.Core.Workflow import ValidationFailed
import six
import six
if six.PY2:
from base64 import encodestring as base64_encodebytes
else:
from base64 import encodebytes as base64_encodebytes
present = False
tz = None
......@@ -54,7 +58,7 @@ class PayzenREST:
"""
def callPayzenApi(self, URL, payzen_dict):
base64string = base64.encodebytes(
base64string = base64_encodebytes(
('%s:%s' % (
self.getServiceUsername(),
self.getServiceApiKey())).encode()).decode().replace('\n', '')
......
import base64
import six
# pylint:disable=no-name-in-module
if six.PY2:
from base64 import encodestring as encodebytes
else:
from base64 import encodebytes
# pylint:enable=no-name-in-module
portal = context.getPortalObject()
expense_record_module = portal.getDefaultModule('Expense Record')
sender = portal.portal_membership.getAuthenticatedMember().getUserValue()
data = bytes(context.getData())
data64 = u''.join(base64.encodebytes(data).decode().splitlines())
photo_data = u'data:%s;base64,%s' % ("image/*", data64)
data64 = ''.join(encodebytes(data).decode().splitlines())
photo_data = 'data:%s;base64,%s' % ("image/*", data64)
expense_record_module.newContent(
comment=comment,
resource_title=currency,
......
......@@ -83,9 +83,15 @@ class DocumentProxyError(Exception):pass
class NotConvertedError(Exception):pass
allow_class(NotConvertedError)
import six
import base64
enc = base64.encodebytes
dec = base64.decodebytes
if six.PY2:
enc = base64.encodestring
dec = base64.decodestring
else:
enc = base64.encodebytes
dec = base64.decodebytes
DOCUMENT_CONVERSION_SERVER_PROXY_TIMEOUT = 360
DOCUMENT_CONVERSION_SERVER_RETRY = 0
# store time (as int) where we had last failure in order
......
......@@ -28,7 +28,11 @@
##############################################################################
from warnings import warn
from base64 import decodebytes
import six
if six.PY2:
from base64 import decodestring as decodebytes
else:
from base64 import decodebytes
from zLOG import LOG
from AccessControl import ClassSecurityInfo, getSecurityManager
......
......@@ -27,7 +27,11 @@
#
##############################################################################
from base64 import encodebytes, decodebytes
import six
if six.PY2:
from base64 import encodestring as encodebytes, decodestring as decodebytes
else:
from base64 import encodebytes, decodebytes
from six.moves.urllib.parse import quote, unquote
from DateTime import DateTime
from zLOG import LOG, PROBLEM
......@@ -54,7 +58,6 @@ from Products import ERP5Security
# TODO pycrypto is obsolete and should be replaced by cryptography or pycryptodome
from Crypto.Cipher import AES
from Crypto import Random
import six
if six.PY3:
import time
time.clock = time.process_time
......
......@@ -18,14 +18,18 @@ from __future__ import absolute_import
from copy import deepcopy
from collections import defaultdict
from base64 import encodebytes
import six
if six.PY2:
from base64 import encodestring as encodebytes
else:
from base64 import encodebytes
from Acquisition import aq_inner, aq_parent
from AccessControl.Permissions import manage_users as ManageUsers
from Products.PluggableAuthService.PluggableAuthService import registerMultiPlugin
from Products.PluggableAuthService.permissions import ManageGroups
from Products.ERP5Type import IS_ZOPE2
import six
# This user is used to bypass all security checks.
SUPER_USER = '__erp5security-=__'
......
......@@ -37,7 +37,6 @@ from .BaseCache import BaseCache
from .BaseCache import CacheEntry
from Products.ERP5Type import interfaces
import zope.interface
from base64 import encodebytes
try:
from Products.ERP5Type.Tool.MemcachedTool import MemcachedDict, SharedDict
......
......@@ -48,13 +48,16 @@ from lxml import etree
from lxml.etree import Element, SubElement
from xml_marshaller.xml_marshaller import Marshaller
from OFS.Image import Pdata
from base64 import standard_b64encode, encodebytes
import six
if six.PY2:
from base64 import standard_b64encode, encodestring as encodebytes
else:
from base64 import standard_b64encode, encodebytes
from hashlib import sha1
from Products.ERP5Type.Utils import ensure_list
#from zLOG import LOG
import six
try:
long_ = long
except NameError: # six.PY3
......
......@@ -20,14 +20,18 @@
from zodbpickle.slowpickle import *
import struct
import base64
import six
if six.PY2:
from base64 import encodestring as base64_encodebytes, decodestring as base64_decodebytes
else:
from base64 import encodebytes as base64_encodebytes, decodebytes as base64_decodebytes
import re
from marshal import loads as mloads
from .xyap import NoBlanks
from .xyap import xyap
from Products.ERP5Type.Utils import str2bytes
import six
from marshal import dumps as mdumps
#from zLOG import LOG
......@@ -42,7 +46,7 @@ else:
def escape(s, encoding='repr'):
if binary(s) and isinstance(s, str):
s = base64.encodebytes(s)[:-1]
s = base64_encodebytes(s)[:-1]
encoding = 'base64'
elif '>' in s or '<' in s or '&' in s:
if not ']]>' in s:
......@@ -56,7 +60,7 @@ def escape(s, encoding='repr'):
def unescape(s, encoding):
if encoding == 'base64':
return base64.decodebytes(s)
return base64_decodebytes(s)
else:
s = s.replace(b'&lt;', b'<')
s = s.replace(b'&gt;', b'>')
......@@ -92,7 +96,7 @@ def convert(S):
if not isinstance(S, six.text_type):
S = S.decode('utf8')
except UnicodeDecodeError:
return 'base64', base64.encodebytes(S)[:-1]
return 'base64', base64_encodebytes(S)[:-1]
else:
new = reprs_re.sub(sub_reprs, S)
### patch end
......@@ -100,7 +104,7 @@ def convert(S):
if not isinstance(S, six.binary_type):
# TODO zope4py3: is this the right place ? this supports Unicode('\n')
S = S.encode('ascii')
return 'base64', base64.encodebytes(S)[:-1]
return 'base64', base64_encodebytes(S)[:-1]
elif '>' in new or '<' in S or '&' in S:
if not ']]>' in S:
return 'cdata', '<![CDATA[\n\n' + new + '\n\n]]>'
......@@ -111,7 +115,7 @@ def convert(S):
# For optimization.
def unconvert(encoding,S):
if encoding == 'base64':
return base64.decodebytes(S)
return base64_decodebytes(S)
else:
return str2bytes(eval(b"'" + S.replace(b'\n', b'') + b"'"))
......@@ -180,7 +184,7 @@ class String(Scalar):
# This is used when strings represent references which need to
# be converted.
encoding = 'base64'
v = base64.encodebytes(self._v)[:-1]
v = base64_encodebytes(self._v)[:-1]
self._v = self.mapping.convertBase64(v).decode()
else:
encoding, self._v = convert(self._v)
......
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