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

Zope4 Support

Add Zope4 support, while keeping Zope2 support for now

See merge request nexedi/wendelin!110
parents 08ac1304 1595f4e4
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
from cStringIO import StringIO from cStringIO import StringIO
import base64 import base64
import binascii import binascii
from httplib import NO_CONTENT
import msgpack import msgpack
import numpy as np import numpy as np
import string import string
...@@ -37,6 +38,14 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase ...@@ -37,6 +38,14 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import createZODBPythonScript, removeZODBPythonScript from Products.ERP5Type.tests.utils import createZODBPythonScript, removeZODBPythonScript
from wendelin.bigarray.array_zodb import ZBigArray from wendelin.bigarray.array_zodb import ZBigArray
from App.version_txt import getZopeVersion
if getZopeVersion() < (4, ): # BBB Zope2
# Zope set http status code 204 for empty response, but
# on Zope 2 this is not correctly reflected in ERP5TypeTestCase.publish,
# for such responses the status is set to 200 (but for "real" requests
# it is set to 204, this only affected the testing)
NO_CONTENT = 200
def getRandomString(): def getRandomString():
return 'test_%s' %''.join([random.choice(string.ascii_letters + string.digits) \ return 'test_%s' %''.join([random.choice(string.ascii_letters + string.digits) \
...@@ -98,12 +107,7 @@ class Test(ERP5TypeTestCase): ...@@ -98,12 +107,7 @@ class Test(ERP5TypeTestCase):
publish_kw = dict(user='ERP5TypeTestCase', env=env, publish_kw = dict(user='ERP5TypeTestCase', env=env,
request_method='POST', stdin=StringIO(body)) request_method='POST', stdin=StringIO(body))
response = self.publish(path, **publish_kw) response = self.publish(path, **publish_kw)
# Due to inconsistencies in the Zope framework, self.assertEqual(NO_CONTENT, response.getStatus())
# a normal instance returns 204. As explained at
# http://blog.ploeh.dk/2013/04/30/rest-lesson-learned-avoid-204-responses/
# turning 200 into 204 automatically when the body is empty is questionable.
self.assertEqual(200, response.getStatus())
# at every ingestion if no specialised Data Ingestion exists it is created # at every ingestion if no specialised Data Ingestion exists it is created
# thus it is needed to wait for server side activities to be processed # thus it is needed to wait for server side activities to be processed
self.tic() self.tic()
...@@ -389,7 +393,7 @@ class Test(ERP5TypeTestCase): ...@@ -389,7 +393,7 @@ class Test(ERP5TypeTestCase):
request_method='POST', stdin=StringIO(body)) request_method='POST', stdin=StringIO(body))
response = self.publish(path, **publish_kw) response = self.publish(path, **publish_kw)
self.assertEqual(200, response.getStatus()) self.assertEqual(NO_CONTENT, response.getStatus())
self.tic() self.tic()
......
...@@ -40,23 +40,41 @@ allow_module('scipy') ...@@ -40,23 +40,41 @@ allow_module('scipy')
allow_module('wendelin.bigarray.array_zodb') allow_module('wendelin.bigarray.array_zodb')
allow_type(np.timedelta64)
allow_type(type(np.c_))
import sklearn.linear_model import sklearn.linear_model
allow_class(sklearn.linear_model.LinearRegression) allow_class(sklearn.linear_model.LinearRegression)
# Modify 'safetype' dict in full_write_guard function # allow write access to ndarray, DataFrame, ZBigArray and RAMArray objects
# of RestrictedPython (closure) directly To allow def allow_full_write(t):
# write access to ndarray, DataFrame, ZBigArray and RAMArray objects """Allow setting and deleting items and attributes for this type.
from RestrictedPython.Guards import full_write_guard
full_write_guard.func_closure[1].cell_contents.__self__[np.ndarray] = True This supports both RestrictedPython-3.6.0, where the safetype is implemented as:
full_write_guard.func_closure[1].cell_contents.__self__[np.core.records.recarray] = True
full_write_guard.func_closure[1].cell_contents.__self__[np.core.records.record] = True safetype = {dict: True, list: True}.has_key
...
safetype(t)
and RestrictedPython-5.1, where the safetype is implemented as:
safetypes = {dict, list}
...
safetype(t)
"""
from RestrictedPython.Guards import full_write_guard
safetype = full_write_guard.__closure__[1].cell_contents
if isinstance(safetype, set): # 5.1
safetype.add(t)
else: # 3.6
safetype.__self__.update({t: True})
allow_full_write(np.ndarray)
allow_full_write(np.core.records.recarray)
allow_full_write(np.core.records.record)
from wendelin.bigarray.array_zodb import ZBigArray from wendelin.bigarray.array_zodb import ZBigArray
full_write_guard.func_closure[1].cell_contents.__self__[ZBigArray] = True allow_full_write(ZBigArray)
allow_type(ZBigArray) allow_type(ZBigArray)
from wendelin.bigarray.array_ram import RAMArray from wendelin.bigarray.array_ram import RAMArray
full_write_guard.func_closure[1].cell_contents.__self__[RAMArray] = True allow_full_write(RAMArray)
allow_type(RAMArray) allow_type(RAMArray)
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