diff --git a/mutalyzer/services/json.py b/mutalyzer/services/json.py index ad4945e2c316a9abd700e388dd17ab37d85bf67e..ae94a5032dc537656261aa60080d87f95710ac55 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 efca9b86c31d152ebe105e79110af6d41c4852b8..97118e12c703d45e198d29a699931f6c87be9a58 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