From f42c1b5ed3c440f21e3ee04fef822e952d381f62 Mon Sep 17 00:00:00 2001 From: Krateng Date: Wed, 8 May 2019 18:44:39 +0200 Subject: [PATCH] Liverpool 4 Barcelona 0 --- monkey.py | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/monkey.py b/monkey.py index 125b116..88fe05f 100644 --- a/monkey.py +++ b/monkey.py @@ -1,19 +1,32 @@ # custom json encoding -# make sure we use the json encoder that bottle uses -try: - from simplejson import JSONEncoder -except ImportError: - try: - from json import JSONEncoder - except ImportError: - from django.utils.simplejson import JSONEncoder + def newdefault(self,object): - return getattr(object.__class__,"__json__", olddefault)(object) + return getattr(object.__class__,"__json__", self._olddefault)(object) -olddefault = JSONEncoder.default -JSONEncoder.default = newdefault + +# just patch every encoder +try: + from simplejson import JSONEncoder + JSONEncoder._olddefault = JSONEncoder.default + JSONEncoder.default = newdefault +except: + pass + +try: + from json import JSONEncoder + JSONEncoder._olddefault = JSONEncoder.default + JSONEncoder.default = newdefault +except: + pass + +try: + from ujson import JSONEncoder + JSONEncoder._olddefault = JSONEncoder.default + JSONEncoder.default = newdefault +except: + pass