From c5a467b86b96d2cb0b4eda13134dac7edb68d0ec Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Sun, 22 Sep 2013 14:29:38 -0500 Subject: try to clarify the docs to avoid "if '__main__'" confusion --- docs/narr/viewconfig.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/narr/viewconfig.rst b/docs/narr/viewconfig.rst index 182676b29..7c76116f7 100644 --- a/docs/narr/viewconfig.rst +++ b/docs/narr/viewconfig.rst @@ -822,7 +822,7 @@ of this: def delete(self): return Response('delete') - if __name__ == '__main__': + def main(global_config, **settings): config = Configurator() config.add_route('rest', '/rest') config.add_view( @@ -831,6 +831,7 @@ of this: RESTView, route_name='rest', attr='post', request_method='POST') config.add_view( RESTView, route_name='rest', attr='delete', request_method='DELETE') + return config.make_wsgi_app() To reduce the amount of repetition in the ``config.add_view`` statements, we can move the ``route_name='rest'`` argument to a ``@view_defaults`` class @@ -857,12 +858,13 @@ decorator on the RESTView class: def delete(self): return Response('delete') - if __name__ == '__main__': + def main(global_config, **settings): config = Configurator() config.add_route('rest', '/rest') config.add_view(RESTView, attr='get', request_method='GET') config.add_view(RESTView, attr='post', request_method='POST') config.add_view(RESTView, attr='delete', request_method='DELETE') + return config.make_wsgi_app() :class:`pyramid.view.view_defaults` accepts the same set of arguments that :class:`pyramid.view.view_config` does, and they have the same meaning. Each -- cgit v1.2.3 From 1034327081839902e691236f60b2a85f74bbc4e3 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Mon, 14 Oct 2013 16:29:32 -0500 Subject: update old ptweens output --- docs/narr/commandline.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/narr/commandline.rst b/docs/narr/commandline.rst index 58b9bdd21..a04b38ae3 100644 --- a/docs/narr/commandline.rst +++ b/docs/narr/commandline.rst @@ -387,12 +387,12 @@ explicit tweens defined in its ``development.ini`` file: Implicit Tween Chain (not used) - Position Name Alias - -------- ---- ----- - - - INGRESS - 0 pyramid_debugtoolbar.toolbar.toolbar_tween_factory pdbt - 1 pyramid.tweens.excview_tween_factory excview - - - MAIN + Position Name + -------- ---- + - INGRESS + 0 pyramid_debugtoolbar.toolbar.toolbar_tween_factory + 1 pyramid.tweens.excview_tween_factory + - MAIN Here's the application configuration section of the ``development.ini`` used by the above ``ptweens`` command which reports that the explicit tween chain -- cgit v1.2.3 From 592ec0178d25767859523c1ac221c6f3cb303875 Mon Sep 17 00:00:00 2001 From: Jeff Hemphill Date: Wed, 16 Oct 2013 20:55:41 -0700 Subject: Add HTML escaping to views.py At least it's less obviously dangerous this way. --- docs/tutorials/wiki2/src/views/tutorial/views.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/tutorials/wiki2/src/views/tutorial/views.py b/docs/tutorials/wiki2/src/views/tutorial/views.py index 5a9c75a61..d54b2a7aa 100644 --- a/docs/tutorials/wiki2/src/views/tutorial/views.py +++ b/docs/tutorials/wiki2/src/views/tutorial/views.py @@ -1,3 +1,4 @@ +import cgi import re from docutils.core import publish_parts @@ -32,10 +33,10 @@ def view_page(request): exists = DBSession.query(Page).filter_by(name=word).all() if exists: view_url = request.route_url('view_page', pagename=word) - return '%s' % (view_url, word) + return '%s' % (view_url, cgi.escape(word)) else: add_url = request.route_url('add_page', pagename=word) - return '%s' % (add_url, word) + return '%s' % (add_url, cgi.escape(word)) content = publish_parts(page.data, writer_name='html')['html_body'] content = wikiwords.sub(check, content) -- cgit v1.2.3 From 3c95b1af3661618490e6a3789fd80755924e7d18 Mon Sep 17 00:00:00 2001 From: Wichert Akkerman Date: Tue, 10 Dec 2013 13:31:23 +0100 Subject: Fix JSONP syntax error --- CHANGES.txt | 3 +++ pyramid/renderers.py | 2 +- pyramid/tests/test_renderers.py | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 9f780fe45..c05c4561e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -51,6 +51,9 @@ Features Bug Fixes --------- +- Add a trailing semicolon to the JSONP response. This fixes JavaScript syntax + errors for old IE versions. + - Fix the ``pcreate`` script so that when the target directory name ends with a slash it does not produce a non-working project directory structure. Previously saying ``pcreate -s starter /foo/bar/`` produced different output diff --git a/pyramid/renderers.py b/pyramid/renderers.py index e90d07b38..88ef285a0 100644 --- a/pyramid/renderers.py +++ b/pyramid/renderers.py @@ -363,7 +363,7 @@ class JSONP(JSON): body = val else: ct = 'application/javascript' - body = '%s(%s)' % (callback, val) + body = '%s(%s);' % (callback, val) response = request.response if response.content_type == response.default_content_type: response.content_type = ct diff --git a/pyramid/tests/test_renderers.py b/pyramid/tests/test_renderers.py index f6b9d2b0d..2bddd2318 100644 --- a/pyramid/tests/test_renderers.py +++ b/pyramid/tests/test_renderers.py @@ -567,7 +567,7 @@ class TestJSONP(unittest.TestCase): request = testing.DummyRequest() request.GET['callback'] = 'callback' result = renderer({'a':'1'}, {'request':request}) - self.assertEqual(result, 'callback({"a": "1"})') + self.assertEqual(result, 'callback({"a": "1"});') self.assertEqual(request.response.content_type, 'application/javascript') -- cgit v1.2.3