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
=== modified file 'utilities/paste'
--- utilities/paste 2009-06-24 20:22:29 +0000
+++ utilities/paste 2009-08-13 09:25:01 +0000
@@ -17,13 +17,15 @@
17import _pythonpath17import _pythonpath
1818
19from ClientCookie import Cookie, CookieJar19from ClientCookie import Cookie, CookieJar
20from mechanize import HTTPRobotRulesProcessor
2021
21from zope.testbrowser.browser import Browser22from zope.testbrowser.browser import Browser
2223
2324
24# Should we be able to override any of these?25# Should we be able to override any of these?
25AUTH_FILE = '~/.lp_auth_cookie'26AUTH_FILE = '~/.lp_auth_cookie'
26PASTE_HOST = 'pastebin.canonical.com'27PRIVATE_PASTE_HOST = 'pastebin.canonical.com'
28PUBLIC_PASTE_HOST = 'pastebin.ubuntu.com'
27PASTE_PATH = ''29PASTE_PATH = ''
28LP_AUTH_INSTRUCTIONS = """30LP_AUTH_INSTRUCTIONS = """
29%s doesn't contain a valid LP authentication cookie.31%s doesn't contain a valid LP authentication cookie.
@@ -41,6 +43,9 @@
41 parser.add_option('-b', '--browser',43 parser.add_option('-b', '--browser',
42 default=False, action='store_true',44 default=False, action='store_true',
43 help='Open web browser to the pastebin.')45 help='Open web browser to the pastebin.')
46 parser.add_option('-p', '--private',
47 default=False, action='store_true',
48 help='Use a private pastebin (pastebin.canonical.com).')
44 parser.add_option('-s', '--syntax',49 parser.add_option('-s', '--syntax',
45 default='text', type='string',50 default='text', type='string',
46 help='The syntax of the pastebin.')51 help='The syntax of the pastebin.')
@@ -113,25 +118,35 @@
113 ('content', content),118 ('content', content),
114 )119 )
115120
116 # Figure out the authentication.
117 lp_cookie = get_lp_auth_cookie(AUTH_FILE)
118 if lp_cookie is None:
119 print LP_AUTH_INSTRUCTIONS
120 return
121 cookiejar = CookieJar()
122 cookiejar.set_cookie(lp_cookie)
123 browser = Browser()121 browser = Browser()
124 browser.mech_browser.set_cookiejar(cookiejar)122 paste_host = PUBLIC_PASTE_HOST
125123 if parser.options.private:
126 browser.open(urljoin('https://' + PASTE_HOST, PASTE_PATH))124 paste_host = PRIVATE_PASTE_HOST
127125 # Figure out the authentication.
128 # We need to authenticate before pasting.126 lp_cookie = get_lp_auth_cookie(AUTH_FILE)
129 oid_form = browser.getForm(id='openid_message')127 if lp_cookie is None:
130 if oid_form is not None:
131 authenticated = authenticate(browser)
132 if not authenticated:
133 print LP_AUTH_INSTRUCTIONS128 print LP_AUTH_INSTRUCTIONS
134 return129 return
130 cookiejar = CookieJar()
131 cookiejar.set_cookie(lp_cookie)
132 browser.mech_browser.set_cookiejar(cookiejar)
133
134 # Remove the the check for robots.txt, since the one on
135 # pastebin.ubuntu.com doesn't allow us to open the page. We're not
136 # really a robot.
137 browser.mech_browser.handlers = [
138 handler for handler in browser.mech_browser.handlers
139 if not isinstance(handler, HTTPRobotRulesProcessor)]
140 browser.open(urljoin('https://' + paste_host, PASTE_PATH))
141
142 if parser.options.private:
143 # We need to authenticate before pasting.
144 oid_form = browser.getForm(id='openid_message')
145 if oid_form is not None:
146 authenticated = authenticate(browser)
147 if not authenticated:
148 print LP_AUTH_INSTRUCTIONS
149 return
135 for name, value in form:150 for name, value in form:
136 browser.getControl(name=name).value = value151 browser.getControl(name=name).value = value
137 browser.getControl('Paste!').click()152 browser.getControl('Paste!').click()