summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hellkamp <marc@gsites.de>2011-10-01 17:30:24 +0200
committerMarcel Hellkamp <marc@gsites.de>2011-10-01 17:30:24 +0200
commitaa655b9007b9f20944bfea346f05779a7c6cfdb9 (patch)
tree5eb11d71ab60aa7d367d4570ae153e536db313d7
parentba8ad1a95c103a530f9abfa871816fe9aff0a34c (diff)
downloadbottle-aa655b9007b9f20944bfea346f05779a7c6cfdb9.tar.gz
A new global variable NORUN prevents run() from starting a server. It is
used by load_app() to work around scripts that call run() on import time.
-rwxr-xr-xbottle.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/bottle.py b/bottle.py
index 5856da6..4a9c1c2 100755
--- a/bottle.py
+++ b/bottle.py
@@ -2235,10 +2235,14 @@ def load_app(target):
""" Load a bottle application from a module and make sure that the import
does not affect the current default application, but returns a separate
application object. See :func:`load` for the target parameter. """
- tmp = app.push() # Create a new "default application"
- rv = load(target) # Import the target module
- app.remove(tmp) # Remove the temporary added default application
- return rv if isinstance(rv, Bottle) else tmp
+ global NORUN; NORUN, nr_old = True, NORUN
+ try:
+ tmp = app.push() # Create a new "default application"
+ rv = load(target) # Import the target module
+ app.remove(tmp) # Remove the temporary added default application
+ return rv if isinstance(rv, Bottle) else tmp
+ finally:
+ NORUN = nr_old
def run(app=None, server='wsgiref', host='127.0.0.1', port=8080,
@@ -2259,6 +2263,7 @@ def run(app=None, server='wsgiref', host='127.0.0.1', port=8080,
:param quiet: Suppress output to stdout and stderr? (default: False)
:param options: Options passed to the server adapter.
"""
+ if NORUN: return
app = app or default_app()
if isinstance(app, basestring):
app = load_app(app)
@@ -2767,6 +2772,7 @@ simpletal_view = functools.partial(view, template_adapter=SimpleTALTemplate)
TEMPLATE_PATH = ['./', './views/']
TEMPLATES = {}
DEBUG = False
+NORUN = False # If set, run() does nothing. Used by load_app()
#: A dict to map HTTP status codes (e.g. 404) to phrases (e.g. 'Not Found')
HTTP_CODES = httplib.responses