Skip to content

Commit

Permalink
add default renderers eagerly so they can be overridden, get rid of u…
Browse files Browse the repository at this point in the history
…seless warning about ordering, comment about global_registries, no longer have a circular import between config and router
  • Loading branch information
mcdonc committed Aug 19, 2011
1 parent eb2a576 commit cfbbd6d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
6 changes: 2 additions & 4 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ Should-Have
- Make it possible to use tween aliases in explicit tween config? If not,
the tween factories of all add-ons must be APIs.

- Merge Michael's route group work (maybe a 1.3 thing).

- Deprecate pyramid.security.view_execution_permitted (it only works for
traversal).

Expand All @@ -29,6 +27,8 @@ Should-Have
Nice-to-Have
------------

- Merge Michael's route group work (maybe a 1.3 thing).

- Kill off ``bfg.routes`` envvars in router.

- Some sort of API for rendering a view callable object to a response from
Expand All @@ -44,8 +44,6 @@ Nice-to-Have

- Alias the stupid long default session factory name.

- Fix indirect circular import between router and config.

- Add narrative docs for wsgiapp and wsgiapp2.

- Provide a ``has_view`` function.
Expand Down
27 changes: 18 additions & 9 deletions pyramid/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
from pyramid.interfaces import IExceptionResponse
from pyramid.interfaces import IDebugLogger

from pyramid.asset import resolve_asset_spec
from pyramid.authorization import ACLAuthorizationPolicy
from pyramid.events import ApplicationCreated
from pyramid.exceptions import ConfigurationError # bw compat
from pyramid.httpexceptions import default_exceptionresponse_view
from pyramid.path import caller_package
from pyramid.path import package_of
from pyramid.registry import Registry
from pyramid.asset import resolve_asset_spec
from pyramid.router import Router
from pyramid.settings import aslist
from pyramid.threadlocal import manager
from pyramid.util import DottedNameResolver
Expand Down Expand Up @@ -217,7 +218,7 @@ def __init__(self,
root_factory=None,
authentication_policy=None,
authorization_policy=None,
renderers=DEFAULT_RENDERERS,
renderers=None,
debug_logger=None,
locale_negotiator=None,
request_factory=None,
Expand Down Expand Up @@ -259,7 +260,7 @@ def __init__(self,

def setup_registry(self, settings=None, root_factory=None,
authentication_policy=None, authorization_policy=None,
renderers=DEFAULT_RENDERERS, debug_logger=None,
renderers=None, debug_logger=None,
locale_negotiator=None, request_factory=None,
renderer_globals_factory=None, default_permission=None,
session_factory=None, default_view_mapper=None,
Expand Down Expand Up @@ -295,6 +296,11 @@ def setup_registry(self, settings=None, root_factory=None,

registry.registerUtility(debug_logger, IDebugLogger)

if renderers is None:
for name, renderer in DEFAULT_RENDERERS:
self.add_renderer(name, renderer)
renderers = []

if exceptionresponse_view is not None:
exceptionresponse_view = self.maybe_dotted(exceptionresponse_view)
self.add_view(exceptionresponse_view, context=IExceptionResponse)
Expand Down Expand Up @@ -324,11 +330,11 @@ def setup_registry(self, settings=None, root_factory=None,
if authorization_policy:
self.set_authorization_policy(authorization_policy)

self.set_root_factory(root_factory)

for name, renderer in renderers:
self.add_renderer(name, renderer)

self.set_root_factory(root_factory)

if locale_negotiator:
self.set_locale_negotiator(locale_negotiator)

Expand Down Expand Up @@ -760,12 +766,15 @@ def make_wsgi_app(self):
:app:`Pyramid` WSGI application representing the committed
configuration state."""
self.commit()
from pyramid.router import Router # avoid circdep
app = Router(self.registry)

# Allow tools like "paster pshell development.ini" to find the 'last'
# registry configured.
global_registries.add(self.registry)
# We push the registry on to the stack here in case any code
# that depends on the registry threadlocal APIs used in
# listeners subscribed to the IApplicationCreated event.

# Push the registry on to the stack in case any code that depends on
# the registry threadlocal APIs used in listeners subscribed to the
# IApplicationCreated event.
self.manager.push({'registry':self.registry, 'request':None})
try:
self.registry.notify(ApplicationCreated(app))
Expand Down
7 changes: 0 additions & 7 deletions pyramid/config/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ def add_renderer(self, name, factory):
The ``factory`` argument is Python reference to an
implementation of a :term:`renderer` factory or a
:term:`dotted Python name` to same.
Note that this function must be called *before* any
``add_view`` invocation that names the renderer name as an
argument. As a result, it's usually a better idea to pass
globally used renderers into the ``Configurator`` constructor
in the sequence of renderers passed as ``renderer`` than it is
to use this method.
"""
factory = self.maybe_dotted(factory)
# if name is None or the empty string, we're trying to register
Expand Down
5 changes: 0 additions & 5 deletions pyramid/config/tweens.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,3 @@ def is_string_or_iterable(v):
if not explicit and alias is not None:
self.action(('tween', alias, explicit))

@action_method
def add_request_handler(self, factory, name): # pragma: no cover
# XXX bw compat for debugtoolbar
return self._add_tween(factory, explicit=False)

0 comments on commit cfbbd6d

Please sign in to comment.