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

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

Issue 5177883412660224: Issue 2234 - Add a WSGI controller to collect email addresses for the Adblock Browser iOS launch (Closed)
Patch Set: Addressed comments Created April 6, 2015, 6:01 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/submitEmail/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 io
19 import fcntl
20
21 from sitescripts.utils import get_config
22 from sitescripts.web import url_handler, form_handler
23
24 @url_handler('/submitEmail')
25 @form_handler
26 def submitEmail(environ, start_response, data):
27 email = data.get('email', '').strip()
28 if not email:
29 start_response('400 Bad Request', [('Content-Type', 'text/plain')])
30 return ['No email address given.']
31
32 filename = get_config().get('submitEmail', 'file')
33 with io.open(filename, 'a', encoding='utf-8') as file:
34 fcntl.lockf(file, fcntl.LOCK_EX)
35 try:
36 file.write(email)
37 file.write(u'\n')
Wladimir Palant 2015/04/06 18:07:30 Nit: just '\n', not a Unicode string?
Sebastian Noack 2015/04/06 18:17:26 Nope, doesn't work, since we have a TextIOWrapper,
38 file.flush()
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/submitEmail/web/__init__.py ('k') | sitescripts/web.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld