[Checkins] SVN: zc.sourcefactory/branches/aaron-flexible-contextual-source-binder/src/zc/sourcefactory/README.txt Added test and example for the Binder change.
Aaron Lehmann
aaron at zope.com
Tue Jan 27 11:24:00 EST 2009
Log message for revision 95222:
Added test and example for the Binder change.
Changed:
U zc.sourcefactory/branches/aaron-flexible-contextual-source-binder/src/zc/sourcefactory/README.txt
-=-
Modified: zc.sourcefactory/branches/aaron-flexible-contextual-source-binder/src/zc/sourcefactory/README.txt
===================================================================
--- zc.sourcefactory/branches/aaron-flexible-contextual-source-binder/src/zc/sourcefactory/README.txt 2009-01-27 15:51:17 UTC (rev 95221)
+++ zc.sourcefactory/branches/aaron-flexible-contextual-source-binder/src/zc/sourcefactory/README.txt 2009-01-27 16:23:59 UTC (rev 95222)
@@ -87,7 +87,26 @@
>>> len(source)
4
+It's possible to have the default machinery return different sources, by
+providing a source_class argument when calling the binder. One can also
+provide arguments to the source.
+ >>> class MultiplierSource(zc.sourcefactory.source.FactoredContextualSource):
+ ... def __init__(self, factory, context, multiplier):
+ ... super(MultiplierSource, self).__init__(factory, context)
+ ... self.multiplier = multiplier
+ ...
+ ... def _get_filtered_values(self):
+ ... for value in self.factory.getValues(self.context):
+ ... yield self.multiplier * value
+ >>> source = binder(context, source_class=MultiplierSource, multiplier=5)
+ >>> list(source)
+ [5, 10, 15, 20]
+ >>> 5 in source
+ True
+ >>> len(source)
+ 4
+
Filtering
=========
More information about the Checkins
mailing list