From dc06b0b30c0508835022567cee40196d6d9cb984 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Thu, 16 Dec 2010 19:03:00 -0500 Subject: - The name ``registry`` is now available in a ``pshell`` environment by default. It is the application registry object. - Changed "Project" chapter slightly to expand on use of ``paster pshell``. --- CHANGES.txt | 5 +++++ docs/narr/project.rst | 17 ++++++++++++++++- pyramid/paster.py | 5 +++-- pyramid/tests/test_paster.py | 9 ++++++--- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index c3f7fb31f..33546e947 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -13,6 +13,9 @@ Features - Added ``debug_routematch`` configuration setting that logs matched routes (including the matchdict and predicates). +- The name ``registry`` is now available in a ``pshell`` environment by + default. It is the application registry object. + Documentation ------------- @@ -22,6 +25,8 @@ Documentation - Added reference to ``BFG_DEBUG_ROUTEMATCH`` envvar and ``debug_routematch`` config file setting to the Environment narrative docs chapter. +- Changed "Project" chapter slightly to expand on use of ``paster pshell``. + Paster Templates ---------------- diff --git a/docs/narr/project.rst b/docs/narr/project.rst index f8a9017db..2b03f7373 100644 --- a/docs/narr/project.rst +++ b/docs/narr/project.rst @@ -287,9 +287,24 @@ the name ``MyProject`` as a section name: [chrism@vitaminf shellenv]$ ../bin/paster pshell development.ini MyProject Python 2.4.5 (#1, Aug 29 2008, 12:27:37) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin - Type "help" for more information. "root" is the Pyramid app root object. + Type "help" for more information. "root" is the Pyramid app root object, + "registry" is the Pyramid registry object. >>> root + >>> registry + + >>> registry.settings['debug_notfound'] + False + >>> from myproject.views import my_view + >>> from pyramid.request import Request + >>> r = Request.blank('/') + >>> my_view(r) + {'project': 'myproject'} + +Two names are made available to the pshell user as globals: ``root`` and +``registry``. ``root`` is the the object returned by the default :term:`root +factory` in your application. ``registry`` is the :term:`application +registry` object (often accessed within view code as ``request.registry``). If you have `IPython `_ installed in the interpreter you use to invoke the ``paster`` command, diff --git a/pyramid/paster.py b/pyramid/paster.py index 0b8c21d4e..07f9ee458 100644 --- a/pyramid/paster.py +++ b/pyramid/paster.py @@ -115,7 +115,7 @@ class PShellCommand(Command): except ImportError: #pragma no cover IPShell = None cprt =('Type "help" for more information. "root" is the Pyramid app ' - 'root object.') + 'root object, "registry" is the Pyramid registry object.') banner = "Python %s on %s\n%s" % (sys.version, sys.platform, cprt) config_file, section_name = self.args self.logging_file_config(config_file) @@ -130,7 +130,8 @@ class PShellCommand(Command): closer() else: try: - self.interact[0](banner, local={'root':root}) + self.interact[0](banner, + local={'root':root,'registry':app.registry}) finally: closer() diff --git a/pyramid/tests/test_paster.py b/pyramid/tests/test_paster.py index 3c13a0ef0..41e6dc441 100644 --- a/pyramid/tests/test_paster.py +++ b/pyramid/tests/test_paster.py @@ -27,7 +27,8 @@ class TestPShellCommand(unittest.TestCase): pushed = app.threadlocal_manager.pushed[0] self.assertEqual(pushed['registry'], dummy_registry) self.assertEqual(pushed['request'].registry, dummy_registry) - self.assertEqual(interact.local, {'root':dummy_root}) + self.assertEqual(interact.local, {'root':dummy_root, + 'registry':dummy_registry}) self.failUnless(interact.banner) self.assertEqual(len(app.threadlocal_manager.popped), 1) @@ -75,7 +76,8 @@ class TestPShellCommand(unittest.TestCase): pushed = app.threadlocal_manager.pushed[0] self.assertEqual(pushed['registry'], dummy_registry) self.assertEqual(pushed['request'].registry, dummy_registry) - self.assertEqual(interact.local, {'root':dummy_root}) + self.assertEqual(interact.local, {'root':dummy_root, + 'registry':dummy_registry}) self.failUnless(interact.banner) self.assertEqual(len(app.threadlocal_manager.popped), 1) self.assertEqual(apped, [(('/foo/bar/myapp.ini', 'myapp'), @@ -103,7 +105,8 @@ class TestPShellCommand(unittest.TestCase): self.assertEqual(loadapp.section_name, 'myapp') self.failUnless(loadapp.relative_to) self.assertEqual(len(app.threadlocal_manager.pushed), 0) - self.assertEqual(interact.local, {'root':root}) + self.assertEqual(interact.local, {'root':root, + 'registry':dummy_registry}) self.failUnless(interact.banner) self.assertEqual(apps, [app]) -- cgit v1.2.3