"""Representation filters for API"""

from flask import make_response, current_app
from bson.json_util import dumps


def output_bson(data, code, headers=None):
    """Makes Flask response with a BSON encoded body

    Copied from module `flask_restful.representations.json`

    """

    settings = current_app.config.get('RESTFUL_JSON', {})

    # If we're in debug mode, and the indent is not set, we set it to a
    # reasonable value here.  Note that this won't override any existing value
    # that was set.  We also set the "sort_keys" value.
    if current_app.debug:
        settings.setdefault('indent', 4)
        settings.setdefault('sort_keys', True)

    # always end the json dumps with a new line
    # see https://github.com/mitsuhiko/flask/pull/1262
    dumped = dumps(data, **settings) + "\n"

    resp = make_response(dumped, code)
    resp.headers.extend(headers or {})
    return resp

"""Representation filters for API"""

from flask import make_response, current_app
from bson.json_util import dumps


def output_bson(data, code, headers=None):
    """Makes Flask response with a JSON encoded body.

    Response items are serialized from MongoDB BSON objects to
    JSON compatible format.

    Modified from module `flask_restful.representations.json`

    """

    settings = current_app.config.get('RESTFUL_JSON', {})

    # If we're in debug mode, and the indent is not set, we set it to a
    # reasonable value here.  Note that this won't override any existing value
    # that was set.  We also set the "sort_keys" value.
    if current_app.debug:
        settings.setdefault('indent', 4)
        settings.setdefault('sort_keys', True)

    # always end the json dumps with a new line
    # see https://github.com/mitsuhiko/flask/pull/1262
    dumped = dumps(data, **settings) + "\n"

    resp = make_response(dumped, code)
    resp.headers.extend(headers or {})
    return resp

Correct JSON/BSON terminology in docstrings
Correct JSON/BSON terminology in docstrings
