author | Julien Cristau <julien.cristau@logilab.fr> |
Fri, 27 Jun 2014 11:48:26 +0200 | |
changeset 9821 | 2077c8da1893 |
parent 9813 | c20956f5862d |
child 10087 | ed0b076c119b |
permissions | -rw-r--r-- |
9045
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
1 |
# copyright 2013-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
3 |
# |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
4 |
# This file is part of CubicWeb. |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
5 |
# |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
9 |
# any later version. |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
10 |
# |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
14 |
# details. |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
15 |
# |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
18 |
"""Official API to access the content of a repository |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
19 |
""" |
9125
9aaf8472bad0
[repoapi] deprecate dbapi compat method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9116
diff
changeset
|
20 |
from logilab.common.deprecation import deprecated |
9aaf8472bad0
[repoapi] deprecate dbapi compat method
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9116
diff
changeset
|
21 |
|
9045
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
22 |
from cubicweb.utils import parse_repo_uri |
9062
fa5bc8aef7ed
[repoapi] add an anonymous_cnx function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9061
diff
changeset
|
23 |
from cubicweb import ConnectionError, ProgrammingError, AuthenticationError |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
24 |
from uuid import uuid4 |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
25 |
from contextlib import contextmanager |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
26 |
from cubicweb.req import RequestSessionBase |
9100
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
27 |
from functools import wraps |
9045
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
28 |
|
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
29 |
### private function for specific method ############################ |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
30 |
|
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
31 |
def _get_inmemory_repo(config, vreg=None): |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
32 |
from cubicweb.server.repository import Repository |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
33 |
from cubicweb.server.utils import TasksManager |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
34 |
return Repository(config, TasksManager(), vreg=vreg) |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
35 |
|
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
36 |
|
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
37 |
### public API ###################################################### |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
38 |
|
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
39 |
def get_repository(uri=None, config=None, vreg=None): |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
40 |
"""get a repository for the given URI or config/vregistry (in case we're |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
41 |
loading the repository for a client, eg web server, configuration). |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
42 |
|
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
43 |
The returned repository may be an in-memory repository or a proxy object |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
44 |
using a specific RPC method, depending on the given URI (pyro or zmq). |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
45 |
""" |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
46 |
if uri is None: |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
47 |
return _get_inmemory_repo(config, vreg) |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
48 |
|
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
49 |
protocol, hostport, appid = parse_repo_uri(uri) |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
50 |
|
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
51 |
if protocol == 'inmemory': |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
52 |
# me may have been called with a dummy 'inmemory://' uri ... |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
53 |
return _get_inmemory_repo(config, vreg) |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
54 |
|
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
55 |
if protocol == 'pyroloc': # direct connection to the instance |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
56 |
from logilab.common.pyro_ext import get_proxy |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
57 |
uri = uri.replace('pyroloc', 'PYRO') |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
58 |
return get_proxy(uri) |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
59 |
|
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
60 |
if protocol == 'pyro': # connection mediated through the pyro ns |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
61 |
from logilab.common.pyro_ext import ns_get_proxy |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
62 |
path = appid.strip('/') |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
63 |
if not path: |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
64 |
raise ConnectionError( |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
65 |
"can't find instance name in %s (expected to be the path component)" |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
66 |
% uri) |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
67 |
if '.' in path: |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
68 |
nsgroup, nsid = path.rsplit('.', 1) |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
69 |
else: |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
70 |
nsgroup = 'cubicweb' |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
71 |
nsid = path |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
72 |
return ns_get_proxy(nsid, defaultnsgroup=nsgroup, nshost=hostport) |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
73 |
|
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
74 |
if protocol.startswith('zmqpickle-'): |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
75 |
from cubicweb.zmqclient import ZMQRepositoryClient |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
76 |
return ZMQRepositoryClient(uri) |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
77 |
else: |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
78 |
raise ConnectionError('unknown protocol: `%s`' % protocol) |
5378a738f333
[repoapi] move get_repository function into a new repoapi module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
79 |
|
9061
e86fdab3d296
[repoapi] add a connect function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9060
diff
changeset
|
80 |
def connect(repo, login, **kwargs): |
e86fdab3d296
[repoapi] add a connect function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9060
diff
changeset
|
81 |
"""Take credential and return associated ClientConnection. |
e86fdab3d296
[repoapi] add a connect function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9060
diff
changeset
|
82 |
|
e86fdab3d296
[repoapi] add a connect function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9060
diff
changeset
|
83 |
The ClientConnection is associated to a new Session object that will be |
e86fdab3d296
[repoapi] add a connect function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9060
diff
changeset
|
84 |
closed when the ClientConnection is closed. |
e86fdab3d296
[repoapi] add a connect function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9060
diff
changeset
|
85 |
|
e86fdab3d296
[repoapi] add a connect function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9060
diff
changeset
|
86 |
raise AuthenticationError if the credential are invalid.""" |
e86fdab3d296
[repoapi] add a connect function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9060
diff
changeset
|
87 |
sessionid = repo.connect(login, **kwargs) |
e86fdab3d296
[repoapi] add a connect function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9060
diff
changeset
|
88 |
session = repo._get_session(sessionid) |
e86fdab3d296
[repoapi] add a connect function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9060
diff
changeset
|
89 |
# XXX the autoclose_session should probably be handle on the session directly |
e86fdab3d296
[repoapi] add a connect function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9060
diff
changeset
|
90 |
# this is something to consider once we have proper server side Connection. |
e86fdab3d296
[repoapi] add a connect function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9060
diff
changeset
|
91 |
return ClientConnection(session, autoclose_session=True) |
e86fdab3d296
[repoapi] add a connect function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9060
diff
changeset
|
92 |
|
9062
fa5bc8aef7ed
[repoapi] add an anonymous_cnx function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9061
diff
changeset
|
93 |
def anonymous_cnx(repo): |
fa5bc8aef7ed
[repoapi] add an anonymous_cnx function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9061
diff
changeset
|
94 |
"""return a ClientConnection for Anonymous user. |
fa5bc8aef7ed
[repoapi] add an anonymous_cnx function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9061
diff
changeset
|
95 |
|
fa5bc8aef7ed
[repoapi] add an anonymous_cnx function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9061
diff
changeset
|
96 |
The ClientConnection is associated to a new Session object that will be |
fa5bc8aef7ed
[repoapi] add an anonymous_cnx function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9061
diff
changeset
|
97 |
closed when the ClientConnection is closed. |
fa5bc8aef7ed
[repoapi] add an anonymous_cnx function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9061
diff
changeset
|
98 |
|
fa5bc8aef7ed
[repoapi] add an anonymous_cnx function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9061
diff
changeset
|
99 |
raises an AuthenticationError if anonymous usage is not allowed |
fa5bc8aef7ed
[repoapi] add an anonymous_cnx function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9061
diff
changeset
|
100 |
""" |
fa5bc8aef7ed
[repoapi] add an anonymous_cnx function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9061
diff
changeset
|
101 |
anoninfo = getattr(repo.config, 'anonymous_user', lambda: None)() |
fa5bc8aef7ed
[repoapi] add an anonymous_cnx function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9061
diff
changeset
|
102 |
if anoninfo is None: # no anonymous user |
fa5bc8aef7ed
[repoapi] add an anonymous_cnx function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9061
diff
changeset
|
103 |
raise AuthenticationError('anonymous access is not authorized') |
fa5bc8aef7ed
[repoapi] add an anonymous_cnx function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9061
diff
changeset
|
104 |
anon_login, anon_password = anoninfo |
fa5bc8aef7ed
[repoapi] add an anonymous_cnx function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9061
diff
changeset
|
105 |
# use vreg's repository cache |
fa5bc8aef7ed
[repoapi] add an anonymous_cnx function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9061
diff
changeset
|
106 |
return connect(repo, anon_login, password=anon_password) |
fa5bc8aef7ed
[repoapi] add an anonymous_cnx function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9061
diff
changeset
|
107 |
|
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
108 |
def _srv_cnx_func(name): |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
109 |
"""Decorate ClientConnection method blindly forward to Connection |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
110 |
THIS TRANSITIONAL PURPOSE |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
111 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
112 |
will be dropped when we have standalone connection""" |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
113 |
def proxy(clt_cnx, *args, **kwargs): |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
114 |
# the ``with`` dance is transitional. We do not have Standalone |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
115 |
# Connection yet so we use this trick to unsure the session have the |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
116 |
# proper cnx loaded. This can be simplified one we have Standalone |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
117 |
# Connection object |
9100
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
118 |
if not clt_cnx._open: |
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
119 |
raise ProgrammingError('Closed client connection') |
9101
e6d1df619949
[client-connection] remove the _srv_cnx usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9100
diff
changeset
|
120 |
return getattr(clt_cnx._cnx, name)(*args, **kwargs) |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
121 |
return proxy |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
122 |
|
9100
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
123 |
def _open_only(func): |
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
124 |
"""decorator for ClientConnection method that check it is open""" |
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
125 |
@wraps(func) |
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
126 |
def check_open(clt_cnx, *args, **kwargs): |
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
127 |
if not clt_cnx._open: |
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
128 |
raise ProgrammingError('Closed client connection') |
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
129 |
return func(clt_cnx, *args, **kwargs) |
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
130 |
return check_open |
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
131 |
|
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
132 |
|
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
133 |
class ClientConnection(RequestSessionBase): |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
134 |
"""A Connection object to be used Client side. |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
135 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
136 |
This object is aimed to be used client side (so potential communication |
9475
7863c546b135
[repoapi] Fix typos in doc strings and comments
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
137 |
with the repo through RPC) and aims to offer some compatibility with the |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
138 |
cubicweb.dbapi.Connection interface. |
9060
8c0016d7a091
[client-connection] add an auto-close property for ClientConnection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9058
diff
changeset
|
139 |
|
9475
7863c546b135
[repoapi] Fix typos in doc strings and comments
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
140 |
The autoclose_session parameter informs the connection that this session |
7863c546b135
[repoapi] Fix typos in doc strings and comments
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
141 |
has been opened explicitly and only for this client connection. The |
7863c546b135
[repoapi] Fix typos in doc strings and comments
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
142 |
connection will close the session on exit. |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
143 |
""" |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
144 |
# make exceptions available through the connection object |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
145 |
ProgrammingError = ProgrammingError |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
146 |
# attributes that may be overriden per connection instance |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
147 |
anonymous_connection = False # XXX really needed ? |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
148 |
is_repo_in_memory = True # BC, always true |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
149 |
|
9060
8c0016d7a091
[client-connection] add an auto-close property for ClientConnection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9058
diff
changeset
|
150 |
def __init__(self, session, autoclose_session=False): |
9813
c20956f5862d
[repoapi] make ClientConnection call RequestSessionBase's init
Julien Cristau <julien.cristau@logilab.fr>
parents:
9774
diff
changeset
|
151 |
super(ClientConnection, self).__init__(session.vreg) |
9096
9d1b5f07d9ca
[ClientConnection] directly use the Connection object to access the database
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9062
diff
changeset
|
152 |
self._session = session # XXX there is no real reason to keep the |
9d1b5f07d9ca
[ClientConnection] directly use the Connection object to access the database
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9062
diff
changeset
|
153 |
# session around function still using it should |
9d1b5f07d9ca
[ClientConnection] directly use the Connection object to access the database
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9062
diff
changeset
|
154 |
# be rewritten and migrated. |
9d1b5f07d9ca
[ClientConnection] directly use the Connection object to access the database
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9062
diff
changeset
|
155 |
self._cnx = None |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
156 |
self._open = None |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
157 |
self._web_request = False |
9582
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
158 |
#: cache entities built during the connection |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
159 |
self._eid_cache = {} |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
160 |
self._set_user(session.user) |
9060
8c0016d7a091
[client-connection] add an auto-close property for ClientConnection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9058
diff
changeset
|
161 |
self._autoclose_session = autoclose_session |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
162 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
163 |
def __enter__(self): |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
164 |
assert self._open is None |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
165 |
self._open = True |
9111
9c867d852067
use standalone Connection to Client Connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9105
diff
changeset
|
166 |
self._cnx = self._session.new_cnx() |
9c867d852067
use standalone Connection to Client Connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9105
diff
changeset
|
167 |
self._cnx.__enter__() |
9096
9d1b5f07d9ca
[ClientConnection] directly use the Connection object to access the database
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9062
diff
changeset
|
168 |
self._cnx.ctx_count += 1 |
9116
57387c6482e5
[repoapi] make ClientConnection.__enter__ return self
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9111
diff
changeset
|
169 |
return self |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
170 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
171 |
def __exit__(self, exc_type, exc_val, exc_tb): |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
172 |
self._open = False |
9096
9d1b5f07d9ca
[ClientConnection] directly use the Connection object to access the database
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9062
diff
changeset
|
173 |
self._cnx.ctx_count -= 1 |
9111
9c867d852067
use standalone Connection to Client Connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9105
diff
changeset
|
174 |
self._cnx.__exit__(exc_type, exc_val, exc_tb) |
9096
9d1b5f07d9ca
[ClientConnection] directly use the Connection object to access the database
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9062
diff
changeset
|
175 |
self._cnx = None |
9060
8c0016d7a091
[client-connection] add an auto-close property for ClientConnection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9058
diff
changeset
|
176 |
if self._autoclose_session: |
9475
7863c546b135
[repoapi] Fix typos in doc strings and comments
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
177 |
# we have to call repo.close to ensure the repo properly forgets the |
7863c546b135
[repoapi] Fix typos in doc strings and comments
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
178 |
# session; calling session.close() is not enough :-( |
9575
754904ac4248
[repoapi] Avoid deprecation warnings from session.id
Julien Cristau <julien.cristau@logilab.fr>
parents:
9554
diff
changeset
|
179 |
self._session.repo.close(self._session.sessionid) |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
180 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
181 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
182 |
# begin silly BC |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
183 |
@property |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
184 |
def _closed(self): |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
185 |
return not self._open |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
186 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
187 |
def close(self): |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
188 |
if self._open: |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
189 |
self.__exit__(None, None, None) |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
190 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
191 |
def __repr__(self): |
9099
b7f7aa1b1123
[client-connection] handle the lack of connection id while not open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9098
diff
changeset
|
192 |
# XXX we probably want to reference the user of the session here |
b7f7aa1b1123
[client-connection] handle the lack of connection id while not open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9098
diff
changeset
|
193 |
if self._open is None: |
b7f7aa1b1123
[client-connection] handle the lack of connection id while not open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9098
diff
changeset
|
194 |
return '<ClientConnection (not open yet)>' |
b7f7aa1b1123
[client-connection] handle the lack of connection id while not open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9098
diff
changeset
|
195 |
elif not self._open: |
b7f7aa1b1123
[client-connection] handle the lack of connection id while not open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9098
diff
changeset
|
196 |
return '<ClientConnection (closed)>' |
b7f7aa1b1123
[client-connection] handle the lack of connection id while not open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9098
diff
changeset
|
197 |
elif self.anonymous_connection: |
9097
39be1e548270
[client-connection] explicit the client part in __repr__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9096
diff
changeset
|
198 |
return '<ClientConnection %s (anonymous)>' % self._cnx.connectionid |
9099
b7f7aa1b1123
[client-connection] handle the lack of connection id while not open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9098
diff
changeset
|
199 |
else: |
b7f7aa1b1123
[client-connection] handle the lack of connection id while not open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9098
diff
changeset
|
200 |
return '<ClientConnection %s>' % self._cnx.connectionid |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
201 |
# end silly BC |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
202 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
203 |
# Main Connection purpose in life ######################################### |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
204 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
205 |
call_service = _srv_cnx_func('call_service') |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
206 |
|
9100
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
207 |
@_open_only |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
208 |
def execute(self, *args, **kwargs): |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
209 |
# the ``with`` dance is transitional. We do not have Standalone |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
210 |
# Connection yet so we use this trick to unsure the session have the |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
211 |
# proper cnx loaded. This can be simplified one we have Standalone |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
212 |
# Connection object |
9101
e6d1df619949
[client-connection] remove the _srv_cnx usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9100
diff
changeset
|
213 |
rset = self._cnx.execute(*args, **kwargs) |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
214 |
rset.req = self |
9058
2f45e99ad753
[client-connect] drop rqlst on rset returned client side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9057
diff
changeset
|
215 |
# XXX keep the same behavior as the old dbapi |
2f45e99ad753
[client-connect] drop rqlst on rset returned client side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9057
diff
changeset
|
216 |
# otherwise multiple tests break. |
2f45e99ad753
[client-connect] drop rqlst on rset returned client side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9057
diff
changeset
|
217 |
# The little internet kitten is very sad about this situation. |
2f45e99ad753
[client-connect] drop rqlst on rset returned client side
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9057
diff
changeset
|
218 |
rset._rqlst = None |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
219 |
return rset |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
220 |
|
9582
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
221 |
@_open_only |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
222 |
def commit(self, *args, **kwargs): |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
223 |
try: |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
224 |
return self._cnx.commit(*args, **kwargs) |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
225 |
finally: |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
226 |
self.drop_entity_cache() |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
227 |
|
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
228 |
@_open_only |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
229 |
def rollback(self, *args, **kwargs): |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
230 |
try: |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
231 |
return self._cnx.rollback(*args, **kwargs) |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
232 |
finally: |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
233 |
self.drop_entity_cache() |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
234 |
|
9554
d2fd866f69a2
[repoapi] add security/hook control and system_sql
Julien Cristau <julien.cristau@logilab.fr>
parents:
9475
diff
changeset
|
235 |
# security ################################################################# |
d2fd866f69a2
[repoapi] add security/hook control and system_sql
Julien Cristau <julien.cristau@logilab.fr>
parents:
9475
diff
changeset
|
236 |
|
d2fd866f69a2
[repoapi] add security/hook control and system_sql
Julien Cristau <julien.cristau@logilab.fr>
parents:
9475
diff
changeset
|
237 |
allow_all_hooks_but = _srv_cnx_func('allow_all_hooks_but') |
d2fd866f69a2
[repoapi] add security/hook control and system_sql
Julien Cristau <julien.cristau@logilab.fr>
parents:
9475
diff
changeset
|
238 |
deny_all_hooks_but = _srv_cnx_func('deny_all_hooks_but') |
d2fd866f69a2
[repoapi] add security/hook control and system_sql
Julien Cristau <julien.cristau@logilab.fr>
parents:
9475
diff
changeset
|
239 |
security_enabled = _srv_cnx_func('security_enabled') |
d2fd866f69a2
[repoapi] add security/hook control and system_sql
Julien Cristau <julien.cristau@logilab.fr>
parents:
9475
diff
changeset
|
240 |
|
d2fd866f69a2
[repoapi] add security/hook control and system_sql
Julien Cristau <julien.cristau@logilab.fr>
parents:
9475
diff
changeset
|
241 |
# direct sql ############################################################### |
d2fd866f69a2
[repoapi] add security/hook control and system_sql
Julien Cristau <julien.cristau@logilab.fr>
parents:
9475
diff
changeset
|
242 |
|
d2fd866f69a2
[repoapi] add security/hook control and system_sql
Julien Cristau <julien.cristau@logilab.fr>
parents:
9475
diff
changeset
|
243 |
system_sql = _srv_cnx_func('system_sql') |
d2fd866f69a2
[repoapi] add security/hook control and system_sql
Julien Cristau <julien.cristau@logilab.fr>
parents:
9475
diff
changeset
|
244 |
|
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
245 |
# session data methods ##################################################### |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
246 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
247 |
get_shared_data = _srv_cnx_func('get_shared_data') |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
248 |
set_shared_data = _srv_cnx_func('set_shared_data') |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
249 |
|
9774
b7b71be569cf
deprecate get/set_shared_data API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9630
diff
changeset
|
250 |
@property |
b7b71be569cf
deprecate get/set_shared_data API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9630
diff
changeset
|
251 |
def transaction_data(self): |
b7b71be569cf
deprecate get/set_shared_data API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9630
diff
changeset
|
252 |
return self._cnx.transaction_data |
b7b71be569cf
deprecate get/set_shared_data API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9630
diff
changeset
|
253 |
|
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
254 |
# meta-data accessors ###################################################### |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
255 |
|
9100
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
256 |
@_open_only |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
257 |
def source_defs(self): |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
258 |
"""Return the definition of sources used by the repository.""" |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
259 |
return self._session.repo.source_defs() |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
260 |
|
9100
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
261 |
@_open_only |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
262 |
def get_schema(self): |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
263 |
"""Return the schema currently used by the repository.""" |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
264 |
return self._session.repo.source_defs() |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
265 |
|
9100
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
266 |
@_open_only |
9459
d3016c08b4ae
[repoapi] drop get_option_value's foreid argument
Julien Cristau <julien.cristau@logilab.fr>
parents:
9458
diff
changeset
|
267 |
def get_option_value(self, option): |
d3016c08b4ae
[repoapi] drop get_option_value's foreid argument
Julien Cristau <julien.cristau@logilab.fr>
parents:
9458
diff
changeset
|
268 |
"""Return the value for `option` in the configuration.""" |
d3016c08b4ae
[repoapi] drop get_option_value's foreid argument
Julien Cristau <julien.cristau@logilab.fr>
parents:
9458
diff
changeset
|
269 |
return self._session.repo.get_option_value(option) |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
270 |
|
9469
032825bbacab
[multi-sources-removal] Drop entities.source column
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9459
diff
changeset
|
271 |
entity_metas = _srv_cnx_func('entity_metas') |
032825bbacab
[multi-sources-removal] Drop entities.source column
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9459
diff
changeset
|
272 |
describe = _srv_cnx_func('describe') # XXX deprecated in 3.19 |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
273 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
274 |
# undo support ############################################################ |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
275 |
|
9100
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
276 |
@_open_only |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
277 |
def undoable_transactions(self, ueid=None, req=None, **actionfilters): |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
278 |
"""Return a list of undoable transaction objects by the connection's |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
279 |
user, ordered by descendant transaction time. |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
280 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
281 |
Managers may filter according to user (eid) who has done the transaction |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
282 |
using the `ueid` argument. Others will only see their own transactions. |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
283 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
284 |
Additional filtering capabilities is provided by using the following |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
285 |
named arguments: |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
286 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
287 |
* `etype` to get only transactions creating/updating/deleting entities |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
288 |
of the given type |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
289 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
290 |
* `eid` to get only transactions applied to entity of the given eid |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
291 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
292 |
* `action` to get only transactions doing the given action (action in |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
293 |
'C', 'U', 'D', 'A', 'R'). If `etype`, action can only be 'C', 'U' or |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
294 |
'D'. |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
295 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
296 |
* `public`: when additional filtering is provided, their are by default |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
297 |
only searched in 'public' actions, unless a `public` argument is given |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
298 |
and set to false. |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
299 |
""" |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
300 |
# the ``with`` dance is transitional. We do not have Standalone |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
301 |
# Connection yet so we use this trick to unsure the session have the |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
302 |
# proper cnx loaded. This can be simplified one we have Standalone |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
303 |
# Connection object |
9101
e6d1df619949
[client-connection] remove the _srv_cnx usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9100
diff
changeset
|
304 |
source = self._cnx.repo.system_source |
e6d1df619949
[client-connection] remove the _srv_cnx usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9100
diff
changeset
|
305 |
txinfos = source.undoable_transactions(self._cnx, ueid, **actionfilters) |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
306 |
for txinfo in txinfos: |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
307 |
txinfo.req = req or self # XXX mostly wrong |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
308 |
return txinfos |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
309 |
|
9100
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
310 |
@_open_only |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
311 |
def transaction_info(self, txuuid, req=None): |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
312 |
"""Return transaction object for the given uid. |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
313 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
314 |
raise `NoSuchTransaction` if not found or if session's user is not |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
315 |
allowed (eg not in managers group and the transaction doesn't belong to |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
316 |
him). |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
317 |
""" |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
318 |
# the ``with`` dance is transitional. We do not have Standalone |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
319 |
# Connection yet so we use this trick to unsure the session have the |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
320 |
# proper cnx loaded. This can be simplified one we have Standalone |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
321 |
# Connection object |
9101
e6d1df619949
[client-connection] remove the _srv_cnx usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9100
diff
changeset
|
322 |
txinfo = self._cnx.repo.system_source.tx_info(self._cnx, txuuid) |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
323 |
if req: |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
324 |
txinfo.req = req |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
325 |
else: |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
326 |
txinfo.cnx = self |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
327 |
return txinfo |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
328 |
|
9100
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
329 |
@_open_only |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
330 |
def transaction_actions(self, txuuid, public=True): |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
331 |
"""Return an ordered list of action effectued during that transaction. |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
332 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
333 |
If public is true, return only 'public' actions, eg not ones triggered |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
334 |
under the cover by hooks, else return all actions. |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
335 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
336 |
raise `NoSuchTransaction` if the transaction is not found or if |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
337 |
session's user is not allowed (eg not in managers group and the |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
338 |
transaction doesn't belong to him). |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
339 |
""" |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
340 |
# the ``with`` dance is transitional. We do not have Standalone |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
341 |
# Connection yet so we use this trick to unsure the session have the |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
342 |
# proper cnx loaded. This can be simplified one we have Standalone |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
343 |
# Connection object |
9101
e6d1df619949
[client-connection] remove the _srv_cnx usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9100
diff
changeset
|
344 |
return self._cnx.repo.system_source.tx_actions(self._cnx, txuuid, public) |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
345 |
|
9100
8a1132c7cbd1
[client-connection] explicitly check that the client-connection is open
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9099
diff
changeset
|
346 |
@_open_only |
9052
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
347 |
def undo_transaction(self, txuuid): |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
348 |
"""Undo the given transaction. Return potential restoration errors. |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
349 |
|
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
350 |
raise `NoSuchTransaction` if not found or if session's user is not |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
351 |
allowed (eg not in managers group and the transaction doesn't belong to |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
352 |
him). |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
353 |
""" |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
354 |
# the ``with`` dance is transitional. We do not have Standalone |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
355 |
# Connection yet so we use this trick to unsure the session have the |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
356 |
# proper cnx loaded. This can be simplified one we have Standalone |
4cba5f2cd57b
[repoapi] introduce a basic ClientConnection class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9045
diff
changeset
|
357 |
# Connection object |
9101
e6d1df619949
[client-connection] remove the _srv_cnx usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9100
diff
changeset
|
358 |
return self._cnx.repo.system_source.undo_transaction(self._cnx, txuuid) |
9053
862040061173
[client-connection] add a request() method for dbapi compatibility
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9052
diff
changeset
|
359 |
|
9582
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
360 |
# cache management |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
361 |
|
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
362 |
def entity_cache(self, eid): |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
363 |
return self._eid_cache[eid] |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
364 |
|
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
365 |
def set_entity_cache(self, entity): |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
366 |
self._eid_cache[entity.eid] = entity |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
367 |
|
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
368 |
def cached_entities(self): |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
369 |
return self._eid_cache.values() |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
370 |
|
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
371 |
def drop_entity_cache(self, eid=None): |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
372 |
if eid is None: |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
373 |
self._eid_cache = {} |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
374 |
else: |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
375 |
del self._eid_cache[eid] |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
376 |
|
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
377 |
# deprecated stuff |
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9575
diff
changeset
|
378 |
|
9404
3e3e9b37e177
fix version number: we still target cw 3.19
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9125
diff
changeset
|
379 |
@deprecated('[3.19] This is a repoapi.ClientConnection object not a dbapi one') |
9053
862040061173
[client-connection] add a request() method for dbapi compatibility
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9052
diff
changeset
|
380 |
def request(self): |
862040061173
[client-connection] add a request() method for dbapi compatibility
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9052
diff
changeset
|
381 |
return self |
9054
d7e78645dab6
[client-connection] add a cursor() method for dbapi compatibility
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9053
diff
changeset
|
382 |
|
9404
3e3e9b37e177
fix version number: we still target cw 3.19
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9125
diff
changeset
|
383 |
@deprecated('[3.19] This is a repoapi.ClientConnection object not a dbapi one') |
9054
d7e78645dab6
[client-connection] add a cursor() method for dbapi compatibility
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9053
diff
changeset
|
384 |
def cursor(self): |
d7e78645dab6
[client-connection] add a cursor() method for dbapi compatibility
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9053
diff
changeset
|
385 |
return self |
9055
2567b7d04e49
[client-connection] add a sessionid property for dbapi compatibility
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9054
diff
changeset
|
386 |
|
9630
e7dbc4f06a48
minor cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9582
diff
changeset
|
387 |
@property |
9404
3e3e9b37e177
fix version number: we still target cw 3.19
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9125
diff
changeset
|
388 |
@deprecated('[3.19] This is a repoapi.ClientConnection object not a dbapi one') |
9055
2567b7d04e49
[client-connection] add a sessionid property for dbapi compatibility
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9054
diff
changeset
|
389 |
def sessionid(self): |
9575
754904ac4248
[repoapi] Avoid deprecation warnings from session.id
Julien Cristau <julien.cristau@logilab.fr>
parents:
9554
diff
changeset
|
390 |
return self._session.sessionid |
9056
e777be2c5007
[client-connection] add a connection property for dbapi compatibility
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9055
diff
changeset
|
391 |
|
e777be2c5007
[client-connection] add a connection property for dbapi compatibility
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9055
diff
changeset
|
392 |
@property |
9404
3e3e9b37e177
fix version number: we still target cw 3.19
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9125
diff
changeset
|
393 |
@deprecated('[3.19] This is a repoapi.ClientConnection object not a dbapi one') |
9056
e777be2c5007
[client-connection] add a connection property for dbapi compatibility
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9055
diff
changeset
|
394 |
def connection(self): |
e777be2c5007
[client-connection] add a connection property for dbapi compatibility
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9055
diff
changeset
|
395 |
return self |
9057
99cd4761aee6
[client-connection] add a repo property for dbapi compatibility
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9056
diff
changeset
|
396 |
|
99cd4761aee6
[client-connection] add a repo property for dbapi compatibility
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9056
diff
changeset
|
397 |
@property |
9404
3e3e9b37e177
fix version number: we still target cw 3.19
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9125
diff
changeset
|
398 |
@deprecated('[3.19] This is a repoapi.ClientConnection object not a dbapi one') |
9057
99cd4761aee6
[client-connection] add a repo property for dbapi compatibility
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9056
diff
changeset
|
399 |
def _repo(self): |
99cd4761aee6
[client-connection] add a repo property for dbapi compatibility
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9056
diff
changeset
|
400 |
return self._session.repo |