summaryrefslogtreecommitdiff
path: root/docs/api.rst
blob: 858a4c0e2f6cd8252744d8b39b0920008247cb7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
:mod:`zope.proxy` API
=====================

:mod:`zope.proxy.interfaces`
----------------------------

.. automodule:: zope.proxy.interfaces

  .. autointerface:: IProxyIntrospection
     :members:
     :member-order: bysource


:mod:`zope.proxy`
-----------------

.. automodule:: zope.proxy
   :members:


:mod:`zope.proxy.decorator`
---------------------------

.. automodule:: zope.proxy.decorator

   .. doctest::

      >>> from zope.interface import Interface
      >>> from zope.interface import directlyProvides
      >>> from zope.interface import implementer
      >>> class I1(Interface):
      ...     pass
      >>> class I2(Interface):
      ...     pass
      >>> class I3(Interface):
      ...     pass
      >>> class I4(Interface):
      ...     pass
      >>> from zope.proxy.decorator import SpecificationDecoratorBase
      >>> @implementer(I1)
      ... class D1(SpecificationDecoratorBase):
      ...   pass
      >>> @implementer(I2)
      ... class D2(SpecificationDecoratorBase):
      ...   pass
      >>> @implementer(I3)
      ... class X(object):
      ...   pass
      >>> x = X()
      >>> directlyProvides(x, I4)

   Interfaces of X are ordered with the directly-provided interfaces first.

   .. doctest::

      >>> from zope.interface import providedBy
      >>> [interface.getName() for interface in list(providedBy(x))]
      ['I4', 'I3']

   When we decorate objects, what order should the interfaces come
   in?  One could argue that decorators are less specific, so they
   should come last.

   .. doctest::

      >>> [interface.getName() for interface in list(providedBy(D1(x)))]
      ['I4', 'I3', 'I1']

      >>> [interface.getName() for interface in list(providedBy(D2(D1(x))))]
      ['I4', 'I3', 'I1', 'I2']

   SpecificationDecorators also work with old-style classes:

   .. doctest::

      >>> @implementer(I3)
      ... class X:
      ...   pass

      >>> x = X()
      >>> directlyProvides(x, I4)

      >>> [interface.getName() for interface in list(providedBy(x))]
      ['I4', 'I3']

      >>> [interface.getName() for interface in list(providedBy(D1(x)))]
      ['I4', 'I3', 'I1']

      >>> [interface.getName() for interface in list(providedBy(D2(D1(x))))]
      ['I4', 'I3', 'I1', 'I2']

   .. autoclass:: DecoratorSpecificationDescriptor
      :members:

   .. autoclass:: SpecificationDecoratorBase