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

Unified Diff: sitescripts/reports/web/submitReport.py

Issue 4901331810648064: Issue 2309 - Reorder Known Issue Sentences in FF Issue Reporter (Closed)
Patch Set: Created April 13, 2015, 9:56 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/reports/template/submitSuccess.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/reports/web/submitReport.py
===================================================================
--- a/sitescripts/reports/web/submitReport.py
+++ b/sitescripts/reports/web/submitReport.py
@@ -12,29 +12,22 @@
# 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 re, os, sys
from urlparse import parse_qs
-from sitescripts.utils import get_config, get_template, setupStderr
+from sitescripts.utils import get_config, get_template
from sitescripts.web import url_handler
import sitescripts.subscriptions.knownIssuesParser as knownIssuesParser
-def dataIterator(source, file):
- for line in source:
- file.write(line)
- yield line
-
@url_handler('/submitReport')
def handleRequest(environ, start_response):
- setupStderr(environ['wsgi.errors'])
-
if not environ.get('HTTP_X_ADBLOCK_PLUS'):
return showError('Please use Adblock Plus to submit reports', start_response)
if environ['REQUEST_METHOD'].upper() != 'POST' or not environ.get('CONTENT_TYPE', '').startswith('text/xml'):
return showError('Unsupported request method', start_response)
params = parse_qs(environ.get('QUERY_STRING', ''))
@@ -45,25 +38,32 @@ def handleRequest(environ, start_respons
guid = params.get('guid', [''])[0].lower()
if not re.match(r'^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$', guid):
return showError('Invalid or missing GUID', start_response)
path = os.path.join(get_config().get('reports', 'dataPath'), guid + '.xml')
if os.path.exists(path) or os.path.exists(path + '.tmp'):
return showError('Duplicate GUID', start_response)
+ try:
+ request_size= int(environ['CONTENT_LENGTH'])
+ except (KeyError, ValueError):
+ return showError('Invalid or missing Content-Length header', start_response)
Sebastian Noack 2015/04/14 06:30:59 Status code should be 411, not 400 here.
Wladimir Palant 2016/02/10 15:43:42 Done.
+
dir = os.path.dirname(path)
if not os.path.exists(dir):
os.makedirs(dir)
try:
file = open(path + '.tmp', 'wb')
- iter = dataIterator(environ['wsgi.input'], file)
- knownIssues = knownIssuesParser.findMatches(iter, params.get('lang', ['en-US'])[0])
+ data = environ['wsgi.input'].read(request_size)
+ file.write(data)
file.close()
+ knownIssues = knownIssuesParser.findMatches(data.splitlines(), params.get('lang', ['en-US'])[0])
+
os.rename(path + '.tmp', path);
except Exception, e:
if os.path.isfile(path + '.tmp'):
os.remove(path + '.tmp')
raise e
template = get_template(get_config().get('reports', 'submitResponseTemplate'))
start_response('200 OK', [('Content-Type', 'application/xhtml+xml; charset=utf-8')])
« no previous file with comments | « sitescripts/reports/template/submitSuccess.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld