# Path: rmr/types.py
# class JsonDict(http.QueryDict):
# 
#     def __init__(self, json_dict=None, mutable=False):
#         if json_dict:
#             for key, value in json_dict.items():
#                 if isinstance(value, list):
#                     # treat list values as set of values of MultiValueDict
#                     self.setlist(key, value)
#                 else:
#                     self[key] = value
#         super().__init__(mutable=mutable)


import json
from django import http
from django.conf import settings
from rmr.types import JsonDict




class RequestDecoder:

    content_type = 'application/json'

    allowed_methods = {
        'POST', 'PUT', 'PATCH',
    }

    def process_request(self, request):
        if request.method not in self.allowed_methods:
            return
        content_type = request.META.get('CONTENT_TYPE', '')
        if not content_type.startswith(self.content_type):
            return
        encoding = request.encoding or settings.DEFAULT_CHARSET
        try:
            body = request.body.decode(encoding=encoding)

# Path: rmr/types.py
# class JsonDict(http.QueryDict):
# 
#     def __init__(self, json_dict=None, mutable=False):
#         if json_dict:
#             for key, value in json_dict.items():
#                 if isinstance(value, list):
#                     # treat list values as set of values of MultiValueDict
#                     self.setlist(key, value)
#                 else:
#                     self[key] = value
#         super().__init__(mutable=mutable)


# Path: rmr/middleware/json.py
import json
from django import http
from django.conf import settings
from rmr.types import JsonDict





class RequestDecoder:

    content_type = 'application/json'

    allowed_methods = {
        'POST', 'PUT', 'PATCH',
    }

    def process_request(self, request):
        if request.method not in self.allowed_methods:
            return
        content_type = request.META.get('CONTENT_TYPE', '')
        if not content_type.startswith(self.content_type):
            return
        encoding = request.encoding or settings.DEFAULT_CHARSET
        try:
            body = request.body.decode(encoding=encoding)

        except UnicodeDecodeError: