Merge lp:~leonardr/launchpadlib/fix-token-authorization into lp:launchpadlib

Proposed by Leonard Richardson
Status: Work in progress
Proposed branch: lp:~leonardr/launchpadlib/fix-token-authorization
Merge into: lp:launchpadlib
Diff against target: 38 lines (+6/-3)
1 file modified
src/launchpadlib/credentials.py (+6/-3)
To merge this branch: bzr merge lp:~leonardr/launchpadlib/fix-token-authorization
Reviewer Review Type Date Requested Status
Paul Hummer (community) Approve
Review via email: mp+39391@code.launchpad.net

Description of the change

This branch fixes a couple of bugs introduced by my branch at https://code.edge.launchpad.net/~leonardr/launchpadlib/remove-broken-code/. I didn't catch the bugs earlier because they are in code that must be tested manually (since it opens a web browser and requires action within the browser), and I shamefully did not test that code manually.

Here's how to test:

>>> from launchpadlib.launchpad import Launchpad
>>> l = Launchpad.login_with("some random consumer key", "edge")

If your web browser opens, the code is working.

1. I restored the max_failed_attempts constructor argument to RequestTokenAuthorizationEngine, even though the only extant authorization engine (the one that opens a web browser) doesn't use it. We may be using this argument at some point in the future, and if we decide not to, that point (not now) is the appropriate time to formally deprecate it.

2. I replaced a call to open_page_in_user_browser (which I'd removed, as it was just a single-use wrapper around webbrowser.open, but I forgot to change the call site) with a call to webbrowser.open.

To post a comment you must log in.
Revision history for this message
Paul Hummer (rockstar) :
review: Approve

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/launchpadlib/credentials.py'
--- src/launchpadlib/credentials.py 2010-10-20 13:14:40 +0000
+++ src/launchpadlib/credentials.py 2010-10-26 17:49:45 +0000
@@ -205,12 +205,15 @@
205 This authorizer simply opens up the end-user's web browser to a205 This authorizer simply opens up the end-user's web browser to a
206 Launchpad URL and lets the end-user authorize the request token206 Launchpad URL and lets the end-user authorize the request token
207 themselves.207 themselves.
208
209 :param max_failed_attempts: Unused by this token authorization
210 mechanism. Any value passed in will be ignored.
208 """211 """
209212
210 WAITING_FOR_USER = "The authorization page:\n (%s)\nshould be opening in your browser. Use your browser to authorize\nthis program to access Launchpad on your behalf. \n\nWaiting to hear from Launchpad about your decision..."213 WAITING_FOR_USER = "The authorization page:\n (%s)\nshould be opening in your browser. Use your browser to authorize\nthis program to access Launchpad on your behalf. \n\nWaiting to hear from Launchpad about your decision..."
211214
212 def __init__(self, web_root, consumer_name, request_token,215 def __init__(self, web_root, consumer_name, request_token,
213 allow_access_levels=[], max_failed_attempts=3):216 allow_access_levels=[], max_failed_attempts=None):
214 web_root = uris.lookup_web_root(web_root)217 web_root = uris.lookup_web_root(web_root)
215 page = "+authorize-token?oauth_token=%s" % request_token218 page = "+authorize-token?oauth_token=%s" % request_token
216 if len(allow_access_levels) > 0:219 if len(allow_access_levels) > 0:
@@ -220,7 +223,7 @@
220223
221 super(AuthorizeRequestTokenWithBrowser, self).__init__(224 super(AuthorizeRequestTokenWithBrowser, self).__init__(
222 web_root, consumer_name, request_token,225 web_root, consumer_name, request_token,
223 allow_access_levels, max_failed_attempts)226 allow_access_levels)
224227
225 def output(self, message):228 def output(self, message):
226 """Display a message.229 """Display a message.
@@ -232,7 +235,7 @@
232 print message235 print message
233236
234 def __call__(self, credentials, web_root):237 def __call__(self, credentials, web_root):
235 self.open_page_in_user_browser(self.authorization_url)238 webbrowser.open(self.authorization_url)
236 self.output(self.WAITING_FOR_USER % self.authorization_url)239 self.output(self.WAITING_FOR_USER % self.authorization_url)
237 while credentials.access_token is None:240 while credentials.access_token is None:
238 time.sleep(access_token_poll_time)241 time.sleep(access_token_poll_time)

Subscribers

People subscribed via source and target branches