drop _prepare_copy method from rset in favor of a more generic copy method stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 21 Oct 2009 09:47:55 +0200
branchstable
changeset 3764 034aa14b740a
parent 3763 bc61e5211477
child 3765 769dc0107f31
child 3768 8c85a2f7f5ad
drop _prepare_copy method from rset in favor of a more generic copy method
devtools/testlib.py
rset.py
--- a/devtools/testlib.py	Wed Oct 21 08:59:14 2009 +0200
+++ b/devtools/testlib.py	Wed Oct 21 09:47:55 2009 +0200
@@ -325,7 +325,7 @@
             if k.endswith('visible') and not v['default']:
                 propdefs[k]['default'] = True
         for view in self.list_views_for(rset):
-            backup_rset = rset._prepare_copy(rset.rows, rset.description)
+            backup_rset = rset.copy(rset.rows, rset.description)
             yield InnerTest(self._testname(rset, view.id, 'view'),
                             self.view, view.id, rset,
                             rset.req.reset_headers(), 'main-template')
--- a/rset.py	Wed Oct 21 08:59:14 2009 +0200
+++ b/rset.py	Wed Oct 21 09:47:55 2009 +0200
@@ -117,11 +117,10 @@
                          self.description +rset.description)
         return self.req.decorate_rset(rset)
 
-    def copy(self):
-        rset = ResultSet(self.rows[:], self.rql, self.args, self.description[:])
-        return self.req.decorate_rset(rset)
-
-    def _prepare_copy(self, rows, descr):
+    def copy(self, rows=None, descr=None):
+        if rows is None:
+            rows = self.rows[:]
+            descr = self.description[:]
         rset = ResultSet(rows, self.rql, self.args, descr)
         return self.req.decorate_rset(rset)
 
@@ -140,7 +139,7 @@
         :rtype: `ResultSet`
         """
         rows, descr = [], []
-        rset = self._prepare_copy(rows, descr)
+        rset = self.copy(rows, descr)
         for row, desc in zip(self.rows, self.description):
             nrow, ndesc = transformcb(row, desc)
             if ndesc: # transformcb returns None for ndesc to skip that row
@@ -163,7 +162,7 @@
         :rtype: `ResultSet`
         """
         rows, descr = [], []
-        rset = self._prepare_copy(rows, descr)
+        rset = self.copy(rows, descr)
         for i in xrange(len(self)):
             if not filtercb(self.get_entity(i, col)):
                 continue
@@ -190,7 +189,7 @@
         :rtype: `ResultSet`
         """
         rows, descr = [], []
-        rset = self._prepare_copy(rows, descr)
+        rset = self.copy(rows, descr)
         if col >= 0:
             entities = sorted(enumerate(self.entities(col)),
                               key=lambda (i, e): keyfunc(e), reverse=reverse)
@@ -237,7 +236,7 @@
 
             if key not in mapping:
                 rows, descr = [], []
-                rset = self._prepare_copy(rows, descr)
+                rset = self.copy(rows, descr)
                 mapping[key] = rset
                 result.append(rset)
             else:
@@ -289,7 +288,7 @@
                     else:
                         self.req.drop_entity_cache(entity.eid)
         else:
-            rset = self._prepare_copy(rows, descr)
+            rset = self.copy(rows, descr)
             if not offset:
                 # can copy built entity caches
                 copy_cache(rset, 'get_entity', self)