/
opt
/
alt
/
python37
/
lib
/
python3.7
/
site-packages
/
paste
/
/opt/alt/python37/lib/python3.7/site-packages/paste
mkdir
upload
Name
Size
Mode
Actions
auth/
-
0755
rm
cowbell/
-
0755
rm
debug/
-
0755
rm
evalexception/
-
0755
rm
exceptions/
-
0755
rm
util/
-
0755
rm
__pycache__/
-
0755
rm
cascade.py
4508
0644
edit
dl
rm
cascade.pyc
4475
0644
edit
dl
rm
cascade.pyo
4475
0644
edit
dl
rm
cgiapp.py
9590
0644
edit
dl
rm
cgiapp.pyc
8554
0644
edit
dl
rm
cgiapp.pyo
8337
0644
edit
dl
rm
cgitb_catcher.py
3752
0644
edit
dl
rm
cgitb_catcher.pyc
3851
0644
edit
dl
rm
cgitb_catcher.pyo
3851
0644
edit
dl
rm
config.py
4312
0644
edit
dl
rm
config.pyc
5284
0644
edit
dl
rm
config.pyo
5284
0644
edit
dl
rm
errordocument.py
13777
0644
edit
dl
rm
errordocument.pyc
13080
0644
edit
dl
rm
errordocument.pyo
13080
0644
edit
dl
rm
fileapp.py
13608
0644
edit
dl
rm
fileapp.pyc
13352
0644
edit
dl
rm
fileapp.pyo
13218
0644
edit
dl
rm
fixture.py
57992
0644
edit
dl
rm
fixture.py.stdlib
58075
0644
edit
dl
rm
fixture.pyc
60726
0644
edit
dl
rm
fixture.pyo
58453
0644
edit
dl
rm
flup_session.py
3941
0644
edit
dl
rm
flup_session.pyc
3959
0644
edit
dl
rm
flup_session.pyo
3959
0644
edit
dl
rm
gzipper.py
3692
0644
edit
dl
rm
gzipper.pyc
4578
0644
edit
dl
rm
gzipper.pyo
4578
0644
edit
dl
rm
httpexceptions.py
24222
0644
edit
dl
rm
httpexceptions.pyc
28380
0644
edit
dl
rm
httpexceptions.pyo
27623
0644
edit
dl
rm
httpheaders.py
43090
0644
edit
dl
rm
httpheaders.pyc
45274
0644
edit
dl
rm
httpheaders.pyo
43974
0644
edit
dl
rm
httpserver.py
55662
0644
edit
dl
rm
httpserver.pyc
48661
0644
edit
dl
rm
httpserver.pyo
47999
0644
edit
dl
rm
lint.py
14999
0644
edit
dl
rm
lint.pyc
17889
0644
edit
dl
rm
lint.pyo
13772
0644
edit
dl
rm
modpython.py
7976
0644
edit
dl
rm
modpython.pyc
8953
0644
edit
dl
rm
modpython.pyo
8953
0644
edit
dl
rm
pony.py
2279
0644
edit
dl
rm
pony.pyc
2753
0644
edit
dl
rm
pony.pyo
2753
0644
edit
dl
rm
progress.py
8162
0644
edit
dl
rm
progress.pyc
9416
0644
edit
dl
rm
progress.pyo
9416
0644
edit
dl
rm
proxy.py
10181
0644
edit
dl
rm
proxy.pyc
8787
0644
edit
dl
rm
proxy.pyo
8787
0644
edit
dl
rm
recursive.py
14664
0644
edit
dl
rm
recursive.pyc
18141
0644
edit
dl
rm
recursive.pyo
17816
0644
edit
dl
rm
registry.py
22193
0644
edit
dl
rm
registry.pyc
22941
0644
edit
dl
rm
registry.pyo
22941
0644
edit
dl
rm
reloader.py
6010
0644
edit
dl
rm
reloader.pyc
6134
0644
edit
dl
rm
reloader.pyo
6134
0644
edit
dl
rm
request.py
14145
0644
edit
dl
rm
request.pyc
14065
0644
edit
dl
rm
request.pyo
13969
0644
edit
dl
rm
response.py
7659
0644
edit
dl
rm
response.pyc
9468
0644
edit
dl
rm
response.pyo
9384
0644
edit
dl
rm
session.py
11335
0644
edit
dl
rm
session.pyc
12053
0644
edit
dl
rm
session.pyo
12053
0644
edit
dl
rm
transaction.py
4362
0644
edit
dl
rm
transaction.pyc
5857
0644
edit
dl
rm
transaction.pyo
5857
0644
edit
dl
rm
translogger.py
4812
0644
edit
dl
rm
translogger.pyc
4374
0644
edit
dl
rm
translogger.pyo
4374
0644
edit
dl
rm
url.py
14624
0644
edit
dl
rm
url.pyc
18581
0644
edit
dl
rm
url.pyo
18581
0644
edit
dl
rm
urlmap.py
9032
0644
edit
dl
rm
urlmap.pyc
9773
0644
edit
dl
rm
urlmap.pyo
9625
0644
edit
dl
rm
urlparser.py
26424
0644
edit
dl
rm
urlparser.pyc
22670
0644
edit
dl
rm
urlparser.pyo
22494
0644
edit
dl
rm
wsgilib.py
20134
0644
edit
dl
rm
wsgilib.pyc
22236
0644
edit
dl
rm
wsgilib.pyo
22180
0644
edit
dl
rm
wsgiwrappers.py
22165
0644
edit
dl
rm
wsgiwrappers.pyc
24450
0644
edit
dl
rm
wsgiwrappers.pyo
24450
0644
edit
dl
rm
Edit:
/opt/alt/python37/lib/python3.7/site-packages/paste/errordocument.py
(13777B)
# (c) 2005-2006 James Gardner <james@pythonweb.org> # This module is part of the Python Paste Project and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php """ Middleware to display error documents for certain status codes The middleware in this module can be used to intercept responses with specified status codes and internally forward the request to an appropriate URL where the content can be displayed to the user as an error document. """ import warnings import sys from urlparse import urlparse from paste.recursive import ForwardRequestException, RecursiveMiddleware, RecursionLoop from paste.util import converters from paste.response import replace_header def forward(app, codes): """ Intercepts a response with a particular status code and returns the content from a specified URL instead. The arguments are: ``app`` The WSGI application or middleware chain. ``codes`` A dictionary of integer status codes and the URL to be displayed if the response uses that code. For example, you might want to create a static file to display a "File Not Found" message at the URL ``/error404.html`` and then use ``forward`` middleware to catch all 404 status codes and display the page you created. In this example ``app`` is your exisiting WSGI applicaiton:: from paste.errordocument import forward app = forward(app, codes={404:'/error404.html'}) """ for code in codes: if not isinstance(code, int): raise TypeError('All status codes should be type int. ' '%s is not valid'%repr(code)) def error_codes_mapper(code, message, environ, global_conf, codes): if codes.has_key(code): return codes[code] else: return None #return _StatusBasedRedirect(app, error_codes_mapper, codes=codes) return RecursiveMiddleware( StatusBasedForward( app, error_codes_mapper, codes=codes, ) ) class StatusKeeper(object): def __init__(self, app, status, url, headers): self.app = app self.status = status self.url = url self.headers = headers def __call__(self, environ, start_response): def keep_status_start_response(status, headers, exc_info=None): for header, value in headers: if header.lower() == 'set-cookie': self.headers.append((header, value)) else: replace_header(self.headers, header, value) return start_response(self.status, self.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'] = '' #raise Exception(self.url, self.status) 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 StatusBasedForward(object): """ Middleware that lets you test a response against a custom mapper object to programatically determine whether to internally forward to another URL and if so, which URL to forward to. If you don't need the full power of this middleware you might choose to use the simpler ``forward`` middleware instead. The arguments are: ``app`` The WSGI application or middleware chain. ``mapper`` A callable that takes a status code as the first parameter, a message as the second, and accepts optional environ, global_conf and named argments afterwards. It should return a URL to forward to or ``None`` if the code is not to be intercepted. ``global_conf`` Optional default configuration from your config file. If ``debug`` is set to ``true`` a message will be written to ``wsgi.errors`` on each internal forward stating the URL forwarded to. ``**params`` Optional, any other configuration and extra arguments you wish to pass which will in turn be passed back to the custom mapper object. Here is an example where a ``404 File Not Found`` status response would be redirected to the URL ``/error?code=404&message=File%20Not%20Found``. This could be useful for passing the status code and message into another application to display an error document: .. code-block:: python from paste.errordocument import StatusBasedForward from paste.recursive import RecursiveMiddleware from urllib import urlencode def error_mapper(code, message, environ, global_conf, kw) if code in [404, 500]: params = urlencode({'message':message, 'code':code}) url = '/error?'%(params) return url else: return None app = RecursiveMiddleware( StatusBasedForward(app, mapper=error_mapper), ) """ def __init__(self, app, mapper, global_conf=None, **params): if global_conf is None: global_conf = {} # @@: global_conf shouldn't really come in here, only in a # separate make_status_based_forward function if global_conf: self.debug = converters.asbool(global_conf.get('debug', False)) else: self.debug = False self.application = app self.mapper = mapper self.global_conf = global_conf self.params = params def __call__(self, environ, start_response): url = [] writer = [] def change_response(status, headers, exc_info=None): status_code = status.split(' ') try: code = int(status_code[0]) except (ValueError, TypeError): raise Exception( 'StatusBasedForward middleware ' 'received an invalid status code %s'%repr(status_code[0]) ) message = ' '.join(status_code[1:]) new_url = self.mapper( code, message, environ, self.global_conf, **self.params ) if not (new_url == None or isinstance(new_url, str)): raise TypeError( 'Expected the url to internally ' 'redirect to in the StatusBasedForward mapper' 'to be a string or None, not %r' % new_url) if new_url: url.append([new_url, status, headers]) # We have to allow the app to write stuff, even though # we'll ignore it: return [].append else: return start_response(status, headers, exc_info) app_iter = self.application(environ, change_response) if url: if hasattr(app_iter, 'close'): app_iter.close() def factory(app): return StatusKeeper(app, status=url[0][1], url=url[0][0], headers=url[0][2]) raise ForwardRequestException(factory=factory) else: return app_iter def make_errordocument(app, global_conf, **kw): """ Paste Deploy entry point to create a error document wrapper. Use like:: [filter-app:main] use = egg:Paste#errordocument next = real-app 500 = /lib/msg/500.html 404 = /lib/msg/404.html """ map = {} for status, redir_loc in kw.items(): try: status = int(status) except ValueError: raise ValueError('Bad status code: %r' % status) map[status] = redir_loc forwarder = forward(app, map) return forwarder __pudge_all__ = [ 'forward', 'make_errordocument', 'empty_error', 'make_empty_error', 'StatusBasedForward', ] ############################################################################### ## Deprecated ############################################################################### def custom_forward(app, mapper, global_conf=None, **kw): """ Deprectated; use StatusBasedForward instead. """ warnings.warn( "errordocuments.custom_forward has been deprecated; please " "use errordocuments.StatusBasedForward", DeprecationWarning, 2) if global_conf is None: global_conf = {} return _StatusBasedRedirect(app, mapper, global_conf, **kw) class _StatusBasedRedirect(object): """ Deprectated; use StatusBasedForward instead. """ def __init__(self, app, mapper, global_conf=None, **kw): warnings.warn( "errordocuments._StatusBasedRedirect has been deprecated; please " "use errordocuments.StatusBasedForward", DeprecationWarning, 2) if global_conf is None: global_conf = {} self.application = app self.mapper = mapper self.global_conf = global_conf self.kw = kw self.fallback_template = """ <html> <head> <title>Error %(code)s</title> </html> <body> <h1>Error %(code)s</h1> <p>%(message)s</p> <hr> <p> Additionally an error occurred trying to produce an error document. A description of the error was logged to <tt>wsgi.errors</tt>. </p> </body> </html> """ def __call__(self, environ, start_response): url = [] code_message = [] try: def change_response(status, headers, exc_info=None): new_url = None parts = status.split(' ') try: code = int(parts[0]) except (ValueError, TypeError): raise Exception( '_StatusBasedRedirect middleware ' 'received an invalid status code %s'%repr(parts[0]) ) message = ' '.join(parts[1:]) new_url = self.mapper( code, message, environ, self.global_conf, self.kw ) if not (new_url == None or isinstance(new_url, str)): raise TypeError( 'Expected the url to internally ' 'redirect to in the _StatusBasedRedirect error_mapper' 'to be a string or None, not %s'%repr(new_url) ) if new_url: url.append(new_url) code_message.append([code, message]) return start_response(status, headers, exc_info) app_iter = self.application(environ, change_response) except: try: import sys error = str(sys.exc_info()[1]) except: error = '' try: code, message = code_message[0] except: code, message = ['', ''] environ['wsgi.errors'].write( 'Error occurred in _StatusBasedRedirect ' 'intercepting the response: '+str(error) ) return [self.fallback_template % {'message': message, 'code': code}] else: if url: url_ = url[0] new_environ = {} for k, v in environ.items(): if k != 'QUERY_STRING': new_environ['QUERY_STRING'] = urlparse(url_)[4] else: new_environ[k] = v class InvalidForward(Exception): pass def eat_start_response(status, headers, exc_info=None): """ We don't want start_response to do anything since it has already been called """ if status[:3] != '200': raise InvalidForward( "The URL %s to internally forward " "to in order to create an error document did not " "return a '200' status code." % url_ ) forward = environ['paste.recursive.forward'] old_start_response = forward.start_response forward.start_response = eat_start_response try: app_iter = forward(url_, new_environ) except InvalidForward, e: code, message = code_message[0] environ['wsgi.errors'].write( 'Error occurred in ' '_StatusBasedRedirect redirecting ' 'to new URL: '+str(url[0]) ) return [ self.fallback_template%{ 'message':message, 'code':code, } ] else: forward.start_response = old_start_response return app_iter else: return app_iter
Save
cmd:
run