From 68ffe8655a2f3ee90649671086db14b45faa2b05 Mon Sep 17 00:00:00 2001 From: Martijn Vermaat <martijn@vermaat.name> Date: Mon, 16 Jul 2012 13:29:10 +0000 Subject: [PATCH] Monkey patch spyne to Json-serialize Fault objects git-svn-id: https://humgenprojects.lumc.nl/svn/mutalyzer/branches/spyne@579 eb6bd6ab-9ccd-42b9-aceb-e2899b4a52f1 --- mutalyzer/services/json.py | 2 ++ mutalyzer/util.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/mutalyzer/services/json.py b/mutalyzer/services/json.py index ad4945e2..ae94a503 100644 --- a/mutalyzer/services/json.py +++ b/mutalyzer/services/json.py @@ -3,6 +3,8 @@ Mutalyzer webservice HTTP/RPC with JSON response payloads. """ +from mutalyzer.util import monkey_patch_spyne; monkey_patch_spyne() + from spyne.application import Application from spyne.protocol.http import HttpRpc from spyne.protocol.json import JsonObject diff --git a/mutalyzer/util.py b/mutalyzer/util.py index efca9b86..97118e12 100644 --- a/mutalyzer/util.py +++ b/mutalyzer/util.py @@ -879,3 +879,25 @@ def monkey_patch_suds(): Import.open = _import_open_patched Import.MUTALYZER_MONKEY_PATCHED = True #monkey_patch_suds + + +def monkey_patch_spyne(): + """ + Apply our monkey-patch for the spyne package. + + Fault objects cannot be serialized by the JsonObject output protocol, + this fixes it. + + Call this function before importing anything from the spyne package. For + example, start your file with the following: + + import monkey; monkey.monkey_patch_spyne() + from spyne.protocol.json import JsonObject + """ + from spyne.model.fault import Fault + + def _to_dict(self, *args, **kwargs): + return dict(faultcode=self.faultcode, faultstring=self.faultstring) + + Fault._to_dict = _to_dict +#monkey_patch_spyne -- GitLab