예제 #1
0
 def test_pretty_indent2(self):
     j = wrap({
         "a": {
             "b1": {
                 "c": {
                     "d": 1,
                     "e": 2,
                     "f": 3
                 }
             },
             "b2": {
                 "c": {
                     "d": 1,
                     "e": 2,
                     "f": 3
                 }
             },
         }
     })
     test = pretty_json(j)
     expecting = (
         '{"a": {\n    "b1": {"c": {\n        "d": 1,\n        "e": 2,\n        "f":'
         ' 3\n    }},\n    "b2": {"c": {\n        "d": 1,\n        "e": 2,\n       '
         ' "f": 3\n    }}\n}}')
     self.assertEqual(test, expecting, "expecting proper indentation")
예제 #2
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 as e:
        # THE PRETTY JSON WILL PROVIDE MORE DETAIL ABOUT THE SERIALIZATION CONCERNS
        from mo_logs import Log

        Log.warning("Serialization of JSON problems", e)
        try:
            return pretty_json(value)
        except Exception, f:
            Log.error("problem serializing object", f)
예제 #3
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 as e:
        # THE PRETTY JSON WILL PROVIDE MORE DETAIL ABOUT THE SERIALIZATION CONCERNS
        from mo_logs import Log

        Log.warning("Serialization of JSON problems", e)
        try:
            return pretty_json(value)
        except Exception, f:
            Log.error("problem serializing object", f)
예제 #4
0
 def test_pretty_indent1(self):
     j = wrap({"a": {"b": {"c": {"d": 1, "e": 2, "f": 3}}}})
     test = pretty_json(j)
     expecting = '{"a": {"b": {"c": {\n    "d": 1,\n    "e": 2,\n    "f": 3\n}}}}'
     self.assertEqual(test, expecting, "expecting proper indentation")
예제 #5
0
 def test_pretty_json(self):
     j = wrap({"not": {"match_all": wrap({})}})
     test = pretty_json(j)
     expecting = '{"not": {"match_all": {}}}'
     self.assertEqual(test, expecting, "expecting empty dict to serialize")