1 | :mod:`waeup.sirp.university.certificatecontainer` -- Certificate containers |
---|
2 | *************************************************************************** |
---|
3 | |
---|
4 | .. module:: waeup.sirp.university.certificatecontainer |
---|
5 | |
---|
6 | Containers for certificates. |
---|
7 | |
---|
8 | .. :doctest: |
---|
9 | .. :layer: waeup.sirp.testing.WAeUPSIRPUnitTestLayer |
---|
10 | |
---|
11 | |
---|
12 | Content Classes (models and containers) |
---|
13 | ======================================= |
---|
14 | |
---|
15 | :class:`CertificateContainer` |
---|
16 | ----------------------------- |
---|
17 | |
---|
18 | .. class:: CertificateContainer() |
---|
19 | |
---|
20 | Create a certificate container instance. |
---|
21 | |
---|
22 | .. attribute:: grok.implements(ICertificateContainer) |
---|
23 | |
---|
24 | .. attribute:: grok.require('waeup.manageUniversity') |
---|
25 | |
---|
26 | :class:`CertificateContainer` instances are instances of |
---|
27 | :class:`grok.Container` that hold and manage instances of |
---|
28 | :class:`waeup.sirp.university.certificate.Certificate`. |
---|
29 | |
---|
30 | >>> from waeup.sirp.university.certificatecontainer import CertificateContainer |
---|
31 | >>> mycontainer = CertificateContainer() |
---|
32 | >>> mycontainer |
---|
33 | <waeup.sirp.university.certificatecontainer.CertificateContainer object at 0x...> |
---|
34 | |
---|
35 | Certificate containers provide `ICertificateContainer`: |
---|
36 | |
---|
37 | >>> from waeup.sirp.university.interfaces import ICertificateContainer |
---|
38 | >>> ICertificateContainer.providedBy(mycontainer) |
---|
39 | True |
---|
40 | |
---|
41 | We can be sure, that the full interface is supported by the |
---|
42 | CertificateContainer class: |
---|
43 | |
---|
44 | >>> from zope.interface.verify import verifyClass |
---|
45 | >>> verifyClass(ICertificateContainer, CertificateContainer) |
---|
46 | True |
---|
47 | |
---|
48 | As normal ``grok.Container``, :class:`CertificateContainer` instances |
---|
49 | can be used like dicts: |
---|
50 | |
---|
51 | >>> list(mycontainer.keys()) |
---|
52 | [] |
---|
53 | |
---|
54 | .. method:: addCertificate(certificate) |
---|
55 | |
---|
56 | Add a certificate. |
---|
57 | |
---|
58 | *certificate* must be an instance of |
---|
59 | :class:`waeup.sirp.university.certificate.Certificate`: |
---|
60 | |
---|
61 | >>> from waeup.sirp.university.certificatecontainer import ( |
---|
62 | ... CertificateContainer) |
---|
63 | >>> mycontainer = CertificateContainer() |
---|
64 | >>> mycontainer.addCertificate('blah') |
---|
65 | Traceback (most recent call last): |
---|
66 | ... |
---|
67 | TypeError: CertificateContainers contain only ICertificate instances |
---|
68 | |
---|
69 | The key of added items is the ``code`` attribute: |
---|
70 | |
---|
71 | >>> from waeup.sirp.university.certificate import Certificate |
---|
72 | >>> mycertificate = Certificate(code='CERTIFICATE1') |
---|
73 | >>> mycontainer.addCertificate(mycertificate) |
---|
74 | 'Certificate added (for tests only).' |
---|
75 | >>> list(mycontainer.keys()) |
---|
76 | [u'CERTIFICATE1'] |
---|
77 | |
---|
78 | .. method:: clear() |
---|
79 | |
---|
80 | Remove all contained certificates: |
---|
81 | |
---|
82 | >>> len(mycontainer.items()) |
---|
83 | 1 |
---|
84 | |
---|
85 | >>> mycontainer.clear() |
---|
86 | >>> len(mycontainer.items()) |
---|
87 | 0 |
---|
88 | |
---|
89 | Utilities |
---|
90 | ========= |
---|
91 | |
---|
92 | :class:`CertificateContainerFactory` |
---|
93 | ------------------------------------ |
---|
94 | |
---|
95 | .. class:: CertificateContainerFactory() |
---|
96 | |
---|
97 | .. attribute:: grok.name(u'waeup.CertificateContainer') |
---|
98 | |
---|
99 | .. attribute:: grok.implements(IFactory) |
---|
100 | |
---|
101 | A named utility to deliver new instances of :class:`CertificateContainer` |
---|
102 | without the need to import the implementation before: |
---|
103 | |
---|
104 | >>> from zope.component import createObject |
---|
105 | >>> mycertificatecontainer = createObject(u'waeup.CertificateContainer') |
---|
106 | >>> mycertificatecontainer |
---|
107 | <waeup.sirp.university.certificatecontainer.CertificateContainer object at 0x...> |
---|
108 | |
---|
109 | The factory complies with the specifications from the |
---|
110 | :class:`IFactory` insterface: |
---|
111 | |
---|
112 | >>> from zope.interface.verify import verifyClass |
---|
113 | >>> from zope.component.interfaces import IFactory |
---|
114 | >>> from waeup.sirp.university.certificatecontainer import ( |
---|
115 | ... CertificateContainerFactory) |
---|
116 | >>> verifyClass(IFactory, CertificateContainerFactory) |
---|
117 | True |
---|
118 | |
---|
119 | This means also, that we can get the interfaces of the created |
---|
120 | object from the factory: |
---|
121 | |
---|
122 | >>> certificatecontainer_factory = CertificateContainerFactory() |
---|
123 | >>> certificatecontainer_factory.getInterfaces() |
---|
124 | <implementedBy waeup.sirp.university.certificatecontainer.CertificateContainer> |
---|
125 | |
---|
126 | |
---|
127 | Examples |
---|
128 | ======== |
---|
129 | |
---|
130 | Getting a certificate container |
---|
131 | ------------------------------- |
---|
132 | |
---|
133 | We can easily create `CertificateContainers`: |
---|
134 | |
---|
135 | >>> from waeup.sirp.university.certificatecontainer import CertificateContainer |
---|
136 | >>> mycontainer = CertificateContainer() |
---|
137 | |
---|
138 | |
---|
139 | Another way to get a certificate container -- without importing the |
---|
140 | class -- is via factories. We registered a factory for certificate |
---|
141 | containers under the name ``waeup.CertificateContainer``. Now we can |
---|
142 | ask for an object by calling the appropriate factory: |
---|
143 | |
---|
144 | >>> from zope.component import createObject |
---|
145 | >>> createObject(u'waeup.CertificateContainer') |
---|
146 | <waeup.sirp.university.certificatecontainer.CertificateContainer object at 0x...> |
---|
147 | |
---|
148 | This way we get a thing that implements ICertificateContainer without |
---|
149 | imports or similar. |
---|
150 | |
---|