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
|
= person_from_principal =
person_from_principal is used to adapt an ILaunchpadPrincipal to an
IPerson. If some other object is passed in, a ComponentLookupError is
raised.
>>> from lp.registry.adapters import person_from_principal
>>> class NoLaunchpadPrincipal:
... id = 42
... person = None
>>> person_from_principal(NoLaunchpadPrincipal())
Traceback (most recent call last):
...
ComponentLookupError
If an ILaunchpadPrincipal is passed in, the principal's .person
attribute is returned. The .person attribute was set when the principal
got created, so that we don't have to look up the Person record every
time we adapt.
>>> from zope.interface import implements
>>> from canonical.launchpad.webapp.interfaces import ILaunchpadPrincipal
>>> cached_person = object()
>>> class LaunchpadPrincipal:
... implements(ILaunchpadPrincipal)
...
... person = cached_person
>>> person_from_principal(LaunchpadPrincipal()) is cached_person
True
|