[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
r5049 - in trunk: gnue-common/src/logic gnue-forms/src/GFObjects
From: |
jcater |
Subject: |
r5049 - in trunk: gnue-common/src/logic gnue-forms/src/GFObjects |
Date: |
Thu, 29 Jan 2004 12:29:39 -0600 (CST) |
Author: jcater
Date: 2004-01-29 12:29:38 -0600 (Thu, 29 Jan 2004)
New Revision: 5049
Modified:
trunk/gnue-common/src/logic/NamespaceCore.py
trunk/gnue-forms/src/GFObjects/GFBlock.py
Log:
added block iterator support; so you can do for foo in myBlock: print
foo.myField (python 2.2+)
Modified: trunk/gnue-common/src/logic/NamespaceCore.py
===================================================================
--- trunk/gnue-common/src/logic/NamespaceCore.py 2004-01-29 04:29:31 UTC
(rev 5048)
+++ trunk/gnue-common/src/logic/NamespaceCore.py 2004-01-29 18:29:38 UTC
(rev 5049)
@@ -280,6 +280,15 @@
string = self.__str__()
return string[key.start:key.stop]
+
+ #
+ # __iter__
+ #
+ # Python iterator support
+ #
+ def __iter__(self):
+ return iter(self._object)
+
#
# NamespaceFunction
#
Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFBlock.py 2004-01-29 04:29:31 UTC (rev
5048)
+++ trunk/gnue-forms/src/GFObjects/GFBlock.py 2004-01-29 18:29:38 UTC (rev
5049)
@@ -137,20 +137,21 @@
self._triggerProperties={'parent': {'get':self.getParent}}
-## def __getitem__(self, index):
-##
-## cnt = self._resultSet.getRecordCount() - 1
-## if index > cnt:
-## raise IndexError
-##
-## self.jumpRecord(index)
-##
-## if cnt == index and self.isEmpty():
-## print "Bad, bad, bad"
-## raise IndexError
-##
-## return self
+
+ # Iterator support (Python 2.2+)
+ def __iter__(self):
+ """
+ Iterator support for Python 2.2+
+
+ Allows you to do:
+ for foo in myBlock:
+ ....
+ """
+ print "Called __iter__"
+ return _BlockIter(self)
+
+
def _buildObject(self):
if hasattr(self, 'rows'):
@@ -606,3 +607,40 @@
+# A simple resultset iterator
+# Lets you use ResultSets as:
+#
+# for record in myResultSet:
+# blah
+#
+# NOTE: Python 2.2+ (but it won't get called in
+# Python 2.1 or below, so not a problem)
+#
+class _BlockIter:
+ def __init__(self, block):
+ self.block = block
+ self.new = 1
+ self.done = 0
+ print "Iterator created"
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ if self.done:
+ raise StopIteration
+ elif self.new:
+ self.block.jumpRecord(0)
+ self.new = 0
+ elif self.block._resultSet.isLastRecord():
+ self.done = 1
+ raise StopIteration
+ else:
+ self.block.nextRecord()
+
+ if self.block.isEmpty() and self.block._resultSet.isLastRecord():
+ self.done = 1
+ raise StopIteration
+
+ return self.block
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- r5049 - in trunk: gnue-common/src/logic gnue-forms/src/GFObjects,
jcater <=