From a21dcd7e1c8623f4aaf3a3659e81247273f652e9 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Wed, 3 Nov 2010 13:26:05 +0200 Subject: [PATCH] document: fix regressions at storage and node_descriptor Since the introduction of __len__, the descriptors were broken for the ftp module. Fix. bzr revid: p_christ@hol.gr-20101103112605-tu6n6529mbdc18ve --- addons/document/document_storage.py | 6 ++++-- addons/document/nodes.py | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/addons/document/document_storage.py b/addons/document/document_storage.py index 64b8b067bae..513da92bfcd 100644 --- a/addons/document/document_storage.py +++ b/addons/document/document_storage.py @@ -181,7 +181,8 @@ class nodefd_db(StringIO, nodes.node_descriptor): cr = ira_browse._cr # reuse the cursor of the browse object, just now cr.execute('SELECT db_datas FROM ir_attachment WHERE id = %s',(ira_browse.id,)) data = cr.fetchone()[0] - self._size = len(data) + if data: + self._size = len(data) StringIO.__init__(self, data) elif mode in ('w', 'w+'): StringIO.__init__(self, None) @@ -260,7 +261,8 @@ class nodefd_db64(StringIO, nodes.node_descriptor): if mode in ('r', 'r+'): data = base64.decodestring(ira_browse.db_datas) - self._size = len(data) + if data: + self._size = len(data) StringIO.__init__(self, data) elif mode in ('w', 'w+'): StringIO.__init__(self, None) diff --git a/addons/document/nodes.py b/addons/document/nodes.py index f025b56698e..c0eef134f25 100644 --- a/addons/document/nodes.py +++ b/addons/document/nodes.py @@ -181,6 +181,14 @@ class node_descriptor(object): def __len__(self): return self.size() + def __nonzero__(self): + """ Ensure that a node_descriptor will never equal False + + Since we do define __len__ and __iter__ for us, we must avoid + being regarded as non-true objects. + """ + return True + def next(self, str): raise NotImplementedError