Merge lp:~bjornt/launchpad/public-paste into lp:launchpad

Proposed by Björn Tillenius
Status: Merged
Approved by: Jonathan Lange
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~bjornt/launchpad/public-paste
Merge into: lp:launchpad
Diff against target: None lines
To merge this branch: bzr merge lp:~bjornt/launchpad/public-paste
Reviewer Review Type Date Requested Status
Jonathan Lange (community) Approve
Review via email: mp+10089@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Björn Tillenius (bjornt) wrote :

Change utilities/paste to use pastebin.ubuntu.com by default.

It's still possible to paste to pastebin.canonical.com by passing the -p
flag.

There's a hack in the code to remove the HTTPRobotRulesProcessor.
handler. We need to remove it, since pastebin.ubuntu.com doesn't allow.
any robots to access the site, so browser.open() fails. It's not trivial
to have zope.browser create a mechanize object without that processor to
begin with.

--
Björn Tillenius | https://launchpad.net/~bjornt

Revision history for this message
Jonathan Lange (jml) wrote :

Thanks so much for doing this. No comments on the code.

There is a bug already filed for this, I'd much appreciate it if you could find it and close it.

Thanks again,
jml

review: Approve
Revision history for this message
Björn Tillenius (bjornt) wrote :

On Thu, Aug 13, 2009 at 10:29:31AM -0000, Jonathan Lange wrote:
> Review: Approve
> Thanks so much for doing this. No comments on the code.

Thanks!

> There is a bug already filed for this, I'd much appreciate it if you
> could find it and close it.

Indeed. The bug is even marked in progress, assigned to me, and linked
to the branch :)

--
Björn Tillenius | https://launchpad.net/~bjornt

Revision history for this message
Jonathan Lange (jml) wrote :

2009/8/13 Björn Tillenius <email address hidden>:
>> There is a bug already filed for this, I'd much appreciate it if you
>> could find it and close it.
>
> Indeed. The bug is even marked in progress, assigned to me, and linked
> to the branch :)
>

Rock'n'roll :)

jml

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utilities/paste'
2--- utilities/paste 2009-06-24 20:22:29 +0000
3+++ utilities/paste 2009-08-13 09:25:01 +0000
4@@ -17,13 +17,15 @@
5 import _pythonpath
6
7 from ClientCookie import Cookie, CookieJar
8+from mechanize import HTTPRobotRulesProcessor
9
10 from zope.testbrowser.browser import Browser
11
12
13 # Should we be able to override any of these?
14 AUTH_FILE = '~/.lp_auth_cookie'
15-PASTE_HOST = 'pastebin.canonical.com'
16+PRIVATE_PASTE_HOST = 'pastebin.canonical.com'
17+PUBLIC_PASTE_HOST = 'pastebin.ubuntu.com'
18 PASTE_PATH = ''
19 LP_AUTH_INSTRUCTIONS = """
20 %s doesn't contain a valid LP authentication cookie.
21@@ -41,6 +43,9 @@
22 parser.add_option('-b', '--browser',
23 default=False, action='store_true',
24 help='Open web browser to the pastebin.')
25+ parser.add_option('-p', '--private',
26+ default=False, action='store_true',
27+ help='Use a private pastebin (pastebin.canonical.com).')
28 parser.add_option('-s', '--syntax',
29 default='text', type='string',
30 help='The syntax of the pastebin.')
31@@ -113,25 +118,35 @@
32 ('content', content),
33 )
34
35- # Figure out the authentication.
36- lp_cookie = get_lp_auth_cookie(AUTH_FILE)
37- if lp_cookie is None:
38- print LP_AUTH_INSTRUCTIONS
39- return
40- cookiejar = CookieJar()
41- cookiejar.set_cookie(lp_cookie)
42 browser = Browser()
43- browser.mech_browser.set_cookiejar(cookiejar)
44-
45- browser.open(urljoin('https://' + PASTE_HOST, PASTE_PATH))
46-
47- # We need to authenticate before pasting.
48- oid_form = browser.getForm(id='openid_message')
49- if oid_form is not None:
50- authenticated = authenticate(browser)
51- if not authenticated:
52+ paste_host = PUBLIC_PASTE_HOST
53+ if parser.options.private:
54+ paste_host = PRIVATE_PASTE_HOST
55+ # Figure out the authentication.
56+ lp_cookie = get_lp_auth_cookie(AUTH_FILE)
57+ if lp_cookie is None:
58 print LP_AUTH_INSTRUCTIONS
59 return
60+ cookiejar = CookieJar()
61+ cookiejar.set_cookie(lp_cookie)
62+ browser.mech_browser.set_cookiejar(cookiejar)
63+
64+ # Remove the the check for robots.txt, since the one on
65+ # pastebin.ubuntu.com doesn't allow us to open the page. We're not
66+ # really a robot.
67+ browser.mech_browser.handlers = [
68+ handler for handler in browser.mech_browser.handlers
69+ if not isinstance(handler, HTTPRobotRulesProcessor)]
70+ browser.open(urljoin('https://' + paste_host, PASTE_PATH))
71+
72+ if parser.options.private:
73+ # We need to authenticate before pasting.
74+ oid_form = browser.getForm(id='openid_message')
75+ if oid_form is not None:
76+ authenticated = authenticate(browser)
77+ if not authenticated:
78+ print LP_AUTH_INSTRUCTIONS
79+ return
80 for name, value in form:
81 browser.getControl(name=name).value = value
82 browser.getControl('Paste!').click()