Beispiel #1
0
def test_jsonhelper():
    from logbook.helpers import to_safe_json

    class Bogus(object):
        def __str__(self):
            return 'bogus'

    rv = to_safe_json([
        None,
        'foo',
        u('jäger'),
        1,
        datetime(2000, 1, 1),
        {
            'jäger1': 1,
            u('jäger2'): 2,
            Bogus(): 3,
            'invalid': object()
        },
        object()  # invalid
    ])

    assert rv == [
        None,
        u('foo'),
        u('jäger'), 1, '2000-01-01T00:00:00Z', {
            u('jäger1'): 1,
            u('jäger2'): 2,
            u('bogus'): 3,
            u('invalid'): None
        }, None
    ]
Beispiel #2
0
 def to_dict(self, json_safe=False):
     """Exports the log record into a dictionary without the information
     that cannot be safely serialized like interpreter frames and
     tracebacks.
     """
     self.pull_information()
     rv = {}
     for key, value in iteritems(self.__dict__):
         if key[:1] != '_' and key not in self._noned_on_close:
             rv[key] = value
     # the extra dict is exported as regular dict
     rv['extra'] = dict(rv['extra'])
     if json_safe:
         return to_safe_json(rv)
     return rv
Beispiel #3
0
 def to_dict(self, json_safe=False):
     """Exports the log record into a dictionary without the information
     that cannot be safely serialized like interpreter frames and
     tracebacks.
     """
     self.pull_information()
     rv = {}
     for key, value in iteritems(self.__dict__):
         if key[:1] != '_' and key not in self._noned_on_close:
             rv[key] = value
     # the extra dict is exported as regular dict
     rv['extra'] = dict(rv['extra'])
     if json_safe:
         return to_safe_json(rv)
     return rv
Beispiel #4
0
 def test_jsonhelper(self):
     from logbook.helpers import to_safe_json
     class Bogus(object):
         def __str__(self):
             return 'bogus'
     rv = to_safe_json([
         None,
         'foo',
         u'jäger',
         1,
         datetime(2000, 1, 1),
         {'jäger1': 1, u'jäger2': 2, Bogus(): 3, 'invalid': object()},
         object()  # invalid
     ])
     self.assertEqual(
         rv, [None, u'foo', u'jäger', 1, '2000-01-01T00:00:00Z',
              {u'jäger1': 1, u'jäger2': 2, u'bogus': 3}])
Beispiel #5
0
def test_jsonhelper():
    from logbook.helpers import to_safe_json

    class Bogus(object):
        def __str__(self):
            return 'bogus'

    rv = to_safe_json([
        None,
        'foo',
        u('jäger'),
        1,
        datetime(2000, 1, 1),
        {'jäger1': 1, u('jäger2'): 2, Bogus(): 3, 'invalid': object()},
        object()  # invalid
    ])

    assert rv == [None, u('foo'), u('jäger'), 1, '2000-01-01T00:00:00Z',
             {u('jäger1'): 1, u('jäger2'): 2, u('bogus'): 3,
              u('invalid'): None}, None]