Author: hwright
Date: Tue Jul 27 18:04:06 2010
New Revision: 979786
URL: http://svn.apache.org/viewvc?rev=979786&view=rev
Log:
Apply the generator architecture to our report generation.
* mouse.py
(Resource.__init__): Accept the new file object.
(generate_report): Return a generator to get the Resources.
(process_report): Iterate over the generator, not an iterable.
Modified:
labs/mouse/mouse.py
Modified: labs/mouse/mouse.py
URL:
http://svn.apache.org/viewvc/labs/mouse/mouse.py?rev=979786&r1=979785&r2=979786&view=diff
==============================================================================
--- labs/mouse/mouse.py (original)
+++ labs/mouse/mouse.py Tue Jul 27 18:04:06 2010
@@ -60,7 +60,7 @@ class _UnknownArchiveError(Exception):
class Resource(object):
- def __init__(self, name):
+ def __init__(self, name, file):
self._name = name
def to_element(self):
@@ -88,11 +88,11 @@ def generate_report(items):
of the form (LABEL, FILE), where LABEL is a textual label for the object, and
FILE is a file-like object which can be used to get the text of the
object.'''
- resources = []
- for item in items():
- resources.append(Resource(item[0]))
+ def report_generator():
+ for item in items():
+ yield Resource(item[0], item[1])
- return resources
+ return report_generator
def process_report(report):
@@ -100,7 +100,7 @@ def process_report(report):
root = ElementTree.Element('rat-report')
- for resource in report:
+ for resource in report():
root.append(resource.to_element())
return ElementTree.tostring(root)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]