• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python jsonutil.dumps函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_separators

    def test_separators(self):
        h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh', 'i-vhbjkhnth',
             {'nifty': 87}, {'field': 'yes', 'morefield': False} ]

        expect = textwrap.dedent("""\
        [
          [
            "blorpie"
          ] ,
          [
            "whoops"
          ] ,
          [] ,
          "d-shtaeou" ,
          "d-nthiouh" ,
          "i-vhbjkhnth" ,
          {
            "nifty" : 87
          } ,
          {
            "field" : "yes" ,
            "morefield" : false
          }
        ]""")


        d1 = json.dumps(h)
        d2 = json.dumps(h, indent=2, sort_keys=True, separators=(' ,', ' : '))

        h1 = json.loads(d1)
        h2 = json.loads(d2)

        self.assertEquals(h1, h)
        self.assertEquals(h2, h)
        self.assertEquals(d2, expect)
开发者ID:bingwei,项目名称:pyutil,代码行数:35,代码来源:test_separators.py


示例2: test_dictrecursion

 def test_dictrecursion(self):
     x = {}
     x["test"] = x
     try:
         json.dumps(x)
     except ValueError:
         pass
     else:
         self.fail("didn't raise ValueError on dict recursion")
     x = {}
     {"a": x, "b": x}
     # ensure that the marker is cleared
     json.dumps(x)
开发者ID:ANTH040,项目名称:CouchPotatoServer,代码行数:13,代码来源:test_recursion.py


示例3: test_dont_Featureify_results

    def test_dont_Featureify_results(self):
        """ _request() is required to return the exact string that the HTTP
        server sent to it -- no transforming it, such as by json-decoding and
        then constructing a Feature. """

        EXAMPLE_RECORD_JSONSTR=json.dumps({ 'geometry' : { 'type' : 'Point', 'coordinates' : [D('10.0'), D('11.0')] }, 'id' : 'my_id', 'type' : 'Feature', 'properties' : { 'key' : 'value'  , 'type' : 'object' } })

        mockhttp = mock.Mock()
        mockhttp.request.return_value = ({'status': '200', 'content-type': 'application/json', }, EXAMPLE_RECORD_JSONSTR)
        self.client.places.http = mockhttp
        res = self.client.places._request("http://thing", 'POST')[1]
        self.failUnlessEqual(res, EXAMPLE_RECORD_JSONSTR)
开发者ID:dsmith,项目名称:python-simplegeo,代码行数:12,代码来源:test_places.py


示例4: test_annotate

    def test_annotate(self):
        mockhttp = mock.Mock()
        headers = {'status': '200', 'content-type': 'application/json'}
        mockhttp.request.return_value = (headers, json.dumps(EXAMPLE_ANNOTATE_RESPONSE))
        self.client.http = mockhttp

        res = self.client.annotate(self.handle, EXAMPLE_ANNOTATIONS, True)

        self.assertEqual(mockhttp.method_calls[0][0], 'request')
        self.assertEqual(mockhttp.method_calls[0][1][0], 'http://api.simplegeo.com:80/%s/features/%s/annotations.json' % (API_VERSION, self.handle))
        self.assertEqual(mockhttp.method_calls[0][1][1], 'POST')

        # Make sure client returns a dict.
        self.failUnless(isinstance(res, dict))
开发者ID:dsmith,项目名称:python-simplegeo,代码行数:14,代码来源:test_client.py


示例5: test_dont_Recordify_results

    def test_dont_Recordify_results(self):
        """ _request() is required to return the exact string that the HTTP
        server sent to it -- no transforming it, such as by json-decoding and
        then constructing a Record. """

        EXAMPLE_RECORD_JSONSTR=json.dumps({ 'geometry' : { 'type' : 'Point', 'coordinates' : [D('10.0'), D('11.0')] }, 'id' : 'my_id', 'type' : 'Feature', 'properties' : { 'key' : 'value'  , 'type' : 'object' } })

        mockagent = MockAgent(FakeSuccessResponse([EXAMPLE_RECORD_JSONSTR], {'status': '200', 'content-type': 'application/json'}))
        self.client.agent = mockagent

        d = self.client._request("http://thing", 'POST')
        d.addCallback(get_body)
        def check(res):
            self.failUnlessEqual(res, EXAMPLE_RECORD_JSONSTR)
        d.addCallback(check)
        return d
开发者ID:simplegeo,项目名称:python-txsimplegeo.shared,代码行数:16,代码来源:test_client.py


示例6: annotate

    def annotate(self, simplegeohandle, annotations, private):
        if not isinstance(annotations, dict):
            raise TypeError('annotations must be of type dict')
        if not len(annotations.keys()):
            raise ValueError('annotations dict is empty')
        for annotation_type in annotations.keys():
            if not len(annotations[annotation_type].keys()):
                raise ValueError('annotation type "%s" is empty' % annotation_type)
        if not isinstance(private, bool):
            raise TypeError('private must be of type bool')

        data = {'annotations': annotations,
                'private': private}

        endpoint = self._endpoint('annotations', simplegeohandle=simplegeohandle)
        return json_decode(self._request(endpoint,
                                        'POST',
                                        data=json.dumps(data))[1])
开发者ID:ieure,项目名称:python-simplegeo,代码行数:18,代码来源:__init__.py


示例7: test_listrecursion

 def test_listrecursion(self):
     x = []
     x.append(x)
     try:
         json.dumps(x)
     except ValueError:
         pass
     else:
         self.fail("didn't raise ValueError on list recursion")
     x = []
     y = [x]
     x.append(y)
     try:
         json.dumps(x)
     except ValueError:
         pass
     else:
         self.fail("didn't raise ValueError on alternating list recursion")
     y = []
     x = [y, y]
     # ensure that the marker is cleared
     json.dumps(x)
开发者ID:ANTH040,项目名称:CouchPotatoServer,代码行数:22,代码来源:test_recursion.py


示例8: test_search

    def test_search(self):
        rec1 = Feature((D('11.03'), D('10.04')), simplegeohandle='SG_abcdefghijkmlnopqrstuv', properties={'name': "Bob's House Of Monkeys", 'category': "monkey dealership"})
        rec2 = Feature((D('11.03'), D('10.05')), simplegeohandle='SG_abcdefghijkmlnopqrstuv', properties={'name': "Monkey Food 'R' Us", 'category': "pet food store"})

        mockhttp = mock.Mock()
        mockhttp.request.return_value = ({'status': '200', 'content-type': 'application/json', }, json.dumps({'type': "FeatureColllection", 'features': [rec1.to_dict(), rec2.to_dict()]}))
        self.client.places.http = mockhttp

        self.failUnlessRaises(AssertionError, self.client.places.search, -91, 100)
        self.failUnlessRaises(AssertionError, self.client.places.search, -81, 361)

        lat = D('11.03')
        lon = D('10.04')
        res = self.client.places.search(lat, lon, query='monkeys', category='animal')
        self.failUnless(isinstance(res, (list, tuple)), (repr(res), type(res)))
        self.failUnlessEqual(len(res), 2)
        self.failUnless(all(isinstance(f, Feature) for f in res))
        self.assertEqual(mockhttp.method_calls[0][0], 'request')
        self.assertEqual(mockhttp.method_calls[0][1][0], 'http://api.simplegeo.com:80/%s/places/%s,%s.json?q=monkeys&category=animal' % (API_VERSION, lat, lon))
        self.assertEqual(mockhttp.method_calls[0][1][1], 'GET')
开发者ID:dsmith,项目名称:python-simplegeo,代码行数:20,代码来源:test_places.py


示例9: test_search_by_my_ip_nonascii

    def test_search_by_my_ip_nonascii(self):
        rec1 = Feature((D('11.03'), D('10.04')), simplegeohandle='SG_abcdefghijkmlnopqrstuv', properties={'name': "Bob's House Of Monkeys", 'category': "monkey dealership"})
        rec2 = Feature((D('11.03'), D('10.05')), simplegeohandle='SG_abcdefghijkmlnopqrstuv', properties={'name': "Monkey Food 'R' Us", 'category': "pet food store"})

        mockhttp = mock.Mock()
        mockhttp.request.return_value = ({'status': '200', 'content-type': 'application/json', }, json.dumps({'type': "FeatureColllection", 'features': [rec1.to_dict(), rec2.to_dict()]}))
        self.client.places.http = mockhttp

        ipaddr = '192.0.32.10'
        self.failUnlessRaises(AssertionError, self.client.places.search_by_my_ip, ipaddr) # Someone accidentally passed an ip addr to search_by_my_ip().

        res = self.client.places.search_by_my_ip(query='monk❥y', category='animal')
        self.failUnless(isinstance(res, (list, tuple)), (repr(res), type(res)))
        self.failUnlessEqual(len(res), 2)
        self.failUnless(all(isinstance(f, Feature) for f in res))
        self.assertEqual(mockhttp.method_calls[-1][0], 'request')
        urlused = mockhttp.method_calls[-1][1][0]
        urlused = urllib.unquote(urlused).decode('utf-8')
        self.assertEqual(urlused, u'http://api.simplegeo.com:80/%s/places/ip.json?q=monk❥y&category=animal' % (API_VERSION,))
        self.assertEqual(mockhttp.method_calls[0][1][1], 'GET')

        res = self.client.places.search_by_my_ip(query='monk❥y', category='anim❥l')
        self.failUnless(isinstance(res, (list, tuple)), (repr(res), type(res)))
        self.failUnlessEqual(len(res), 2)
        self.failUnless(all(isinstance(f, Feature) for f in res))
        self.assertEqual(mockhttp.method_calls[-1][0], 'request')
        urlused = mockhttp.method_calls[-1][1][0]
        urlused = urllib.unquote(urlused).decode('utf-8')
        self.assertEqual(urlused, u'http://api.simplegeo.com:80/%s/places/ip.json?q=monk❥y&category=anim❥l' % (API_VERSION,))
        self.assertEqual(mockhttp.method_calls[0][1][1], 'GET')
开发者ID:dsmith,项目名称:python-simplegeo,代码行数:30,代码来源:test_places.py


示例10: test_encoding6

 def test_encoding6(self):
     u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
     j = json.dumps([u], ensure_ascii=False)
     self.assertEquals(j, u'["%s"]' % (u,))
开发者ID:bingwei,项目名称:pyutil,代码行数:4,代码来源:test_unicode.py


示例11: test_encoding4

 def test_encoding4(self):
     u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
     j = json.dumps([u])
     self.assertEquals(j, '["\\u03b1\\u03a9"]')
开发者ID:bingwei,项目名称:pyutil,代码行数:4,代码来源:test_unicode.py


示例12: test_no_terms_search_by_ip

    def test_no_terms_search_by_ip(self):
        rec1 = Feature((D('11.03'), D('10.04')), simplegeohandle='SG_abcdefghijkmlnopqrstuv', properties={'name': "Bob's House Of Monkeys", 'category': "monkey dealership"})
        rec2 = Feature((D('11.03'), D('10.05')), simplegeohandle='SG_abcdefghijkmlnopqrstuv', properties={'name': "Monkey Food 'R' Us", 'category': "pet food store"})

        mockhttp = mock.Mock()
        mockhttp.request.return_value = ({'status': '200', 'content-type': 'application/json', }, json.dumps({'type': "FeatureColllection", 'features': [rec1.to_dict(), rec2.to_dict()]}))
        self.client.places.http = mockhttp

        ipaddr = '192.0.32.10'
        res = self.client.places.search_by_ip(ipaddr)
        self.failUnless(isinstance(res, (list, tuple)), (repr(res), type(res)))
        self.failUnlessEqual(len(res), 2)
        self.failUnless(all(isinstance(f, Feature) for f in res))
        self.assertEqual(mockhttp.method_calls[0][0], 'request')
        self.assertEqual(mockhttp.method_calls[0][1][0], 'http://api.simplegeo.com:80/%s/places/%s.json' % (API_VERSION, ipaddr))
        self.assertEqual(mockhttp.method_calls[0][1][1], 'GET')
开发者ID:dsmith,项目名称:python-simplegeo,代码行数:16,代码来源:test_places.py


示例13: test_dumps

 def test_dumps(self):
     self.assertEquals(json.dumps({}), '{}')
开发者ID:ANTH040,项目名称:CouchPotatoServer,代码行数:2,代码来源:test_dump.py


示例14: mockrequest

        def mockrequest(*args, **kwargs):
            self.assertEqual(args[0], 'http://api.simplegeo.com:80/%s/places' % (API_VERSION,))
            self.assertEqual(args[1], 'POST')

            bodyobj = json.loads(kwargs['body'])
            self.failUnlessEqual(bodyobj['id'], None)
            methods_called.append(('request', args, kwargs))
            mockhttp.request = mockrequest2
            return ({'status': '202', 'content-type': 'application/json', 'location': newloc}, json.dumps({'id': handle}))
开发者ID:dsmith,项目名称:python-simplegeo,代码行数:9,代码来源:test_places.py


示例15: test_radius_search_by_my_ip

    def test_radius_search_by_my_ip(self):
        mockhttp = mock.Mock()
        mockhttp.request.return_value = ({'status': '200', 'content-type': 'application/json', }, json.dumps({'type': "FeatureColllection", 'features': []}))
        self.client.places.http = mockhttp

        ipaddr = '192.0.32.10'
        radius = D('0.01')
        self.failUnlessRaises((AssertionError, TypeError), self.client.places.search_by_my_ip, ipaddr, radius=radius) # Someone accidentally passed an ip addr to search_by_my_ip().

        res = self.client.places.search_by_my_ip(radius=radius)
        self.failUnless(isinstance(res, (list, tuple)), (repr(res), type(res)))
        self.failUnlessEqual(len(res), 0)

        self.assertEqual(mockhttp.method_calls[0][0], 'request')
        self.assertEqual(mockhttp.method_calls[0][1][0], 'http://api.simplegeo.com:80/%s/places/ip.json?radius=%s' % (API_VERSION, radius))
        self.assertEqual(mockhttp.method_calls[0][1][1], 'GET')
开发者ID:dsmith,项目名称:python-simplegeo,代码行数:16,代码来源:test_places.py


示例16: test_floats

 def test_floats(self):
     for num in [1617161771.7650001, math.pi, math.pi**100, math.pi**-100]:
         self.assertEquals(float(json.dumps(num)), num)
开发者ID:ANTH040,项目名称:CouchPotatoServer,代码行数:3,代码来源:test_float.py


示例17: test_encode

 def test_encode(self):
     self.failUnlessEqual(jsonutil.dumps(zero_point_one), "0.1")
开发者ID:ANTH040,项目名称:CouchPotatoServer,代码行数:2,代码来源:test_jsonutil.py


示例18: test_default

 def test_default(self):
     self.assertEquals(
         json.dumps(type, default=repr),
         json.dumps(repr(type)))
开发者ID:bingwei,项目名称:pyutil,代码行数:4,代码来源:test_default.py


示例19: ue

def ue(N):
    return jsonutil.dumps(l)
开发者ID:ANTH040,项目名称:CouchPotatoServer,代码行数:2,代码来源:bench_json.py


示例20: test_parse

 def test_parse(self):
     # test in/out equivalence and parsing
     res = json.loads(JSON)
     out = json.dumps(res)
     self.assertEquals(res, json.loads(out))
     self.failUnless("2.3456789012E+676" in json.dumps(res, allow_nan=False))
开发者ID:ANTH040,项目名称:CouchPotatoServer,代码行数:6,代码来源:test_pass1.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python misc.Options类代码示例发布时间:2022-05-27
下一篇:
Python ucare_cli.main函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap