def test_copy_cache(self):
     class Foo(object):
         @cached(cacheattr=u'_foo')
         def foo(self, args):
             """ what's up doc ? """
     foo = Foo()
     foo.foo(1)
     self.assertEqual(foo._foo, {(1,): None})
     foo2 = Foo()
     self.assertFalse(hasattr(foo2, '_foo'))
     copy_cache(foo2, 'foo', foo)
     self.assertEqual(foo2._foo, {(1,): None})
Exemplo n.º 2
0
 def test_copy_cache(self):
     class Foo(object):
         @cached(cacheattr=u'_foo')
         def foo(self, args):
             """ what's up doc ? """
     foo = Foo()
     foo.foo(1)
     self.assertEqual(foo._foo, {(1,): None})
     foo2 = Foo()
     self.assertFalse(hasattr(foo2, '_foo'))
     copy_cache(foo2, 'foo', foo)
     self.assertEqual(foo2._foo, {(1,): None})
Exemplo n.º 3
0
    def limit(self, limit, offset=0, inplace=False):
        """limit the result set to the given number of rows optionally starting
        from an index different than 0

        :type limit: int
        :param limit: the maximum number of results

        :type offset: int
        :param offset: the offset index

        :type inplace: bool
        :param inplace:
          if true, the result set is modified in place, else a new result set
          is returned and the original is left unmodified

        :rtype: `ResultSet`
        """
        stop = limit + offset
        rows = self.rows[offset:stop]
        descr = self.description[offset:stop]
        if inplace:
            rset = self
            rset.rows, rset.description = rows, descr
            rset.rowcount = len(rows)
            clear_cache(rset, 'description_struct')
            if offset:
                clear_cache(rset, 'get_entity')
            # we also have to fix/remove from the request entity cache entities
            # which get a wrong rset reference by this limit call
            for entity in self.req.cached_entities():
                if entity.cw_rset is self:
                    if offset <= entity.cw_row < stop:
                        entity.cw_row = entity.cw_row - offset
                    else:
                        entity.cw_rset = entity.as_rset()
                        entity.cw_row = entity.cw_col = 0
        else:
            rset = self.copy(rows, descr)
            if not offset:
                # can copy built entity caches
                copy_cache(rset, 'get_entity', self)
        rset.limited = (limit, offset)
        return rset