[shared data] remove get/set_shared_data api

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

authorAurelien Campeas <aurelien.campeas@logilab.fr>
changeseta8da99005878
branchdefault
phasedraft
hiddenyes
parent revision#0db00b80c58c [source/native] session -> cnx
child revision#0e3418b0cd5f remove pyro support (closes #2919309)
files modified by this revision
dbapi.py
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 a8da990058784f3d4a2a9d3e1ebb81a3c813cb08
# Parent 0db00b80c58ced5a45f85d262a2da2d1c9229366
[shared data] remove get/set_shared_data api

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

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)
@@ -626,34 +610,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/repoapi.py b/repoapi.py
@@ -238,13 +238,10 @@
61 
62      system_sql = _srv_cnx_func('system_sql')
63 
64      # session data methods #####################################################
65 
66 -    get_shared_data = _srv_cnx_func('get_shared_data')
67 -    set_shared_data = _srv_cnx_func('set_shared_data')
68 -
69      @property
70      def transaction_data(self):
71          return self._cnx.transaction_data
72 
73      # meta-data accessors ######################################################
diff --git a/server/repository.py b/server/repository.py
@@ -744,34 +744,10 @@
74          """raise `BadConnectionId` if the connection is no more valid, else
75          return its latest activity timestamp.
76          """
77          return self._get_session(sessionid, setcnxset=False).timestamp
78 
79 -    @deprecated('[3.19] use session or transaction data')
80 -    def get_shared_data(self, sessionid, key, default=None, pop=False, txdata=False):
81 -        """return value associated to key in the session's data dictionary or
82 -        session's transaction's data if `txdata` is true.
83 -
84 -        If pop is True, value will be removed from the dictionary.
85 -
86 -        If key isn't defined in the dictionary, value specified by the
87 -        `default` argument will be returned.
88 -        """
89 -        session = self._get_session(sessionid, setcnxset=False)
90 -        return session.get_shared_data(key, default, pop, txdata)
91 -
92 -    @deprecated('[3.19] use session or transaction data')
93 -    def set_shared_data(self, sessionid, key, value, txdata=False):
94 -        """set value associated to `key` in shared data
95 -
96 -        if `txdata` is true, the value will be added to the repository session's
97 -        transaction's data which are cleared on commit/rollback of the current
98 -        transaction.
99 -        """
100 -        session = self._get_session(sessionid, setcnxset=False)
101 -        session.set_shared_data(key, value, txdata)
102 -
103      def commit(self, sessionid, txid=None):
104          """commit transaction for the session with the given id"""
105          self.debug('begin commit for session %s', sessionid)
106          try:
107              session = self._get_session(sessionid)
diff --git a/server/session.py b/server/session.py
@@ -546,32 +546,10 @@
108 
109      @property
110      def rql_rewriter(self):
111          return self._rewriter
112 
113 -    @_open_only
114 -    @deprecated('[3.19] use session or transaction data')
115 -    def get_shared_data(self, key, default=None, pop=False, txdata=False):
116 -        """return value associated to `key` in session data"""
117 -        if txdata:
118 -            data = self.transaction_data
119 -        else:
120 -            data = self._session_data
121 -        if pop:
122 -            return data.pop(key, default)
123 -        else:
124 -            return data.get(key, default)
125 -
126 -    @_open_only
127 -    @deprecated('[3.19] use session or transaction data')
128 -    def set_shared_data(self, key, value, txdata=False):
129 -        """set value associated to `key` in session data"""
130 -        if txdata:
131 -            self.transaction_data[key] = value
132 -        else:
133 -            self._session_data[key] = value
134 -
135      def clear(self):
136          """reset internal data"""
137          self.transaction_data = {}
138          #: ordered list of operations to be processed on commit/rollback
139          self.pending_operations = []
@@ -1263,12 +1241,10 @@
140        containing some shared data that should be cleared at the end of the
141        connection. Hooks and operations may put arbitrary data in there, and
142        this may also be used as a communication channel between the client and
143        the repository.
144 
145 -    .. automethod:: cubicweb.server.session.Session.get_shared_data
146 -    .. automethod:: cubicweb.server.session.Session.set_shared_data
147      .. automethod:: cubicweb.server.session.Session.added_in_transaction
148      .. automethod:: cubicweb.server.session.Session.deleted_in_transaction
149 
150      Connection state information:
151 
@@ -1556,32 +1532,10 @@
152      def local_perm_cache(self, value):
153          #base class assign an empty dict:-(
154          assert value == {}
155          pass
156 
157 -    # shared data handling ###################################################
158 -
159 -    @deprecated('[3.19] use session or transaction data')
160 -    def get_shared_data(self, key, default=None, pop=False, txdata=False):
161 -        """return value associated to `key` in session data"""
162 -        if txdata:
163 -            return self._cnx.get_shared_data(key, default, pop, txdata=True)
164 -        else:
165 -            data = self.data
166 -        if pop:
167 -            return data.pop(key, default)
168 -        else:
169 -            return data.get(key, default)
170 -
171 -    @deprecated('[3.19] use session or transaction data')
172 -    def set_shared_data(self, key, value, txdata=False):
173 -        """set value associated to `key` in session data"""
174 -        if txdata:
175 -            return self._cnx.set_shared_data(key, value, txdata=True)
176 -        else:
177 -            self.data[key] = value
178 -
179      # server-side service call #################################################
180 
181      call_service = cnx_meth('call_service')
182 
183      # request interface #######################################################
diff --git a/server/test/unittest_repository.py b/server/test/unittest_repository.py
@@ -170,30 +170,10 @@
184 
185      def test_invalid_cnxid(self):
186          self.assertRaises(BadConnectionId, self.repo.execute, 0, 'Any X')
187          self.assertRaises(BadConnectionId, self.repo.close, None)
188 
189 -    def test_shared_data(self):
190 -        repo = self.repo
191 -        cnxid = repo.connect(self.admlogin, password=self.admpassword)
192 -        repo.set_shared_data(cnxid, 'data', 4)
193 -        cnxid2 = repo.connect(self.admlogin, password=self.admpassword)
194 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
195 -        self.assertEqual(repo.get_shared_data(cnxid2, 'data'), None)
196 -        repo.set_shared_data(cnxid2, 'data', 5)
197 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
198 -        self.assertEqual(repo.get_shared_data(cnxid2, 'data'), 5)
199 -        repo.get_shared_data(cnxid2, 'data', pop=True)
200 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
201 -        self.assertEqual(repo.get_shared_data(cnxid2, 'data'), None)
202 -        repo.close(cnxid)
203 -        repo.close(cnxid2)
204 -        self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid, 'data')
205 -        self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid2, 'data')
206 -        self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid, 'data', 1)
207 -        self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid2, 'data', 1)
208 -
209      def test_check_session(self):
210          repo = self.repo
211          cnxid = repo.connect(self.admlogin, password=self.admpassword)
212          self.assertIsInstance(repo.check_session(cnxid), float)
213          repo.close(cnxid)
@@ -444,23 +424,10 @@
214          self.assertEqual(repo.describe(cnxid, 2), (u'CWGroup', 'system', None, 'system'))
215          repo.close(cnxid)
216          self.assertRaises(BadConnectionId, repo.user_info, cnxid)
217          self.assertRaises(BadConnectionId, repo.describe, cnxid, 1)
218 
219 -    def test_shared_data_api(self):
220 -        repo = self.repo
221 -        cnxid = repo.connect(self.admlogin, password=self.admpassword)
222 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), None)
223 -        repo.set_shared_data(cnxid, 'data', 4)
224 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
225 -        repo.get_shared_data(cnxid, 'data', pop=True)
226 -        repo.get_shared_data(cnxid, 'whatever', pop=True)
227 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), None)
228 -        repo.close(cnxid)
229 -        self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid, 'data', 0)
230 -        self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid, 'data')
231 -
232      def test_schema_is_relation(self):
233          with self.admin_access.repo_cnx() as cnx:
234              no_is_rset = cnx.execute('Any X WHERE NOT X is ET')
235              self.assertFalse(no_is_rset, no_is_rset.description)
236 
diff --git a/test/unittest_dbapi.py b/test/unittest_dbapi.py
@@ -55,25 +55,10 @@
237          cnx.close()
238          self.assertRaises(ProgrammingError, cnx.user, None)
239          self.assertRaises(ProgrammingError, cnx.entity_metas, 1)
240          self.assertRaises(ProgrammingError, cnx.describe, 1)
241 
242 -    def test_shared_data_api(self):
243 -        cnx = _repo_connect(self.repo, login='anon', password='anon')
244 -        self.assertEqual(cnx.get_shared_data('data'), None)
245 -        cnx.set_shared_data('data', 4)
246 -        self.assertEqual(cnx.get_shared_data('data'), 4)
247 -        cnx.get_shared_data('data', pop=True)
248 -        cnx.get_shared_data('whatever', pop=True)
249 -        self.assertEqual(cnx.get_shared_data('data'), None)
250 -        cnx.set_shared_data('data', 4)
251 -        self.assertEqual(cnx.get_shared_data('data'), 4)
252 -        cnx.close()
253 -        self.assertRaises(ProgrammingError, cnx.check)
254 -        self.assertRaises(ProgrammingError, cnx.set_shared_data, 'data', 0)
255 -        self.assertRaises(ProgrammingError, cnx.get_shared_data, 'data')
256 -
257      def test_web_compatible_request(self):
258          config = cwconfig.CubicWebNoAppConfiguration()
259          cnx = _repo_connect(self.repo, login='admin', password='gingkow')
260          with tempattr(cnx.vreg, 'config', config):
261              cnx.use_web_compatible_requests('http://perdu.com')
diff --git a/web/request.py b/web/request.py
@@ -1059,12 +1059,10 @@
262              self._ = self.__ = unicode
263              self.pgettext = lambda x, y: unicode(y)
264 
265      entity_metas = _cnx_func('entity_metas')
266      source_defs = _cnx_func('source_defs')
267 -    get_shared_data = _cnx_func('get_shared_data')
268 -    set_shared_data = _cnx_func('set_shared_data')
269      describe = _cnx_func('describe') # deprecated XXX
270 
271      # server-side service call #################################################
272 
273      def call_service(self, regid, **kwargs):