diff options
| author | Chris McDonough <chrism@plope.com> | 2012-08-03 15:11:54 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2012-08-03 15:11:54 -0400 |
| commit | 92b64cca2994774987cbce88cef89e9f71366185 (patch) | |
| tree | 12074d3509c8c549a81d0523d4967d8fae1cc05d | |
| parent | c2000a61c0b2eb637c31b1123d2ed59a0d08acbe (diff) | |
| parent | aa62a18c7e5f39a42ca777c871cf7cf61ffd869b (diff) | |
| download | pyramid-92b64cca2994774987cbce88cef89e9f71366185.tar.gz pyramid-92b64cca2994774987cbce88cef89e9f71366185.tar.bz2 pyramid-92b64cca2994774987cbce88cef89e9f71366185.zip | |
Merge branch 'master' of github.com:Pylons/pyramid
| -rw-r--r-- | CHANGES.txt | 12 | ||||
| -rw-r--r-- | docs/index.rst | 12 | ||||
| -rw-r--r-- | docs/narr/firstapp.rst | 3 | ||||
| -rw-r--r-- | pyramid/mako_templating.py | 19 | ||||
| -rw-r--r-- | pyramid/tests/test_mako_templating.py | 32 |
5 files changed, 47 insertions, 31 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index ecb2bf659..94553955c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -17,6 +17,12 @@ Bug Fixes during iteration`` exception. It no longer does. See https://github.com/Pylons/pyramid/issues/635 for more information. +- In Mako Templates lookup, check if the uri is already adjusted and bring + it back to an asset spec. Normally occurs with inherited templates or + included components. + https://github.com/Pylons/pyramid/issues/606 + https://github.com/Pylons/pyramid/issues/607 + Features -------- @@ -50,9 +56,9 @@ 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 - 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 +- 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', {}). - When there is a predicate mismatch exception (seen when no view matches for diff --git a/docs/index.rst b/docs/index.rst index 31c2fde6b..c84314274 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -13,15 +13,9 @@ Here is one of the simplest :app:`Pyramid` applications you can make: .. literalinclude:: narr/helloworld.py -When saved to ``helloworld.py``, the above application can be run via: - -.. code-block:: text - - $ easy_install pyramid - $ python helloworld.py - -When you visit ``http://localhost:8080/hello/world`` in a browser, you will -see the text ``Hello, world!``. +After you install :app:`Pyramid` and run this application, when you visit +``http://localhost:8080/hello/world`` in a browser, you will see the text +``Hello, world!`` See :ref:`firstapp_chapter` for a full explanation of how this application works. Read the :ref:`html_narrative_documentation` to understand how diff --git a/docs/narr/firstapp.rst b/docs/narr/firstapp.rst index 1ca188d7e..a86826d86 100644 --- a/docs/narr/firstapp.rst +++ b/docs/narr/firstapp.rst @@ -8,7 +8,8 @@ Creating Your First :app:`Pyramid` Application In this chapter, we will walk through the creation of a tiny :app:`Pyramid` application. After we're finished creating the application, we'll explain in -more detail how it works. +more detail how it works. It assumes you already have :app:`Pyramid` installed. +If you do not, head over to the :ref:`installing_chapter` section. .. _helloworld_imperative: diff --git a/pyramid/mako_templating.py b/pyramid/mako_templating.py index bb4ccb2f0..d1ee68878 100644 --- a/pyramid/mako_templating.py +++ b/pyramid/mako_templating.py @@ -42,12 +42,17 @@ class PkgResourceTemplateLookup(TemplateLookup): def get_template(self, uri): """Fetch a template from the cache, or check the filesystem for it - + In addition to the basic filesystem lookup, this subclass will use pkg_resource to load a file using the asset specification syntax. - + """ + if '$' in uri: + # Checks if the uri is already adjusted and brings it back to + # an asset spec. Normally occurs with inherited templates or + # included components. + uri = uri.replace('$', ':') isabs = os.path.isabs(uri) if (not isabs) and (':' in uri): # Windows can't cope with colons in filenames, so we replace the @@ -70,7 +75,7 @@ class PkgResourceTemplateLookup(TemplateLookup): return TemplateLookup.get_template(self, uri) -registry_lock = threading.Lock() +registry_lock = threading.Lock() class MakoRendererFactoryHelper(object): def __init__(self, settings_prefix=None): @@ -143,7 +148,7 @@ class MakoRendererFactoryHelper(object): registry_lock.acquire() try: - registry.registerUtility(lookup, IMakoLookup, + registry.registerUtility(lookup, IMakoLookup, name=settings_prefix) finally: registry_lock.release() @@ -166,15 +171,15 @@ 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`` + 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 self.lookup = lookup - + def implementation(self): return self.lookup.get_template(self.path) diff --git a/pyramid/tests/test_mako_templating.py b/pyramid/tests/test_mako_templating.py index 41fa9bdc4..46826d9dd 100644 --- a/pyramid/tests/test_mako_templating.py +++ b/pyramid/tests/test_mako_templating.py @@ -135,7 +135,7 @@ class Test_renderer_factory(Base, unittest.TestCase): self._callFUT(info) lookup = self._getLookup() self.assertEqual(lookup.template_args['input_encoding'], 'utf-16') - + def test_with_error_handler(self): settings = {'mako.directories':self.templates_dir, 'mako.error_handler':'pyramid.tests'} @@ -383,7 +383,7 @@ class MakoLookupTemplateRendererTests(Base, unittest.TestCase): result = instance.implementation().render_unicode() self.assertTrue(isinstance(result, text_type)) self.assertEqual(result, text_('result')) - + class TestIntegration(unittest.TestCase): def setUp(self): import pyramid.mako_templating @@ -406,7 +406,7 @@ class TestIntegration(unittest.TestCase): self.config.add_settings({'reload_templates': True}) result = render('helloworld.mak', {'a':1}).replace('\r','') self.assertEqual(result, text_('\nHello föö\n', 'utf-8')) - + def test_render_inheritance(self): from pyramid.renderers import render result = render('helloinherit.mak', {}).replace('\r','') @@ -434,7 +434,7 @@ class TestIntegration(unittest.TestCase): {'a':1}) self.assertEqual(result.ubody.replace('\r', ''), text_('\nHello föö\n', 'utf-8')) - + def test_render_with_abs_path(self): from pyramid.renderers import render result = render('/helloworld.mak', {'a':1}).replace('\r','') @@ -446,7 +446,7 @@ class TestIntegration(unittest.TestCase): self.assertEqual( result.implementation().render_unicode().replace('\r',''), text_('\nHello föö\n', 'utf-8')) - + def test_template_not_found(self): from pyramid.renderers import render from mako.exceptions import TemplateLookupException @@ -484,7 +484,7 @@ class TestPkgResourceTemplateLookup(unittest.TestCase): inst = self._makeOne(directories=[fixturedir]) result = inst.get_template('helloworld.mak') self.assertFalse(result is None) - + def test_get_template_asset_spec_with_filesystem_checks(self): inst = self._makeOne(filesystem_checks=True) result = inst.get_template('pyramid.tests:fixtures/helloworld.mak') @@ -498,7 +498,17 @@ class TestPkgResourceTemplateLookup(unittest.TestCase): self.assertFalse(result is None) finally: shutil.rmtree(tmpdir, ignore_errors=True) - + + def test_get_template_asset_spec_with_uri_adjusted(self): + inst = self._makeOne(filesystem_checks=True) + result = inst.get_template('pyramid.tests$fixtures/helloworld.mak') + self.assertFalse(result is None) + + def test_get_template_asset_spec_with_uri_not_adjusted(self): + inst = self._makeOne(filesystem_checks=True) + result = inst.get_template('pyramid.tests:fixtures/helloworld.mak') + self.assertFalse(result is None) + def test_get_template_asset_spec_missing(self): from mako.exceptions import TopLevelLookupException fixturedir = self.get_fixturedir() @@ -510,7 +520,7 @@ class TestMakoRenderingException(unittest.TestCase): def _makeOne(self, text): from pyramid.mako_templating import MakoRenderingException return MakoRenderingException(text) - + def test_repr_and_str(self): exc = self._makeOne('text') self.assertEqual(str(exc), 'text') @@ -519,7 +529,7 @@ class TestMakoRenderingException(unittest.TestCase): class DummyLookup(object): def __init__(self, exc=None): self.exc = exc - + def get_template(self, path): self.path = path return self @@ -533,8 +543,8 @@ class DummyLookup(object): raise self.exc self.values = values return text_('result') - + class DummyRendererInfo(object): def __init__(self, kw): self.__dict__.update(kw) - + |
