Commit c2481a75 authored by Klaus Wölfel's avatar Klaus Wölfel

DataArray: content type response header

parent 4dfcdc5f
...@@ -74,12 +74,12 @@ class DataArray(BigFile): ...@@ -74,12 +74,12 @@ class DataArray(BigFile):
Set numpy array to this ERP5 Data Array. Set numpy array to this ERP5 Data Array.
""" """
self.array = value self.array = value
# ZBigArray requirement: before we can compute it (with subobject # ZBigArray requirement: before we can compute it (with subobject
# .zfile) have to be made explicitly known to connection or current # .zfile) have to be made explicitly known to connection or current
# transaction committed (XXX: impossible to use as raises ConflictErrors) # transaction committed (XXX: impossible to use as raises ConflictErrors)
transaction.commit() transaction.commit()
def getArraySlice(self, start, end): def getArraySlice(self, start, end):
""" """
Implement array slicing in its most simple list alike form. Implement array slicing in its most simple list alike form.
...@@ -87,14 +87,14 @@ class DataArray(BigFile): ...@@ -87,14 +87,14 @@ class DataArray(BigFile):
array reference directly. array reference directly.
""" """
return self.getArray()[start:end] return self.getArray()[start:end]
security.declareProtected(Permissions.AccessContentsInformation, 'getSize') security.declareProtected(Permissions.AccessContentsInformation, 'getSize')
def getSize(self, default=None): def getSize(self, default=None):
""" """
Implement getSize interface for ndarray Implement getSize interface for ndarray
""" """
return self.getArray().nbytes return self.getArray().nbytes
security.declareProtected(Permissions.View, 'index_html') security.declareProtected(Permissions.View, 'index_html')
def index_html(self, REQUEST, RESPONSE, format=_MARKER, inline=_MARKER, **kw): def index_html(self, REQUEST, RESPONSE, format=_MARKER, inline=_MARKER, **kw):
""" """
...@@ -104,10 +104,10 @@ class DataArray(BigFile): ...@@ -104,10 +104,10 @@ class DataArray(BigFile):
# we served a chunk of content in response to a range request. # we served a chunk of content in response to a range request.
return '' return ''
# XXX: what we do? We can not transmit entire Big Array?
return '' return ''
def _range_request_handler(self, REQUEST, RESPONSE): def _range_request_handler(self, REQUEST, RESPONSE):
RESPONSE.setHeader("Content-Type", "application/octet-stream")
# HTTP Range header handling: return True if we've served a range # HTTP Range header handling: return True if we've served a range
# chunk out of our data. # chunk out of our data.
range = REQUEST.get_header('Range', None) range = REQUEST.get_header('Range', None)
...@@ -122,7 +122,7 @@ class DataArray(BigFile): ...@@ -122,7 +122,7 @@ class DataArray(BigFile):
# get byte view of array because we interpret ranges in bytes # get byte view of array because we interpret ranges in bytes
data = self.getArray()[:].view("uint8").ravel() data = self.getArray()[:].view("uint8").ravel()
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
# the whole object. Support both ETags and Last-Modified dates! # the whole object. Support both ETags and Last-Modified dates!
...@@ -182,8 +182,7 @@ class DataArray(BigFile): ...@@ -182,8 +182,7 @@ 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(data[start:end].tobytes())
RESPONSE.write(data[start:end].tobytes()) RESPONSE.write(data[start:end].tobytes())
else: else:
boundary = choose_boundary() boundary = choose_boundary()
......
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