--- a/RadonMetrics/CodeMetricsCalculator.py Mon Sep 14 20:18:39 2015 +0200 +++ b/RadonMetrics/CodeMetricsCalculator.py Tue Sep 15 19:22:38 2015 +0200 @@ -5,6 +5,11 @@ from __future__ import unicode_literals +try: + str = unicode # __IGNORE_EXCEPTION __IGNORE_WARNING__ +except NameError: + pass + import multiprocessing @@ -122,5 +127,26 @@ @rtype (list) """ from radon.raw import analyze - res = analyze(text) + try: + res = __raw2Dict(analyze(text)) + except Exception as err: + res = {"error": str(err)} return (res, ) + + +def __raw2Dict(obj): + """ + Private function to convert an object holding raw analysis results into a + dictionary. + + @param obj object as returned from analyze() + @type radon.raw.Module + @return conversion result + @rtype dict + """ + result = {} + for a in obj._fields: + v = getattr(obj, a, None) + if v is not None: + result[a] = v + return result