'mediagoblin.meddleware.noop:NoOpMeddleware',
'mediagoblin.meddleware.csrf:CsrfMeddleware',
)
+
+
+class BaseMeddleware(object):
+
+ def __init__(self, mg_app):
+ self.app = mg_app
+
+ def process_request(self, request):
+ pass
+
+ def process_response(self, request, response):
+ pass
from wtforms import Form, HiddenField, validators
from mediagoblin import mg_globals
+from mediagoblin.meddleware import BaseMeddleware
# Use the system (hardware-based) random number generator if it exists.
# -- this optimization is lifted from Django
return form.csrf_token
-class CsrfMeddleware(object):
+class CsrfMeddleware(BaseMeddleware):
"""CSRF Protection Meddleware
Adds a CSRF Cookie to responses and verifies that it is present
CSRF_KEYLEN = 64
SAFE_HTTP_METHODS = ("GET", "HEAD", "OPTIONS", "TRACE")
- def __init__(self, mg_app):
- self.app = mg_app
-
def process_request(self, request):
"""For non-safe requests, confirm that the tokens are present
and match.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-class NoOpMeddleware(object):
+from mediagoblin.meddleware import BaseMeddleware
- def __init__(self, mg_app):
- self.app = mg_app
+class NoOpMeddleware(BaseMeddleware):
def process_request(self, request):
pass
from mediagoblin.init.config import read_mediagoblin_config
from mediagoblin.decorators import _make_safe
from mediagoblin.db.open import setup_connection_and_db_from_config
+from mediagoblin.meddleware import BaseMeddleware
MEDIAGOBLIN_TEST_DB_NAME = u'__mediagoblin_tests__'
class BadCeleryEnviron(Exception): pass
-class TestingMeddleware(object):
+class TestingMeddleware(BaseMeddleware):
"""
Meddleware for the Unit tests
create a new method and call it from process_*.
"""
- def __init__(self, mg_app):
- self.app = mg_app
-
- def process_request(self, request):
- pass
-
def process_response(self, request, response):
# All following tests should be for html only!
if response.content_type != "text/html":