[shared data] remove get/set_shared_data api

It was redundant with session_data and transaction_data and costly to maintain.

Closes #3938370.

authorAurelien Campeas <aurelien.campeas@logilab.fr>
changeset06402468c137
branchdefault
phasedraft
hiddenyes
parent revision#bbe9af4d4e18 [entity/req] pass the _cw object to cw_instantiate
child revision#5666e7891282 Remove remote repository-access-through-pyro support
files modified by this revision
dbapi.py
doc/3.21.rst
repoapi.py
server/repository.py
server/session.py
server/test/unittest_repository.py
test/unittest_dbapi.py
web/request.py
# HG changeset patch
# User Aurelien Campeas <aurelien.campeas@logilab.fr>
# Date 1401813425 -7200
# Tue Jun 03 18:37:05 2014 +0200
# Node ID 06402468c1374e809ea54af097a766b61a710d67
# Parent bbe9af4d4e183896d272291019f929b6edb30c41
[shared data] remove get/set_shared_data api

It was redundant with session_data and transaction_data
and costly to maintain.

Closes #3938370.

diff --git a/dbapi.py b/dbapi.py
@@ -339,26 +339,10 @@
1          if eid is None:
2              self._eid_cache = {}
3          else:
4              del self._eid_cache[eid]
5 
6 -    # low level session data management #######################################
7 -
8 -    @deprecated('[3.19] use session or transaction data')
9 -    def get_shared_data(self, key, default=None, pop=False, txdata=False):
10 -        """see :meth:`Connection.get_shared_data`"""
11 -        return self.cnx.get_shared_data(key, default, pop, txdata)
12 -
13 -    @deprecated('[3.19] use session or transaction data')
14 -    def set_shared_data(self, key, value, txdata=False, querydata=None):
15 -        """see :meth:`Connection.set_shared_data`"""
16 -        if querydata is not None:
17 -            txdata = querydata
18 -            warn('[3.10] querydata argument has been renamed to txdata',
19 -                 DeprecationWarning, stacklevel=2)
20 -        return self.cnx.set_shared_data(key, value, txdata)
21 -
22      # server session compat layer #############################################
23 
24      def entity_metas(self, eid):
25          """return a tuple (type, sourceuri, extid) for the entity with id <eid>"""
26          return self.cnx.entity_metas(eid)
@@ -623,34 +607,10 @@
27      def _txid(self, cursor=None): # pylint: disable=E0202
28          # XXX could now handle various isolation level!
29          # return a dict as bw compat trick
30          return {'txid': currentThread().getName()}
31 
32 -    # session data methods #####################################################
33 -
34 -    @check_not_closed
35 -    def get_shared_data(self, key, default=None, pop=False, txdata=False):
36 -        """return value associated to key in the session's data dictionary or
37 -        session's transaction's data if `txdata` is true.
38 -
39 -        If pop is True, value will be removed from the dictionary.
40 -
41 -        If key isn't defined in the dictionary, value specified by the
42 -        `default` argument will be returned.
43 -        """
44 -        return self._repo.get_shared_data(self.sessionid, key, default, pop, txdata)
45 -
46 -    @check_not_closed
47 -    def set_shared_data(self, key, value, txdata=False):
48 -        """set value associated to `key` in shared data
49 -
50 -        if `txdata` is true, the value will be added to the repository
51 -        session's query data which are cleared on commit/rollback of the current
52 -        transaction.
53 -        """
54 -        return self._repo.set_shared_data(self.sessionid, key, value, txdata)
55 -
56      # meta-data accessors ######################################################
57 
58      @check_not_closed
59      def source_defs(self):
60          """Return the definition of sources used by the repository."""
diff --git a/doc/3.21.rst b/doc/3.21.rst
@@ -5,5 +5,9 @@
61  Deprecated code drops
62  ---------------------
63 
64  * the user_callback api has been removed; people should use plain
65    ajax functions instead
66 +
67 +* the get/set_shared_data api has been removed; people should use
68 +  transaction_data or session_data instead
69 +
diff --git a/repoapi.py b/repoapi.py
@@ -238,13 +238,10 @@
70 
71      system_sql = _srv_cnx_func('system_sql')
72 
73      # session data methods #####################################################
74 
75 -    get_shared_data = _srv_cnx_func('get_shared_data')
76 -    set_shared_data = _srv_cnx_func('set_shared_data')
77 -
78      @property
79      def transaction_data(self):
80          return self._cnx.transaction_data
81 
82      # meta-data accessors ######################################################
diff --git a/server/repository.py b/server/repository.py
@@ -747,34 +747,10 @@
83          """raise `BadConnectionId` if the connection is no more valid, else
84          return its latest activity timestamp.
85          """
86          return self._get_session(sessionid, setcnxset=False).timestamp
87 
88 -    @deprecated('[3.19] use session or transaction data')
89 -    def get_shared_data(self, sessionid, key, default=None, pop=False, txdata=False):
90 -        """return value associated to key in the session's data dictionary or
91 -        session's transaction's data if `txdata` is true.
92 -
93 -        If pop is True, value will be removed from the dictionary.
94 -
95 -        If key isn't defined in the dictionary, value specified by the
96 -        `default` argument will be returned.
97 -        """
98 -        session = self._get_session(sessionid, setcnxset=False)
99 -        return session.get_shared_data(key, default, pop, txdata)
100 -
101 -    @deprecated('[3.19] use session or transaction data')
102 -    def set_shared_data(self, sessionid, key, value, txdata=False):
103 -        """set value associated to `key` in shared data
104 -
105 -        if `txdata` is true, the value will be added to the repository session's
106 -        transaction's data which are cleared on commit/rollback of the current
107 -        transaction.
108 -        """
109 -        session = self._get_session(sessionid, setcnxset=False)
110 -        session.set_shared_data(key, value, txdata)
111 -
112      def commit(self, sessionid, txid=None):
113          """commit transaction for the session with the given id"""
114          self.debug('begin commit for session %s', sessionid)
115          try:
116              session = self._get_session(sessionid)
diff --git a/server/session.py b/server/session.py
@@ -545,32 +545,10 @@
117 
118      @property
119      def rql_rewriter(self):
120          return self._rewriter
121 
122 -    @_open_only
123 -    @deprecated('[3.19] use session or transaction data', stacklevel=3)
124 -    def get_shared_data(self, key, default=None, pop=False, txdata=False):
125 -        """return value associated to `key` in session data"""
126 -        if txdata:
127 -            data = self.transaction_data
128 -        else:
129 -            data = self._session_data
130 -        if pop:
131 -            return data.pop(key, default)
132 -        else:
133 -            return data.get(key, default)
134 -
135 -    @_open_only
136 -    @deprecated('[3.19] use session or transaction data', stacklevel=3)
137 -    def set_shared_data(self, key, value, txdata=False):
138 -        """set value associated to `key` in session data"""
139 -        if txdata:
140 -            self.transaction_data[key] = value
141 -        else:
142 -            self._session_data[key] = value
143 -
144      def clear(self):
145          """reset internal data"""
146          self.transaction_data = {}
147          #: ordered list of operations to be processed on commit/rollback
148          self.pending_operations = []
@@ -1264,12 +1242,10 @@
149        containing some shared data that should be cleared at the end of the
150        connection. Hooks and operations may put arbitrary data in there, and
151        this may also be used as a communication channel between the client and
152        the repository.
153 
154 -    .. automethod:: cubicweb.server.session.Session.get_shared_data
155 -    .. automethod:: cubicweb.server.session.Session.set_shared_data
156      .. automethod:: cubicweb.server.session.Session.added_in_transaction
157      .. automethod:: cubicweb.server.session.Session.deleted_in_transaction
158 
159      Connection state information:
160 
@@ -1557,32 +1533,10 @@
161      def local_perm_cache(self, value):
162          #base class assign an empty dict:-(
163          assert value == {}
164          pass
165 
166 -    # shared data handling ###################################################
167 -
168 -    @deprecated('[3.19] use session or transaction data')
169 -    def get_shared_data(self, key, default=None, pop=False, txdata=False):
170 -        """return value associated to `key` in session data"""
171 -        if txdata:
172 -            return self._cnx.get_shared_data(key, default, pop, txdata=True)
173 -        else:
174 -            data = self.data
175 -        if pop:
176 -            return data.pop(key, default)
177 -        else:
178 -            return data.get(key, default)
179 -
180 -    @deprecated('[3.19] use session or transaction data')
181 -    def set_shared_data(self, key, value, txdata=False):
182 -        """set value associated to `key` in session data"""
183 -        if txdata:
184 -            return self._cnx.set_shared_data(key, value, txdata=True)
185 -        else:
186 -            self.data[key] = value
187 -
188      # server-side service call #################################################
189 
190      call_service = cnx_meth('call_service')
191 
192      # request interface #######################################################
diff --git a/server/test/unittest_repository.py b/server/test/unittest_repository.py
@@ -170,30 +170,10 @@
193 
194      def test_invalid_cnxid(self):
195          self.assertRaises(BadConnectionId, self.repo.execute, 0, 'Any X')
196          self.assertRaises(BadConnectionId, self.repo.close, None)
197 
198 -    def test_shared_data(self):
199 -        repo = self.repo
200 -        cnxid = repo.connect(self.admlogin, password=self.admpassword)
201 -        repo.set_shared_data(cnxid, 'data', 4)
202 -        cnxid2 = repo.connect(self.admlogin, password=self.admpassword)
203 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
204 -        self.assertEqual(repo.get_shared_data(cnxid2, 'data'), None)
205 -        repo.set_shared_data(cnxid2, 'data', 5)
206 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
207 -        self.assertEqual(repo.get_shared_data(cnxid2, 'data'), 5)
208 -        repo.get_shared_data(cnxid2, 'data', pop=True)
209 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
210 -        self.assertEqual(repo.get_shared_data(cnxid2, 'data'), None)
211 -        repo.close(cnxid)
212 -        repo.close(cnxid2)
213 -        self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid, 'data')
214 -        self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid2, 'data')
215 -        self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid, 'data', 1)
216 -        self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid2, 'data', 1)
217 -
218      def test_check_session(self):
219          repo = self.repo
220          cnxid = repo.connect(self.admlogin, password=self.admpassword)
221          self.assertIsInstance(repo.check_session(cnxid), float)
222          repo.close(cnxid)
@@ -446,23 +426,10 @@
223          self.assertEqual(repo.describe(cnxid, 2), (u'CWGroup', 'system', None, 'system'))
224          repo.close(cnxid)
225          self.assertRaises(BadConnectionId, repo.user_info, cnxid)
226          self.assertRaises(BadConnectionId, repo.describe, cnxid, 1)
227 
228 -    def test_shared_data_api(self):
229 -        repo = self.repo
230 -        cnxid = repo.connect(self.admlogin, password=self.admpassword)
231 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), None)
232 -        repo.set_shared_data(cnxid, 'data', 4)
233 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
234 -        repo.get_shared_data(cnxid, 'data', pop=True)
235 -        repo.get_shared_data(cnxid, 'whatever', pop=True)
236 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), None)
237 -        repo.close(cnxid)
238 -        self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid, 'data', 0)
239 -        self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid, 'data')
240 -
241      def test_schema_is_relation(self):
242          with self.admin_access.repo_cnx() as cnx:
243              no_is_rset = cnx.execute('Any X WHERE NOT X is ET')
244              self.assertFalse(no_is_rset, no_is_rset.description)
245 
diff --git a/test/unittest_dbapi.py b/test/unittest_dbapi.py
@@ -55,25 +55,10 @@
246          cnx.close()
247          self.assertRaises(ProgrammingError, cnx.user, None)
248          self.assertRaises(ProgrammingError, cnx.entity_metas, 1)
249          self.assertRaises(ProgrammingError, cnx.describe, 1)
250 
251 -    def test_shared_data_api(self):
252 -        cnx = _repo_connect(self.repo, login='anon', password='anon')
253 -        self.assertEqual(cnx.get_shared_data('data'), None)
254 -        cnx.set_shared_data('data', 4)
255 -        self.assertEqual(cnx.get_shared_data('data'), 4)
256 -        cnx.get_shared_data('data', pop=True)
257 -        cnx.get_shared_data('whatever', pop=True)
258 -        self.assertEqual(cnx.get_shared_data('data'), None)
259 -        cnx.set_shared_data('data', 4)
260 -        self.assertEqual(cnx.get_shared_data('data'), 4)
261 -        cnx.close()
262 -        self.assertRaises(ProgrammingError, cnx.check)
263 -        self.assertRaises(ProgrammingError, cnx.set_shared_data, 'data', 0)
264 -        self.assertRaises(ProgrammingError, cnx.get_shared_data, 'data')
265 -
266      def test_web_compatible_request(self):
267          config = cwconfig.CubicWebNoAppConfiguration()
268          cnx = _repo_connect(self.repo, login='admin', password='gingkow')
269          with tempattr(cnx.vreg, 'config', config):
270              cnx.use_web_compatible_requests('http://perdu.com')
diff --git a/web/request.py b/web/request.py
@@ -1007,12 +1007,10 @@
271              self._ = self.__ = unicode
272              self.pgettext = lambda x, y: unicode(y)
273 
274      entity_metas = _cnx_func('entity_metas')
275      source_defs = _cnx_func('source_defs')
276 -    get_shared_data = _cnx_func('get_shared_data')
277 -    set_shared_data = _cnx_func('set_shared_data')
278      describe = _cnx_func('describe') # deprecated XXX
279 
280      # security #################################################################
281 
282      security_enabled = _cnx_func('security_enabled')