| Index: sitescripts/formsubscribe/web/formsubscribe.py |
| =================================================================== |
| new file mode 100644 |
| --- /dev/null |
| +++ b/sitescripts/formsubscribe/web/formsubscribe.py |
| @@ -0,0 +1,41 @@ |
| +# 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 codecs |
| +import fcntl |
| + |
| +from sitescripts.utils import get_config |
| +from sitescripts.web import url_handler, form_handler |
| + |
| +@url_handler('/formsubscribe') |
|
Sebastian Noack
2015/04/05 17:07:01
Well, double-/single-quotes are currently quite mi
|
| +@form_handler |
| +def handleRequest(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('formsubscribe', 'file') |
| + 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
|
| + fcntl.lockf(file, fcntl.LOCK_EX) |
|
kzar
2015/04/05 15:45:14
How does this work if the file is already locked?
|
| + try: |
| + print >>file, email |
| + 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."] |