Author: rjollos
Date: Thu Jun 20 23:28:09 2013
New Revision: 1495235
URL: http://svn.apache.org/r1495235
Log:
Refs #514: Extract code from `trac.web.main` to function
`load_boostrap_handler` in `trac.hooks`.
Modified:
bloodhound/trunk/trac/trac/hooks.py
bloodhound/trunk/trac/trac/web/main.py
Modified: bloodhound/trunk/trac/trac/hooks.py
URL:
http://svn.apache.org/viewvc/bloodhound/trunk/trac/trac/hooks.py?rev=1495235&r1=1495234&r2=1495235&view=diff
==============================================================================
--- bloodhound/trunk/trac/trac/hooks.py (original)
+++ bloodhound/trunk/trac/trac/hooks.py Thu Jun 20 23:28:09 2013
@@ -19,6 +19,8 @@ import os
import imp
import inspect
+import pkg_resources
+
from trac.config import Configuration
from trac.env import open_environment
from trac.util.concurrency import threading
@@ -222,5 +224,25 @@ class DefaultBootstrapHandler(BootstrapH
default_bootstrap_handler = DefaultBootstrapHandler()
+def load_bootstrap_handler(bootstrap_ep, log=None):
+ """Load handler for environment lookup and instantiation of request objects
+
+ :param bootstrap_ep: entry point specification
+ :param log: file-like object used to report errors
+ """
+ bootstrap = None
+ if bootstrap_ep:
+ try:
+ ep = pkg_resources.EntryPoint.parse('x = ' + bootstrap_ep)
+ bootstrap = ep.load(require=False)
+ except Exception, e:
+ if log:
+ log.write("[FAIL] [Trac] entry point '%s'. Reason %s" %
+ (bootstrap_ep, repr(exception_to_unicode(e))))
+ if bootstrap is None:
+ bootstrap = default_bootstrap_handler
+ return bootstrap
+
+
# Recursive imports
from trac.web.main import send_project_index, get_environments
Modified: bloodhound/trunk/trac/trac/web/main.py
URL:
http://svn.apache.org/viewvc/bloodhound/trunk/trac/trac/web/main.py?rev=1495235&r1=1495234&r2=1495235&view=diff
==============================================================================
--- bloodhound/trunk/trac/trac/web/main.py (original)
+++ bloodhound/trunk/trac/trac/web/main.py Thu Jun 20 23:28:09 2013
@@ -342,13 +342,12 @@ class RequestDispatcher(Component):
_slashes_re = re.compile(r'/+')
-def dispatch_request(environ, start_response, bootstrap=None):
+
+def dispatch_request(environ, start_response):
"""Main entry point for the Trac web interface.
:param environ: the WSGI environment dict
:param start_response: the WSGI callback for starting the response
- :param bootstrap: handler responsible for environment lookup and
- instantiating request objects
"""
# SCRIPT_URL is an Apache var containing the URL before URL rewriting
@@ -382,21 +381,10 @@ def dispatch_request(environ, start_resp
locale.setlocale(locale.LC_ALL, environ['trac.locale'])
- if bootstrap is None:
- bootstrap_ep = environ['trac.bootstrap_handler']
- if bootstrap_ep:
- from pkg_resources import EntryPoint
- try:
- ep = EntryPoint.parse('x = ' + bootstrap_ep)
- bootstrap = ep.load(require=False)
- except Exception, e:
- log = environ.get('wsgi.errors')
- if log:
- log.write("[FAIL] [Trac] Entry point '%s'. Reason %s" %
- (bootstrap_ep, repr(exception_to_unicode(e))))
- if bootstrap is None:
- from trac.hooks import default_bootstrap_handler
- bootstrap = default_bootstrap_handler
+ # Load handler for environment lookup and instantiation of request objects
+ from trac.hooks import load_bootstrap_handler
+ bootstrap = load_bootstrap_handler(environ['trac.bootstrap_handler'],
+ environ.get('wsgi.errors'))
# Determine the environment