From 177cc97059379cce0865bb739e89f0c855b5cc49 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Sun, 22 Sep 2019 20:04:17 +0200
Subject: [PATCH] misc: make middlewares compatible with MIDDLEWARE settings
 (#36335)

---
 hobo/middleware/cors.py          | 3 ++-
 hobo/middleware/stats.py         | 6 +-----
 hobo/middleware/utils.py         | 3 ++-
 hobo/middleware/version.py       | 3 ++-
 hobo/middleware/xforwardedfor.py | 3 ++-
 hobo/multitenant/middleware.py   | 3 ++-
 hobo/scrutiny/wsgi/middleware.py | 3 ++-
 7 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/hobo/middleware/cors.py b/hobo/middleware/cors.py
index a753653..8e789b6 100644
--- a/hobo/middleware/cors.py
+++ b/hobo/middleware/cors.py
@@ -2,8 +2,9 @@ import os.path
 
 from django.conf import settings
 from django.http import HttpResponse
+from django.utils.deprecation import MiddlewareMixin
 
-class CORSMiddleware(object):
+class CORSMiddleware(MiddlewareMixin):
     def process_request(self, request):
         """
         If CORS preflight header, then create an
diff --git a/hobo/middleware/stats.py b/hobo/middleware/stats.py
index 08db097..4774b6d 100644
--- a/hobo/middleware/stats.py
+++ b/hobo/middleware/stats.py
@@ -20,14 +20,10 @@ import time
 import django
 from django.db import connection
 from django.http import HttpResponse
+from django.utils.deprecation import MiddlewareMixin
 
 import prometheus_client
 
-if django.VERSION >= (1, 10, 0):
-    from django.utils.deprecation import MiddlewareMixin
-else:
-    MiddlewareMixin = object
-
 
 requests_total_by_host_view_status_method = prometheus_client.Counter(
     'django_http_requests_total_by_host_view_status_method',
diff --git a/hobo/middleware/utils.py b/hobo/middleware/utils.py
index f403fb9..f6b39a1 100644
--- a/hobo/middleware/utils.py
+++ b/hobo/middleware/utils.py
@@ -1,6 +1,7 @@
 import threading
+from django.utils.deprecation import MiddlewareMixin
 
-class StoreRequestMiddleware(object):
+class StoreRequestMiddleware(MiddlewareMixin):
     collection = {}
 
     def process_request(self, request):
diff --git a/hobo/middleware/version.py b/hobo/middleware/version.py
index dd9956e..5d4ad50 100644
--- a/hobo/middleware/version.py
+++ b/hobo/middleware/version.py
@@ -1,10 +1,11 @@
 import json
 
 from django.http import HttpResponse
+from django.utils.deprecation import MiddlewareMixin
 
 from hobo.scrutiny.wsgi import middleware
 
-class VersionMiddleware(object):
+class VersionMiddleware(MiddlewareMixin):
     def process_request(self, request):
         if request.method == 'GET' and (request.path == '/__version__' or
                 request.path == '/__version__/'):
diff --git a/hobo/middleware/xforwardedfor.py b/hobo/middleware/xforwardedfor.py
index 98b3be7..d0614e3 100644
--- a/hobo/middleware/xforwardedfor.py
+++ b/hobo/middleware/xforwardedfor.py
@@ -1,7 +1,8 @@
 from django.conf import settings
+from django.utils.deprecation import MiddlewareMixin
 
 
-class XForwardedForMiddleware(object):
+class XForwardedForMiddleware(MiddlewareMixin):
     '''Copy the first address from X-Forwarded-For header to the REMOTE_ADDR meta.
 
        This middleware should only be used if you are sure the header cannot be
diff --git a/hobo/multitenant/middleware.py b/hobo/multitenant/middleware.py
index ef47f83..b560844 100644
--- a/hobo/multitenant/middleware.py
+++ b/hobo/multitenant/middleware.py
@@ -2,6 +2,7 @@ import os
 import glob
 import hashlib
 
+from django.utils.deprecation import MiddlewareMixin
 from django.utils.encoding import smart_bytes
 from django.conf import settings
 from django.db import connection
@@ -14,7 +15,7 @@ SENTINEL = object()
 class TenantNotFound(RuntimeError):
     pass
 
-class TenantMiddleware(object):
+class TenantMiddleware(MiddlewareMixin):
     """
     This middleware should be placed at the very top of the middleware stack.
     Selects the proper database schema using the request host. Can fail in
diff --git a/hobo/scrutiny/wsgi/middleware.py b/hobo/scrutiny/wsgi/middleware.py
index 213b682..8bb74dc 100644
--- a/hobo/scrutiny/wsgi/middleware.py
+++ b/hobo/scrutiny/wsgi/middleware.py
@@ -1,4 +1,5 @@
 from django.utils.six.moves.urllib.parse import quote
+from django.utils.deprecation import MiddlewareMixin
 
 import json
 import pkg_resources
@@ -7,7 +8,7 @@ try:
 except ImportError:
     apt_cache = None
 
-class VersionMiddleware(object):
+class VersionMiddleware(MiddlewareMixin):
     ENTROUVERT_PACKAGES = [
             'wcs',
             'wcs-au-quotidien',
-- 
2.23.0

