MCPcopy Index your code
hub / github.com/fluentpython/example-code-2e / _handle

Method _handle

21-async/mojifinder/bottle.py:850–883  ·  view source on GitHub ↗
(self, environ)

Source from the content-addressed store, hash-verified

848 return tob(template(ERROR_PAGE_TEMPLATE, e=res))
849
850 def _handle(self, environ):
851 path = environ['bottle.raw_path'] = environ['PATH_INFO']
852 if py3k:
853 try:
854 environ['PATH_INFO'] = path.encode('latin1').decode('utf8')
855 except UnicodeError:
856 return HTTPError(400, 'Invalid path string. Expected UTF-8')
857
858 try:
859 environ['bottle.app'] = self
860 request.bind(environ)
861 response.bind()
862 try:
863 self.trigger_hook('before_request')
864 route, args = self.router.match(environ)
865 environ['route.handle'] = route
866 environ['bottle.route'] = route
867 environ['route.url_args'] = args
868 return route.call(**args)
869 finally:
870 self.trigger_hook('after_request')
871
872 except HTTPResponse:
873 return _e()
874 except RouteReset:
875 route.reset()
876 return self._handle(environ)
877 except (KeyboardInterrupt, SystemExit, MemoryError):
878 raise
879 except Exception:
880 if not self.catchall: raise
881 stacktrace = format_exc()
882 environ['wsgi.errors'].write(stacktrace)
883 return HTTPError(500, "Internal Server Error", _e(), stacktrace)
884
885 def _cast(self, out, peek=None):
886 """ Try to convert the parameter into something WSGI compatible and set

Callers 1

wsgiMethod · 0.95

Calls 7

trigger_hookMethod · 0.95
HTTPErrorClass · 0.85
_eFunction · 0.85
decodeMethod · 0.80
callMethod · 0.80
matchMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected