From: Daniel P. Berrange Date: Tue, 13 Oct 2015 15:52:07 +0000 (+0100) Subject: runtime: avoid assumption that all objects provide __call__ X-Git-Tag: 2.10~12^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91255f86f6dc3b828142cc339155bcb5a7797486;p=thirdparty%2Fjinja.git 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 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 "