当前位置: 首页>>代码示例>>Python>>正文


Python json.dumps函数代码示例

本文整理汇总了Python中raven.utils.json.dumps函数的典型用法代码示例。如果您正苦于以下问题:Python dumps函数的具体用法?Python dumps怎么用?Python dumps使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了dumps函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: encode

 def encode(self, data):
     """
     Serializes ``data`` into a raw string.
     """
     # not all data keys are json serializable
     data_copy = {}
     for key in data:
         try:
             json.dumps(data[key])  # check if serializable
             data_copy[key] = data[key]
         except TypeError:
             pass
     return base64.b64encode(zlib.compress(json.dumps(data_copy).encode('utf8')))
开发者ID:Goldmund-Wyldebeast-Wunderliebe,项目名称:raven-python,代码行数:13,代码来源:base.py

示例2: test_unknown_type

    def test_unknown_type(self):
        class Unknown(object):
            def __repr__(self):
                return "Unknown object"

        obj = Unknown()
        assert json.dumps(obj) == '"Unknown object"'
开发者ID:CGenie,项目名称:raven-python,代码行数:7,代码来源:tests.py

示例3: send

    def send(self, **data):
        """
        Sends the message to the server.

        If ``servers`` was passed into the constructor, this will serialize the data and pipe it to
        each server using ``send_remote()``. Otherwise, this will communicate with ``sentry.models.GroupedMessage``
        directly.
        """
        message = base64.b64encode(json.dumps(data).encode('zlib'))

        for url in self.servers:
            timestamp = time.time()
            signature = get_signature(message, timestamp, self.secret_key or self.key)
            headers = {
                'X-Sentry-Auth': get_auth_header(signature, timestamp, 'raven/%s' % (raven.VERSION,), self.public_key),
                'Content-Type': 'application/octet-stream',
            }

            try:
                self.send_remote(url=url, data=message, headers=headers)
            except urllib2.HTTPError, e:
                body = e.read()
                self.logger.error('Unable to reach Sentry log server: %s (url: %%s, body: %%s)' % (e,), url, body,
                             exc_info=True, extra={'data': {'body': body, 'remote_url': url}})
                self.logger.log(data.pop('level', None) or logging.ERROR, data.pop('message', None))
            except urllib2.URLError, e:
                self.logger.error('Unable to reach Sentry log server: %s (url: %%s)' % (e,), url,
                             exc_info=True, extra={'data': {'remote_url': url}})
                self.logger.log(data.pop('level', None) or logging.ERROR, data.pop('message', None))
开发者ID:Lothiraldan,项目名称:raven,代码行数:29,代码来源:base.py

示例4: test_recurse_exception

    def test_recurse_exception(self):
        class NonAsciiRepr(object):
            def __repr__(self):
                return six.b('中文')

        x = [NonAsciiRepr()]
        result = transform(x, max_depth=1)
        self.assertEqual(json.dumps(result), six.b('["<class \'tests.utils.encoding.tests.NonAsciiRepr\'>"]'))
开发者ID:CGenie,项目名称:raven-python,代码行数:8,代码来源:tests.py

示例5: test_custom_transport

    def test_custom_transport(self):
        c = Client(dsn="mock://some_username:[email protected]:8143/1")

        data = dict(a=42, b=55, c=list(range(50)))
        c.send(**data)

        mock_cls = c._transport_cache['mock://some_username:[email protected]:8143/1'].get_transport()

        expected_message = zlib.decompress(c.encode(data))
        actual_message = zlib.decompress(mock_cls._data)

        # These loads()/dumps() pairs order the dict keys before comparing the string.
        # See GH504
        self.assertEqual(
            json.dumps(json.loads(expected_message.decode('utf-8')), sort_keys=True),
            json.dumps(json.loads(actual_message.decode('utf-8')), sort_keys=True)
        )
开发者ID:MSeal,项目名称:raven-python,代码行数:17,代码来源:tests.py

示例6: test_custom_transport

    def test_custom_transport(self):
        c = Client(dsn="mock://some_username:[email protected]:8143/1")

        data = dict(a=42, b=55, c=list(range(50)))
        c.send(**data)

        expected_message = zlib.decompress(base64.b64decode(c.encode(data)))
        self.assertIn('mock://localhost:8143/api/1/store/', Client._registry._transports)
        mock_cls = Client._registry._transports['mock://localhost:8143/api/1/store/']

        actual_message = zlib.decompress(base64.b64decode(mock_cls._data))

        # These loads()/dumps() pairs order the dict keys before comparing the string.
        # See GH504
        self.assertEqual(
            json.dumps(json.loads(expected_message.decode('utf-8')), sort_keys=True),
            json.dumps(json.loads(actual_message.decode('utf-8')), sort_keys=True)
        )
开发者ID:alexkiro,项目名称:raven-python,代码行数:18,代码来源:tests.py

示例7: _convert_to_json

def _convert_to_json(sentry_data):
    """Tries to convert data to json using Raven's json
    serialiser. Everything in data should be serializable except
    possibly the contents of
    sentry_data['sentry.interfaces.Exception']. If a serialisation
    error occurs, a new attempt is made without the exception info. If
    that also doesn't work, then an empty JSON string '{}' is
    returned."""

    try:
        return json.dumps(sentry_data)
    except TypeError, e:
        # try again without exception info
        if record.exc_info:
            sentry_data.pop(SENTRY_INTERFACES_EXCEPTION)
            try:
                return json.dumps(sentry_data)
            except TypeError, e:
                pass
开发者ID:jakm,项目名称:snitch,代码行数:19,代码来源:log2json.py

示例8: send

    def send(self, **data):
        """
        Sends the message to the server.

        If ``servers`` was passed into the constructor, this will serialize the data and pipe it to
        each server using ``send_remote()``. Otherwise, this will communicate with ``sentry.models.GroupedMessage``
        directly.
        """
        message = base64.b64encode(json.dumps(data).encode('zlib'))

        for url in self.servers:
            timestamp = time.time()
            signature = get_signature(message, timestamp, self.secret_key or self.key)
            headers = {
                'X-Sentry-Auth': get_auth_header(signature, timestamp, 'raven/%s' % (raven.VERSION,), self.public_key),
                'Content-Type': 'application/octet-stream',
            }

            self.send_remote(url=url, data=message, headers=headers)
开发者ID:mahendra,项目名称:raven,代码行数:19,代码来源:base.py

示例9: test_scrub_sensitive_post

    def test_scrub_sensitive_post(self):
        config = self.config

        def view(request):
            self.request = request
            raise ExpectedException()

        config.add_view(view, name='', renderer='string')

        app = self._makeApp()

        with mock.patch.object(pyramid_crow.Client,
                               'send') as mock_send:
            self.assertRaises(ExpectedException, app.post, '/',
                              params=(('password', 'ohno'),))

        sentry_data = mock_send.call_args[1]

        dumped_data = json.dumps(sentry_data)
        self.assertNotIn('ohno', dumped_data)
开发者ID:douglatornell,项目名称:pyramid_crow,代码行数:20,代码来源:tests.py

示例10: send

    def send(self, **kwargs):
        """
        Sends the message to the server.

        If ``servers`` was passed into the constructor, this will serialize the data and pipe it to
        each server using ``send_remote()``. Otherwise, this will communicate with ``sentry.models.GroupedMessage``
        directly.
        """
        message = base64.b64encode(json.dumps(kwargs).encode("zlib"))
        for url in self.servers:
            timestamp = time.time()
            signature = get_signature(self.key, message, timestamp)
            headers = {
                "Authorization": get_auth_header(
                    signature, timestamp, "%s/%s" % (self.__class__.__name__, raven.VERSION)
                ),
                "Content-Type": "application/octet-stream",
            }

            try:
                self.send_remote(url=url, data=message, headers=headers)
            except urllib2.HTTPError, e:
                body = e.read()
                logger.error(
                    "Unable to reach Sentry log server: %s (url: %%s, body: %%s)" % (e,),
                    url,
                    body,
                    exc_info=True,
                    extra={"data": {"body": body, "remote_url": url}},
                )
                logger.log(kwargs.pop("level", None) or logging.ERROR, kwargs.pop("message", None))
            except urllib2.URLError, e:
                logger.error(
                    "Unable to reach Sentry log server: %s (url: %%s)" % (e,),
                    url,
                    exc_info=True,
                    extra={"data": {"remote_url": url}},
                )
                logger.log(kwargs.pop("level", None) or logging.ERROR, kwargs.pop("message", None))
开发者ID:ncfcmark,项目名称:raven-python,代码行数:39,代码来源:base.py

示例11: test_uuid

 def test_uuid(self):
     res = uuid.uuid4()
     json.dumps(res) == '"%s"' % res.hex
开发者ID:1Anastaska,项目名称:raven-python,代码行数:3,代码来源:tests.py

示例12: test_frozenset

 def test_frozenset(self):
     res = frozenset(['foo', 'bar'])
     self.assertEquals(json.dumps(res), '["foo", "bar"]')
开发者ID:Ender27182818,项目名称:raven,代码行数:3,代码来源:tests.py

示例13: test_datetime

 def test_datetime(self):
     res = datetime.datetime(day=1, month=1, year=2011, hour=1, minute=1, second=1)
     self.assertEquals(json.dumps(res), '"2011-01-01T01:01:01.000000Z"')
开发者ID:Ender27182818,项目名称:raven,代码行数:3,代码来源:tests.py

示例14: test_uuid

 def test_uuid(self):
     res = uuid.uuid4()
     self.assertEquals(json.dumps(res), '"%s"' % res.hex)
开发者ID:Ender27182818,项目名称:raven,代码行数:3,代码来源:tests.py

示例15: test_decimal

 def test_decimal(self):
     d = {"decimal": Decimal("123.45")}
     assert json.dumps(d) == '{"decimal": "Decimal(\'123.45\')"}'
开发者ID:CGenie,项目名称:raven-python,代码行数:3,代码来源:tests.py


注:本文中的raven.utils.json.dumps函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。