--- a/rset.py Thu Jan 20 09:16:52 2011 +0100
+++ b/rset.py Wed Jan 19 19:19:56 2011 +0100
@@ -386,6 +386,19 @@
if self.rows[i][col] is not None:
yield self.get_entity(i, col)
+ def iter_rows_with_entities(self):
+ """ iterates over rows, and for each row
+ eids are converted to plain entities
+ """
+ for i, row in enumerate(self):
+ _row = []
+ for j, col in enumerate(row):
+ try:
+ _row.append(self.get_entity(i, j) if col is not None else col)
+ except NotAnEntity:
+ _row.append(col)
+ yield _row
+
def complete_entity(self, row, col=0, skip_bytes=True):
"""short cut to get an completed entity instance for a particular
row (all instance's attributes have been fetched)
--- a/test/unittest_rset.py Thu Jan 20 09:16:52 2011 +0100
+++ b/test/unittest_rset.py Wed Jan 19 19:19:56 2011 +0100
@@ -382,6 +382,14 @@
self.assertEqual(set(e.e_schema.type for e in rset.entities(1)),
set(['CWGroup',]))
+ def test_iter_rows_with_entities(self):
+ rset = self.execute('Any U,UN,G,GN WHERE U in_group G, U login UN, G name GN')
+ # make sure we have at least one element
+ self.failUnless(rset)
+ out = list(rset.iter_rows_with_entities())[0]
+ self.assertEqual( out[0].login, out[1] )
+ self.assertEqual( out[2].name, out[3] )
+
def test_printable_rql(self):
rset = self.execute(u'CWEType X WHERE X final FALSE')
self.assertEqual(rset.printable_rql(),