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
=== modified file 'setup.py'
--- setup.py 2010-06-16 19:48:04 +0000
+++ setup.py 2010-06-21 15:38:24 +0000
@@ -60,7 +60,7 @@
60 license='LGPL v3',60 license='LGPL v3',
61 install_requires=[61 install_requires=[
62 'httplib2',62 'httplib2',
63 'lazr.restfulclient>=0.9.18',63 'lazr.restfulclient>=0.9.19',
64 'lazr.uri',64 'lazr.uri',
65 'oauth',65 'oauth',
66 'setuptools',66 'setuptools',
6767
=== modified file 'src/launchpadlib/NEWS.txt'
--- src/launchpadlib/NEWS.txt 2010-06-16 19:48:04 +0000
+++ src/launchpadlib/NEWS.txt 2010-06-21 15:38:24 +0000
@@ -2,6 +2,12 @@
2NEWS for launchpadlib2NEWS for launchpadlib
3=====================3=====================
44
51.6.2 (2010-06-21)
6==================
7
8- Extended the optimization from version 1.6.1 to apply to Launchpad's
9 top-level collection of people.
10
51.6.1 (2010-06-16)111.6.1 (2010-06-16)
6==================12==================
713
814
=== modified file 'src/launchpadlib/__init__.py'
--- src/launchpadlib/__init__.py 2010-06-16 19:48:04 +0000
+++ src/launchpadlib/__init__.py 2010-06-21 15:38:24 +0000
@@ -14,4 +14,4 @@
14# You should have received a copy of the GNU Lesser General Public License14# You should have received a copy of the GNU Lesser General Public License
15# along with launchpadlib. If not, see <http://www.gnu.org/licenses/>.15# along with launchpadlib. If not, see <http://www.gnu.org/licenses/>.
1616
17__version__ = '1.6.1'17__version__ = '1.6.2'
1818
=== modified file 'src/launchpadlib/docs/toplevel.txt'
--- src/launchpadlib/docs/toplevel.txt 2010-06-16 19:48:04 +0000
+++ src/launchpadlib/docs/toplevel.txt 2010-06-21 15:38:24 +0000
@@ -49,23 +49,63 @@
49 ubuntu49 ubuntu
5050
51The person collection does lookups by a person's Launchpad51The person collection does lookups by a person's Launchpad
52name. Looking up a person from the top-level collection of people52name.
53*does* trigger an HTTP request, since there's no other way to tell
54whether a given person should be represented by a 'person' object or a
55'team' object.
5653
57 >>> person = launchpad.people['salgado']54 >>> person = launchpad.people['salgado']
58 send: 'GET /.../~salgado ...'
59 ...
60 >>> print person.name55 >>> print person.name
56 send: 'GET /.../~salgado ...'
57 ...
61 salgado58 salgado
6259
63 >>> team = launchpad.people['rosetta-admins']60 >>> team = launchpad.people['rosetta-admins']
61 >>> print team.name
64 send: 'GET /1.0/~rosetta-admins ...'62 send: 'GET /1.0/~rosetta-admins ...'
65 ...63 ...
66 >>> print team.name
67 rosetta-admins64 rosetta-admins
6865
66How does launchpadlib know that 'salgado' is a person and
67'rosetta-admins' is a team?
68
69 >>> print person.resource_type_link
70 http://.../1.0/#person
71 >>> 'default_membership_period' in person.lp_attributes
72 False
73
74 >>> print team.resource_type_link
75 http://.../1.0/#team
76 >>> 'default_membership_period' in team.lp_attributes
77 True
78
79The truth is that it doesn't know, not before making that HTTP
80request. Until the HTTP request is made, launchpadlib assumes
81everything in launchpad.people[] is a team (since a team has strictly
82more capabilities than a person).
83
84 >>> person2 = launchpad.people['salgado']
85 >>> 'default_membership_period' in person2.lp_attributes
86 True
87
88But accessing any attribute of an object--even trying to see what kind
89of object 'salgado' is--will trigger the HTTP request that will
90determine that 'salgado' is actually a person.
91
92 >>> print person2.resource_type_link
93 send: 'GET /.../~salgado ...'
94 ...
95 http://.../1.0/#person
96
97 >>> 'default_membership_period' in person2.lp_attributes
98 False
99
100Accessing an attribute of an object that might be a team will trigger
101the HTTP request, and then cause an error if the object turns out not
102to be a team.
103
104 >>> person3 = launchpad.people['salgado']
105 >>> person3.default_membership_period
106 Traceback (most recent call last):
107 AttributeError: 'Entry' object has no attribute 'default_membership_period'
108
69Cleanup.109Cleanup.
70110
71 >>> httplib2.debuglevel = None111 >>> httplib2.debuglevel = None
72112
=== modified file 'src/launchpadlib/launchpad.py'
--- src/launchpadlib/launchpad.py 2010-06-16 19:48:04 +0000
+++ src/launchpadlib/launchpad.py 2010-06-21 15:38:24 +0000
@@ -50,7 +50,7 @@
50 # The only way to determine whether a string corresponds to a50 # The only way to determine whether a string corresponds to a
51 # person or a team object is to ask the server, so looking up an51 # person or a team object is to ask the server, so looking up an
52 # entry from the PersonSet always requires making an HTTP request.52 # entry from the PersonSet always requires making an HTTP request.
53 collection_of = None53 collection_of = 'team'
5454
5555
56class BugSet(CollectionWithKeyBasedLookup):56class BugSet(CollectionWithKeyBasedLookup):

Subscribers

People subscribed via source and target branches