Ticket #12649: 12649-csrf-migration-helper-file-path-in-unicode-exception.diff

File 12649-csrf-migration-helper-file-path-in-unicode-exception.diff, 804 bytes (added by akaihola, 6 years ago)

the path of the bad HTML file is appended to the exception error message

  • extras/csrf_migration_helper.py

    diff --git a/extras/csrf_migration_helper.py b/extras/csrf_migration_helper.py
    index bc352a1..2934ca8 100644
    a b class Template(object): 
    176176            return self._content
    177177        except AttributeError:
    178178            fd = open(self.absolute_filename)
    179             content = fd.read().decode(TEMPLATE_ENCODING)
     179            try:
     180                content = fd.read().decode(TEMPLATE_ENCODING)
     181            except UnicodeDecodeError, e:
     182                message = '%s in %s' % (
     183                    e[4], self.absolute_filename.encode('UTF-8', 'ignore'))
     184                raise UnicodeDecodeError(*(e.args[:4] + (message,)))
    180185            fd.close()
    181186            self._content = content
    182187            return content
Back to Top