Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: sitescripts/formsubscribe/web/formsubscribe.py

Issue 5177883412660224: Issue 2234 - Add a WSGI controller to collect email addresses for the Adblock Browser iOS launch (Closed)
Patch Set: Created April 2, 2015, 2 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sitescripts/formsubscribe/web/__init__.py ('k') | sitescripts/web.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # coding: utf-8
2
3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH
5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation.
9 #
10 # Adblock Plus is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17
18 import codecs
19 import fcntl
20
21 from sitescripts.utils import get_config
22 from sitescripts.web import url_handler, form_handler
23
24 utf8_writer = codecs.getwriter('utf-8')
25
26 @url_handler('/formsubscribe')
27 @form_handler
28 def handleRequest(environ, start_response, data):
29 email = data.get('email', '').strip()
30 if not email:
31 start_response('400 Bad Request', [('Content-Type', 'text/plain')])
32 return ['No email address given.']
33
34 with open(get_config().get('formsubscribe', 'file'), 'a', 0) as file:
35 file = utf8_writer(file)
36 fcntl.lockf(file, fcntl.LOCK_EX)
37 try:
38 print >>file, email
39 finally:
40 fcntl.lockf(file, fcntl.LOCK_UN)
41
42 start_response('200 OK', [('Content-Type', 'text/plain')])
43 return ["Thanks for your submission! We'll notify you before the launch."]
OLDNEW
« no previous file with comments | « sitescripts/formsubscribe/web/__init__.py ('k') | sitescripts/web.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld