--- a/rset.py Thu May 14 10:24:56 2009 +0200
+++ b/rset.py Thu May 14 11:38:40 2009 +0200
@@ -11,7 +11,7 @@
from rql import nodes
from cubicweb import NotAnEntity
-
+
class ResultSet(object):
"""a result set wrap a RQL query result. This object implements a partial
@@ -53,12 +53,12 @@
self.req = None
# actions cache
self._rsetactions = None
-
+
def __str__(self):
if not self.rows:
return '<empty resultset %s>' % self.rql
return '<resultset %s (%s rows)>' % (self.rql, len(self.rows))
-
+
def __repr__(self):
if not self.rows:
return '<empty resultset for %r>' % self.rql
@@ -85,22 +85,22 @@
actions = self.vreg.possible_vobjects('actions', self.req, self, **kwargs)
self._rsetactions[key] = actions
return actions
-
+
def __len__(self):
"""returns the result set's size"""
return self.rowcount
def __nonzero__(self):
return self.rowcount
-
+
def __getitem__(self, i):
"""returns the ith element of the result set"""
return self.rows[i] #ResultSetRow(self.rows[i])
-
+
def __getslice__(self, i, j):
"""returns slice [i:j] of the result set"""
return self.rows[i:j]
-
+
def __iter__(self):
"""Returns an iterator over rows"""
return iter(self.rows)
@@ -126,7 +126,7 @@
:param transformcb:
a callable which should take a row and its type description as
parameters, and return the transformed row and type description.
-
+
:type col: int
:param col: the column index
@@ -199,7 +199,7 @@
def split_rset(self, keyfunc=None, col=0, return_dict=False):
"""Splits the result set in multiple result set according to a given key
-
+
:type keyfunc: callable(entity or FinalType)
:param keyfunc:
a callable which should take a value of the rset in argument and
@@ -256,7 +256,7 @@
: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
@@ -289,7 +289,7 @@
copy_cache(rset, 'get_entity', self)
rset.limited = (limit, offset)
return rset
-
+
def printable_rql(self, encoded=False):
"""return the result set's origin rql as a string, with arguments
substitued
@@ -301,11 +301,11 @@
if isinstance(rqlstr, unicode):
return rqlstr
return unicode(rqlstr, encoding)
- else:
+ else:
if isinstance(rqlstr, unicode):
return rqlstr.encode(encoding)
return rqlstr
-
+
# client helper methods ###################################################
def entities(self, col=0):
@@ -320,7 +320,7 @@
def get_entity(self, row, col=None):
"""special method for query retreiving a single entity, returns a
partially initialized Entity instance.
-
+
WARNING: due to the cache wrapping this function, you should NEVER
give row as a named parameter (i.e. rset.get_entity(req, 0)
is OK but rset.get_entity(row=0, req=req) isn't
@@ -351,7 +351,7 @@
partially means that only attributes selected in the RQL
query will be directly assigned to the entity.
-
+
:type row,col: int, int
:param row,col:
row and col numbers localizing the entity among the result's table
@@ -427,7 +427,7 @@
@cached
def syntax_tree(self):
- """get the syntax tree for the source query.
+ """get the syntax tree for the source query.
:rtype: rql.stmts.Statement
:return: the RQL syntax tree of the originating query
@@ -441,12 +441,12 @@
else:
rqlst = self.vreg.parse(self.req, self.rql, self.args)
return rqlst
-
+
@cached
def column_types(self, col):
"""return the list of different types in the column with the given col
index default to 0 (ie the first column)
-
+
:type col: int
:param col: the index of the desired column
@@ -483,7 +483,7 @@
etype = self.description[row][col]
if self.vreg.schema.eschema(etype).is_final():
# final type, find a better one to locate the correct subquery
- # (ambiguous if possible)
+ # (ambiguous if possible)
for i in xrange(len(rqlst.children[0].selection)):
if i == col:
continue
@@ -522,7 +522,7 @@
__, rhs = rel.get_variable_parts()
return rhs.eval(self.args)
return None
-
+
def attr_desc_iterator(rqlst, index=0):
"""return an iterator on a list of 2-uple (index, attr_relation)