Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubicweb
Commits
6ee2a7b6f194
Commit
a6002ca6
authored
Jun 02, 2010
by
Sylvain Thénault
Browse files
[external storage] refactor to give session to storage's callback (needed by vcsfile storage)
--HG-- branch : stable
parent
865c1779cc84
Changes
3
Hide whitespace changes
Inline
Side-by-side
server/sources/native.py
View file @
6ee2a7b6
...
...
@@ -452,8 +452,7 @@ class NativeSQLSource(SQLAdapterMixIn, AbstractSource):
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
...
...
server/sources/storages.py
View file @
6ee2a7b6
...
...
@@ -33,10 +33,10 @@ class Storage(object):
"""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 valu
e
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 @@ class BytesFileSystemStorage(Storage):
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
"""
...
...
server/sqlutils.py
View file @
6ee2a7b6
...
...
@@ -202,7 +202,7 @@ class SQLAdapterMixIn(object):
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 @@ class SQLAdapterMixIn(object):
# 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 @@ class SQLAdapterMixIn(object):
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 @@ class SQLAdapterMixIn(object):
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment