diff --git a/jinja2/environment.py b/jinja2/environment.py index b406b5a..1f6496b 100644 --- a/jinja2/environment.py +++ b/jinja2/environment.py @@ -879,13 +879,12 @@ class Template(object): and compatible settings. >>> template = Template('Hello {{ name }}!') - >>> template.render(name='John Doe') - u'Hello John Doe!' - + >>> template.render(name='John Doe') == u'Hello John Doe!' + True >>> stream = template.stream(name='John Doe') - >>> stream.next() - u'Hello John Doe!' - >>> stream.next() + >>> next(stream) == u'Hello John Doe!' + True + >>> next(stream) Traceback (most recent call last): ... StopIteration @@ -1032,10 +1031,10 @@ class Template(object): exported template variables from the Python layer: >>> t = Template('{% macro foo() %}42{% endmacro %}23') - >>> unicode(t.module) - u'23' - >>> t.module.foo() - u'42' + >>> str(t.module) + '23' + >>> t.module.foo() == u'42' + True """ if self._module is not None: return self._module diff --git a/jinja2/meta.py b/jinja2/meta.py index 3110cff..3dbab7c 100644 --- a/jinja2/meta.py +++ b/jinja2/meta.py @@ -39,8 +39,8 @@ def find_undeclared_variables(ast): >>> from jinja2 import Environment, meta >>> env = Environment() >>> ast = env.parse('{% set foo = 42 %}{{ bar + foo }}') - >>> meta.find_undeclared_variables(ast) - set(['bar']) + >>> meta.find_undeclared_variables(ast) == set(['bar']) + True .. admonition:: Implementation diff --git a/jinja2/runtime.py b/jinja2/runtime.py index 792fb9a..9e818df 100644 --- a/jinja2/runtime.py +++ b/jinja2/runtime.py @@ -444,7 +444,7 @@ class Macro(object): @implements_to_string class Undefined(object): """The default undefined type. This undefined type can be printed and - iterated over, but every other access will raise an :exc:`UndefinedError`: + iterated over, but every other access will raise an :exc:`jinja2.exceptions.UndefinedError`: >>> foo = Undefined(name='foo') >>> str(foo) @@ -454,7 +454,7 @@ class Undefined(object): >>> foo + 42 Traceback (most recent call last): ... - UndefinedError: 'foo' is undefined + jinja2.exceptions.UndefinedError: 'foo' is undefined """ __slots__ = ('_undefined_hint', '_undefined_obj', '_undefined_name', '_undefined_exception') @@ -468,7 +468,7 @@ class Undefined(object): @internalcode def _fail_with_undefined_error(self, *args, **kwargs): """Regular callback function for undefined objects that raises an - `UndefinedError` on call. + `jinja2.exceptions.UndefinedError` on call. """ if self._undefined_hint is None: if self._undefined_obj is missing: @@ -620,7 +620,7 @@ class DebugUndefined(Undefined): >>> foo + 42 Traceback (most recent call last): ... - UndefinedError: 'foo' is undefined + jinja2.exceptions.UndefinedError: 'foo' is undefined """ __slots__ = () @@ -645,15 +645,15 @@ class StrictUndefined(Undefined): >>> str(foo) Traceback (most recent call last): ... - UndefinedError: 'foo' is undefined + jinja2.exceptions.UndefinedError: 'foo' is undefined >>> not foo Traceback (most recent call last): ... - UndefinedError: 'foo' is undefined + jinja2.exceptions.UndefinedError: 'foo' is undefined >>> foo + 42 Traceback (most recent call last): ... - UndefinedError: 'foo' is undefined + jinja2.exceptions.UndefinedError: 'foo' is undefined """ __slots__ = () __iter__ = __str__ = __len__ = __nonzero__ = __eq__ = \ diff --git a/jinja2/sandbox.py b/jinja2/sandbox.py index 0b6383a..7e40ab3 100644 --- a/jinja2/sandbox.py +++ b/jinja2/sandbox.py @@ -23,8 +23,14 @@ from jinja2._compat import string_types, PY2 MAX_RANGE = 100000 #: attributes of function objects that are considered unsafe. -UNSAFE_FUNCTION_ATTRIBUTES = set(['func_closure', 'func_code', 'func_dict', - 'func_defaults', 'func_globals']) +if PY2: + UNSAFE_FUNCTION_ATTRIBUTES = set(['func_closure', 'func_code', 'func_dict', + 'func_defaults', 'func_globals']) +else: + # On versions > python 2 the special attributes on functions are gone, + # but they remain on methods and generators for whatever reason. + UNSAFE_FUNCTION_ATTRIBUTES = set() + #: unsafe method attributes. function attributes are unsafe for methods too UNSAFE_METHOD_ATTRIBUTES = set(['im_class', 'im_func', 'im_self']) @@ -32,11 +38,6 @@ UNSAFE_METHOD_ATTRIBUTES = set(['im_class', 'im_func', 'im_self']) #: unsafe generator attirbutes. UNSAFE_GENERATOR_ATTRIBUTES = set(['gi_frame', 'gi_code']) -# On versions > python 2 the special attributes on functions are gone, -# but they remain on methods and generators for whatever reason. -if not PY2: - UNSAFE_FUNCTION_ATTRIBUTES = set() - import warnings # make sure we don't warn in python 2.6 about stuff we don't care about @@ -124,9 +125,7 @@ def is_internal_attribute(obj, attr): :meth:`~SandboxedEnvironment.is_safe_attribute` is overridden. >>> from jinja2.sandbox import is_internal_attribute - >>> is_internal_attribute(lambda: None, "func_code") - True - >>> is_internal_attribute((lambda x:x).func_code, 'co_code') + >>> is_internal_attribute(str, "mro") True >>> is_internal_attribute(str, "upper") False diff --git a/jinja2-debug.py b/scripts/jinja2-debug.py similarity index 91% rename from jinja2-debug.py rename to scripts/jinja2-debug.py index 80bbc62..d052adc 100755 --- a/jinja2-debug.py +++ b/scripts/jinja2-debug.py @@ -21,7 +21,7 @@ env = jinja2.Environment(extensions=['jinja2.ext.i18n', 'jinja2.ext.do', def shell_init_func(): def _compile(x): - print env.compile(x, raw=True) + print(env.compile(x, raw=True)) result = { 'e': env, 'c': _compile, @@ -34,7 +34,7 @@ def shell_init_func(): def action_compile(): - print env.compile(sys.stdin.read(), raw=True) + print(env.compile(sys.stdin.read(), raw=True)) action_shell = script.make_shell(shell_init_func) diff --git a/setup.cfg b/setup.cfg index 058cdfc..573a4ee 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,4 +5,5 @@ universal = 1 release = egg_info -RDb '' [pytest] -norecursedirs = .* *.egg *.egg-info env* artwork docs examples +norecursedirs = .* *.egg *.egg-info env* artwork docs examples ext scripts +addopts = --doctest-modules --ignore=setup.py