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

Unified Diff: sitescripts/formsubscribe/web/formsubscribe.py

Issue 5177883412660224: Issue 2234 - Add a WSGI controller to collect email addresses for the Adblock Browser iOS launch (Closed)
Patch Set: Use codecs.open() Created April 5, 2015, 11:53 a.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
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."]

Powered by Google App Engine
This is Rietveld