mirror of
https://gitee.com/openharmony/third_party_jinja2
synced 2024-11-23 15:19:46 +00:00
TemplateSyntaxError can be pickled
This commit is contained in:
parent
715f357abc
commit
b23a0dec2d
@ -99,6 +99,8 @@ Unreleased
|
||||
``UndefinedError`` consistently. ``select_template`` will show the
|
||||
undefined message in the list of attempts rather than the empty
|
||||
string. :issue:`1037`
|
||||
- ``TemplateSyntaxError`` can be pickled. :pr:`1117`
|
||||
|
||||
|
||||
Version 2.10.3
|
||||
--------------
|
||||
|
@ -141,6 +141,13 @@ class TemplateSyntaxError(TemplateError):
|
||||
|
||||
return u'\n'.join(lines)
|
||||
|
||||
def __reduce__(self):
|
||||
# https://bugs.python.org/issue1692335 Exceptions that take
|
||||
# multiple required arguments have problems with pickling.
|
||||
# Without this, raises TypeError: __init__() missing 1 required
|
||||
# positional argument: 'lineno'
|
||||
return self.__class__, (self.message, self.lineno, self.name, self.filename)
|
||||
|
||||
|
||||
class TemplateAssertionError(TemplateSyntaxError):
|
||||
"""Like a template syntax error, but covers cases where something in the
|
||||
|
@ -10,6 +10,7 @@
|
||||
"""
|
||||
import pytest
|
||||
|
||||
import pickle
|
||||
import re
|
||||
import sys
|
||||
from traceback import format_exception
|
||||
@ -71,6 +72,12 @@ ZeroDivisionError: (int(eger)? )?division (or modulo )?by zero
|
||||
(jinja2\.exceptions\.)?TemplateSyntaxError: wtf
|
||||
line 42''')
|
||||
|
||||
def test_pickleable_syntax_error(self, fs_env):
|
||||
original = TemplateSyntaxError("bad template", 42, "test", "test.txt")
|
||||
unpickled = pickle.loads(pickle.dumps(original))
|
||||
assert str(original) == str(unpickled)
|
||||
assert original.name == unpickled.name
|
||||
|
||||
def test_include_syntax_error_source(self, filesystem_loader):
|
||||
e = Environment(loader=ChoiceLoader(
|
||||
[
|
||||
|
Loading…
Reference in New Issue
Block a user