Fixing a few bugs in the debug middleware and legacy iPython support.
This commit is contained in:
@@ -34,8 +34,9 @@ class IPythonShell(object):
|
||||
shell = InteractiveShellEmbed(banner2=banner)
|
||||
shell(local_ns=ns)
|
||||
except ImportError:
|
||||
# Support for the IPython <= 0.10 shell API
|
||||
from IPython.Shell import IPShellEmbed
|
||||
shell = IPShellEmbed(argv=self.args)
|
||||
shell = IPShellEmbed(argv=[])
|
||||
shell.set_banner(shell.IP.BANNER + '\n\n' + banner)
|
||||
shell(local_ns=ns, global_ns={})
|
||||
|
||||
@@ -48,7 +49,7 @@ class ShellCommand(BaseCommand):
|
||||
SHELLS = {
|
||||
'python': NativePythonShell,
|
||||
'ipython': IPythonShell
|
||||
}
|
||||
}
|
||||
|
||||
arguments = BaseCommand.arguments + ({
|
||||
'command': ['--shell', '-s'],
|
||||
|
||||
@@ -1,6 +1,40 @@
|
||||
import sys
|
||||
from recursive import ForwardRequestException
|
||||
|
||||
|
||||
class StatusPersist(object):
|
||||
|
||||
def __init__(self, app, status, url):
|
||||
self.app = app
|
||||
self.status = status
|
||||
self.url = url
|
||||
|
||||
def __call__(self, environ, start_response):
|
||||
def keep_status_start_response(status, headers, exc_info=None):
|
||||
return start_response(self.status, headers, exc_info)
|
||||
parts = self.url.split('?')
|
||||
environ['PATH_INFO'] = parts[0]
|
||||
if len(parts) > 1:
|
||||
environ['QUERY_STRING'] = parts[1]
|
||||
else:
|
||||
environ['QUERY_STRING'] = ''
|
||||
|
||||
try:
|
||||
return self.app(environ, keep_status_start_response)
|
||||
except RecursionLoop, e:
|
||||
environ['wsgi.errors'].write(
|
||||
'Recursion error getting error page: %s\n' % e
|
||||
)
|
||||
keep_status_start_response(
|
||||
'500 Server Error',
|
||||
[('Content-type', 'text/plain')],
|
||||
sys.exc_info()
|
||||
)
|
||||
return [
|
||||
'Error: %s. (Error page could not be fetched)' % self.status
|
||||
]
|
||||
|
||||
|
||||
class ErrorDocumentMiddleware(object):
|
||||
|
||||
def __init__(self, app, error_map):
|
||||
@@ -12,14 +46,20 @@ class ErrorDocumentMiddleware(object):
|
||||
def replacement_start_response(status, headers, exc_info=None):
|
||||
try:
|
||||
status_code = status.split(' ')[0]
|
||||
except ValueError, TypeError:
|
||||
except (ValueError, TypeError):
|
||||
raise Exception((
|
||||
'ErrorDocumentMiddleware received an invalid '
|
||||
'status %s' % status
|
||||
))
|
||||
|
||||
if status_code in self.error_map:
|
||||
raise ForwardRequestException(self.error_map[status_code])
|
||||
def factory(app):
|
||||
return StatusPersist(
|
||||
app,
|
||||
status,
|
||||
self.error_map[status_code]
|
||||
)
|
||||
raise ForwardRequestException(factory=factory)
|
||||
|
||||
return start_response(status, headers, exc_info)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from pecan.middleware.logger import TransLogger
|
||||
from webtest import TestApp
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
import unittest2 as unittest # pragma: nocover
|
||||
import unittest2 as unittest # pragma: nocover
|
||||
else:
|
||||
import unittest # pragma: nocover
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from cStringIO import StringIO
|
||||
from pecan import make_app, expose, request, redirect, abort
|
||||
from pecan import make_app, expose, redirect, abort
|
||||
from pecan.core import state
|
||||
from pecan.hooks import (
|
||||
PecanHook, TransactionHook, HookController, RequestViewerHook
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
def iscontroller(obj):
|
||||
|
||||
Reference in New Issue
Block a user