summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hellkamp <marc@gsites.de>2012-05-14 16:26:37 +0200
committerMarcel Hellkamp <marc@gsites.de>2012-05-14 16:27:43 +0200
commit85aa8c26235bc3415ed9d78571639d700703631d (patch)
tree63e1e58064787f6ac8f5191aa0316b1eebbf68bc
parentfe21d79106d13aa349aaea3bd6e42573608af0d8 (diff)
downloadbottle-85aa8c26235bc3415ed9d78571639d700703631d.tar.gz
Fix: IOError with mod_wsgi
mod_wsgi restricts sys.stdin attribute access.
-rw-r--r--bottle.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/bottle.py b/bottle.py
index ed15b5b..8198a7e 100644
--- a/bottle.py
+++ b/bottle.py
@@ -64,8 +64,13 @@ py25 = py < (2,6,0)
# Workaround for the missing "as" keyword in py3k.
def _e(): return sys.exc_info()[1]
-# Workaround for the "print is a keyword/function" dilemma.
-_stdout, _stderr = sys.stdout.write, sys.stderr.write
+# Workaround for the "print is a keyword/function" Python 2/3 dilemma
+# and a fallback for mod_wsgi (resticts stdout/err attribute access)
+try:
+ _stdout, _stderr = sys.stdout.write, sys.stderr.write
+except IOError:
+ _stdout = lambda x: sys.stdout.write(x)
+ _stderr = lambda x: sys.stderr.write(x)
# Lots of stdlib and builtin differences.
if py3k: