diff options
| author | Paul Everitt <paul@agendaless.com> | 2013-08-14 16:07:31 -0400 |
|---|---|---|
| committer | Paul Everitt <paul@agendaless.com> | 2013-08-14 16:07:31 -0400 |
| commit | e1662cb4bcc7a872db9744b53e0ef5780ae5b24a (patch) | |
| tree | 2fa43b016ff6008f73c4f73a9edc471fc778280c | |
| parent | 2d81001b80195e31a45c4d088285c5ed93712989 (diff) | |
| parent | 0cd88bcb8a309c8ae890883459c55deaccd3794f (diff) | |
| download | pyramid-e1662cb4bcc7a872db9744b53e0ef5780ae5b24a.tar.gz pyramid-e1662cb4bcc7a872db9744b53e0ef5780ae5b24a.tar.bz2 pyramid-e1662cb4bcc7a872db9744b53e0ef5780ae5b24a.zip | |
Merge remote-tracking branch 'origin/master'
| -rw-r--r-- | CHANGES.txt | 16 | ||||
| -rw-r--r-- | pyramid/mako_templating.py | 18 | ||||
| -rw-r--r-- | pyramid/tests/test_mako_templating.py | 15 | ||||
| -rw-r--r-- | pyramid/util.py | 16 |
4 files changed, 43 insertions, 22 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) diff --git a/pyramid/util.py b/pyramid/util.py index 02bd7ba2a..73f3ebdb0 100644 --- a/pyramid/util.py +++ b/pyramid/util.py @@ -69,22 +69,18 @@ class InstancePropertyMixin(object): can accept multiple ``(name, property)`` pairs generated via :meth:`pyramid.util.InstancePropertyMixin._make_property`. - ``attrs`` is a sequence of 2-tuples *or* a data structure with - an ``.items()`` method which returns a sequence of 2-tuples + ``properties`` is a sequence of two-tuples *or* a data structure + with an ``.items()`` method which returns a sequence of two-tuples (presumably a dictionary). It will be used to add several properties to the instance in a manner that is more efficient than simply calling ``set_property`` repeatedly. """ - - if hasattr(properties, 'items'): - attrs = properties.items() - else: - attrs = properties attrs = dict(properties) - parent = self.__class__ - cls = type(parent.__name__, (parent, object), attrs) - self.__class__ = cls + if attrs: + parent = self.__class__ + cls = type(parent.__name__, (parent, object), attrs) + self.__class__ = cls def _set_extensions(self, extensions): for name, fn in iteritems_(extensions.methods): |
