summaryrefslogtreecommitdiff
path: root/addons/document/nodes.py
diff options
context:
space:
mode:
authorP. Christeas <p_christ@hol.gr>2010-11-03 13:25:34 +0200
committerP. Christeas <p_christ@hol.gr>2010-11-03 13:25:34 +0200
commit7f882e14cf2948a4fe4b2b2b34fa085e6dba4278 (patch)
treec58be91cccc0159574dcea0aed0a2c25a018fbff /addons/document/nodes.py
parentdeffd9703d2a42b079db87dfff3633a63d268a9b (diff)
document: enhance API for iter() on node_descriptors
Starting from WebDAV, the node_descriptors will need to act as stream objects, iterable. This way, we hope to minimize copies of the huge chunks of data each descriptor may contain (still, pywebdav will use a single large buffer). bzr revid: p_christ@hol.gr-20101103112534-go57aeaw946utfc5
Diffstat (limited to 'addons/document/nodes.py')
-rw-r--r--addons/document/nodes.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/addons/document/nodes.py b/addons/document/nodes.py
index 190e0d9c3ce..1a903614028 100644
--- a/addons/document/nodes.py
+++ b/addons/document/nodes.py
@@ -175,6 +175,15 @@ class node_descriptor(object):
def write(self, str):
raise NotImplementedError
+ def size(self):
+ raise NotImplementedError
+
+ def __len__(self):
+ return self.size()
+
+ def next(self, str):
+ raise NotImplementedError
+
class node_class(object):
""" this is a superclass for our inodes
It is an API for all code that wants to access the document files.
@@ -1403,11 +1412,13 @@ class nodefd_content(StringIO, node_descriptor):
def __init__(self, parent, cr, mode, ctx):
node_descriptor.__init__(self, parent)
self._context=ctx
+ self._size = 0L
if mode in ('r', 'r+'):
cntobj = parent.context._dirobj.pool.get('document.directory.content')
data = cntobj.process_read(cr, parent.context.uid, parent, ctx)
if data:
+ self._size = len(data)
parent.content_length = len(data)
StringIO.__init__(self, data)
elif mode in ('w', 'w+'):
@@ -1421,6 +1432,9 @@ class nodefd_content(StringIO, node_descriptor):
raise IOError(errno.EINVAL, "Invalid file mode")
self.mode = mode
+ def size(self):
+ return self._size
+
def close(self):
# we now open a *separate* cursor, to update the data.
# FIXME: this may be improved, for concurrency handling