コード例 #1
0
def typed_encode(value):
    """
    pypy DOES NOT OPTIMIZE GENERATOR CODE WELL
    """
    try:
        _buffer = UnicodeBuilder(1024)
        _typed_encode(value, _buffer)
        output = _buffer.build()
        return output
    except Exception, e:
        # THE PRETTY JSON WILL PROVIDE MORE DETAIL ABOUT THE SERIALIZATION CONCERNS
        from pyLibrary.debugs.logs import Log

        Log.warning("Serialization of JSON problems", e)
        try:
            return pretty_json(value)
        except Exception, f:
            Log.error("problem serializing object", f)
コード例 #2
0
 def test_pretty_json(self):
     j = wrap({"not":{"match_all": wrap({})}})
     test = pretty_json(j)
     expecting = u'{"not": {"match_all": {}}}'
     self.assertEqual(test, expecting, "expecting empty dict to serialize")