15 # |
15 # |
16 # You should have received a copy of the GNU Lesser General Public License along |
16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """Official API to access the content of a repository.""" |
18 """Official API to access the content of a repository.""" |
19 |
19 |
20 from warnings import warn |
|
21 |
|
22 from six import add_metaclass |
|
23 |
|
24 from logilab.common.deprecation import class_deprecated |
|
25 |
|
26 from cubicweb import AuthenticationError |
20 from cubicweb import AuthenticationError |
27 from cubicweb.server.session import Connection |
21 from cubicweb.server.session import Connection |
28 |
22 |
29 |
23 |
30 def get_repository(uri=None, config=None, vreg=None): |
24 def get_repository(config, vreg=None): |
31 """get a repository for the given URI or config/vregistry (in case we're |
25 """get a repository for the given URI or config/vregistry (in case we're |
32 loading the repository for a client, eg web server, configuration). |
26 loading the repository for a client, eg web server, configuration). |
33 |
27 |
34 The returned repository may be an in-memory repository or a proxy object |
28 The returned repository may be an in-memory repository or a proxy object |
35 using a specific RPC method, depending on the given URI. |
29 using a specific RPC method, depending on the given URI. |
36 """ |
30 """ |
37 if uri is not None: |
|
38 warn('[3.22] get_repository only wants a config') |
|
39 |
|
40 assert config is not None, 'get_repository(config=config)' |
|
41 return config.repository(vreg) |
31 return config.repository(vreg) |
42 |
32 |
43 |
33 |
44 def connect(repo, login, **kwargs): |
34 def connect(repo, login, **kwargs): |
45 """Take credential and return associated Connection. |
35 """Take credential and return associated Connection. |
61 if anoninfo is None: # no anonymous user |
51 if anoninfo is None: # no anonymous user |
62 raise AuthenticationError('anonymous access is not authorized') |
52 raise AuthenticationError('anonymous access is not authorized') |
63 anon_login, anon_password = anoninfo |
53 anon_login, anon_password = anoninfo |
64 # use vreg's repository cache |
54 # use vreg's repository cache |
65 return connect(repo, anon_login, password=anon_password) |
55 return connect(repo, anon_login, password=anon_password) |
66 |
|
67 |
|
68 @add_metaclass(class_deprecated) |
|
69 class ClientConnection(Connection): |
|
70 __deprecation_warning__ = '[3.20] %(cls)s is deprecated, use Connection instead' |
|