From 530da46905753a1e950bcc7e736d72a7309033c6 Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Thu, 4 Aug 2011 10:05:11 +0200 Subject: Silence UnicodeDecodeErrors, but try to collect some demo data. --- extras/appengine/sqlformat/legacy.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'extras/appengine/sqlformat') diff --git a/extras/appengine/sqlformat/legacy.py b/extras/appengine/sqlformat/legacy.py index 9d53479..6d3aaf8 100644 --- a/extras/appengine/sqlformat/legacy.py +++ b/extras/appengine/sqlformat/legacy.py @@ -105,7 +105,18 @@ def _get_examples(): def _get_sql(data, files=None): sql = None if files is not None and 'datafile' in files: - sql = files['datafile'].read().decode('utf-8') + raw = files['datafile'].read() + try: + sql = raw.decode('utf-8') + except UnicodeDecodeError, err: + logging.error(err) + logging.debug(repr(raw)) + sql = (u'-- UnicodeDecodeError: %s\n' + u'-- Please make sure to upload UTF-8 encoded data for now.\n' + u'-- If you want to help improving this part of the application\n' + u'-- please file a bug with some demo data at:\n' + u'-- http://code.google.com/p/python-sqlparse/issues/entry\n' + u'-- Thanks!\n' % err) if not sql: sql = data.get('data') return sql or '' -- cgit v1.2.1