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
1=== modified file 'src/lazr/restfulclient/NEWS.txt'
2--- src/lazr/restfulclient/NEWS.txt 2010-06-21 14:02:23 +0000
3+++ src/lazr/restfulclient/NEWS.txt 2010-06-25 15:12:28 +0000
4@@ -2,6 +2,12 @@
5 NEWS for lazr.restfulclient
6 ===========================
7
8+0.9.20 (2010-06-25)
9+===================
10+
11+ - It's now possible to pass a relative URL (relative to the versioned
12+ service root) into load().
13+
14 0.9.19 (2010-06-21)
15 ===================
16
17
18=== modified file 'src/lazr/restfulclient/docs/entries.txt'
19--- src/lazr/restfulclient/docs/entries.txt 2010-06-16 17:40:18 +0000
20+++ src/lazr/restfulclient/docs/entries.txt 2010-06-25 15:12:28 +0000
21@@ -171,7 +171,35 @@
22 >>> print new_recipe.dish.name
23 Roast chicken
24
25-You can't bookmark a random URI.
26+You can bookmark a URI relative to the version of the web service
27+currently in use.
28+
29+ >>> cookbooks = service.load("cookbooks")
30+ >>> print cookbooks['The Joy of Cooking'].self_link
31+ http://cookbooks.dev/1.0/cookbooks/The%20Joy%20of%20Cooking
32+
33+ >>> cookbook = service.load("/cookbooks/The%20Joy%20of%20Cooking")
34+ >>> print cookbook.self_link
35+ http://cookbooks.dev/1.0/cookbooks/The%20Joy%20of%20Cooking
36+
37+ >>> service_root = service.load("")
38+ >>> print service_root.cookbooks['The Joy of Cooking'].name
39+ The Joy of Cooking
40+
41+But you can't provide the web service version and bookmark a URI
42+relative to the service root.
43+
44+ >>> cookbooks = service.load("/1.0/cookbooks")
45+ Traceback (most recent call last):
46+ ...
47+ HTTPError: HTTP Error 404: Not Found
48+ ...
49+
50+(That code attempts to load http://cookbooks.dev/1.0/1.0/cookbooks,
51+which doesn't exist.)
52+
53+You can't bookmark an absolute or relative URI that has nothing to do
54+with the web service.
55
56 >>> bookmark = 'http://cookbooks.dev/'
57 >>> service.load(bookmark)
58@@ -180,6 +208,12 @@
59 HTTPError: HTTP Error 404: Not Found
60 ...
61
62+ >>> service.load("/no-such-url")
63+ Traceback (most recent call last):
64+ ...
65+ HTTPError: HTTP Error 404: Not Found
66+ ...
67+
68 You can't bookmark the return value of a named operation. This is not
69 really desirable, but that's how things work right now.
70
71@@ -190,7 +224,6 @@
72 ...
73 ValueError: Couldn't determine the resource type of...
74
75-
76 Moving an entry
77 ---------------
78
79
80=== modified file 'src/lazr/restfulclient/resource.py'
81--- src/lazr/restfulclient/resource.py 2010-06-21 14:02:23 +0000
82+++ src/lazr/restfulclient/resource.py 2010-06-25 15:12:28 +0000
83@@ -450,6 +450,13 @@
84
85 def load(self, url):
86 """Load a resource given its URL."""
87+ parsed = urlparse(url)
88+ if parsed.scheme == '':
89+ # This is a relative URL. Make it absolute by joining
90+ # it with the service root resource.
91+ if len(url) > 0 and url[0] == '/':
92+ url = url[1:]
93+ url = self._root_uri.append(url)
94 document = self._browser.get(url)
95 try:
96 representation = simplejson.loads(unicode(document))
97
98=== modified file 'src/lazr/restfulclient/version.txt'
99--- src/lazr/restfulclient/version.txt 2010-06-21 14:02:23 +0000
100+++ src/lazr/restfulclient/version.txt 2010-06-25 15:12:28 +0000
101@@ -1,1 +1,1 @@
102-0.9.19
103+0.9.20

Subscribers

People subscribed via source and target branches