Commit ad2c135c authored by Jérome Perrin's avatar Jérome Perrin

*: use base64 encodebytes for python3.9

parent d46d4761
......@@ -73,7 +73,7 @@ class ERP5CookieCrumblerTests (CookieCrumblerTests):
self.req = makerequest(root, self.responseOut)
self.credentials = quote(
base64.encodestring('abraham:pass-w').replace('\012', ''))
base64.encodebytes('abraham:pass-w').replace('\012', ''))
def testCookieLongLogin(self):
# verify the user and auth cookie get set
......@@ -88,7 +88,7 @@ class ERP5CookieCrumblerTests (CookieCrumblerTests):
'abrahammmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm')
resp = self.req.response
self.assertIn('__ac', resp.cookies)
self.credentials = base64.encodestring('%s:%s' % (long_name, long_pass)).replace('\012', '')
self.credentials = base64.encodebytes('%s:%s' % (long_name, long_pass)).replace('\012', '')
self.assertEqual(resp.cookies['__ac']['value'],
self.credentials)
self.assertEqual(resp.cookies['__ac'][normalizeCookieParameterName('path')], '/')
......
......@@ -58,8 +58,8 @@ def convertToOdf(self, name, data):
to work with (and we for example have to figure out portal_type)
"""
sp = mkProxy(self)
kw = sp.run_convert(name,base64.encodestring(data))
odf = base64.decodestring(kw['data'])
kw = sp.run_convert(name,base64.encodebytes(data))
odf = base64.decodebytes(kw['data'])
return odf
def mkProxy(self):
......@@ -74,7 +74,7 @@ def mkProxy(self):
def generateFile(self, name, data, format): # pylint: disable=redefined-builtin
sp = mkProxy(self)
kw = sp.run_generate(name, data, None, format)
res = base64.decodestring(kw['data'])
res = base64.decodebytes(kw['data'])
return res
def getAttrFromFilename(self, fname):
......
"""
Proxy role as Manager is required here to access getResultList
"""
from base64 import decodestring
from base64 import decodebytes
if REQUEST:
return RuntimeError("You cannot run this script in the url")
......@@ -11,7 +11,7 @@ pdf_data_list = []
for result in active_process.getResultList():
if result.reference in image_list:
pdf_data_list.append(
image_module.newContent(data=decodestring(result.detail),
image_module.newContent(data=decodebytes(result.detail),
portal_type="Image",
temp_object=True).convert(format="pdf")[1])
......
......@@ -782,7 +782,7 @@ class TestOAuth2(ERP5TypeTestCase):
"""
Get a token, renew it, terminate session.
"""
basic_auth = 'Basic ' + bytes2str(base64.encodestring(
basic_auth = 'Basic ' + bytes2str(base64.encodebytes(
str2bytes(_TEST_USER_LOGIN + ':' + self.__password),
)).rstrip()
oauth2_server_connector = self.__oauth2_server_connector_value.getPath()
......
......@@ -157,7 +157,7 @@ class _SimpleHTTPRequest(object):
def _authUserPW(self):
if self._auth.lower().startswith('basic '):
return bytes2str(base64.decodestring(
return bytes2str(base64.decodebytes(
self._auth.split(None, 1)[1],
)).split(':', 1)
......
......@@ -20,7 +20,7 @@ except KeyError:
try:
encoded = name.replace("definition_view/", "", 1)
name = base64.decodestring(encoded)
name = base64.decodebytes(encoded)
base_64 = True
except binascii.Error:
pass
......
......@@ -54,7 +54,7 @@ class PayzenREST:
"""
def callPayzenApi(self, URL, payzen_dict):
base64string = base64.encodestring(
base64string = base64.encodebytes(
'%s:%s' % (
self.getServiceUsername(),
self.getServiceApiKey())).replace('\n', '')
......
......@@ -3,7 +3,7 @@ portal = context.getPortalObject()
expense_record_module = portal.getDefaultModule('Expense Record')
sender = portal.portal_membership.getAuthenticatedMember().getUserValue()
data = context.getData()
data64 = u''.join(base64.encodestring(data).splitlines())
data64 = u''.join(base64.encodebytes(data).splitlines())
photo_data = u'data:%s;base64,%s' % ("image/*", data64)
expense_record_module.newContent(
comment=comment,
......
......@@ -36,7 +36,7 @@ To send specific encoded data, please make your attachment dict look like:
"mime_type": "text/html",
"encode": "noop",
"add_header_list": [("Content-Transfer-Encoding", "my-encoding")],
"data": encodestring(html_data),
"data": encodebytes(html_data),
}
"""
......
......@@ -48,7 +48,7 @@ class ShaCacheMixin(object):
self.shacache.publish()
self.header_dict = {
'Content-Type': 'application/json',
'Authorization': 'Basic %s' % (base64.encodestring('ERP5TypeTestCase:').strip())
'Authorization': 'Basic %s' % (base64.encodebytes('ERP5TypeTestCase:').strip())
}
self.shacache_url = self.shacache.absolute_url()
self.tic()
......
......@@ -60,7 +60,7 @@ class TestShaCacheExternal(ShaCacheMixin, ShaSecurityMixin, ERP5TypeTestCase):
# Define POST headers with Authentication
self.content_type = 'application/json'
authentication_string = 'lucas:lucas'
base64string = base64.encodestring(authentication_string).strip()
base64string = base64.encodebytes(authentication_string).strip()
self.header_dict = {'Authorization': 'Basic %s' % base64string,
'Content-Type': self.content_type}
......
......@@ -61,7 +61,7 @@ class TestShaDirExternal(ShaDirMixin, ShaSecurityMixin, ERP5TypeTestCase):
# Define POST headers with Authentication
self.content_type = 'application/json'
authentication_string = 'lucas:lucas'
base64string = base64.encodestring(authentication_string).strip()
base64string = base64.encodebytes(authentication_string).strip()
self.header_dict = {'Authorization': 'Basic %s' % base64string,
'Content-Type': self.content_type}
......
......@@ -45,7 +45,7 @@ zope_url = url.rsplit('/', 2)[0]
import base64
browser.mech_browser.addheaders.append(
('Authorization',
'Basic %s' % base64.encodestring('%s:%s' % (username, password))))
'Basic %s' % base64.encodebytes('%s:%s' % (username, password))))
for index in range(user_nbr):
new_username = "%s%d" % (new_username_prefix, index)
......
......@@ -64,7 +64,7 @@ import struct
from base64 import b64encode, b64decode
from Products.ERP5Type.Message import translateString
from zLOG import LOG, INFO, WARNING
from base64 import decodestring
from base64 import decodebytes
import subprocess
import time
from Products.ERP5Type.Utils import bytes2str, str2bytes, unicode2str
......@@ -410,7 +410,7 @@ class TemplateTool (BaseTool):
"""
Import Business Template from passed base64 encoded text.
"""
import_file = StringIO(decodestring(file_data))
import_file = StringIO(decodebytes(file_data))
return self.importFile(import_file = import_file, id = id, REQUEST = REQUEST,
batch_mode = batch_mode, **kw)
......
......@@ -4,7 +4,7 @@ import six.moves.http_client
connection = six.moves.http_client.HTTPConnection('192.168.242.68:12001')
import base64
base64string = base64.encodestring('zope:insecure')[:-1]
base64string = base64.encodebytes('zope:insecure')[:-1]
n = 1 << 20
......
......@@ -84,8 +84,8 @@ class NotConvertedError(Exception):pass
allow_class(NotConvertedError)
import base64
enc = base64.encodestring
dec = base64.decodestring
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,7 @@
##############################################################################
from warnings import warn
from base64 import decodestring
from base64 import decodebytes
from zLOG import LOG
from AccessControl import ClassSecurityInfo, getSecurityManager
......@@ -106,7 +106,7 @@ class BaseExtensibleTraversableMixin(ExtensibleTraversableMixin):
# this logic is copied from identify() in
# AccessControl.User.BasicUserFolder.
if auth and auth.lower().startswith('basic '):
name = decodestring(auth.split(' ')[-1]).split(':', 1)[0]
name = decodebytes(auth.split(' ')[-1]).split(':', 1)[0]
if name is not None:
user = portal_membership._huntUser(name, self)
else:
......
......@@ -99,7 +99,7 @@ class URLOpener(FancyURLopener):
if not host: raise IOError('http error', 'no host given')
if user_passwd:
import base64
auth = base64.encodestring(user_passwd).strip()
auth = base64.encodebytes(user_passwd).strip()
else:
auth = None
h = six.moves.http_client.HTTP(host)
......
......@@ -27,7 +27,7 @@
#
##############################################################################
from base64 import encodestring, decodestring
from base64 import encodebytes, decodebytes
from six.moves.urllib.parse import quote, unquote
from DateTime import DateTime
from zLOG import LOG, PROBLEM
......@@ -270,7 +270,7 @@ class ERP5KeyAuthPlugin(ERP5UserManager, CookieAuthHelper):
default_cookie = request.get(self.default_cookie_name, None)
if default_cookie is not None:
#Cookie is found
cookie_val = decodestring(unquote(default_cookie))
cookie_val = decodebytes(unquote(default_cookie))
if cookie_val is not None:
login, password = cookie_val.split(':')
creds['login'] = login
......@@ -305,7 +305,7 @@ class ERP5KeyAuthPlugin(ERP5UserManager, CookieAuthHelper):
response.setCookie(self.cookie_name, quote(cookie_val), path='/')#, expires=expires)
response.expireCookie(self.default_cookie_name, path='/')
elif login is not None and new_password is not None:
cookie_val = encodestring('%s:%s' % (login, new_password))
cookie_val = encodebytes('%s:%s' % (login, new_password))
cookie_val = cookie_val.rstrip()
response.setCookie(self.default_cookie_name, quote(cookie_val), path='/')
response.expireCookie(self.cookie_name, path='/')
......
......@@ -18,7 +18,7 @@ from __future__ import absolute_import
from copy import deepcopy
from collections import defaultdict
from base64 import encodestring
from base64 import encodebytes
from Acquisition import aq_inner, aq_parent
from AccessControl.Permissions import manage_users as ManageUsers
......@@ -77,7 +77,7 @@ if IS_ZOPE2: # BBB
except AttributeError:
pass
else:
medusa_headers['authorization'] = 'Basic %s' % encodestring('%s:' % username).rstrip()
medusa_headers['authorization'] = 'Basic %s' % encodebytes('%s:' % username).rstrip()
else:
REQUEST._orig_env['REMOTE_USER'] = username
else: # zope4
......
......@@ -37,7 +37,7 @@ from .BaseCache import BaseCache
from .BaseCache import CacheEntry
from Products.ERP5Type import interfaces
import zope.interface
from base64 import encodestring
from base64 import encodebytes
try:
from Products.ERP5Type.Tool.MemcachedTool import MemcachedDict, SharedDict
......
......@@ -233,7 +233,7 @@ def Folder_asXML(object, omit_xml_declaration=True, root=None):
## The code below was initially from OFS.XMLExportImport
from six import string_types as basestring
from base64 import encodestring
from base64 import encodebytes
from ZODB.serialize import referencesf
from ZODB.ExportImport import TemporaryFile, export_end_marker
from ZODB.utils import p64
......@@ -293,8 +293,8 @@ def reorderPickle(jar, p):
def _mapOid(id_mapping, oid):
idprefix = str(u64(oid))
id = id_mapping[idprefix]
old_aka = encodestring(oid)[:-1]
aka=encodestring(p64(long_(id)))[:-1] # Rebuild oid based on mapped id
old_aka = encodebytes(oid)[:-1]
aka=encodebytes(p64(long_(id)))[:-1] # Rebuild oid based on mapped id
id_mapping.setConvertedAka(old_aka, aka)
return idprefix+'.', id, aka
......
......@@ -42,7 +42,7 @@ else:
def escape(s, encoding='repr'):
if binary(s) and isinstance(s, str):
s = base64.encodestring(s)[:-1]
s = base64.encodebytes(s)[:-1]
encoding = 'base64'
elif '>' in s or '<' in s or '&' in s:
if not ']]>' in s:
......@@ -56,7 +56,7 @@ def escape(s, encoding='repr'):
def unescape(s, encoding):
if encoding == 'base64':
return base64.decodestring(s)
return base64.decodebytes(s)
else:
s = s.replace(b'&lt;', b'<')
s = s.replace(b'&gt;', b'>')
......@@ -92,12 +92,12 @@ def convert(S):
if not isinstance(S, six.text_type):
S.decode('utf8')
except UnicodeDecodeError:
return 'base64', base64.encodestring(S)[:-1]
return 'base64', base64.encodebytes(S)[:-1]
else:
new = reprs_re.sub(sub_reprs, S)
### patch end
if len(new) > (1.4*len(S)):
return 'base64', base64.encodestring(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]]>'
......@@ -108,7 +108,7 @@ def convert(S):
# For optimization.
def unconvert(encoding,S):
if encoding == 'base64':
return base64.decodestring(S)
return base64.decodebytes(S)
else:
return str2bytes(eval(b"'" + S.replace(b'\n', b'') + b"'"))
......@@ -173,7 +173,7 @@ class String(Scalar):
# This is used when strings represent references which need to
# be converted.
encoding = 'base64'
v = base64.encodestring(self._v)[:-1]
v = base64.encodebytes(self._v)[:-1]
self._v = self.mapping.convertBase64(v)
else:
encoding, self._v = convert(self._v)
......
......@@ -192,7 +192,7 @@ def credentialsChanged(self, user, name, pw, request=None):
reponse = request['RESPONSE']
# <patch>
# We don't want new lines, so use base64.standard_b64encode instead of
# base64.encodestring
# base64.encodebytes
ac = standard_b64encode('%s:%s' % (name, pw)).rstrip()
# </patch>
method = self.getCookieMethod('setAuthCookie',
......
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