Merge lp:~leonardr/lazr.restfulclient/load-relative-uri into lp:lazr.restfulclient

Proposed by Leonard Richardson
Status: Merged
Merged at revision: 102
Proposed branch: lp:~leonardr/lazr.restfulclient/load-relative-uri
Merge into: lp:lazr.restfulclient
Diff against target: 103 lines (+49/-3)
4 files modified
src/lazr/restfulclient/NEWS.txt (+6/-0)
src/lazr/restfulclient/docs/entries.txt (+35/-2)
src/lazr/restfulclient/resource.py (+7/-0)
src/lazr/restfulclient/version.txt (+1/-1)
To merge this branch: bzr merge lp:~leonardr/lazr.restfulclient/load-relative-uri
Reviewer Review Type Date Requested Status
Abel Deuring (community) code Approve
Review via email: mp+28511@code.launchpad.net

Description of the change

This branch makes load() support relative URIs, a tiny feature whose absence has caused a lot of problems. The URIs in question are relative to the versioned service root (eg. http://api.launchpad.net/1.0/), since you can't load objects from other web services or other versions of the Launchpad web service.

To post a comment you must log in.
Revision history for this message
Abel Deuring (adeuring) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/lazr/restfulclient/NEWS.txt'
--- src/lazr/restfulclient/NEWS.txt 2010-06-21 14:02:23 +0000
+++ src/lazr/restfulclient/NEWS.txt 2010-06-25 15:12:28 +0000
@@ -2,6 +2,12 @@
2NEWS for lazr.restfulclient2NEWS for lazr.restfulclient
3===========================3===========================
44
50.9.20 (2010-06-25)
6===================
7
8 - It's now possible to pass a relative URL (relative to the versioned
9 service root) into load().
10
50.9.19 (2010-06-21)110.9.19 (2010-06-21)
6===================12===================
713
814
=== modified file 'src/lazr/restfulclient/docs/entries.txt'
--- src/lazr/restfulclient/docs/entries.txt 2010-06-16 17:40:18 +0000
+++ src/lazr/restfulclient/docs/entries.txt 2010-06-25 15:12:28 +0000
@@ -171,7 +171,35 @@
171 >>> print new_recipe.dish.name171 >>> print new_recipe.dish.name
172 Roast chicken172 Roast chicken
173173
174You can't bookmark a random URI.174You can bookmark a URI relative to the version of the web service
175currently in use.
176
177 >>> cookbooks = service.load("cookbooks")
178 >>> print cookbooks['The Joy of Cooking'].self_link
179 http://cookbooks.dev/1.0/cookbooks/The%20Joy%20of%20Cooking
180
181 >>> cookbook = service.load("/cookbooks/The%20Joy%20of%20Cooking")
182 >>> print cookbook.self_link
183 http://cookbooks.dev/1.0/cookbooks/The%20Joy%20of%20Cooking
184
185 >>> service_root = service.load("")
186 >>> print service_root.cookbooks['The Joy of Cooking'].name
187 The Joy of Cooking
188
189But you can't provide the web service version and bookmark a URI
190relative to the service root.
191
192 >>> cookbooks = service.load("/1.0/cookbooks")
193 Traceback (most recent call last):
194 ...
195 HTTPError: HTTP Error 404: Not Found
196 ...
197
198(That code attempts to load http://cookbooks.dev/1.0/1.0/cookbooks,
199which doesn't exist.)
200
201You can't bookmark an absolute or relative URI that has nothing to do
202with the web service.
175203
176 >>> bookmark = 'http://cookbooks.dev/'204 >>> bookmark = 'http://cookbooks.dev/'
177 >>> service.load(bookmark)205 >>> service.load(bookmark)
@@ -180,6 +208,12 @@
180 HTTPError: HTTP Error 404: Not Found208 HTTPError: HTTP Error 404: Not Found
181 ...209 ...
182210
211 >>> service.load("/no-such-url")
212 Traceback (most recent call last):
213 ...
214 HTTPError: HTTP Error 404: Not Found
215 ...
216
183You can't bookmark the return value of a named operation. This is not217You can't bookmark the return value of a named operation. This is not
184really desirable, but that's how things work right now.218really desirable, but that's how things work right now.
185219
@@ -190,7 +224,6 @@
190 ...224 ...
191 ValueError: Couldn't determine the resource type of...225 ValueError: Couldn't determine the resource type of...
192226
193
194Moving an entry227Moving an entry
195---------------228---------------
196229
197230
=== modified file 'src/lazr/restfulclient/resource.py'
--- src/lazr/restfulclient/resource.py 2010-06-21 14:02:23 +0000
+++ src/lazr/restfulclient/resource.py 2010-06-25 15:12:28 +0000
@@ -450,6 +450,13 @@
450450
451 def load(self, url):451 def load(self, url):
452 """Load a resource given its URL."""452 """Load a resource given its URL."""
453 parsed = urlparse(url)
454 if parsed.scheme == '':
455 # This is a relative URL. Make it absolute by joining
456 # it with the service root resource.
457 if len(url) > 0 and url[0] == '/':
458 url = url[1:]
459 url = self._root_uri.append(url)
453 document = self._browser.get(url)460 document = self._browser.get(url)
454 try:461 try:
455 representation = simplejson.loads(unicode(document))462 representation = simplejson.loads(unicode(document))
456463
=== modified file 'src/lazr/restfulclient/version.txt'
--- src/lazr/restfulclient/version.txt 2010-06-21 14:02:23 +0000
+++ src/lazr/restfulclient/version.txt 2010-06-25 15:12:28 +0000
@@ -1,1 +1,1 @@
10.9.1910.9.20

Subscribers

People subscribed via source and target branches