Merge lp:~leonardr/launchpadlib/shim-users into lp:launchpadlib

Proposed by Leonard Richardson
Status: Merged
Approved by: Gary Poster
Approved revision: 91
Merged at revision: 90
Proposed branch: lp:~leonardr/launchpadlib/shim-users
Merge into: lp:launchpadlib
Diff against target: 127 lines (+56/-10)
5 files modified
setup.py (+1/-1)
src/launchpadlib/NEWS.txt (+6/-0)
src/launchpadlib/__init__.py (+1/-1)
src/launchpadlib/docs/toplevel.txt (+47/-7)
src/launchpadlib/launchpad.py (+1/-1)
To merge this branch: bzr merge lp:~leonardr/launchpadlib/shim-users
Reviewer Review Type Date Requested Status
Gary Poster Approve
Review via email: mp+28067@code.launchpad.net

Description of the change

This branch takes advantage of the functionality provided by https://code.edge.launchpad.net/~leonardr/lazr.restfulclient/server-takes-precedence/+merge/28059 to make the top-level collection of people use shim objects. This will save an HTTP request or two in many launchpadlib scripts.

To post a comment you must log in.
Revision history for this message
Gary Poster (gary) wrote :

Thank you

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'setup.py'
2--- setup.py 2010-06-16 19:48:04 +0000
3+++ setup.py 2010-06-21 15:38:24 +0000
4@@ -60,7 +60,7 @@
5 license='LGPL v3',
6 install_requires=[
7 'httplib2',
8- 'lazr.restfulclient>=0.9.18',
9+ 'lazr.restfulclient>=0.9.19',
10 'lazr.uri',
11 'oauth',
12 'setuptools',
13
14=== modified file 'src/launchpadlib/NEWS.txt'
15--- src/launchpadlib/NEWS.txt 2010-06-16 19:48:04 +0000
16+++ src/launchpadlib/NEWS.txt 2010-06-21 15:38:24 +0000
17@@ -2,6 +2,12 @@
18 NEWS for launchpadlib
19 =====================
20
21+1.6.2 (2010-06-21)
22+==================
23+
24+- Extended the optimization from version 1.6.1 to apply to Launchpad's
25+ top-level collection of people.
26+
27 1.6.1 (2010-06-16)
28 ==================
29
30
31=== modified file 'src/launchpadlib/__init__.py'
32--- src/launchpadlib/__init__.py 2010-06-16 19:48:04 +0000
33+++ src/launchpadlib/__init__.py 2010-06-21 15:38:24 +0000
34@@ -14,4 +14,4 @@
35 # You should have received a copy of the GNU Lesser General Public License
36 # along with launchpadlib. If not, see <http://www.gnu.org/licenses/>.
37
38-__version__ = '1.6.1'
39+__version__ = '1.6.2'
40
41=== modified file 'src/launchpadlib/docs/toplevel.txt'
42--- src/launchpadlib/docs/toplevel.txt 2010-06-16 19:48:04 +0000
43+++ src/launchpadlib/docs/toplevel.txt 2010-06-21 15:38:24 +0000
44@@ -49,23 +49,63 @@
45 ubuntu
46
47 The person collection does lookups by a person's Launchpad
48-name. Looking up a person from the top-level collection of people
49-*does* trigger an HTTP request, since there's no other way to tell
50-whether a given person should be represented by a 'person' object or a
51-'team' object.
52+name.
53
54 >>> person = launchpad.people['salgado']
55- send: 'GET /.../~salgado ...'
56- ...
57 >>> print person.name
58+ send: 'GET /.../~salgado ...'
59+ ...
60 salgado
61
62 >>> team = launchpad.people['rosetta-admins']
63+ >>> print team.name
64 send: 'GET /1.0/~rosetta-admins ...'
65 ...
66- >>> print team.name
67 rosetta-admins
68
69+How does launchpadlib know that 'salgado' is a person and
70+'rosetta-admins' is a team?
71+
72+ >>> print person.resource_type_link
73+ http://.../1.0/#person
74+ >>> 'default_membership_period' in person.lp_attributes
75+ False
76+
77+ >>> print team.resource_type_link
78+ http://.../1.0/#team
79+ >>> 'default_membership_period' in team.lp_attributes
80+ True
81+
82+The truth is that it doesn't know, not before making that HTTP
83+request. Until the HTTP request is made, launchpadlib assumes
84+everything in launchpad.people[] is a team (since a team has strictly
85+more capabilities than a person).
86+
87+ >>> person2 = launchpad.people['salgado']
88+ >>> 'default_membership_period' in person2.lp_attributes
89+ True
90+
91+But accessing any attribute of an object--even trying to see what kind
92+of object 'salgado' is--will trigger the HTTP request that will
93+determine that 'salgado' is actually a person.
94+
95+ >>> print person2.resource_type_link
96+ send: 'GET /.../~salgado ...'
97+ ...
98+ http://.../1.0/#person
99+
100+ >>> 'default_membership_period' in person2.lp_attributes
101+ False
102+
103+Accessing an attribute of an object that might be a team will trigger
104+the HTTP request, and then cause an error if the object turns out not
105+to be a team.
106+
107+ >>> person3 = launchpad.people['salgado']
108+ >>> person3.default_membership_period
109+ Traceback (most recent call last):
110+ AttributeError: 'Entry' object has no attribute 'default_membership_period'
111+
112 Cleanup.
113
114 >>> httplib2.debuglevel = None
115
116=== modified file 'src/launchpadlib/launchpad.py'
117--- src/launchpadlib/launchpad.py 2010-06-16 19:48:04 +0000
118+++ src/launchpadlib/launchpad.py 2010-06-21 15:38:24 +0000
119@@ -50,7 +50,7 @@
120 # The only way to determine whether a string corresponds to a
121 # person or a team object is to ask the server, so looking up an
122 # entry from the PersonSet always requires making an HTTP request.
123- collection_of = None
124+ collection_of = 'team'
125
126
127 class BugSet(CollectionWithKeyBasedLookup):

Subscribers

People subscribed via source and target branches