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 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."] |
OLD | NEW |