| Index: sitescripts/submitEmail/web/submitEmail.py |
| =================================================================== |
| new file mode 100644 |
| --- /dev/null |
| +++ b/sitescripts/submitEmail/web/submitEmail.py |
| @@ -0,0 +1,43 @@ |
| +# coding: utf-8 |
| + |
| +# This file is part of the Adblock Plus web scripts, |
| +# Copyright (C) 2006-2015 Eyeo GmbH |
| +# |
| +# Adblock Plus is free software: you can redistribute it and/or modify |
| +# it under the terms of the GNU General Public License version 3 as |
| +# published by the Free Software Foundation. |
| +# |
| +# Adblock Plus is distributed in the hope that it will be useful, |
| +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| +# GNU General Public License for more details. |
| +# |
| +# You should have received a copy of the GNU General Public License |
| +# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| + |
| +import io |
| +import fcntl |
| + |
| +from sitescripts.utils import get_config |
| +from sitescripts.web import url_handler, form_handler |
| + |
| +@url_handler('/submitEmail') |
| +@form_handler |
| +def submitEmail(environ, start_response, data): |
| + email = data.get('email', '').strip() |
| + if not email: |
| + start_response('400 Bad Request', [('Content-Type', 'text/plain')]) |
| + return ['No email address given.'] |
| + |
| + filename = get_config().get('submitEmail', 'file') |
| + with io.open(filename, 'a', encoding='utf-8') as file: |
| + fcntl.lockf(file, fcntl.LOCK_EX) |
| + try: |
| + file.write(email) |
| + 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,
|
| + file.flush() |
| + finally: |
| + fcntl.lockf(file, fcntl.LOCK_UN) |
| + |
| + start_response('200 OK', [('Content-Type', 'text/plain')]) |
| + return ["Thanks for your submission! We'll notify you before the launch."] |