def _unpack_response(response, cursor_id=None, as_class=dict, tz_aware=False):
response_flag = struct.unpack("<STR_LIT>", response[:<NUM_LIT:4>])[<NUM_LIT:0>]<EOL>if response_flag & <NUM_LIT:1>:<EOL><INDENT>assert cursor_id is not None<EOL>raise InterfaceError("<STR_LIT>" %<EOL>cursor_id)<EOL><DEDENT>elif response_flag & <NUM_LIT:2>:<EOL><INDENT>error_object = bson.BSON(response[<NUM_LIT:20>:]).decode()<EOL>if error_object["<STR_LIT>"] == "<STR_LIT>":<EOL><INDENT>raise DatabaseError("<STR_LIT>")<EOL><DEDENT>raise DatabaseError("<STR_LIT>" %<EOL>error_object["<STR_LIT>"])<EOL><DEDENT>result = {}<EOL>result["<STR_LIT>"] = struct.unpack("<STR_LIT>", response[<NUM_LIT:4>:<NUM_LIT:12>])[<NUM_LIT:0>]<EOL>result["<STR_LIT>"] = struct.unpack("<STR_LIT>", response[<NUM_LIT:12>:<NUM_LIT:16>])[<NUM_LIT:0>]<EOL>result["<STR_LIT>"] = struct.unpack("<STR_LIT>", response[<NUM_LIT:16>:<NUM_LIT:20>])[<NUM_LIT:0>]<EOL>result["<STR_LIT:data>"] = bson.decode_all(response[<NUM_LIT:20>:], as_class, tz_aware)<EOL>assert len(result["<STR_LIT:data>"]) == result["<STR_LIT>"]<EOL>return result<EOL>
Unpack a response from the database.

    Check the response for errors and unpack, returning a dictionary
    containing the response data.

    :Parameters:
      - `response`: byte string as returned from the database
      - `cursor_id` (optional): cursor_id we sent to get this response -
        used for raising an informative exception when we get cursor id not
        valid at server response
      - `as_class` (optional): class to use for resulting documents