From 2b528f0fffe12fb39ac9c874e32b501305217d23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 24 Jan 2017 09:19:18 +0100 Subject: [PATCH] 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. --- pillar/api/utils/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pillar/api/utils/__init__.py b/pillar/api/utils/__init__.py index 3af84d31..59c36bdd 100644 --- a/pillar/api/utils/__init__.py +++ b/pillar/api/utils/__init__.py @@ -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']"""