Left: | ||
Right: |
OLD | NEW |
---|---|
(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 @url_handler('/formsubscribe') | |
Sebastian Noack
2015/04/05 17:07:01
Well, double-/single-quotes are currently quite mi
| |
25 @form_handler | |
26 def handleRequest(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('formsubscribe', 'file') | |
33 with codecs.open(filename, 'a', 'utf-8', buffering=0) as file: | |
Sebastian Noack
2015/04/06 09:53:17
In fact there are attempts to deprecate codecs.ope
| |
34 fcntl.lockf(file, fcntl.LOCK_EX) | |
kzar
2015/04/05 15:45:14
How does this work if the file is already locked?
| |
35 try: | |
36 print >>file, email | |
37 finally: | |
38 fcntl.lockf(file, fcntl.LOCK_UN) | |
39 | |
40 start_response('200 OK', [('Content-Type', 'text/plain')]) | |
41 return ["Thanks for your submission! We'll notify you before the launch."] | |
OLD | NEW |