Commit 35447649 authored by Ekaterina's avatar Ekaterina

erp5_wendelin: fix byte size of data array and add test

parent f27a9a0b
...@@ -125,7 +125,7 @@ class DataArray(BigFile): ...@@ -125,7 +125,7 @@ class DataArray(BigFile):
zarray = self.getArray() zarray = self.getArray()
if zarray is not None: if zarray is not None:
return zarray.dtype return zarray.dtype
security.declareProtected(Permissions.AccessContentsInformation, 'getArrayDtypeNames') security.declareProtected(Permissions.AccessContentsInformation, 'getArrayDtypeNames')
def getArrayDtypeNames(self): def getArrayDtypeNames(self):
""" """
...@@ -179,7 +179,6 @@ class DataArray(BigFile): ...@@ -179,7 +179,6 @@ class DataArray(BigFile):
ranges = HTTPRangeSupport.parseRange(range) ranges = HTTPRangeSupport.parseRange(range)
array = self.getArray() array = self.getArray()
factor = array.nbytes / array.shape[0]
if if_range is not None: if if_range is not None:
# Only send ranges if the data isn't modified, otherwise send # Only send ranges if the data isn't modified, otherwise send
...@@ -240,9 +239,10 @@ class DataArray(BigFile): ...@@ -240,9 +239,10 @@ class DataArray(BigFile):
RESPONSE.setHeader('Content-Range', RESPONSE.setHeader('Content-Range',
'bytes %d-%d/%d' % (start, end - 1, self.getSize())) 'bytes %d-%d/%d' % (start, end - 1, self.getSize()))
RESPONSE.setStatus(206) # Partial content RESPONSE.setStatus(206) # Partial content
self.log(str((start, end)))
# convert ranges from bytes to array indices # convert array to bytes
RESPONSE.write(array[start/factor:end/factor].tobytes()) data = array[:].view('<b').reshape((-1,))[start:end].tobytes()
RESPONSE.setBody(data, lock=True)
else: else:
boundary = choose_boundary() boundary = choose_boundary()
...@@ -260,6 +260,7 @@ class DataArray(BigFile): ...@@ -260,6 +260,7 @@ class DataArray(BigFile):
# will only accept x-byteranges. # will only accept x-byteranges.
draftprefix = (request_range is not None) and 'x-' or '' draftprefix = (request_range is not None) and 'x-' or ''
self.log(size)
RESPONSE.setHeader('Content-Length', size) RESPONSE.setHeader('Content-Length', size)
RESPONSE.setHeader('Accept-Ranges', 'bytes') RESPONSE.setHeader('Accept-Ranges', 'bytes')
RESPONSE.setHeader('Last-Modified', rfc1123_date(self._data_mtime())) RESPONSE.setHeader('Last-Modified', rfc1123_date(self._data_mtime()))
...@@ -267,17 +268,19 @@ class DataArray(BigFile): ...@@ -267,17 +268,19 @@ class DataArray(BigFile):
'multipart/%sbyteranges; boundary=%s' % ( 'multipart/%sbyteranges; boundary=%s' % (
draftprefix, boundary)) draftprefix, boundary))
RESPONSE.setStatus(206) # Partial content RESPONSE.setStatus(206) # Partial content
data = ''
for start, end in ranges: for start, end in ranges:
RESPONSE.write('\r\n--%s\r\n' % boundary) data = '{data}\r\n--{boundary}\r\n'\
RESPONSE.write('Content-Type: %s\r\n' % 'Content-Type: {content_type}\r\n'\
self.content_type) 'Content-Range: bytes {start:d}-{end:d}/{size:d}\r\n\r\n'\
RESPONSE.write( '{array}'.format(data=data,
'Content-Range: bytes %d-%d/%d\r\n\r\n' % ( boundary=boundary,
start, end - 1, self.getSize())) content_type=self.content_type,
start=start,
# convert ranges from bytes to array indices end=end-1,
RESPONSE.write(array[start/factor:end/factor].tobytes()) size=self.getSize(),
array=array[:].view('<b').reshape((-1,))[start:end].tobytes())
RESPONSE.write('\r\n--%s--\r\n' % boundary)
return True data = '{}\r\n--{}--\r\n'.format(data, boundary)
RESPONSE.setBody(data, lock=True)
return True
\ No newline at end of file
...@@ -46,9 +46,9 @@ ...@@ -46,9 +46,9 @@
<key> <string>text_content_warning_message</string> </key> <key> <string>text_content_warning_message</string> </key>
<value> <value>
<tuple> <tuple>
<string>W:133, 42: Redefining built-in \'format\' (redefined-builtin)</string> <string>W:139, 42: Redefining built-in \'format\' (redefined-builtin)</string>
<string>W:165, 4: Redefining built-in \'range\' (redefined-builtin)</string> <string>W:171, 4: Redefining built-in \'range\' (redefined-builtin)</string>
<string>W:192, 10: No exception type(s) specified (bare-except)</string> <string>W:197, 10: No exception type(s) specified (bare-except)</string>
</tuple> </tuple>
</value> </value>
</item> </item>
...@@ -104,24 +104,28 @@ ...@@ -104,24 +104,28 @@
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<list> <key> <string>_log</string> </key>
<dictionary> <value>
<item> <list>
<key> <string>action</string> </key> <dictionary>
<value> <string>validate</string> </value> <item>
</item> <key> <string>action</string> </key>
<item> <value> <string>validate</string> </value>
<key> <string>validation_state</string> </key> </item>
<value> <string>validated</string> </value> <item>
</item> <key> <string>validation_state</string> </key>
</dictionary> <value> <string>validated</string> </value>
</list> </item>
</tuple> </dictionary>
</list>
</value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </ZopeData>
...@@ -33,6 +33,10 @@ import numpy as np ...@@ -33,6 +33,10 @@ import numpy as np
import string import string
import random import random
import urllib import urllib
import requests
import StringIO as st
from Products.ERP5Type.Log import log
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) \
...@@ -229,6 +233,18 @@ class Test(ERP5TypeTestCase): ...@@ -229,6 +233,18 @@ class Test(ERP5TypeTestCase):
self.assertTrue( self.assertTrue(
np.array_equal(data_array.getArraySlice(0,100), \ np.array_equal(data_array.getArraySlice(0,100), \
new_array[:100])) new_array[:100]))
# test get array by request if exists and chech that length is correct
data_arrays = self.portal.data_array_module.objectValues()
spectrum_array = [o for o in data_arrays if o.getTitle() == 'pydata-spectrum2']
if len(spectrum_array) == 1:
spectrum_array_id = spectrum_array[0].getId()
headers = {'Range': 'bytes=0-'}
url = 'https://softinst127199.host.vifib.net/erp5/web_site_module/pydata_runner/hateoas/data_array_module/' + spectrum_array_id
response = requests.get(url, auth=('zope', 'aybvtnkf'), headers=headers)
response_string = st.StringIO()
response_string.write(response.content)
self.assertEquals(response_string.len, spectrum_array[0].getSize())
def test_04_DataBucket(self): def test_04_DataBucket(self):
""" """
......
...@@ -46,7 +46,8 @@ ...@@ -46,7 +46,8 @@
<key> <string>text_content_warning_message</string> </key> <key> <string>text_content_warning_message</string> </key>
<value> <value>
<tuple> <tuple>
<string>W: 63, 35: Unused variable \'data_product\' (unused-variable)</string> <string>W: 67, 35: Unused variable \'data_product\' (unused-variable)</string>
<string>W: 39, 0: Unused log imported from Products.ERP5Type.Log (unused-import)</string>
</tuple> </tuple>
</value> </value>
</item> </item>
...@@ -102,24 +103,28 @@ ...@@ -102,24 +103,28 @@
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<list> <key> <string>_log</string> </key>
<dictionary> <value>
<item> <list>
<key> <string>action</string> </key> <dictionary>
<value> <string>validate</string> </value> <item>
</item> <key> <string>action</string> </key>
<item> <value> <string>validate</string> </value>
<key> <string>validation_state</string> </key> </item>
<value> <string>validated</string> </value> <item>
</item> <key> <string>validation_state</string> </key>
</dictionary> <value> <string>validated</string> </value>
</list> </item>
</tuple> </dictionary>
</list>
</value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </ZopeData>
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