← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:services-oauth-print-function into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:services-oauth-print-function into launchpad:master.

Commit message:
Convert lp.services.oauth to preferred __future__ imports

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/392385
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:services-oauth-print-function into launchpad:master.
diff --git a/lib/lp/services/oauth/doc/oauth-pages.txt b/lib/lp/services/oauth/doc/oauth-pages.txt
index 14d20a6..858a4ec 100644
--- a/lib/lp/services/oauth/doc/oauth-pages.txt
+++ b/lib/lp/services/oauth/doc/oauth-pages.txt
@@ -34,7 +34,7 @@ consumer's request to access Launchpad on their behalf.
     ...         html, parse_only=SoupStrainer(attrs={'type': 'hidden'}))
     ...     for tag in soup.findAll(attrs={'type': 'hidden'}):
     ...         if tag['value']:
-    ...             print tag['name'], tag['value']
+    ...             print(tag['name'], tag['value'])
 
 When the client doesn't specify a duration, the resulting request
 token will have no expiration date set.
@@ -42,7 +42,7 @@ token will have no expiration date set.
     >>> from datetime import datetime
     >>> view, token = get_view_with_fresh_token({})
     >>> view.reviewToken(OAuthPermission.READ_PRIVATE, None)
-    >>> print token.date_expires
+    >>> print(token.date_expires)
     None
 
 When the client specifies a duration, the resulting request
@@ -61,7 +61,7 @@ When the consumer doesn't specify a context, the token will not have a
 context either.
 
     >>> view, token = get_view_with_fresh_token({})
-    >>> print view.token_context
+    >>> print(view.token_context)
     None
 
     # Note that the token is stored in a hidden field in the HTML so that
@@ -73,11 +73,11 @@ context either.
     >>> view.reviewToken(OAuthPermission.READ_PRIVATE, None)
     >>> token.person.name
     u'salgado'
-    >>> print token.context
+    >>> print(token.context)
     None
     >>> token.permission
     <DBItem OAuthPermission.READ_PRIVATE...
-    >>> print token.is_reviewed
+    >>> print(token.is_reviewed)
     True
 
 The context can be a product, and if it's specified it will be carried
diff --git a/lib/lp/services/oauth/stories/access-token.txt b/lib/lp/services/oauth/stories/access-token.txt
index 1269194..e1e8ed7 100644
--- a/lib/lp/services/oauth/stories/access-token.txt
+++ b/lib/lp/services/oauth/stories/access-token.txt
@@ -28,7 +28,7 @@ access token.
     >>> anon_browser.open(
     ...     'http://launchpad.test/+access-token', data=urlencode(data))
 
-    >>> print anon_browser.contents
+    >>> print(anon_browser.contents)
     oauth_token=...&oauth_token_secret=...
 
 Any further attempt to exchange that request token for an access token
@@ -56,7 +56,7 @@ with the token's key and secret.
     >>> data2['oauth_signature'] = '&'.join(['', secret])
     >>> anon_browser.open(
     ...     'http://launchpad.test/+access-token', data=urlencode(data2))
-    >>> print anon_browser.contents
+    >>> print(anon_browser.contents)
     oauth_token=...&oauth_token_secret=...&lp.context=firefox
 
 The consumer shall not attempt to exchange any given request token
@@ -66,10 +66,10 @@ before it's been reviewed, though, or it'll get a 401 response.
     >>> data2 = data.copy()
     >>> data2['oauth_token'] = token.key
     >>> data2['oauth_signature'] = '&'.join(['', secret])
-    >>> print http(r"""
+    >>> print(http(r"""
     ... GET /+access-token?%s HTTP/1.1
     ... Host: launchpad.test
-    ... """ % urlencode(data2))
+    ... """ % urlencode(data2)))
     HTTP/1.1 401 Unauthorized
     ...
     Request token has not yet been reviewed. Try again later.
@@ -78,20 +78,20 @@ If the token is missing or the signature is wrong the response will
 also be 401.
 
     >>> data2['oauth_signature'] = '&'.join(['foobar', secret])
-    >>> print http(r"""
+    >>> print(http(r"""
     ... GET /+access-token?%s HTTP/1.1
     ... Host: launchpad.test
-    ... """ % urlencode(data2))
+    ... """ % urlencode(data2)))
     HTTP/1.1 401 Unauthorized
     ...
     Invalid OAuth signature.
 
     >>> data3 = data.copy()
     >>> del(data3['oauth_token'])
-    >>> print http(r"""
+    >>> print(http(r"""
     ... GET /+access-token?%s HTTP/1.1
     ... Host: launchpad.test
-    ... """ % urlencode(data3))
+    ... """ % urlencode(data3)))
     HTTP/1.1 401 Unauthorized
     ...
     No request token specified.
@@ -103,10 +103,10 @@ exchanged for an access token.
 
     >>> token.review(salgado, OAuthPermission.UNAUTHORIZED)
     >>> data2['oauth_signature'] = '&'.join(['', secret])
-    >>> print http(r"""
+    >>> print(http(r"""
     ... GET /+access-token?%s HTTP/1.1
     ... Host: launchpad.test
-    ... """ % urlencode(data2))
+    ... """ % urlencode(data2)))
     HTTP/1.1 403 Forbidden
     ...
     End-user refused to authorize request token.
diff --git a/lib/lp/services/oauth/stories/authorize-token.txt b/lib/lp/services/oauth/stories/authorize-token.txt
index cc339bd..1ad5c47 100644
--- a/lib/lp/services/oauth/stories/authorize-token.txt
+++ b/lib/lp/services/oauth/stories/authorize-token.txt
@@ -46,7 +46,7 @@ it involves OpenID, which would complicate this test quite a bit.)
     'Authorize application to access Launchpad on your behalf'
 
     >>> main_content = find_tag_by_id(browser.contents, 'maincontent')
-    >>> print extract_text(main_content)
+    >>> print(extract_text(main_content))
     Authorize application to access Launchpad on your behalf
     Integrating foobar123451432 into your Launchpad account
     The application identified as foobar123451432 wants to access Launchpad on
@@ -60,7 +60,7 @@ except for 'Desktop Integration', which must be specifically requested.
     >>> def print_access_levels(main_content):
     ...     actions = main_content.findAll('input', attrs={'type': 'submit'})
     ...     for action in actions:
-    ...         print action['value']
+    ...         print(action['value'])
 
     >>> print_access_levels(main_content)
     No Access
@@ -140,7 +140,7 @@ by the user is restricted to things related to that context.
     ...     "http://launchpad.test/+authorize-token?%s";
     ...     % urlencode(params_with_context))
     >>> main_content = find_tag_by_id(browser.contents, 'maincontent')
-    >>> print extract_text(main_content)
+    >>> print(extract_text(main_content))
     Authorize application to access Launchpad on your behalf
     Integrating foobar123451432 into your Launchpad account
     The application...wants to access things related to Mozilla Firefox...
@@ -218,7 +218,7 @@ If no oauth_callback is specified, we don't redirect the user.
 
     >>> browser.url
     'http://launchpad.test/+authorize-token'
-    >>> print extract_text(find_tag_by_id(browser.contents, 'maincontent'))
+    >>> print(extract_text(find_tag_by_id(browser.contents, 'maincontent')))
     Authorize application to access Launchpad on your behalf
     Almost finished ...
     To finish authorizing the application identified as foobar123451432 to
@@ -233,7 +233,7 @@ exchanged for an access token), we will explain that to the user.
     >>> params = dict(oauth_callback='http://example.com/oauth')
     >>> browser.open(
     ...     "http://launchpad.test/+authorize-token?%s"; % urlencode(params))
-    >>> print extract_text(find_tag_by_id(browser.contents, 'maincontent'))
+    >>> print(extract_text(find_tag_by_id(browser.contents, 'maincontent')))
     Authorize application to access Launchpad on your behalf
     Unable to identify application
     The information provided by the remote application was incorrect or
@@ -246,7 +246,7 @@ exchanged for an access token), we will explain that to the user.
     ...     oauth_token='zzzzzz', oauth_callback='http://example.com/oauth')
     >>> browser.open(
     ...     "http://launchpad.test/+authorize-token?%s"; % urlencode(params))
-    >>> print extract_text(find_tag_by_id(browser.contents, 'maincontent'))
+    >>> print(extract_text(find_tag_by_id(browser.contents, 'maincontent')))
     Authorize application to access Launchpad on your behalf
     Unable to identify application
     The information provided by the remote application was incorrect or
@@ -268,7 +268,7 @@ the success message is printed.
     ...     oauth_token=token.key, oauth_callback='http://example.com/oauth')
     >>> browser.open(
     ...     "http://launchpad.test/+authorize-token?%s"; % urlencode(params))
-    >>> print extract_text(find_tag_by_id(browser.contents, 'maincontent'))
+    >>> print(extract_text(find_tag_by_id(browser.contents, 'maincontent')))
     Authorize application to access Launchpad on your behalf
     Almost finished ...
     To finish authorizing the application identified as foobar123451432
@@ -291,7 +291,7 @@ If the token has expired, we notify the user, and inhibit the callback.
     >>> browser.url
     'http://launchpad.test/+authorize-token'
     >>> [tag] = find_tags_by_class(browser.contents, 'error message')
-    >>> print extract_text(tag)
+    >>> print(extract_text(tag))
     This request token has expired and can no longer be reviewed.
 
 Desktop integration
@@ -318,9 +318,9 @@ special warning about giving access to every program running on their
 desktop.
 
     >>> params = dict(oauth_token=token.key)
-    >>> print extract_text(
+    >>> print(extract_text(
     ...     authorize_token_main_content(
-    ...         'allow_permission=DESKTOP_INTEGRATION'))
+    ...         'allow_permission=DESKTOP_INTEGRATION')))
     Authorize application to access Launchpad on your behalf
     Confirm Computer Access
     The Ubuntu computer called mycomputer wants access to your
@@ -423,7 +423,7 @@ If the client chooses a permanent desktop integration, the request
 token is approved and has no expiration date.
 
     >>> token = integrate_desktop("Until I Disable It")
-    >>> print extract_text(find_tag_by_id(browser.contents, 'maincontent'))
+    >>> print(extract_text(find_tag_by_id(browser.contents, 'maincontent')))
     Authorize application to access Launchpad on your behalf
     Almost finished ...
     The Ubuntu computer called mycomputer now has access to your
@@ -431,11 +431,11 @@ token is approved and has no expiration date.
     start using its Launchpad integration features.
     See all applications authorized to access Launchpad on your behalf.
 
-    >>> print token.is_reviewed
+    >>> print(token.is_reviewed)
     True
-    >>> print token.permission.name
+    >>> print(token.permission.name)
     DESKTOP_INTEGRATION
-    >>> print token.date_expires
+    >>> print(token.date_expires)
     None
 
 Accepting time-limited integration
@@ -447,7 +447,7 @@ one hour.
 
     >>> token = integrate_desktop("For One Hour")
 
-    >>> print extract_text(find_tag_by_id(browser.contents, 'maincontent'))
+    >>> print(extract_text(find_tag_by_id(browser.contents, 'maincontent')))
     Authorize application to access Launchpad on your behalf
     Almost finished ...
     The Ubuntu computer called mycomputer now has access to your
@@ -458,9 +458,9 @@ one hour.
     keep using its Launchpad integration features.
     See all applications authorized to access Launchpad on your behalf.
 
-    >>> print token.is_reviewed
+    >>> print(token.is_reviewed)
     True
-    >>> print token.permission.name
+    >>> print(token.permission.name)
     DESKTOP_INTEGRATION
     >>> token.date_expires is None
     False
@@ -476,13 +476,13 @@ Here we authorize a token for one day.
 
     >>> token = integrate_desktop("For One Day")
 
-    >>> print extract_text(find_tag_by_id(browser.contents, 'maincontent'))
+    >>> print(extract_text(find_tag_by_id(browser.contents, 'maincontent')))
     Authorize application to access Launchpad on your behalf
     Almost finished ...
     The integration you just authorized will expire in 23 hours.
     ...
 
-    >>> print token.is_reviewed
+    >>> print(token.is_reviewed)
     True
     >>> token.date_expires is None
     False
@@ -492,15 +492,15 @@ a date.
 
     >>> token = integrate_desktop("For One Week")
 
-    >>> print extract_text(find_tag_by_id(browser.contents, 'maincontent'))
+    >>> print(extract_text(find_tag_by_id(browser.contents, 'maincontent')))
     Authorize application to access Launchpad on your behalf
     Almost finished ...
     The integration you just authorized will expire 2...
     ...
 
-    >>> print token.is_reviewed
+    >>> print(token.is_reviewed)
     True
-    >>> print token.permission.name
+    >>> print(token.permission.name)
     DESKTOP_INTEGRATION
     >>> token.date_expires is None
     False
@@ -514,14 +514,14 @@ cannot be exchanged for an access token.
     >>> token = integrate_desktop(
     ...     """Do Not Allow "mycomputer" to Access my Launchpad Account.""")
 
-    >>> print extract_text(find_tag_by_id(browser.contents, 'maincontent'))
+    >>> print(extract_text(find_tag_by_id(browser.contents, 'maincontent')))
     Authorize application to access Launchpad on your behalf
     You decided against desktop integration
     You decided not to give mycomputer access to your Launchpad
     account. You can always change your mind later.
     See all applications authorized to access Launchpad on your behalf.
 
-    >>> print token.is_reviewed
+    >>> print(token.is_reviewed)
     True
-    >>> print token.permission.name
+    >>> print(token.permission.name)
     UNAUTHORIZED
diff --git a/lib/lp/services/oauth/stories/managing-tokens.txt b/lib/lp/services/oauth/stories/managing-tokens.txt
index 5d8fc63..d0fe794 100644
--- a/lib/lp/services/oauth/stories/managing-tokens.txt
+++ b/lib/lp/services/oauth/stories/managing-tokens.txt
@@ -26,10 +26,10 @@ and/or revoked from that user's +oauth-tokens page.
     # View the tokens.
     >>> my_browser = setupBrowser(auth='Basic salgado@xxxxxxxxxx:test')
     >>> my_browser.open('http://launchpad.test/~salgado/+oauth-tokens')
-    >>> print my_browser.title
+    >>> print(my_browser.title)
     Authorized applications...
     >>> main_content = find_tag_by_id(my_browser.contents, 'maincontent')
-    >>> print extract_text(main_content)
+    >>> print(extract_text(main_content))
     Authorized applications
     ...
     Claimed tokens:
@@ -50,7 +50,7 @@ authorization.
 
     >>> li = find_tag_by_id(main_content, 'tokens').find('li')
     >>> for input in li.find('form').findAll('input'):
-    ...     print input['name'], input['value']
+    ...     print(input['name'], input['value'])
     consumer_key System-wide: Ubuntu (mycomputer)
     token_key ...
     token_type access_token
@@ -58,7 +58,7 @@ authorization.
 
     >>> li2 = li.findNextSibling('li')
     >>> for input in li2.find('form').findAll('input'):
-    ...     print input['name'], input['value']
+    ...     print(input['name'], input['value'])
     consumer_key foobar123451432
     token_key salgado-read-nonprivate
     token_type access_token
@@ -66,7 +66,7 @@ authorization.
 
     >>> li3 = li2.findNext('li')
     >>> for input in li3.find('form').findAll('input'):
-    ...     print input['name'], input['value']
+    ...     print(input['name'], input['value'])
     consumer_key launchpad-library
     token_key salgado-change-anything
     token_type access_token
@@ -74,7 +74,7 @@ authorization.
 
     >>> li4 = li3.findNext('li')
     >>> for input in li4.find('form').findAll('input'):
-    ...     print input['name'], input['value']
+    ...     print(input['name'], input['value'])
     consumer_key oauthconsumerkey...
     token_key ...
     token_type request_token
@@ -85,13 +85,13 @@ Launchpad on that user's behalf anymore, nor will that application be
 shown as one of the authorized ones.
 
     >>> my_browser.getControl('Revoke Authorization', index=2).click()
-    >>> print my_browser.title
+    >>> print(my_browser.title)
     Authorized applications...
     >>> print_feedback_messages(my_browser.contents)
     Authorization revoked successfully.
 
     >>> my_browser.open('http://launchpad.test/~salgado/+oauth-tokens')
-    >>> print extract_text(find_tag_by_id(my_browser.contents, 'maincontent'))
+    >>> print(extract_text(find_tag_by_id(my_browser.contents, 'maincontent')))
     Authorized applications
     ...
     Claimed tokens:
@@ -118,7 +118,7 @@ include that.
     >>> access_token, _ = token.createAccessToken()
     >>> logout()
     >>> my_browser.open('http://launchpad.test/~salgado/+oauth-tokens')
-    >>> print extract_text(find_tag_by_id(my_browser.contents, 'maincontent'))
+    >>> print(extract_text(find_tag_by_id(my_browser.contents, 'maincontent')))
     Authorized applications
     ...
     launchpad-library
diff --git a/lib/lp/services/oauth/stories/request-token.txt b/lib/lp/services/oauth/stories/request-token.txt
index f72e378..91e3100 100644
--- a/lib/lp/services/oauth/stories/request-token.txt
+++ b/lib/lp/services/oauth/stories/request-token.txt
@@ -12,7 +12,7 @@ a request token which may later be exchanged for an access token.
     >>> anon_browser.open(
     ...     'http://launchpad.test/+request-token', data=urlencode(data))
 
-    >>> print anon_browser.contents
+    >>> print(anon_browser.contents)
     oauth_token=...&oauth_token_secret=...
 
 The consumer can ask for a JSON representation of the request token,
@@ -46,7 +46,7 @@ so that the application can proceed.
     >>> from lp.testing import login, logout
     >>> from lp.services.oauth.interfaces import IOAuthConsumerSet
     >>> login('salgado@xxxxxxxxxx')
-    >>> print getUtility(IOAuthConsumerSet).getByKey(u'joe-feed-reader')
+    >>> print(getUtility(IOAuthConsumerSet).getByKey(u'joe-feed-reader'))
     None
 
     >>> logout()
@@ -55,7 +55,7 @@ so that the application can proceed.
     >>> anon_browser.open(
     ...     'http://launchpad.test/+request-token', data=urlencode(data2))
 
-    >>> print anon_browser.contents
+    >>> print(anon_browser.contents)
     oauth_token=...&oauth_token_secret=...
 
     >>> login('salgado@xxxxxxxxxx')
@@ -67,10 +67,10 @@ If the consumer key is empty, we respond with a 401 status.
 
     >>> data2 = data.copy()
     >>> data2['oauth_consumer_key'] = ''
-    >>> print http(r"""
+    >>> print(http(r"""
     ... GET /+request-token?%s HTTP/1.1
     ... Host: launchpad.test
-    ... """ % urlencode(data2))
+    ... """ % urlencode(data2)))
     HTTP/1.1 401 Unauthorized
     ...
     WWW-Authenticate: OAuth realm="https://api.launchpad.net";
@@ -81,14 +81,14 @@ concatenated values of the consumer secret and token secret, separated
 by a & character. That means, in our case, the signature should be only
 an '&', since there's no token yet and the consumer secret is empty.
 
-    >>> data['oauth_signature']
-    '&'
+    >>> print(data['oauth_signature'])
+    &
     >>> data2 = data.copy()
     >>> data2['oauth_signature'] = '&somesecret'
-    >>> print http(r"""
+    >>> print(http(r"""
     ... GET /+request-token?%s HTTP/1.1
     ... Host: launchpad.test
-    ... """ % urlencode(data2))
+    ... """ % urlencode(data2)))
     HTTP/1.1 401 Unauthorized
     ...
 
@@ -97,9 +97,9 @@ get a 400 response.
 
     >>> data2 = data.copy()
     >>> data2['oauth_signature_method'] = 'HMAC-SHA1'
-    >>> print http(r"""
+    >>> print(http(r"""
     ... GET /+request-token?%s HTTP/1.1
     ... Host: launchpad.test
-    ... """ % urlencode(data2))
+    ... """ % urlencode(data2)))
     HTTP/1.1 400 Bad Request
     ...
diff --git a/lib/lp/services/oauth/tests/test_doc.py b/lib/lp/services/oauth/tests/test_doc.py
index 7ce594c..0edb518 100644
--- a/lib/lp/services/oauth/tests/test_doc.py
+++ b/lib/lp/services/oauth/tests/test_doc.py
@@ -8,10 +8,14 @@ Run the doctests and pagetests.
 import os
 
 from lp.services.testing import build_test_suite
+from lp.testing.pages import setUpGlobs
+from lp.testing.systemdocs import setUp
 
 
 here = os.path.dirname(os.path.realpath(__file__))
 
 
 def test_suite():
-    return build_test_suite(here)
+    return build_test_suite(
+        here, setUp=lambda test: setUp(test, future=True),
+        pageTestsSetUp=lambda test: setUpGlobs(test, future=True))