sourcefactory – Contextual Sources Module

Smarter contextual sources, that can do faster containment checks.

class waeup.kofa.sourcefactory.SmartBasicContextualSourceFactory[source]

Abstract base implementation for a basic but smart contextual source factory.

These factories use any contains(value, context) method of factored sources to speed up containment checks.

Instances of this class can be used as replacement for zc.sourcefactory.BasicContextualSourceFactory. If your implementation derived from SmartBasicContextualFactory additionally provides a smart contains() method, you only get benefits from using this class.

The basic requirements for a working SmartBasicContextualSourceFactory are the same as for regular ones: you have to implement a getValues(context) method. You can (optionally) implements a contains(value, context) method.

__doc__ = 'Abstract base implementation for a basic but smart contextual\n source factory.\n\n These factories use any `contains(value, context)` method of\n factored sources to speed up containment checks.\n\n Instances of this class can be used as replacement for\n `zc.sourcefactory.BasicContextualSourceFactory`. If your\n implementation derived from :class:`SmartBasicContextualFactory`\n additionally provides a smart `contains()` method, you only get\n benefits from using this class.\n\n The basic requirements for a working\n `SmartBasicContextualSourceFactory` are the same as for regular\n ones: you have to implement a `getValues(context)` method. You can\n (optionally) implements a `contains(value, context)` method.\n '
__module__ = 'waeup.kofa.sourcefactory'
class waeup.kofa.sourcefactory.SmartContextualSourceFactory[source]
__doc__ = None
__module__ = 'waeup.kofa.sourcefactory'
source_class

alias of SmartFactoredContextualSource

class waeup.kofa.sourcefactory.SmartFactoredContextualSource(factory, context)[source]

A contextual source that can be faster.

Regular ContextualSources from zc.sourcefactory suffer from very expensive and slow containment checks. __contains__ is executed as a lookup over the complete set of possible values.

If, however, a source could do this lookup faster, it had no chance to do that with regular ContextualSources.

This source instead looks for a contains() method of a contextual source first and if it has one, this method is called with value and context as arguments.

If a source does not provide contains(), the expensive default lookup method is done instead.

__contains__(value)[source]

Check whether value is part of the source.

If the factored source provides a contains(value, context) method, this method is called for faster containment checks. If not, then the getValues() method of a factored source is used to examine each single item contained in the source.

__doc__ = 'A contextual source that can be faster.\n\n Regular ContextualSources from zc.sourcefactory suffer from very\n expensive and slow containment checks. __contains__ is executed as\n a lookup over the complete set of possible values.\n\n If, however, a source could do this lookup faster, it had no\n chance to do that with regular ContextualSources.\n\n This source instead looks for a `contains()` method of a\n contextual source first and if it has one, this method is called\n with `value` and `context` as arguments.\n\n If a source does not provide `contains()`, the expensive default\n lookup method is done instead.\n '
__module__ = 'waeup.kofa.sourcefactory'