Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
140
Merge Requests
140
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
6512da0d
Commit
6512da0d
authored
Mar 06, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
*: fix python2 compatibility with base64.encodebytes
parent
b664b54f
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
82 additions
and
32 deletions
+82
-32
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testCookieCrumbler.py
...ateItem/portal_components/test.erp5.testCookieCrumbler.py
+7
-3
bt5/erp5_oauth2_authorisation/TestTemplateItem/portal_components/test.erp5.testOAuth2Server.py
...plateItem/portal_components/test.erp5.testOAuth2Server.py
+6
-2
bt5/erp5_payzen_secure_payment/DocumentTemplateItem/portal_components/document.erp5.PayzenService.py
...lateItem/portal_components/document.erp5.PayzenService.py
+6
-2
bt5/erp5_smart_assistant/SkinTemplateItem/portal_skins/erp5_smart_assistant/Query_createExpenseRecord.py
...l_skins/erp5_smart_assistant/Query_createExpenseRecord.py
+8
-2
bt5/erp5_web_shacache/TestTemplateItem/portal_components/test.erp5.ShaCacheMixin.py
...TemplateItem/portal_components/test.erp5.ShaCacheMixin.py
+7
-2
bt5/networkcache_erp5/TestTemplateItem/portal_components/test.erp5.testShaCacheExternal.py
...eItem/portal_components/test.erp5.testShaCacheExternal.py
+6
-2
product/ERP5/bootstrap/erp5_core/DocumentTemplateItem/portal_components/document.erp5.Document.py
...tTemplateItem/portal_components/document.erp5.Document.py
+8
-2
product/ERP5/bootstrap/erp5_core/MixinTemplateItem/portal_components/mixin.erp5.BaseExtensibleTraversableMixin.py
...l_components/mixin.erp5.BaseExtensibleTraversableMixin.py
+5
-1
product/ERP5Security/ERP5KeyAuthPlugin.py
product/ERP5Security/ERP5KeyAuthPlugin.py
+5
-2
product/ERP5Security/__init__.py
product/ERP5Security/__init__.py
+6
-2
product/ERP5Type/CachePlugins/DistributedRamCache.py
product/ERP5Type/CachePlugins/DistributedRamCache.py
+0
-1
product/ERP5Type/XMLExportImport/__init__.py
product/ERP5Type/XMLExportImport/__init__.py
+6
-3
product/ERP5Type/XMLExportImport/ppml.py
product/ERP5Type/XMLExportImport/ppml.py
+12
-8
No files found.
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testCookieCrumbler.py
View file @
6512da0d
...
@@ -11,7 +11,11 @@
...
@@ -11,7 +11,11 @@
#
#
##############################################################################
##############################################################################
import
base64
import
six
if
six
.
PY2
:
from
base64
import
encodestring
as
base64_encodebytes
else
:
from
base64
import
encodebytes
as
base64_encodebytes
from
six.moves
import
cStringIO
as
StringIO
from
six.moves
import
cStringIO
as
StringIO
import
unittest
import
unittest
from
six.moves.urllib.parse
import
quote
from
six.moves.urllib.parse
import
quote
...
@@ -73,7 +77,7 @@ class ERP5CookieCrumblerTests (CookieCrumblerTests):
...
@@ -73,7 +77,7 @@ class ERP5CookieCrumblerTests (CookieCrumblerTests):
self
.
req
=
makerequest
(
root
,
self
.
responseOut
)
self
.
req
=
makerequest
(
root
,
self
.
responseOut
)
self
.
credentials
=
quote
(
self
.
credentials
=
quote
(
base64
.
encodebytes
(
b'abraham:pass-w'
).
decode
().
replace
(
'
\
012
'
,
''
))
base64
_
encodebytes
(
b'abraham:pass-w'
).
decode
().
replace
(
'
\
012
'
,
''
))
def
testCookieLongLogin
(
self
):
def
testCookieLongLogin
(
self
):
# verify the user and auth cookie get set
# verify the user and auth cookie get set
...
@@ -88,7 +92,7 @@ class ERP5CookieCrumblerTests (CookieCrumblerTests):
...
@@ -88,7 +92,7 @@ class ERP5CookieCrumblerTests (CookieCrumblerTests):
'abrahammmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm'
)
'abrahammmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm'
)
resp
=
self
.
req
.
response
resp
=
self
.
req
.
response
self
.
assertIn
(
'__ac'
,
resp
.
cookies
)
self
.
assertIn
(
'__ac'
,
resp
.
cookies
)
self
.
credentials
=
base64
.
encodebytes
((
'%s:%s'
%
(
long_name
,
long_pass
)).
encode
()).
decode
().
replace
(
'
\
012
'
,
''
)
self
.
credentials
=
base64
_
encodebytes
((
'%s:%s'
%
(
long_name
,
long_pass
)).
encode
()).
decode
().
replace
(
'
\
012
'
,
''
)
self
.
assertEqual
(
resp
.
cookies
[
'__ac'
][
'value'
],
self
.
assertEqual
(
resp
.
cookies
[
'__ac'
][
'value'
],
self
.
credentials
)
self
.
credentials
)
self
.
assertEqual
(
resp
.
cookies
[
'__ac'
][
normalizeCookieParameterName
(
'path'
)],
'/'
)
self
.
assertEqual
(
resp
.
cookies
[
'__ac'
][
normalizeCookieParameterName
(
'path'
)],
'/'
)
...
...
bt5/erp5_oauth2_authorisation/TestTemplateItem/portal_components/test.erp5.testOAuth2Server.py
View file @
6512da0d
...
@@ -26,6 +26,11 @@
...
@@ -26,6 +26,11 @@
##############################################################################
##############################################################################
from
__future__
import
print_function
from
__future__
import
print_function
import
base64
import
base64
import
six
if
six
.
PY2
:
from
base64
import
encodestring
as
base64_encodebytes
else
:
from
base64
import
encodebytes
as
base64_encodebytes
from
collections
import
defaultdict
from
collections
import
defaultdict
from
functools
import
partial
,
wraps
from
functools
import
partial
,
wraps
import
hashlib
import
hashlib
...
@@ -37,7 +42,6 @@ import pprint
...
@@ -37,7 +42,6 @@ import pprint
from
time
import
time
from
time
import
time
import
unittest
import
unittest
from
six.moves.urllib.parse
import
parse_qsl
,
quote
,
unquote
,
urlencode
,
urlsplit
,
urlunsplit
from
six.moves.urllib.parse
import
parse_qsl
,
quote
,
unquote
,
urlencode
,
urlsplit
,
urlunsplit
import
six
from
AccessControl.SecurityManagement
import
getSecurityManager
,
setSecurityManager
from
AccessControl.SecurityManagement
import
getSecurityManager
,
setSecurityManager
from
DateTime
import
DateTime
from
DateTime
import
DateTime
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
...
@@ -782,7 +786,7 @@ class TestOAuth2(ERP5TypeTestCase):
...
@@ -782,7 +786,7 @@ class TestOAuth2(ERP5TypeTestCase):
"""
"""
Get a token, renew it, terminate session.
Get a token, renew it, terminate session.
"""
"""
basic_auth
=
'Basic '
+
bytes2str
(
base64
.
encodebytes
(
basic_auth
=
'Basic '
+
bytes2str
(
base64
_
encodebytes
(
str2bytes
(
_TEST_USER_LOGIN
+
':'
+
self
.
__password
),
str2bytes
(
_TEST_USER_LOGIN
+
':'
+
self
.
__password
),
)).
rstrip
()
)).
rstrip
()
oauth2_server_connector
=
self
.
__oauth2_server_connector_value
.
getPath
()
oauth2_server_connector
=
self
.
__oauth2_server_connector_value
.
getPath
()
...
...
bt5/erp5_payzen_secure_payment/DocumentTemplateItem/portal_components/document.erp5.PayzenService.py
View file @
6512da0d
...
@@ -4,13 +4,17 @@ from Products.ERP5Type import Permissions, PropertySheet
...
@@ -4,13 +4,17 @@ from Products.ERP5Type import Permissions, PropertySheet
from
Products.ERP5Type.XMLObject
import
XMLObject
from
Products.ERP5Type.XMLObject
import
XMLObject
import
hashlib
import
hashlib
from
zLOG
import
LOG
,
WARNING
from
zLOG
import
LOG
,
WARNING
import
base64
import
datetime
import
datetime
import
os
import
os
import
time
import
time
import
requests
import
requests
from
Products.ERP5Type.Core.Workflow
import
ValidationFailed
from
Products.ERP5Type.Core.Workflow
import
ValidationFailed
import
six
import
six
import
six
if
six
.
PY2
:
from
base64
import
encodestring
as
base64_encodebytes
else
:
from
base64
import
encodebytes
as
base64_encodebytes
present
=
False
present
=
False
tz
=
None
tz
=
None
...
@@ -54,7 +58,7 @@ class PayzenREST:
...
@@ -54,7 +58,7 @@ class PayzenREST:
"""
"""
def
callPayzenApi
(
self
,
URL
,
payzen_dict
):
def
callPayzenApi
(
self
,
URL
,
payzen_dict
):
base64string
=
base64
.
encodebytes
(
base64string
=
base64
_
encodebytes
(
(
'%s:%s'
%
(
(
'%s:%s'
%
(
self
.
getServiceUsername
(),
self
.
getServiceUsername
(),
self
.
getServiceApiKey
())).
encode
()).
decode
().
replace
(
'
\
n
'
,
''
)
self
.
getServiceApiKey
())).
encode
()).
decode
().
replace
(
'
\
n
'
,
''
)
...
...
bt5/erp5_smart_assistant/SkinTemplateItem/portal_skins/erp5_smart_assistant/Query_createExpenseRecord.py
View file @
6512da0d
import
base64
import
six
if
six
.
PY2
:
from
base64
import
encodestring
as
encodebytes
else
:
from
base64
import
encodebytes
portal
=
context
.
getPortalObject
()
portal
=
context
.
getPortalObject
()
expense_record_module
=
portal
.
getDefaultModule
(
'Expense Record'
)
expense_record_module
=
portal
.
getDefaultModule
(
'Expense Record'
)
sender
=
portal
.
portal_membership
.
getAuthenticatedMember
().
getUserValue
()
sender
=
portal
.
portal_membership
.
getAuthenticatedMember
().
getUserValue
()
data
=
bytes
(
context
.
getData
())
data
=
bytes
(
context
.
getData
())
data64
=
u''
.
join
(
base64
.
encodebytes
(
data
).
decode
().
splitlines
())
data64
=
u''
.
join
(
encodebytes
(
data
).
decode
().
splitlines
())
photo_data
=
u'data:%s;base64,%s'
%
(
"image/*"
,
data64
)
photo_data
=
u'data:%s;base64,%s'
%
(
"image/*"
,
data64
)
expense_record_module
.
newContent
(
expense_record_module
.
newContent
(
comment
=
comment
,
comment
=
comment
,
...
...
bt5/erp5_web_shacache/TestTemplateItem/portal_components/test.erp5.ShaCacheMixin.py
View file @
6512da0d
...
@@ -28,10 +28,15 @@
...
@@ -28,10 +28,15 @@
##############################################################################
##############################################################################
import
base64
import
six
if
six
.
PY2
:
from
base64
import
encodestring
as
base64_encodebytes
else
:
from
base64
import
encodebytes
as
base64_encodebytes
import
hashlib
import
hashlib
import
random
import
random
class
ShaCacheMixin
(
object
):
class
ShaCacheMixin
(
object
):
"""
"""
ShaCache - Mixin Class
ShaCache - Mixin Class
...
@@ -48,7 +53,7 @@ class ShaCacheMixin(object):
...
@@ -48,7 +53,7 @@ class ShaCacheMixin(object):
self
.
shacache
.
publish
()
self
.
shacache
.
publish
()
self
.
header_dict
=
{
self
.
header_dict
=
{
'Content-Type'
:
'application/json'
,
'Content-Type'
:
'application/json'
,
'Authorization'
:
'Basic %s'
%
(
base64
.
encodebytes
(
b'ERP5TypeTestCase:'
).
decode
().
strip
())
'Authorization'
:
'Basic %s'
%
(
base64
_
encodebytes
(
b'ERP5TypeTestCase:'
).
decode
().
strip
())
}
}
self
.
shacache_url
=
self
.
shacache
.
absolute_url
()
self
.
shacache_url
=
self
.
shacache
.
absolute_url
()
self
.
tic
()
self
.
tic
()
...
...
bt5/networkcache_erp5/TestTemplateItem/portal_components/test.erp5.testShaCacheExternal.py
View file @
6512da0d
...
@@ -27,8 +27,12 @@
...
@@ -27,8 +27,12 @@
#
#
##############################################################################
##############################################################################
import
six
if
six
.
PY2
:
from
base64
import
encodestring
as
base64_encodebytes
else
:
from
base64
import
encodebytes
as
base64_encodebytes
import
base64
import
six.moves.http_client
import
six.moves.http_client
from
unittest
import
expectedFailure
from
unittest
import
expectedFailure
from
DateTime
import
DateTime
from
DateTime
import
DateTime
...
@@ -60,7 +64,7 @@ class TestShaCacheExternal(ShaCacheMixin, ShaSecurityMixin, ERP5TypeTestCase):
...
@@ -60,7 +64,7 @@ class TestShaCacheExternal(ShaCacheMixin, ShaSecurityMixin, ERP5TypeTestCase):
# Define POST headers with Authentication
# Define POST headers with Authentication
self
.
content_type
=
'application/json'
self
.
content_type
=
'application/json'
authentication_string
=
b'lucas:lucas'
authentication_string
=
b'lucas:lucas'
base64string
=
base64
.
encodebytes
(
authentication_string
).
decode
().
strip
()
base64string
=
base64
_
encodebytes
(
authentication_string
).
decode
().
strip
()
self
.
header_dict
=
{
'Authorization'
:
'Basic %s'
%
base64string
,
self
.
header_dict
=
{
'Authorization'
:
'Basic %s'
%
base64string
,
'Content-Type'
:
self
.
content_type
}
'Content-Type'
:
self
.
content_type
}
...
...
product/ERP5/bootstrap/erp5_core/DocumentTemplateItem/portal_components/document.erp5.Document.py
View file @
6512da0d
...
@@ -83,9 +83,15 @@ class DocumentProxyError(Exception):pass
...
@@ -83,9 +83,15 @@ class DocumentProxyError(Exception):pass
class
NotConvertedError
(
Exception
):
pass
class
NotConvertedError
(
Exception
):
pass
allow_class
(
NotConvertedError
)
allow_class
(
NotConvertedError
)
import
six
import
base64
import
base64
enc
=
base64
.
encodebytes
if
six
.
PY2
:
dec
=
base64
.
decodebytes
enc
=
base64
.
encodestring
dec
=
base64
.
decodestring
else
:
enc
=
base64
.
encodebytes
dec
=
base64
.
decodebytes
DOCUMENT_CONVERSION_SERVER_PROXY_TIMEOUT
=
360
DOCUMENT_CONVERSION_SERVER_PROXY_TIMEOUT
=
360
DOCUMENT_CONVERSION_SERVER_RETRY
=
0
DOCUMENT_CONVERSION_SERVER_RETRY
=
0
# store time (as int) where we had last failure in order
# store time (as int) where we had last failure in order
...
...
product/ERP5/bootstrap/erp5_core/MixinTemplateItem/portal_components/mixin.erp5.BaseExtensibleTraversableMixin.py
View file @
6512da0d
...
@@ -28,7 +28,11 @@
...
@@ -28,7 +28,11 @@
##############################################################################
##############################################################################
from
warnings
import
warn
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
zLOG
import
LOG
from
AccessControl
import
ClassSecurityInfo
,
getSecurityManager
from
AccessControl
import
ClassSecurityInfo
,
getSecurityManager
...
...
product/ERP5Security/ERP5KeyAuthPlugin.py
View file @
6512da0d
...
@@ -27,7 +27,11 @@
...
@@ -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
six.moves.urllib.parse
import
quote
,
unquote
from
DateTime
import
DateTime
from
DateTime
import
DateTime
from
zLOG
import
LOG
,
PROBLEM
from
zLOG
import
LOG
,
PROBLEM
...
@@ -54,7 +58,6 @@ from Products import ERP5Security
...
@@ -54,7 +58,6 @@ from Products import ERP5Security
# TODO pycrypto is obsolete and should be replaced by cryptography or pycryptodome
# TODO pycrypto is obsolete and should be replaced by cryptography or pycryptodome
from
Crypto.Cipher
import
AES
from
Crypto.Cipher
import
AES
from
Crypto
import
Random
from
Crypto
import
Random
import
six
if
six
.
PY3
:
if
six
.
PY3
:
import
time
import
time
time
.
clock
=
time
.
process_time
time
.
clock
=
time
.
process_time
...
...
product/ERP5Security/__init__.py
View file @
6512da0d
...
@@ -18,14 +18,18 @@ from __future__ import absolute_import
...
@@ -18,14 +18,18 @@ from __future__ import absolute_import
from
copy
import
deepcopy
from
copy
import
deepcopy
from
collections
import
defaultdict
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
Acquisition
import
aq_inner
,
aq_parent
from
AccessControl.Permissions
import
manage_users
as
ManageUsers
from
AccessControl.Permissions
import
manage_users
as
ManageUsers
from
Products.PluggableAuthService.PluggableAuthService
import
registerMultiPlugin
from
Products.PluggableAuthService.PluggableAuthService
import
registerMultiPlugin
from
Products.PluggableAuthService.permissions
import
ManageGroups
from
Products.PluggableAuthService.permissions
import
ManageGroups
from
Products.ERP5Type
import
IS_ZOPE2
from
Products.ERP5Type
import
IS_ZOPE2
import
six
# This user is used to bypass all security checks.
# This user is used to bypass all security checks.
SUPER_USER
=
'__erp5security-=__'
SUPER_USER
=
'__erp5security-=__'
...
...
product/ERP5Type/CachePlugins/DistributedRamCache.py
View file @
6512da0d
...
@@ -37,7 +37,6 @@ from .BaseCache import BaseCache
...
@@ -37,7 +37,6 @@ from .BaseCache import BaseCache
from
.BaseCache
import
CacheEntry
from
.BaseCache
import
CacheEntry
from
Products.ERP5Type
import
interfaces
from
Products.ERP5Type
import
interfaces
import
zope.interface
import
zope.interface
from
base64
import
encodebytes
try
:
try
:
from
Products.ERP5Type.Tool.MemcachedTool
import
MemcachedDict
,
SharedDict
from
Products.ERP5Type.Tool.MemcachedTool
import
MemcachedDict
,
SharedDict
...
...
product/ERP5Type/XMLExportImport/__init__.py
View file @
6512da0d
...
@@ -48,13 +48,16 @@ from lxml import etree
...
@@ -48,13 +48,16 @@ from lxml import etree
from
lxml.etree
import
Element
,
SubElement
from
lxml.etree
import
Element
,
SubElement
from
xml_marshaller.xml_marshaller
import
Marshaller
from
xml_marshaller.xml_marshaller
import
Marshaller
from
OFS.Image
import
Pdata
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
hashlib
import
sha1
from
Products.ERP5Type.Utils
import
ensure_list
from
Products.ERP5Type.Utils
import
ensure_list
#from zLOG import LOG
#from zLOG import LOG
import
six
try
:
try
:
long_
=
long
long_
=
long
except
NameError
:
# six.PY3
except
NameError
:
# six.PY3
...
...
product/ERP5Type/XMLExportImport/ppml.py
View file @
6512da0d
...
@@ -20,14 +20,18 @@
...
@@ -20,14 +20,18 @@
from
zodbpickle.slowpickle
import
*
from
zodbpickle.slowpickle
import
*
import
struct
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
import
re
from
marshal
import
loads
as
mloads
from
marshal
import
loads
as
mloads
from
.xyap
import
NoBlanks
from
.xyap
import
NoBlanks
from
.xyap
import
xyap
from
.xyap
import
xyap
from
Products.ERP5Type.Utils
import
str2bytes
from
Products.ERP5Type.Utils
import
str2bytes
import
six
from
marshal
import
dumps
as
mdumps
from
marshal
import
dumps
as
mdumps
#from zLOG import LOG
#from zLOG import LOG
...
@@ -42,7 +46,7 @@ else:
...
@@ -42,7 +46,7 @@ else:
def
escape
(
s
,
encoding
=
'repr'
):
def
escape
(
s
,
encoding
=
'repr'
):
if
binary
(
s
)
and
isinstance
(
s
,
str
):
if
binary
(
s
)
and
isinstance
(
s
,
str
):
s
=
base64
.
encodebytes
(
s
)[:
-
1
]
s
=
base64
_
encodebytes
(
s
)[:
-
1
]
encoding
=
'base64'
encoding
=
'base64'
elif
'>'
in
s
or
'<'
in
s
or
'&'
in
s
:
elif
'>'
in
s
or
'<'
in
s
or
'&'
in
s
:
if
not
']]>'
in
s
:
if
not
']]>'
in
s
:
...
@@ -56,7 +60,7 @@ def escape(s, encoding='repr'):
...
@@ -56,7 +60,7 @@ def escape(s, encoding='repr'):
def
unescape
(
s
,
encoding
):
def
unescape
(
s
,
encoding
):
if
encoding
==
'base64'
:
if
encoding
==
'base64'
:
return
base64
.
decodebytes
(
s
)
return
base64
_
decodebytes
(
s
)
else
:
else
:
s
=
s
.
replace
(
b'<'
,
b'<'
)
s
=
s
.
replace
(
b'<'
,
b'<'
)
s
=
s
.
replace
(
b'>'
,
b'>'
)
s
=
s
.
replace
(
b'>'
,
b'>'
)
...
@@ -92,7 +96,7 @@ def convert(S):
...
@@ -92,7 +96,7 @@ def convert(S):
if
not
isinstance
(
S
,
six
.
text_type
):
if
not
isinstance
(
S
,
six
.
text_type
):
S
=
S
.
decode
(
'utf8'
)
S
=
S
.
decode
(
'utf8'
)
except
UnicodeDecodeError
:
except
UnicodeDecodeError
:
return
'base64'
,
base64
.
encodebytes
(
S
)[:
-
1
]
return
'base64'
,
base64
_
encodebytes
(
S
)[:
-
1
]
else
:
else
:
new
=
reprs_re
.
sub
(
sub_reprs
,
S
)
new
=
reprs_re
.
sub
(
sub_reprs
,
S
)
### patch end
### patch end
...
@@ -100,7 +104,7 @@ def convert(S):
...
@@ -100,7 +104,7 @@ def convert(S):
if
not
isinstance
(
S
,
six
.
binary_type
):
if
not
isinstance
(
S
,
six
.
binary_type
):
# TODO zope4py3: is this the right place ? this supports Unicode('\n')
# TODO zope4py3: is this the right place ? this supports Unicode('\n')
S
=
S
.
encode
(
'ascii'
)
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
:
elif
'>'
in
new
or
'<'
in
S
or
'&'
in
S
:
if
not
']]>'
in
S
:
if
not
']]>'
in
S
:
return
'cdata'
,
'<![CDATA[
\
n
\
n
'
+
new
+
'
\
n
\
n
]]>'
return
'cdata'
,
'<![CDATA[
\
n
\
n
'
+
new
+
'
\
n
\
n
]]>'
...
@@ -111,7 +115,7 @@ def convert(S):
...
@@ -111,7 +115,7 @@ def convert(S):
# For optimization.
# For optimization.
def
unconvert
(
encoding
,
S
):
def
unconvert
(
encoding
,
S
):
if
encoding
==
'base64'
:
if
encoding
==
'base64'
:
return
base64
.
decodebytes
(
S
)
return
base64
_
decodebytes
(
S
)
else
:
else
:
return
str2bytes
(
eval
(
b"'"
+
S
.
replace
(
b'
\
n
'
,
b''
)
+
b"'"
))
return
str2bytes
(
eval
(
b"'"
+
S
.
replace
(
b'
\
n
'
,
b''
)
+
b"'"
))
...
@@ -180,7 +184,7 @@ class String(Scalar):
...
@@ -180,7 +184,7 @@ class String(Scalar):
# This is used when strings represent references which need to
# This is used when strings represent references which need to
# be converted.
# be converted.
encoding
=
'base64'
encoding
=
'base64'
v
=
base64
.
encodebytes
(
self
.
_v
)[:
-
1
]
v
=
base64
_
encodebytes
(
self
.
_v
)[:
-
1
]
self
.
_v
=
self
.
mapping
.
convertBase64
(
v
).
decode
()
self
.
_v
=
self
.
mapping
.
convertBase64
(
v
).
decode
()
else
:
else
:
encoding
,
self
.
_v
=
convert
(
self
.
_v
)
encoding
,
self
.
_v
=
convert
(
self
.
_v
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment