Changeset 6240 for main/waeup.sirp/trunk/src/waeup
- Timestamp:
- 30 May 2011, 01:48:59 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/university/certificatecontainer.py
r6236 r6240 11 11 12 12 class CertificateContainer(grok.Container): 13 """See interfaces for description. 13 """A storage for certificates. 14 15 A :class:`CertificateContainer` stores 16 :class:`waeup.sirp.university.Certificate` instances. 17 18 It is a :class:`grok.Container` basically acting like a standard 19 Python dictionary. That means you can add certificates like items 20 in a normal dictionary and also get certificates by using 21 :meth:`values`, :meth:`keys`, and :meth:`items`. 22 23 This container type is picky about its contents: only real 24 certificates can be stored here and each new certificate must 25 provide a unique `code`. See :meth:`addCertificate` for details. 26 27 Each :class:`CertificateContainer` provides 28 :iface:`ICertificateContainer`. 14 29 """ 15 30 grok.implements(ICertificateContainer) … … 17 32 18 33 def __setitem__(self, name, certificate): 19 """XXX: docstring missing. 34 """Insert `certificate` with `name` as key into container. 35 36 The certificate must be an object implementing 37 :iface:`waeup.sirp.university.interfaces.ICertificate`. If 38 not, a :exc:`TypeError` is raised. 39 40 If the certificate `code` does not equal `name` a 41 :exc:`ValueError` is raised. 42 43 If the `code` attribute of `certificate` is already in use by 44 another certificate stored in the local site 45 (:class:`waeup.sirp.app.University` instance), then a 46 :exc:`waeup.sirp.interfaces.DuplicationError` will be raised. 47 48 If `name` is already used as a key, a :exc:`KeyError` will be 49 raised. 20 50 """ 21 51 if not ICertificate.providedBy(certificate): 22 52 raise TypeError('CertificateContainers contain only ' 23 53 'ICertificate instances') 54 55 # Only accept certs with code == key. 56 if certificate.code != name: 57 raise ValueError('key must match certificate code: ' 58 '%s, %s' % (name, certificate.code)) 59 24 60 # Lookup catalog. If we find none: no duplicates possible. 25 61 cat = queryUtility(ICatalog, name='certificates_catalog', default=None) … … 36 72 37 73 def addCertificate(self, certificate): 74 """Add `certificate` to the container. 75 76 The certificate must be an object implementing 77 :iface:`waeup.sirp.university.interfaces.ICertificate`. If 78 not, a :exc:`TypeError` is raised. 79 80 The certificate will be stored in the container with its 81 `code` attribute as key. If this key is already used for 82 another certificate stored in the local site 83 (:class:`waeup.sirp.app.University` instance), then a 84 :exc:`waeup.sirp.interfaces.DuplicationError` will be raised. 85 """ 38 86 self[getattr(certificate, 'code', None)] = certificate 39 87
Note: See TracChangeset for help on using the changeset viewer.