From 1aa978c074afce7f821634e5aa8366caa07ee437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20B=C3=BCchler?= Date: Wed, 23 May 2012 09:28:53 +0300 Subject: Fixed a few glitches in the "Using a Route Prefix to Compose Applications" section of the docs/narr/urldispatch.rst docs. --- docs/narr/urldispatch.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/narr/urldispatch.rst b/docs/narr/urldispatch.rst index acbccbdfd..ecf3d026a 100644 --- a/docs/narr/urldispatch.rst +++ b/docs/narr/urldispatch.rst @@ -954,7 +954,7 @@ will be prepended with the first: from pyramid.config import Configurator def timing_include(config): - config.add_route('show_times', /times') + config.add_route('show_times', '/times') def users_include(config): config.add_route('show_users', '/show') @@ -966,7 +966,7 @@ will be prepended with the first: In the above configuration, the ``show_users`` route will still have an effective route pattern of ``/users/show``. The ``show_times`` route -however, will have an effective pattern of ``/users/timing/show_times``. +however, will have an effective pattern of ``/users/timing/times``. Route prefixes have no impact on the requirement that the set of route *names* in any given Pyramid configuration must be entirely unique. If you @@ -981,7 +981,7 @@ that may be added in the future. For example: from pyramid.config import Configurator def timing_include(config): - config.add_route('timing.show_times', /times') + config.add_route('timing.show_times', '/times') def users_include(config): config.add_route('users.show_users', '/show') -- cgit v1.2.3 From a319249fdb6e0539e65e0b297829ed8c7f799b98 Mon Sep 17 00:00:00 2001 From: Jeff Cook Date: Thu, 7 Jun 2012 14:00:07 -0600 Subject: Update documentation to clarify purpose of BeforeRender.rendering_val. --- docs/narr/hooks.rst | 15 +++++++++++++++ pyramid/events.py | 20 ++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/docs/narr/hooks.rst b/docs/narr/hooks.rst index a2143b3c5..30eec04f0 100644 --- a/docs/narr/hooks.rst +++ b/docs/narr/hooks.rst @@ -289,6 +289,21 @@ keys added to the renderer globals dictionary by all :class:`pyramid.events.BeforeRender` subscribers and renderer globals factories must be unique. +The dictionary returned from the view is accessible through the +:attr:`rendering_val` attribute of a :class:`~pyramid.events.BeforeRender` +event, like so: + +.. code-block:: python + :linenos: + + from pyramid.events import subscriber + from pyramid.events import BeforeRender + + @subscriber(BeforeRender) + def read_return(event): + # 'mykey' is returned from the view + print(event.rendering_val['mykey']) + See the API documentation for the :class:`~pyramid.events.BeforeRender` event interface at :class:`pyramid.interfaces.IBeforeRender`. diff --git a/pyramid/events.py b/pyramid/events.py index e181ef33f..1941c594c 100644 --- a/pyramid/events.py +++ b/pyramid/events.py @@ -200,10 +200,22 @@ class BeforeRender(dict): setting an overriding value (which can be done using ``.get`` or ``__contains__`` of the event object). - The event has an additional attribute named ``rendering_val``. This is - the (non-system) value returned by a view or passed to ``render*`` as - ``value``. This feature is new in Pyramid 1.2. - + The dictionary returned from the view is accessible through the + :attr:`rendering_val` attribute of a :class:`~pyramid.events.BeforeRender` + event, like so:: + + from pyramid.events import subscriber + from pyramid.events import BeforeRender + + @subscriber(BeforeRender) + def read_return(event): + # "mykey" is returned from the view + print(event.rendering_val['mykey']) + + In other words, ``rendering_val`` is the (non-system) value returned by a + view or passed to ``render*`` as ``value``. This feature is new in Pyramid + 1.2. + For a description of the values present in the renderer globals dictionary, see :ref:`renderer_system_values`. -- cgit v1.2.3 From 0487d5e05dd61d6d7482212d40fb5884e06f582a Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Tue, 12 Jun 2012 11:18:37 -0500 Subject: docs reference setup_logging instead of fileConfig --- docs/narr/commandline.rst | 7 +++++-- docs/narr/logging.rst | 7 ++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/narr/commandline.rst b/docs/narr/commandline.rst index 4be436836..af53c1f78 100644 --- a/docs/narr/commandline.rst +++ b/docs/narr/commandline.rst @@ -654,8 +654,11 @@ use the following command: .. code-block:: python - import logging.config - logging.config.fileConfig('/path/to/my/development.ini') + import pyramid.paster + pyramid.paster.setup_logging('/path/to/my/development.ini') + +See :ref:`logging_chapter` for more information on logging within +:app:`Pyramid`. .. index:: single: console script diff --git a/docs/narr/logging.rst b/docs/narr/logging.rst index 044655c1f..f4c38abb6 100644 --- a/docs/narr/logging.rst +++ b/docs/narr/logging.rst @@ -14,7 +14,7 @@ how to send log messages to loggers that you've configured. which help configure logging. All of the scaffolds which ship along with :app:`Pyramid` do this. If you're not using a scaffold, or if you've used a third-party scaffold which does not create these files, the - configuration information in this chapter will not be applicable. + configuration information in this chapter may not be applicable. .. _logging_config: @@ -36,10 +36,11 @@ application-related and logging-related sections in the configuration file can coexist peacefully, and the logging-related sections in the file are used from when you run ``pserve``. -The ``pserve`` command calls the `logging.fileConfig function +The ``pserve`` command calls the :func:`pyramid.paster.setup_logging` +function, a thin wrapper around the `logging.fileConfig `_ using the specified ini file if it contains a ``[loggers]`` section (all of the -scaffold-generated ``.ini`` files do). ``logging.fileConfig`` reads the +scaffold-generated ``.ini`` files do). ``setup_logging`` reads the logging configuration from the ini file upon which ``pserve`` was invoked. -- cgit v1.2.3 From b555e98c477056a7b32a46294c42c11a3b96b432 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Fri, 1 Jun 2012 07:56:13 -0700 Subject: Add "py33" to tox.ini --- tox.ini | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 97aa6c4d0..85bd41bda 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py26,py27,py32,pypy,cover + py26,py27,py32,py33,pypy,cover [testenv] commands = @@ -21,6 +21,14 @@ deps = virtualenv venusian +[testenv:py33] +commands = + python setup.py test -q +deps = + WebTest + virtualenv + venusian + [testenv:cover] basepython = python2.6 -- cgit v1.2.3 From 366f9d5960c0cb85ef0ab9403e37e19fc85961d0 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Fri, 1 Jun 2012 07:59:11 -0700 Subject: Add .travis.yml for Travis CI (http://travis-ci.org/) --- .travis.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..cb4cc69e1 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: python + +python: + - 2.6 + - 2.7 + - pypy + - 3.2 + +matrix: + allow_failures: + - python: pypy + +script: python setup.py test + -- cgit v1.2.3 From b5478966861d3de23ca299c26891f9709cf09ad7 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Wed, 13 Jun 2012 08:06:15 -0700 Subject: Add "Marc Abramowitz" to CONTRIBUTORS.txt --- CONTRIBUTORS.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 98f73d5f9..027fc0857 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -172,3 +172,5 @@ Contributors - Wayne Witzel III, 2012/03/27 - Marin Rukavina, 2012/05/03 + +- Marc Abramowitz, 2012/06/13 -- cgit v1.2.3 From e07b4f8edd32766dd0c8327d04a9c7b99d8dc2e9 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Thu, 14 Jun 2012 17:27:28 -0700 Subject: Remove blank line from .travis.yml --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cb4cc69e1..2e737af04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,4 +11,3 @@ matrix: - python: pypy script: python setup.py test - -- cgit v1.2.3 From 2516df30d73afdf6606ad3d89b7c24ab496f356d Mon Sep 17 00:00:00 2001 From: Jeff Cook Date: Sun, 17 Jun 2012 01:20:37 -0600 Subject: docs: Add view callable example to section on rendering_val. --- docs/narr/hooks.rst | 31 +++++++++++++++++++++++-------- pyramid/events.py | 18 +++++++++++++++--- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/docs/narr/hooks.rst b/docs/narr/hooks.rst index 30eec04f0..332805152 100644 --- a/docs/narr/hooks.rst +++ b/docs/narr/hooks.rst @@ -291,18 +291,33 @@ factories must be unique. The dictionary returned from the view is accessible through the :attr:`rendering_val` attribute of a :class:`~pyramid.events.BeforeRender` -event, like so: +event. + +Suppose you return ``{'mykey': 'somevalue', 'mykey2': 'somevalue2'}`` from +your view callable, like so: .. code-block:: python - :linenos: + :linenos: - from pyramid.events import subscriber - from pyramid.events import BeforeRender + from pyramid.view import view_config - @subscriber(BeforeRender) - def read_return(event): - # 'mykey' is returned from the view - print(event.rendering_val['mykey']) + @view_config(renderer='some_renderer') + def myview(request): + return {'mykey': 'somevalue', 'mykey2': 'somevalue2'} + +:attr:`rendering_val` can be used to access these values from the +:class:`~pyramid.events.BeforeRender` object: + +.. code-block:: python + :linenos: + + from pyramid.events import subscriber + from pyramid.events import BeforeRender + + @subscriber(BeforeRender) + def read_return(event): + # {'mykey': 'somevalue'} is returned from the view + print(event.rendering_val['mykey']) See the API documentation for the :class:`~pyramid.events.BeforeRender` event interface at :class:`pyramid.interfaces.IBeforeRender`. diff --git a/pyramid/events.py b/pyramid/events.py index 1941c594c..db274823c 100644 --- a/pyramid/events.py +++ b/pyramid/events.py @@ -202,17 +202,29 @@ class BeforeRender(dict): The dictionary returned from the view is accessible through the :attr:`rendering_val` attribute of a :class:`~pyramid.events.BeforeRender` - event, like so:: + event. + + Suppose you return ``{'mykey': 'somevalue', 'mykey2': 'somevalue2'}`` from + your view callable, like so:: + + from pyramid.view import view_config + + @view_config(renderer='some_renderer') + def myview(request): + return {'mykey': 'somevalue', 'mykey2': 'somevalue2'} + + :attr:`rendering_val` can be used to access these values from the + :class:`~pyramid.events.BeforeRender` object:: from pyramid.events import subscriber from pyramid.events import BeforeRender @subscriber(BeforeRender) def read_return(event): - # "mykey" is returned from the view + # {'mykey': 'somevalue'} is returned from the view print(event.rendering_val['mykey']) - In other words, ``rendering_val`` is the (non-system) value returned by a + In other words, :attr:`rendering_val` is the (non-system) value returned by a view or passed to ``render*`` as ``value``. This feature is new in Pyramid 1.2. -- cgit v1.2.3 From 4761ec79e1f3e0daeb4ba8351c27eb2a715f07a4 Mon Sep 17 00:00:00 2001 From: Jeff Cook Date: Sun, 17 Jun 2012 01:24:20 -0600 Subject: CONTRIBUTORS: Add self / accept contribution terms --- CONTRIBUTORS.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 98f73d5f9..2baeea3dc 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -172,3 +172,5 @@ Contributors - Wayne Witzel III, 2012/03/27 - Marin Rukavina, 2012/05/03 + +- Jeff Cook, 2012/06/16 -- cgit v1.2.3 From 5b1f04fb91b2da701c9ea913883874eda5c3dafb Mon Sep 17 00:00:00 2001 From: Blaise Laflamme Date: Tue, 19 Jun 2012 14:42:56 -0400 Subject: added namespace test --- pyramid/tests/fixtures/components.mak | 3 +++ pyramid/tests/fixtures/hellocompo.mak | 3 +++ pyramid/tests/test_mako_templating.py | 5 +++++ 3 files changed, 11 insertions(+) create mode 100644 pyramid/tests/fixtures/components.mak create mode 100644 pyramid/tests/fixtures/hellocompo.mak diff --git a/pyramid/tests/fixtures/components.mak b/pyramid/tests/fixtures/components.mak new file mode 100644 index 000000000..cc886805c --- /dev/null +++ b/pyramid/tests/fixtures/components.mak @@ -0,0 +1,3 @@ +<%def name="comp()"> +World! + \ No newline at end of file diff --git a/pyramid/tests/fixtures/hellocompo.mak b/pyramid/tests/fixtures/hellocompo.mak new file mode 100644 index 000000000..142676a11 --- /dev/null +++ b/pyramid/tests/fixtures/hellocompo.mak @@ -0,0 +1,3 @@ +<%namespace name="comp" file="pyramid.tests:fixtures/components.mak"/> +Namespace +Hello ${comp.comp()} \ No newline at end of file diff --git a/pyramid/tests/test_mako_templating.py b/pyramid/tests/test_mako_templating.py index fbb04273b..8b738c21d 100644 --- a/pyramid/tests/test_mako_templating.py +++ b/pyramid/tests/test_mako_templating.py @@ -402,6 +402,11 @@ class TestIntegration(unittest.TestCase): result = render('hello_inherit_pkg.mak', {}).replace('\r','') self.assertEqual(result, text_('Layout\nHello World!\n')) + def test_render_namespace(self): + from pyramid.renderers import render + result = render('hellocompo.mak', {}).replace('\r','') + self.assertEqual(result, text_('\nNamespace\nHello \nWorld!\n')) + def test_render_to_response(self): from pyramid.renderers import render_to_response result = render_to_response('helloworld.mak', {'a':1}) -- cgit v1.2.3 From f71ed59edb74e9a13362521918e2660e4e4263ba Mon Sep 17 00:00:00 2001 From: Blaise Laflamme Date: Tue, 19 Jun 2012 16:32:41 -0400 Subject: added a new makodef renderer to call a def inside a mako template, fixed tests and removed old tuple way of calling def. Based on zzzeek example of client/server templating. --- pyramid/config/rendering.py | 1 + pyramid/mako_templating.py | 19 +++++++++++-------- pyramid/tests/test_mako_templating.py | 21 ++++++++++----------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/pyramid/config/rendering.py b/pyramid/config/rendering.py index 926511b7b..bfa41ee03 100644 --- a/pyramid/config/rendering.py +++ b/pyramid/config/rendering.py @@ -21,6 +21,7 @@ DEFAULT_RENDERERS = ( ('.pt', chameleon_zpt.renderer_factory), ('.mak', mako_renderer_factory), ('.mako', mako_renderer_factory), + ('.makodef', mako_renderer_factory), ('json', renderers.json_renderer_factory), ('string', renderers.string_renderer_factory), ) diff --git a/pyramid/mako_templating.py b/pyramid/mako_templating.py index 208e54bf5..48288c930 100644 --- a/pyramid/mako_templating.py +++ b/pyramid/mako_templating.py @@ -1,4 +1,5 @@ import os +import re import sys import threading @@ -76,7 +77,11 @@ class MakoRendererFactoryHelper(object): self.settings_prefix = settings_prefix def __call__(self, info): - path = info.name + p = re.compile( + r'(?P[\w_.:/]+)' + r'(?:\#(?P[\w_]+))?' + ) + path, defname = p.match(info.name).group("path", "defname") registry = info.registry settings = info.settings settings_prefix = self.settings_prefix @@ -141,7 +146,7 @@ class MakoRendererFactoryHelper(object): finally: registry_lock.release() - return MakoLookupTemplateRenderer(path, lookup) + return MakoLookupTemplateRenderer(path, defname, lookup) renderer_factory = MakoRendererFactoryHelper('mako.') @@ -156,8 +161,9 @@ class MakoRenderingException(Exception): @implementer(ITemplateRenderer) class MakoLookupTemplateRenderer(object): - def __init__(self, path, lookup): + def __init__(self, path, defname, lookup): self.path = path + self.defname = defname self.lookup = lookup def implementation(self): @@ -167,16 +173,13 @@ class MakoLookupTemplateRenderer(object): context = system.pop('context', None) if context is not None: system['_context'] = context - def_name = None - if isinstance(value, tuple): - def_name, value = value try: system.update(value) except (TypeError, ValueError): raise ValueError('renderer was passed non-dictionary as value') template = self.implementation() - if def_name is not None: - template = template.get_def(def_name) + if self.defname is not None: + template = template.get_def(self.defname) try: result = template.render_unicode(**system) except: diff --git a/pyramid/tests/test_mako_templating.py b/pyramid/tests/test_mako_templating.py index 8b738c21d..cd7b140d6 100644 --- a/pyramid/tests/test_mako_templating.py +++ b/pyramid/tests/test_mako_templating.py @@ -315,7 +315,7 @@ class MakoLookupTemplateRendererTests(Base, unittest.TestCase): def test_instance_implements_ITemplate(self): from zope.interface.verify import verifyObject from pyramid.interfaces import ITemplateRenderer - verifyObject(ITemplateRenderer, self._makeOne(None, None)) + verifyObject(ITemplateRenderer, self._makeOne(None, None, None)) def test_class_implements_ITemplate(self): from zope.interface.verify import verifyClass @@ -324,7 +324,7 @@ class MakoLookupTemplateRendererTests(Base, unittest.TestCase): def test_call(self): lookup = DummyLookup() - instance = self._makeOne('path', lookup) + instance = self._makeOne('path', None, lookup) result = instance({}, {'system':1}) self.assertTrue(isinstance(result, text_type)) self.assertEqual(result, text_('result')) @@ -332,29 +332,28 @@ class MakoLookupTemplateRendererTests(Base, unittest.TestCase): def test_call_with_system_context(self): # lame lookup = DummyLookup() - instance = self._makeOne('path', lookup) + instance = self._makeOne('path', None, lookup) result = instance({}, {'context':1}) self.assertTrue(isinstance(result, text_type)) self.assertEqual(result, text_('result')) self.assertEqual(lookup.values, {'_context':1}) - def test_call_with_tuple_value(self): + def test_call_with_defname(self): lookup = DummyLookup() - instance = self._makeOne('path', lookup) - result = instance(('fub', {}), {'context':1}) - self.assertEqual(lookup.deffed, 'fub') + instance = self._makeOne('path', 'defname', lookup) + result = instance({}, {'system':1}) + self.assertTrue(isinstance(result, text_type)) self.assertEqual(result, text_('result')) - self.assertEqual(lookup.values, {'_context':1}) def test_call_with_nondict_value(self): lookup = DummyLookup() - instance = self._makeOne('path', lookup) + instance = self._makeOne('path', None, lookup) self.assertRaises(ValueError, instance, None, {}) def test_call_render_raises(self): from pyramid.mako_templating import MakoRenderingException lookup = DummyLookup(exc=NotImplementedError) - instance = self._makeOne('path', lookup) + instance = self._makeOne('path', None, lookup) try: instance({}, {}) except MakoRenderingException as e: @@ -364,7 +363,7 @@ class MakoLookupTemplateRendererTests(Base, unittest.TestCase): def test_implementation(self): lookup = DummyLookup() - instance = self._makeOne('path', lookup) + instance = self._makeOne('path', None, lookup) result = instance.implementation().render_unicode() self.assertTrue(isinstance(result, text_type)) self.assertEqual(result, text_('result')) -- cgit v1.2.3 From c358304043e7e68c7fc97dff42f88633b8f15c69 Mon Sep 17 00:00:00 2001 From: Blaise Laflamme Date: Tue, 19 Jun 2012 18:49:53 -0400 Subject: added removed tuple for bw compat --- pyramid/mako_templating.py | 3 +++ pyramid/tests/test_mako_templating.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/pyramid/mako_templating.py b/pyramid/mako_templating.py index 48288c930..f866e2630 100644 --- a/pyramid/mako_templating.py +++ b/pyramid/mako_templating.py @@ -173,6 +173,9 @@ 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 try: system.update(value) except (TypeError, ValueError): diff --git a/pyramid/tests/test_mako_templating.py b/pyramid/tests/test_mako_templating.py index cd7b140d6..6cfa3ea4b 100644 --- a/pyramid/tests/test_mako_templating.py +++ b/pyramid/tests/test_mako_templating.py @@ -338,6 +338,14 @@ class MakoLookupTemplateRendererTests(Base, unittest.TestCase): self.assertEqual(result, text_('result')) self.assertEqual(lookup.values, {'_context':1}) + def test_call_with_tuple_value(self): + lookup = DummyLookup() + instance = self._makeOne('path', None, lookup) + result = instance(('fub', {}), {'context':1}) + self.assertEqual(lookup.deffed, 'fub') + self.assertEqual(result, text_('result')) + self.assertEqual(lookup.values, {'_context':1}) + def test_call_with_defname(self): lookup = DummyLookup() instance = self._makeOne('path', 'defname', lookup) -- cgit v1.2.3 From 59f8017b4a4aa9767bab49b39db362e973bdacf1 Mon Sep 17 00:00:00 2001 From: Blaise Laflamme Date: Tue, 19 Jun 2012 19:28:55 -0400 Subject: removed .makodef, use tuple value if defname in renderer (bw compat), changed format for package:some/template#defname.mako --- pyramid/config/rendering.py | 1 - pyramid/mako_templating.py | 7 ++++++- pyramid/tests/test_mako_templating.py | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pyramid/config/rendering.py b/pyramid/config/rendering.py index bfa41ee03..926511b7b 100644 --- a/pyramid/config/rendering.py +++ b/pyramid/config/rendering.py @@ -21,7 +21,6 @@ DEFAULT_RENDERERS = ( ('.pt', chameleon_zpt.renderer_factory), ('.mak', mako_renderer_factory), ('.mako', mako_renderer_factory), - ('.makodef', mako_renderer_factory), ('json', renderers.json_renderer_factory), ('string', renderers.string_renderer_factory), ) diff --git a/pyramid/mako_templating.py b/pyramid/mako_templating.py index f866e2630..8bd9381f0 100644 --- a/pyramid/mako_templating.py +++ b/pyramid/mako_templating.py @@ -80,8 +80,10 @@ class MakoRendererFactoryHelper(object): p = re.compile( r'(?P[\w_.:/]+)' r'(?:\#(?P[\w_]+))?' + r'(\.(?P.*))' ) - path, defname = p.match(info.name).group("path", "defname") + asset, defname, ext = p.match(info.name).group('path', 'defname', 'ext') + path = '%s.%s' % (asset, ext) registry = info.registry settings = info.settings settings_prefix = self.settings_prefix @@ -176,6 +178,9 @@ class MakoLookupTemplateRenderer(object): if self.defname is None: if isinstance(value, tuple): self.defname, value = value + else: + if isinstance(value, tuple): + _, 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 6cfa3ea4b..41fa9bdc4 100644 --- a/pyramid/tests/test_mako_templating.py +++ b/pyramid/tests/test_mako_templating.py @@ -353,6 +353,14 @@ class MakoLookupTemplateRendererTests(Base, unittest.TestCase): self.assertTrue(isinstance(result, text_type)) self.assertEqual(result, text_('result')) + def test_call_with_defname_with_tuple_value(self): + lookup = DummyLookup() + instance = self._makeOne('path', 'defname', lookup) + result = instance(('defname', {}), {'context':1}) + self.assertEqual(lookup.deffed, 'defname') + self.assertEqual(result, text_('result')) + self.assertEqual(lookup.values, {'_context':1}) + def test_call_with_nondict_value(self): lookup = DummyLookup() instance = self._makeOne('path', None, lookup) -- cgit v1.2.3 From b015d702d4c5367cd24fa05bd8d83462b6d59ac1 Mon Sep 17 00:00:00 2001 From: Blaise Laflamme Date: Tue, 19 Jun 2012 19:30:01 -0400 Subject: renamed path for asset in regex --- pyramid/mako_templating.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyramid/mako_templating.py b/pyramid/mako_templating.py index 8bd9381f0..b02daa23c 100644 --- a/pyramid/mako_templating.py +++ b/pyramid/mako_templating.py @@ -78,11 +78,11 @@ class MakoRendererFactoryHelper(object): def __call__(self, info): p = re.compile( - r'(?P[\w_.:/]+)' + r'(?P[\w_.:/]+)' r'(?:\#(?P[\w_]+))?' r'(\.(?P.*))' ) - asset, defname, ext = p.match(info.name).group('path', 'defname', 'ext') + asset, defname, ext = p.match(info.name).group('asset', 'defname', 'ext') path = '%s.%s' % (asset, ext) registry = info.registry settings = info.settings -- cgit v1.2.3 From ea009a6d4a1ffa8585faa85581848f6e74a57dfc Mon Sep 17 00:00:00 2001 From: Blaise Laflamme Date: Tue, 19 Jun 2012 20:12:55 -0400 Subject: added docs and changes for using defs in mako renderer --- CHANGES.txt | 5 +++++ docs/narr/templates.rst | 16 ++++++++++++++++ pyramid/mako_templating.py | 7 +++++++ 3 files changed, 28 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 7c2af4451..3cb2f2848 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -41,3 +41,8 @@ Features - The static view machinery now raises (rather than returns) ``HTTPNotFound`` and ``HTTPMovedPermanently`` exceptions, so these can be caught by the NotFound view (and other exception views). + +- The mako renderer now accepts a def name and returns the template def + result for the view being called. The uri format using an asset spec is + package:path/to/template#defname.mako. The old way of returning a tuple + from the view is supported for backward compatibility, ('defname', {}). diff --git a/docs/narr/templates.rst b/docs/narr/templates.rst index 9db0b1c4d..4ac01c96e 100644 --- a/docs/narr/templates.rst +++ b/docs/narr/templates.rst @@ -714,6 +714,22 @@ This template doesn't use any advanced features of Mako, only the :term:`renderer globals`. See the `the Mako documentation `_ to use more advanced features. +Using def inside Mako Templates +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To use a def inside a Mako template, given a :term:`Mako` template file named +``foo.mak`` and a def named ``bar``, you can configure the template as a +:term:`renderer` like so: + +.. code-block:: python + :linenos: + + from pyramid.view import view_config + + @view_config(renderer='foo#defname.mak') + def my_view(request): + return {'project':'my project'} + .. index:: single: automatic reloading of templates single: template automatic reload diff --git a/pyramid/mako_templating.py b/pyramid/mako_templating.py index b02daa23c..bb4ccb2f0 100644 --- a/pyramid/mako_templating.py +++ b/pyramid/mako_templating.py @@ -163,6 +163,13 @@ class MakoRenderingException(Exception): @implementer(ITemplateRenderer) class MakoLookupTemplateRenderer(object): + """ Render a :term:`Mako` template using the template + implied by the ``path`` argument.The ``path`` argument may be a + package-relative path, an absolute path, or a :term:`asset + specification`. If a defname is defined, in the form of + package:path/to/template#defname.mako, a function named ``defname`` + inside the template will then be rendered. + """ def __init__(self, path, defname, lookup): self.path = path self.defname = defname -- cgit v1.2.3 From 6cea47e9c34841cdf109899e8d965c67af3a5ce9 Mon Sep 17 00:00:00 2001 From: Blaise Laflamme Date: Tue, 19 Jun 2012 20:20:17 -0400 Subject: fixed typos --- CHANGES.txt | 2 +- docs/narr/templates.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 3cb2f2848..1fd92fe19 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -42,7 +42,7 @@ Features and ``HTTPMovedPermanently`` exceptions, so these can be caught by the NotFound view (and other exception views). -- The mako renderer now accepts a def name and returns the template def +- The mako renderer now accepts a defname and returns the template def result for the view being called. The uri format using an asset spec is package:path/to/template#defname.mako. The old way of returning a tuple from the view is supported for backward compatibility, ('defname', {}). diff --git a/docs/narr/templates.rst b/docs/narr/templates.rst index 4ac01c96e..5656026ae 100644 --- a/docs/narr/templates.rst +++ b/docs/narr/templates.rst @@ -718,7 +718,7 @@ Using def inside Mako Templates ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To use a def inside a Mako template, given a :term:`Mako` template file named -``foo.mak`` and a def named ``bar``, you can configure the template as a +``foo.mak`` and a defname ``bar``, you can configure the template as a :term:`renderer` like so: .. code-block:: python -- cgit v1.2.3 From c2d65ff71dac6a9b15119db8c2fb09884f4060e3 Mon Sep 17 00:00:00 2001 From: Blaise Laflamme Date: Tue, 19 Jun 2012 20:22:34 -0400 Subject: fixed typos --- CHANGES.txt | 2 +- docs/narr/templates.rst | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 1fd92fe19..3cb2f2848 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -42,7 +42,7 @@ Features and ``HTTPMovedPermanently`` exceptions, so these can be caught by the NotFound view (and other exception views). -- The mako renderer now accepts a defname and returns the template def +- The mako renderer now accepts a def name and returns the template def result for the view being called. The uri format using an asset spec is package:path/to/template#defname.mako. The old way of returning a tuple from the view is supported for backward compatibility, ('defname', {}). diff --git a/docs/narr/templates.rst b/docs/narr/templates.rst index 5656026ae..860010a1a 100644 --- a/docs/narr/templates.rst +++ b/docs/narr/templates.rst @@ -718,7 +718,7 @@ Using def inside Mako Templates ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To use a def inside a Mako template, given a :term:`Mako` template file named -``foo.mak`` and a defname ``bar``, you can configure the template as a +``foo.mak`` and a def named ``bar``, you can configure the template as a :term:`renderer` like so: .. code-block:: python @@ -726,7 +726,7 @@ To use a def inside a Mako template, given a :term:`Mako` template file named from pyramid.view import view_config - @view_config(renderer='foo#defname.mak') + @view_config(renderer='foo#bar.mak') def my_view(request): return {'project':'my project'} -- cgit v1.2.3 From fe9316332511de945924effd8a049db79f34e761 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Tue, 19 Jun 2012 21:42:44 -0400 Subject: point at pyramid_beaker docs rather than its github page --- docs/narr/sessions.rst | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/narr/sessions.rst b/docs/narr/sessions.rst index 6ff9e3dea..1aa1b6341 100644 --- a/docs/narr/sessions.rst +++ b/docs/narr/sessions.rst @@ -151,13 +151,12 @@ Using Alternate Session Factories --------------------------------- At the time of this writing, exactly one alternate session factory -implementation exists, named ``pyramid_beaker``. This is a session -factory that uses the `Beaker `_ library -as a backend. Beaker has support for file-based sessions, database -based sessions, and encrypted cookie-based sessions. See -`http://github.com/Pylons/pyramid_beaker -`_ for more information about -``pyramid_beaker``. +implementation exists, named ``pyramid_beaker``. This is a session factory +that uses the `Beaker `_ library as a backend. +Beaker has support for file-based sessions, database based sessions, and +encrypted cookie-based sessions. See `the pyramid_beaker documentation +`_ for more +information about ``pyramid_beaker``. .. index:: single: session factory (custom) -- cgit v1.2.3 From 5f8493cbfd9dac153f7442f1cffc117f85280716 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Sun, 24 Jun 2012 10:25:40 -0400 Subject: Try newly-enabled travis-ci. See http://travis-ci.org/#\!/Pylons/pyramid --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2e737af04..665d15384 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,8 @@ python: - pypy - 3.2 -matrix: - allow_failures: - - python: pypy +#matrix: +# allow_failures: +# - python: pypy script: python setup.py test -- cgit v1.2.3 From a0e59d530726ab3f67b1c389cf8baecc13309ed6 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Sun, 24 Jun 2012 10:35:49 -0400 Subject: Un-comment the PyPy 'allow_failures' bit. We need an explanation for why the PyPy tests fail under travis-ci. --- .travis.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 665d15384..c637dc215 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,10 @@ python: - pypy - 3.2 -#matrix: -# allow_failures: -# - python: pypy +# Why does travis-ci's PyPy blow up? Pyramid's tests +# run fine under tox. +matrix: + allow_failures: + - python: pypy script: python setup.py test -- cgit v1.2.3 From 71b473705f73b12a35422d3aa257906e4a99d853 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Sun, 24 Jun 2012 10:52:16 -0400 Subject: Send notifications to pyramid-checkins. Note that we rely on the default settings (failures always send, success sends only on change.). --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index c637dc215..490fd2df7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,3 +13,7 @@ matrix: - python: pypy script: python setup.py test + +notifications: + email: + - pyramid-checkins@lists.repoze.org -- cgit v1.2.3 From 6ef753257617acf8aaf3daaca22de3783970cffe Mon Sep 17 00:00:00 2001 From: Jeff Cook Date: Wed, 4 Jul 2012 18:52:54 -0600 Subject: Include instructions for recursive submodule checkout of Sphinx themes. --- HACKING.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/HACKING.txt b/HACKING.txt index dd735bf22..38c263ed7 100644 --- a/HACKING.txt +++ b/HACKING.txt @@ -127,13 +127,19 @@ using to develop Pyramid): 1. Run ``$yourvenv/bin/python setup.py dev docs``. This will cause Sphinx and all development requirements to be installed in your virtualenv. -2. cd to the ``docs`` directory within your Pyramid checkout and execute +2. Update all git submodules from the top-level of your Pyramid checkout, like + so: + git submodule update --init --recursive + This will checkout theme subrepositories and prevent error conditions when + HTML docs are generated. + +3. cd to the ``docs`` directory within your Pyramid checkout and execute ``make clean html SPHINXBUILD=$yourvenv/bin/sphinx-build``. The ``SPHINXBUILD=...`` hair is there in order to tell it to use the virtualenv Python, which will have both Sphinx and Pyramid (for API documentation generation) installed. -3. Open the ``docs/_build/html/index.html`` file to see the resulting HTML +4. Open the ``docs/_build/html/index.html`` file to see the resulting HTML rendering. Change Log -- cgit v1.2.3 From 88bbd46c9a5fab52548f26fe4655a89c00332ad5 Mon Sep 17 00:00:00 2001 From: Maxim Avanov Date: Tue, 10 Jul 2012 21:26:34 +0400 Subject: Replacement markers of url dispatcher can contain regex with colons. --- pyramid/tests/test_urldispatch.py | 8 ++++++++ pyramid/urldispatch.py | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pyramid/tests/test_urldispatch.py b/pyramid/tests/test_urldispatch.py index e15242f75..b2164717e 100644 --- a/pyramid/tests/test_urldispatch.py +++ b/pyramid/tests/test_urldispatch.py @@ -311,6 +311,14 @@ class TestCompileRoute(unittest.TestCase): self.assertEqual(matcher('foo/baz/biz/buz/bar'), None) self.assertEqual(generator({'baz':1, 'buz':2, 'bar': 'html'}), '/foo/1/biz/2.html') + + def test_custom_regex_with_colons(self): + matcher, generator = self._callFUT('foo/{baz}/biz/{buz:(?:[^/\.]+)}.{bar}') + self.assertEqual(matcher('/foo/baz/biz/buz.bar'), + {'baz':'baz', 'buz':'buz', 'bar':'bar'}) + self.assertEqual(matcher('foo/baz/biz/buz/bar'), None) + self.assertEqual(generator({'baz':1, 'buz':2, 'bar': 'html'}), + '/foo/1/biz/2.html') def test_mixed_newstyle_oldstyle_pattern_defaults_to_newstyle(self): # pattern: '\\/foo\\/(?Pabc)\\/biz\\/(?P[^/]+)\\/bar$' diff --git a/pyramid/urldispatch.py b/pyramid/urldispatch.py index cccff14ba..4182ea665 100644 --- a/pyramid/urldispatch.py +++ b/pyramid/urldispatch.py @@ -148,7 +148,9 @@ def _compile_route(route): name = pat.pop() # unicode name = name[1:-1] if ':' in name: - name, reg = name.split(':') + # reg may contain colons as well, + # so we must strictly split name into two parts + name, reg = name.split(':', 1) else: reg = '[^/]+' gen.append('%%(%s)s' % native_(name)) # native -- cgit v1.2.3 From 3074e78a5b3818bf6c6cb43b832e4ab1df845e16 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Tue, 10 Jul 2012 15:56:38 -0400 Subject: garden --- CHANGES.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 3cb2f2848..c06b8106d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -9,6 +9,9 @@ Bug Fixes return the empty list. This was incorrect, it should have unconditionally returned ``[Everyone]``, and now does. +- Explicit url dispatch regexes can now contain colons. + https://github.com/Pylons/pyramid/issues/629 + Features -------- -- cgit v1.2.3 From e652518e00cde05b55b065196a460efd9bc86e32 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Fri, 13 Jul 2012 12:08:18 -0400 Subject: - On at least one 64-bit Ubuntu system under Python 3.2, using the ``view_config`` decorator caused a ``RuntimeError: dictionary changed size during iteration`` exception. It no longer does. See https://github.com/Pylons/pyramid/issues/635 for more information. - Fixes issue #635. --- CHANGES.txt | 5 +++++ pyramid/view.py | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index c06b8106d..c6afaf0c7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -12,6 +12,11 @@ Bug Fixes - Explicit url dispatch regexes can now contain colons. https://github.com/Pylons/pyramid/issues/629 +- On at least one 64-bit Ubuntu system under Python 3.2, using the + ``view_config`` decorator caused a ``RuntimeError: dictionary changed size + during iteration`` exception. It no longer does. See + https://github.com/Pylons/pyramid/issues/635 for more information. + Features -------- diff --git a/pyramid/view.py b/pyramid/view.py index bb531c326..1df0849c0 100644 --- a/pyramid/view.py +++ b/pyramid/view.py @@ -199,7 +199,7 @@ class view_config(object): custom_predicates=default, context=default, decorator=default, mapper=default, http_cache=default, match_param=default): - L = locals() + L = dict(locals()) # See issue #635 for dict() rationale if (context is not default) or (for_ is not default): L['context'] = context or for_ for k, v in L.items(): @@ -367,7 +367,7 @@ class notfound_view_config(object): path_info=default, custom_predicates=default, decorator=default, mapper=default, match_param=default, append_slash=False): - L = locals() + L = dict(locals()) # See issue #635 for dict() rationale for k, v in L.items(): if k not in ('self', 'L') and v is not default: self.__dict__[k] = v @@ -432,7 +432,7 @@ class forbidden_view_config(object): xhr=default, accept=default, header=default, path_info=default, custom_predicates=default, decorator=default, mapper=default, match_param=default): - L = locals() + L = dict(locals()) # See issue #635 for dict() rationale for k, v in L.items(): if k not in ('self', 'L') and v is not default: self.__dict__[k] = v -- cgit v1.2.3 From 70ba5b97f53ac178dac8f81109596fb47bbadde5 Mon Sep 17 00:00:00 2001 From: Siddhartha Kasivajhula Date: Sat, 21 Jul 2012 14:29:00 -0700 Subject: corrected table name tables->pages --- docs/tutorials/wiki2/design.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tutorials/wiki2/design.rst b/docs/tutorials/wiki2/design.rst index 2e6fc0e77..deaf32ef6 100644 --- a/docs/tutorials/wiki2/design.rst +++ b/docs/tutorials/wiki2/design.rst @@ -20,7 +20,7 @@ Models We'll be using a SQLite database to hold our wiki data, and we'll be using :term:`SQLAlchemy` to access the data in this database. -Within the database, we define a single table named `tables`, whose elements +Within the database, we define a single table named `pages`, whose elements will store the wiki pages. There are two columns: `name` and `data`. URLs like ``/PageName`` will try to find an element in -- cgit v1.2.3 From 14f9fe44ec75c055d89374a7852e1ca2af0ff31c Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Wed, 25 Jul 2012 14:02:10 -0500 Subject: add logging call to wsgi setup --- docs/tutorials/modwsgi/index.rst | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/tutorials/modwsgi/index.rst b/docs/tutorials/modwsgi/index.rst index e070f8eda..d11167344 100644 --- a/docs/tutorials/modwsgi/index.rst +++ b/docs/tutorials/modwsgi/index.rst @@ -73,9 +73,10 @@ commands and files. .. code-block:: python - from pyramid.paster import get_app - application = get_app( - '/Users/chrism/modwsgi/env/myapp/production.ini', 'main') + from pyramid.paster import get_app, setup_logging + ini_path = '/Users/chrism/modwsgi/env/myapp/production.ini' + setup_logging(ini_path) + application = get_app(ini_path, 'main') The first argument to ``get_app`` is the project configuration file name. It's best to use the ``production.ini`` file provided by your @@ -85,6 +86,10 @@ commands and files. ``application`` is important: mod_wsgi requires finding such an assignment when it opens the file. + The call to ``setup_logging`` initializes the standard library's + `logging` module to allow logging within your application. + See :ref:`logging_config`. + #. Make the ``pyramid.wsgi`` script executable. .. code-block:: text -- cgit v1.2.3