[external storage] refactor to give session to storage's callback (needed by vcsfile storage)
--- a/server/sources/native.py Wed Jun 02 13:00:27 2010 +0200
+++ b/server/sources/native.py Wed Jun 02 13:01:45 2010 +0200
@@ -452,8 +452,7 @@
cursor = self.doexec(session, sql, args)
else:
raise
-
- results = self.process_result(cursor, cbs)
+ results = self.process_result(cursor, cbs, session=session)
assert dbg_results(results)
return results
--- a/server/sources/storages.py Wed Jun 02 13:00:27 2010 +0200
+++ b/server/sources/storages.py Wed Jun 02 13:01:45 2010 +0200
@@ -33,10 +33,10 @@
"""abstract storage
* If `source_callback` is true (by default), the callback will be run during
- query result process of fetched attribute's valu and should have the
+ query result process of fetched attribute's value and should have the
following prototype::
- callback(self, source, value)
+ callback(self, source, session, value)
where `value` is the value actually stored in the backend. None values
will be skipped (eg callback won't be called).
@@ -99,7 +99,7 @@
self.default_directory = defaultdir
self.fsencoding = fsencoding
- def callback(self, source, value):
+ def callback(self, source, session, value):
"""sql generator callback when some attribute with a custom storage is
accessed
"""
--- a/server/sqlutils.py Wed Jun 02 13:00:27 2010 +0200
+++ b/server/sqlutils.py Wed Jun 02 13:01:45 2010 +0200
@@ -202,7 +202,7 @@
return newargs
return query_args
- def process_result(self, cursor, column_callbacks=None):
+ def process_result(self, cursor, column_callbacks=None, session=None):
"""return a list of CubicWeb compliant values from data in the given cursor
"""
# use two different implementations to avoid paying the price of
@@ -210,9 +210,10 @@
# lookup
if not column_callbacks:
return self._process_result(cursor)
- return self._cb_process_result(cursor, column_callbacks)
+ assert session
+ return self._cb_process_result(cursor, column_callbacks, session)
- def _process_result(self, cursor, column_callbacks=None):
+ def _process_result(self, cursor):
# begin bind to locals for optimization
descr = cursor.description
encoding = self._dbencoding
@@ -230,7 +231,7 @@
results[i] = result
return results
- def _cb_process_result(self, cursor, column_callbacks):
+ def _cb_process_result(self, cursor, column_callbacks, session):
# begin bind to locals for optimization
descr = cursor.description
encoding = self._dbencoding
@@ -249,7 +250,7 @@
value = process_value(value, descr[col], encoding, binary)
else:
for cb in cbstack:
- value = cb(self, value)
+ value = cb(self, session, value)
result.append(value)
results[i] = result
return results