Added pillar.api.utils.bsonify(some_dict)

It was used in an experiment in Flamenco as an alternative to JSON; it
might still be used in the future if BSON turns out to be significantly
faster to generate.
This commit is contained in:
Sybren A. Stüvel 2017-01-24 09:19:18 +01:00
parent 9b90070191
commit 2b528f0fff

View File

@ -85,6 +85,18 @@ def jsonify(mongo_doc, status=200, headers=None):
headers=headers)
def bsonify(mongo_doc, status=200, headers=None):
"""BSonifies a Mongo document into a Flask response object."""
import bson
data = bson.BSON.encode(mongo_doc)
return current_app.response_class(data,
mimetype='application/bson',
status=status,
headers=headers)
def skip_when_testing(func):
"""Decorator, skips the decorated function when app.config['TESTING']"""