~landscape/zope3/ztk-1.1.3

« back to all changes in this revision

Viewing changes to src/zc/sourcefactory/adapters.txt

  • Committer: Sidnei da Silva
  • Date: 2010-07-05 21:07:01 UTC
  • Revision ID: sidnei.da.silva@canonical.com-20100705210701-zmqhqrbzad1mhzsl
- Reduce deps

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
===========================
2
 
Common adapters for sources
3
 
===========================
4
 
 
5
 
To allow adapting factored sources specific to the factory, a couple of
6
 
standard interfaces that can be adapters are re-adapted as using a
7
 
multi-adapter for (FactoredSource, SourceFactory).
8
 
 
9
 
ISourceQueriables
10
 
=================
11
 
 
12
 
  >>> from zc.sourcefactory.basic import BasicSourceFactory
13
 
  >>> class Factory(BasicSourceFactory):
14
 
  ...     def getValues(self):
15
 
  ...         return [1,2,3]
16
 
  >>> source = Factory()
17
 
 
18
 
  >>> from zope.schema.interfaces import ISourceQueriables
19
 
  >>> import zope.interface
20
 
  >>> class SourceQueriables(object):
21
 
  ...     zope.interface.implements(ISourceQueriables)
22
 
  ...     def __init__(self, source, factory):
23
 
  ...         self.source = source
24
 
  ...         self.factory = factory
25
 
  ...     def getQueriables(self):
26
 
  ...         return [('test', None)]
27
 
 
28
 
  >>> from zc.sourcefactory.source import FactoredSource
29
 
  >>> zope.component.provideAdapter(factory=SourceQueriables,
30
 
  ...                               provides=ISourceQueriables,
31
 
  ...                               adapts=(FactoredSource, Factory))
32
 
 
33
 
  >>> queriables = ISourceQueriables(source)
34
 
  >>> queriables.factory
35
 
  <Factory object at 0x...>
36
 
  >>> queriables.source
37
 
  <zc.sourcefactory.source.FactoredSource object at 0x...>
38
 
  >>> queriables.getQueriables()
39
 
  [('test', None)]
40
 
 
41
 
Cleanup
42
 
-------
43
 
 
44
 
  >>> zope.component.getSiteManager().unregisterAdapter(factory=SourceQueriables,
45
 
  ...     provided=ISourceQueriables, required=(FactoredSource, Factory))
46
 
  True