[rset] make rsets picklable (again ?) #1056422 stable
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Fri, 11 Jun 2010 18:47:53 +0200
branchstable
changeset 5740 46207f491a51
parent 5737 ae49022bf411
child 5741 bbef88618fbb
[rset] make rsets picklable (again ?) #1056422
rset.py
test/unittest_rset.py
--- a/rset.py	Fri Jun 11 15:54:29 2010 +0200
+++ b/rset.py	Fri Jun 11 18:47:53 2010 +0200
@@ -44,6 +44,9 @@
     :type rql: str or unicode
     :param rql: the original RQL query string
     """
+    _picklable_attributes = set(['limited', 'rows', 'description', '_rsetactions',
+                                 'args', 'rowcount', '_rqlst', 'rql'])
+
     def __init__(self, results, rql, args=None, description=(), rqlst=None):
         self.rows = results
         self.rowcount = results and len(results) or 0
@@ -117,6 +120,10 @@
         """Returns an iterator over rows"""
         return iter(self.rows)
 
+    def __getstate__(self):
+        return dict((k, v) for k, v in self.__dict__.iteritems()
+                    if k in self._picklable_attributes)
+
     def __add__(self, rset):
         # XXX buggy implementation (.rql and .args attributes at least much
         # probably differ)
--- a/test/unittest_rset.py	Fri Jun 11 15:54:29 2010 +0200
+++ b/test/unittest_rset.py	Fri Jun 11 18:47:53 2010 +0200
@@ -21,6 +21,7 @@
 """
 
 from urlparse import urlsplit
+import pickle
 
 from rql import parse
 
@@ -84,6 +85,8 @@
             params2 = dict(pair.split('=') for pair in info1[3].split('&'))
             self.assertDictEquals(params1, params2)
 
+    def test_pickle(self):
+        self.assertEquals(len(pickle.dumps(self.rset)), 392)
 
     def test_build_url(self):
         req = self.request()