Commit Graph

149 Commits

Author SHA1 Message Date
David Lord
07c0b875e5 Merge pull request #502 from berrange/callable
runtime: avoid assumption that all objects provide __call__
2017-07-07 14:00:44 -07:00
Adrian Moennich
c2ee56db0e Add support for namespace attribute assignment 2017-06-24 10:56:54 +02:00
Adrian Moennich
bc076b3e25 Add changed() to loop context 2017-06-24 10:52:06 +02:00
Adrian Moennich
9bdb547b0e Add previtem/nextitem to loop context
related: #641
2017-06-24 10:52:06 +02:00
Adrian Moennich
a8a9ec2f29 Fix custom contexts in fast resolve mode
closes #675
2017-03-15 19:19:04 +01:00
Armin Ronacher
add79164c4 Fixed async macro autoescape. Fixes #671 2017-01-28 15:33:09 +01:00
Armin Ronacher
c6ddeb7d5f Add support back for custom resolves on old resolve method 2017-01-12 20:10:58 +01:00
Armin Ronacher
be16786d2d Fixed some string literal warnings. Fixes #646 2017-01-08 23:40:38 +01:00
Armin Ronacher
b1a56de18a Support new scoping rules in scoped blocks 2017-01-08 11:21:32 +01:00
Armin Ronacher
6235644d33 Add support for explicit callers
This adds support for a never intended Jinja2 feature which however
worked in limited support before due to a bug with the identifier
scoping.  A quick github code search indicates that developers
commonly did this to set the default caller to none.

This fixes #642
2017-01-08 02:16:41 +01:00
Armin Ronacher
bbe0a4174c Bump up the copyright to 2017 2017-01-07 16:17:14 +01:00
Armin Ronacher
d67f0fd4cc Generalize scoping. This fixes #603 2017-01-07 15:35:50 +01:00
Armin Ronacher
cb4b551e12 Fixed self references in macros 2017-01-06 20:57:30 +01:00
Armin Ronacher
b9655a457d Set macro autoescape behavior at call instead of compile time. Fixes #565 2017-01-06 14:29:38 +01:00
Armin Ronacher
46025fb3c7 Do not emit make_logging_undefined to runtime 2017-01-05 23:33:27 +01:00
Armin Ronacher
9b2a4f49c6 Changed behavior of macro defaults to be frame bound 2017-01-03 23:45:30 +01:00
Armin Ronacher
1205e641ed First pass on integrating id tracking 2017-01-03 23:45:29 +01:00
Armin Ronacher
ebed13eb2b Changelog and __rsub__ handling 2017-01-03 19:33:25 +01:00
Armin Ronacher
479d870eba Merge pull request #530 from nick-garcia/master
Subtraction from Undefined does not raise UndefinedError
2017-01-03 19:31:01 +01:00
Armin Ronacher
acab87a436 Support the same set of loop functions for async mode 2016-12-28 21:49:00 +01:00
Armin Ronacher
d4e14fc4d2 Added support for async loop context 2016-12-28 20:06:34 +01:00
Nick Garcia
dd85761ced Setting __sub__ equal to _fail_with_undefined_error so subtractions with
undefined variables will fail properly like other arithemtic operations.
2016-01-07 15:23:26 -08:00
Daniel P. Berrange
91255f86f6 runtime: avoid assumption that all objects provide __call__
Objects which are backed by native extensions do not provide
a __call__ attribute, but are none the less callable if the
native extension provides a 'tp_call' implementation.

The jinja2.runtime.Context.call method unconditionally
access the '__call__' attribute causing an exception to be
raised if the object was a native extension method.

A demo of the problem can be seen using PyGObject:

  $ cat demo.py
  #!/usr/bin/python

  from gi.repository import Gio
  from jinja2 import Environment

  f = Gio.File.new_for_path("/some/file.txt")
  print f.get_uri()

  t = Environment().from_string("""{{f.get_uri()}}""")
  print t.render(f=f)

Which when run results in

 $ ./demo.py
 file:///some/file.txt
 Traceback (most recent call last):
   File "./demo.py", line 10, in <module>
     print t.render(f=f)
   File "/usr/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
     return self.environment.handle_exception(exc_info, True)
   File "/usr/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
     reraise(exc_type, exc_value, tb)
   File "<template>", line 1, in top-level template code
     AttributeError: 'gi.FunctionInfo' object has no attribute '__call__'

After this patch it produces

 $ ./demo.py
 file:///some/file.txt
 file:///some/file.txt

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2015-10-13 16:52:07 +01:00
ThiefMaster
f22fdd5ffe Let the Environment override the Context
closes #404
2015-04-06 14:19:43 +02:00
Markus Unterwaditzer
599c1360bc Fix doctests
Fix #427
2015-03-22 14:22:52 +01:00
Armin Ronacher
7b32f8f8d1 Fixed a Python 3 regression. 2014-06-06 22:17:05 +06:00
Armin Ronacher
6e9dfbf2de Added tests for logging undefined and added it to the docs. 2014-06-06 22:14:45 +06:00
Armin Ronacher
d2641be848 Added support for logging of undefined objects.
fixup!

fixup!
2014-06-06 22:01:35 +06:00
Christoph Reiter
4eb30f1dec Fix loop context length calculation for iterators. Fixes #244
This resulted in wrong values for revindex and revindex0
while looping over an iterator.
2014-03-30 17:40:08 +02:00
Armin Ronacher
8db47916de Merge branch '2.7-maintenance' 2013-08-07 14:28:50 +01:00
Armin Ronacher
563fd2e74a Fixed warnings if Python is run with -3.
This also adds proper hashing and comparision support to
undefined objects.

This fixes #224
2013-08-07 12:48:37 +01:00
Armin Ronacher
b89d1a8fe3 Since we no longer support 2.5 we can use the builtin next() function 2013-05-20 16:54:48 +01:00
Armin Ronacher
568352e07d Documented loop.depth and added loop.depth0. 2013-05-20 09:26:57 +01:00
Armin Ronacher
ff0b5f5836 feature to version check for context dict methods 2013-05-20 02:15:04 +01:00
Armin Ronacher
eb12114219 Removed an unnecessary check 2013-05-20 02:12:34 +01:00
Armin Ronacher
28c7488224 Make the runtime leak less of the version hacks 2013-05-20 01:51:26 +01:00
Armin Ronacher
7e239b4d16 Added unicode mixin for unified string logic 2013-05-19 14:43:18 +01:00
Armin Ronacher
7e245e2678 PY3 -> PY2 macro 2013-05-19 14:34:54 +01:00
Armin Ronacher
e909867721 Moved all six usages (ignoring testsuite) into jinja2._compat 2013-05-19 14:16:13 +01:00
Armin Ronacher
c87d4cf11f six.advance_iterator -> next 2013-05-19 13:46:22 +01:00
Armin Ronacher
adb599994a Merge branch 'master' into sprint-branch 2013-05-18 11:58:37 +01:00
Armin Ronacher
9962c10b25 Cleanup and changelog entry for new contextfunction behavior 2013-05-18 11:58:12 +01:00
Daniel Neuhäuser
d0708db4bf Remove unused imports 2013-05-18 12:52:40 +02:00
Thomas Waldmann
7d29562ff9 python 3 port: manual fixes, remove 2to3 from setup.py, remove fixers 2013-05-18 00:06:22 +02:00
Thomas Waldmann
e0003555f8 python 3 port: automated changes by a slightly modified python-modernize
(replacing unicode with six.text_type, but not replacing u"" by six.u(""))
2013-05-17 23:52:14 +02:00
Richard Eames
71fc228879 - Allow callable classes to have contextfunction and the like 2013-04-15 23:49:02 -06:00
Armin Ronacher
99b22854ea Added changelog entry for #92 and changed LoopContext.End to _last_iteration 2012-01-25 00:42:54 +01:00
Jason Kotenko
776567cc4e Fixed loop.last to not consume the entire iterator to determine if this is
the last iteration of the loop.
2012-01-24 14:19:08 -08:00
jason kirtland
355d96f942 Removed dead code. 2011-04-25 11:19:22 -07:00
Armin Ronacher
3383e1ca37 join now also accepts parameters 2011-01-24 01:13:51 +01:00