summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaise Laflamme <blaise@laflamme.org>2013-08-13 21:25:13 -0700
committerBlaise Laflamme <blaise@laflamme.org>2013-08-13 21:25:13 -0700
commitca33b9a632c5cd97d5de1e375c5992f7dd4f6323 (patch)
tree0f5220472ac8daa73867702ae47e94d0d6a80994
parent6a227f73e7dedb0bc551242a44a86bf03f4e6f42 (diff)
parent3de54e3009f624f3c3dabe531fbcc25483368fe4 (diff)
downloadpyramid-ca33b9a632c5cd97d5de1e375c5992f7dd4f6323.tar.gz
pyramid-ca33b9a632c5cd97d5de1e375c5992f7dd4f6323.tar.bz2
pyramid-ca33b9a632c5cd97d5de1e375c5992f7dd4f6323.zip
Merge pull request #1082 from Pylons/fix.mako.partial.1037
Fix.mako.partial.1037
-rw-r--r--CHANGES.txt16
-rw-r--r--pyramid/mako_templating.py18
-rw-r--r--pyramid/tests/test_mako_templating.py15
3 files changed, 37 insertions, 12 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 0479e3011..76522695a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -133,6 +133,10 @@ Features
Bug Fixes
---------
+- Fixed a Mako renderer bug returning a tuple with a previous defname value
+ in some circumstances. See https://github.com/Pylons/pyramid/issues/1037
+ for more information.
+
- Make the ``pyramid.config.assets.PackageOverrides`` object implement the API
for ``__loader__`` objects specified in PEP 302. Proxies to the
``__loader__`` set by the importer, if present; otherwise, raises
@@ -270,7 +274,7 @@ Features
@subscriber(SomeOtherEvent)
def asubscriber(event):
pass
-
+
And you wanted to use a subscriber predicate::
@subscriber([SomeEvent, SomeContextType], mypredicate=True)
@@ -344,7 +348,7 @@ Features
@subscriber([SomeContextType, SomeEvent])
def asubscriber(event):
- # bzzt! you'll be getting the context here as ``event``, and it'll
+ # bzzt! you'll be getting the context here as ``event``, and it'll
# be useless
Existing multiple-argument subscribers continue to work without issue, so you
@@ -614,7 +618,7 @@ Bug Fixes
https://github.com/Pylons/pyramid/issues/606
https://github.com/Pylons/pyramid/issues/607
-- In Mako Templates lookup, check for absolute uri (using mako directories)
+- In Mako Templates lookup, check for absolute uri (using mako directories)
when mixing up inheritance with asset specs.
https://github.com/Pylons/pyramid/issues/662
@@ -833,13 +837,13 @@ Backwards Incompatibilities
* ``registerAdapter``, use
``pyramid.config.Configurator.registry.registerAdapter`` instead.
- * ``registerSubscriber``, use
+ * ``registerSubscriber``, use
``pyramid.config.Configurator.add_subscriber`` instead.
- * ``registerRoute``, use
+ * ``registerRoute``, use
``pyramid.config.Configurator.add_route`` instead.
- * ``registerSettings``, use
+ * ``registerSettings``, use
``pyramid.config.Configurator.add_settings`` instead.
- In Pyramid 1.3 and previous, the ``__call__`` method of a Response object
diff --git a/pyramid/mako_templating.py b/pyramid/mako_templating.py
index 8d4583d82..c07ee227f 100644
--- a/pyramid/mako_templating.py
+++ b/pyramid/mako_templating.py
@@ -2,6 +2,7 @@ import os
import posixpath
import sys
import threading
+import warnings
from zope.interface import (
implementer,
@@ -215,12 +216,17 @@ class MakoLookupTemplateRenderer(object):
context = system.pop('context', None)
if context is not None:
system['_context'] = context
- if self.defname is None:
- if isinstance(value, tuple):
- self.defname, value = value
- else:
- if isinstance(value, tuple):
- _, value = value
+ # tuple returned to be deprecated
+ if isinstance(value, tuple):
+ warnings.warn(
+ 'Using a tuple in the form (\'defname\', {}) to render a '
+ 'Mako partial will be deprecated in the future. Use a '
+ 'Mako template renderer as documented in the "Using A '
+ 'Mako def name Within a Renderer Name" chapter of the '
+ 'Pyramid narrative documentation instead',
+ DeprecationWarning,
+ 3)
+ self.defname, value = value
try:
system.update(value)
except (TypeError, ValueError):
diff --git a/pyramid/tests/test_mako_templating.py b/pyramid/tests/test_mako_templating.py
index f607a5497..a57ac0aaa 100644
--- a/pyramid/tests/test_mako_templating.py
+++ b/pyramid/tests/test_mako_templating.py
@@ -416,6 +416,21 @@ class MakoLookupTemplateRendererTests(Base, maybe_unittest()):
self.assertEqual(result, text_('result'))
self.assertEqual(lookup.values, {'_context':1})
+ def test_call_with_defname_with_tuple_value_twice(self):
+ lookup = DummyLookup()
+ instance1 = self._makeOne('path', 'defname', lookup)
+ result1 = instance1(('defname1', {}), {'context':1})
+ self.assertEqual(lookup.deffed, 'defname1')
+ self.assertEqual(result1, text_('result'))
+ self.assertEqual(lookup.values, {'_context':1})
+ instance2 = self._makeOne('path', 'defname', lookup)
+ result2 = instance2(('defname2', {}), {'context':2})
+ self.assertNotEqual(lookup.deffed, 'defname1')
+ self.assertEqual(lookup.deffed, 'defname2')
+ self.assertEqual(result2, text_('result'))
+ self.assertEqual(lookup.values, {'_context':2})
+
+
def test_call_with_nondict_value(self):
lookup = DummyLookup()
instance = self._makeOne('path', None, lookup)