
import json
from bson import json_util

from flask.wrappers import Request, cached_property

def getBoolean(string):
    if string is None:
        return False
    return {
        '1': True, 'yes': True, 'true': True, 'on': True,
        '0': False, 'no': False, 'false': False, 'off': False, '': False, None: False
    }[string.lower()]


class ExtRequest(Request):
    @cached_property
    def json(self):
        """If the mimetype is `application/json` this will contain the
        parsed JSON data.
        """
        if self.mimetype in ('application/json','application/extjson'):
            if 'ext' in self.mimetype:
                objhook = json_util.object_hook
            else:
                objhook = None

            request_charset = self.mimetype_params.get('charset')
            if request_charset is not None:
                j = json.loads(self.data, encoding=request_charset, object_hook=objhook )
            else:
                j = json.loads(self.data, object_hook=objhook)

            return j




import json
from bson import json_util, BSON

from flask.wrappers import Request, cached_property

def getBoolean(string):
    if string is None:
        return False
    return {
        '1': True, 'yes': True, 'true': True, 'on': True,
        '0': False, 'no': False, 'false': False, 'off': False, '': False, None: False
    }[string.lower()]


class ExtRequest(Request):
    @cached_property
    def json(self):
        """If the mimetype is `application/json` this will contain the
        parsed JSON data.
        """
        if self.mimetype == 'application/bson':
            return BSON(self.data).decode()

        if self.mimetype in ('application/json','application/extjson'):
            if 'ext' in self.mimetype:
                objhook = json_util.object_hook
            else:
                objhook = None

            request_charset = self.mimetype_params.get('charset')
            if request_charset is not None:
                j = json.loads(self.data, encoding=request_charset, object_hook=objhook )
            else:
                j = json.loads(self.data, object_hook=objhook)

            return j



Add support for decoding data serialized as BSON.
Add support for decoding data serialized as BSON.

  
  import json
- from bson import json_util
+ from bson import json_util, BSON
  
  from flask.wrappers import Request, cached_property
  
  def getBoolean(string):
      if string is None:
          return False
      return {
          '1': True, 'yes': True, 'true': True, 'on': True,
          '0': False, 'no': False, 'false': False, 'off': False, '': False, None: False
      }[string.lower()]
  
  
  class ExtRequest(Request):
      @cached_property
      def json(self):
          """If the mimetype is `application/json` this will contain the
          parsed JSON data.
          """
+         if self.mimetype == 'application/bson':
+             return BSON(self.data).decode()
+ 
          if self.mimetype in ('application/json','application/extjson'):
              if 'ext' in self.mimetype:
                  objhook = json_util.object_hook
              else:
                  objhook = None
  
              request_charset = self.mimetype_params.get('charset')
              if request_charset is not None:
                  j = json.loads(self.data, encoding=request_charset, object_hook=objhook )
              else:
                  j = json.loads(self.data, object_hook=objhook)
  
              return j
  
  
  
Add support for decoding data serialized as BSON.
## Code Before:

import json
from bson import json_util

from flask.wrappers import Request, cached_property

def getBoolean(string):
    if string is None:
        return False
    return {
        '1': True, 'yes': True, 'true': True, 'on': True,
        '0': False, 'no': False, 'false': False, 'off': False, '': False, None: False
    }[string.lower()]


class ExtRequest(Request):
    @cached_property
    def json(self):
        """If the mimetype is `application/json` this will contain the
        parsed JSON data.
        """
        if self.mimetype in ('application/json','application/extjson'):
            if 'ext' in self.mimetype:
                objhook = json_util.object_hook
            else:
                objhook = None

            request_charset = self.mimetype_params.get('charset')
            if request_charset is not None:
                j = json.loads(self.data, encoding=request_charset, object_hook=objhook )
            else:
                j = json.loads(self.data, object_hook=objhook)

            return j



## Instruction:
Add support for decoding data serialized as BSON.
## Code After:

import json
from bson import json_util, BSON

from flask.wrappers import Request, cached_property

def getBoolean(string):
    if string is None:
        return False
    return {
        '1': True, 'yes': True, 'true': True, 'on': True,
        '0': False, 'no': False, 'false': False, 'off': False, '': False, None: False
    }[string.lower()]


class ExtRequest(Request):
    @cached_property
    def json(self):
        """If the mimetype is `application/json` this will contain the
        parsed JSON data.
        """
        if self.mimetype == 'application/bson':
            return BSON(self.data).decode()

        if self.mimetype in ('application/json','application/extjson'):
            if 'ext' in self.mimetype:
                objhook = json_util.object_hook
            else:
                objhook = None

            request_charset = self.mimetype_params.get('charset')
            if request_charset is not None:
                j = json.loads(self.data, encoding=request_charset, object_hook=objhook )
            else:
                j = json.loads(self.data, object_hook=objhook)

            return j


