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
1=== modified file 'src/launchpadlib/credentials.py'
2--- src/launchpadlib/credentials.py 2010-10-20 13:14:40 +0000
3+++ src/launchpadlib/credentials.py 2010-10-26 17:49:45 +0000
4@@ -205,12 +205,15 @@
5 This authorizer simply opens up the end-user's web browser to a
6 Launchpad URL and lets the end-user authorize the request token
7 themselves.
8+
9+ :param max_failed_attempts: Unused by this token authorization
10+ mechanism. Any value passed in will be ignored.
11 """
12
13 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..."
14
15 def __init__(self, web_root, consumer_name, request_token,
16- allow_access_levels=[], max_failed_attempts=3):
17+ allow_access_levels=[], max_failed_attempts=None):
18 web_root = uris.lookup_web_root(web_root)
19 page = "+authorize-token?oauth_token=%s" % request_token
20 if len(allow_access_levels) > 0:
21@@ -220,7 +223,7 @@
22
23 super(AuthorizeRequestTokenWithBrowser, self).__init__(
24 web_root, consumer_name, request_token,
25- allow_access_levels, max_failed_attempts)
26+ allow_access_levels)
27
28 def output(self, message):
29 """Display a message.
30@@ -232,7 +235,7 @@
31 print message
32
33 def __call__(self, credentials, web_root):
34- self.open_page_in_user_browser(self.authorization_url)
35+ webbrowser.open(self.authorization_url)
36 self.output(self.WAITING_FOR_USER % self.authorization_url)
37 while credentials.access_token is None:
38 time.sleep(access_token_poll_time)

Subscribers

People subscribed via source and target branches