morepath.core
– Default Morepath Configuration¶
This module contains default Morepath configuration shared by all Morepath applications. It is the only part of the Morepath implementation that uses directives like user of Morepath does.
It uses Morepath directives to configure:
- view predicates (for model, request method, etc), including what HTTP errors should be returned when a view cannot be matched.
- converters for common Python values (int, date, etc)
- a tween that catches exceptions raised by application code and looks up an exception view for it.
- a default exception view for HTTP exceptions defined by
webob.exc
, i.e. subclasses ofwebob.exc.HTTPException
.
Should you wish to do so you could even override these directives in a
subclass of morepath.App
. We do not guarantee we won’t break
your code with future version of Morepath if you do that, though.
-
morepath.core.
body_model_predicate
(self, obj, request)¶ match request.body_obj with body_model by class.
Predicate for
morepath.App.view()
.
-
morepath.core.
body_model_unprocessable
(self, obj, request)¶ if body_model not matched, 422.
Fallback for
morepath.App.view()
.
-
morepath.core.
date_converter
()¶ Converter for date.
-
morepath.core.
datetime_converter
()¶ Converter for datetime.
-
morepath.core.
excview_tween_factory
(app, handler)¶ Exception views.
If an exception is raised by application code and a view is declared for that exception class, use it.
If no view can be found, raise it all the way up – this will be a 500 internal server error and an exception logged.
-
morepath.core.
int_converter
()¶ Converter for int.
-
morepath.core.
method_not_allowed
(self, obj, request)¶ if request predicate not matched, method not allowed.
Fallback for
morepath.App.view()
.
-
morepath.core.
model_not_found
(self, obj, request)¶ if model not matched, HTTP 404.
Fallback for
morepath.App.view()
.
-
morepath.core.
model_predicate
(self, obj, request)¶ match model argument by class.
Predicate for
morepath.App.view()
.
-
morepath.core.
name_not_found
(self, obj, request)¶ if name not matched, HTTP 404.
Fallback for
morepath.App.view()
.
-
morepath.core.
name_predicate
(self, obj, request)¶ match name argument with request.view_name.
Predicate for
morepath.App.view()
.
-
morepath.core.
poisoned_host_header_protection_tween_factory
(app, handler)¶ Protect Morepath applications against the most basic host header poisoning attacts.
The regex approach has been copied from the Django project. To find more about this particular kind of attack have a look at the following references:
-
morepath.core.
request_method_predicate
(self, obj, request)¶ match request method.
Predicate for
morepath.App.view()
.
-
morepath.core.
standard_exception_view
(self, request)¶ We want the webob standard responses for any webob-based HTTP exception.
Applies to subclasses of
webob.HTTPException
.
-
morepath.core.
str_converter
()¶ Converter for non-text str.
-
morepath.core.
unicode_converter
()¶ Converter for text.