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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sitescripts/submitEmail/web/__init__.py ('k') | sitescripts/web.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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."]
« 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