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

Python json.dumps函数代码示例

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

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



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

示例1: test_json_body_alternate_charset

 def test_json_body_alternate_charset(self):
     from pyramid.compat import json
     request = self._makeOne({'REQUEST_METHOD':'POST'})
     inp = text_(
         b'/\xe6\xb5\x81\xe8\xa1\x8c\xe8\xb6\x8b\xe5\x8a\xbf',
         'utf-8'
         )
     if PY3: # pragma: no cover
         body = bytes(json.dumps({'a':inp}), 'utf-16')
     else:
         body = json.dumps({'a':inp}).decode('utf-8').encode('utf-16')
     request.body = body
     request.content_type = 'application/json; charset=utf-16'
     self.assertEqual(request.json_body, {'a':inp})
开发者ID:HorizonXP,项目名称:pyramid,代码行数:14,代码来源:test_request.py


示例2: notify_observers

 def notify_observers(self, msg):
     out = json.dumps(msg)
     for obs in self.observers:
         obs.put(out)
         obs.put(StopIteration)
     # for now just kill observers once a message is sent instead
     # of playing with chunked encoding
     self.observers = []
开发者ID:dhiraka,项目名称:tictactoe-1,代码行数:8,代码来源:model.py


示例3: _render

 def _render(value, system):
     request = system.get('request')
     if request is not None:
         response = request.response
         ct = response.content_type
         if ct == response.default_content_type:
             response.content_type = 'application/json'
     return json.dumps(value, default=default_encoder)
开发者ID:yoshrote,项目名称:columns2,代码行数:8,代码来源:view.py


示例4: test_json_body_alternate_charset

 def test_json_body_alternate_charset(self):
     from pyramid.compat import json
     request = self._makeOne({'REQUEST_METHOD':'POST'})
     request.charset = 'latin-1'
     la = unicode('La Pe\xc3\xb1a', 'utf-8')
     body = json.dumps({'a':la}, encoding='latin-1')
     request.body = body
     self.assertEqual(request.json_body, {'a':la})
开发者ID:deshank,项目名称:pyramid,代码行数:8,代码来源:test_request.py


示例5: _render

 def _render(value, system):
     request = system.get("request")
     if request is not None:
         response = request.response
         ct = response.content_type
         if ct == response.default_content_type:
             response.content_type = "application/json"
     return json.dumps(value)
开发者ID:helduel,项目名称:pyramid,代码行数:8,代码来源:renderers.py


示例6: _makeDummyRequest

    def _makeDummyRequest(self, request_data=None):
        from pyramid.testing import DummyRequest
        request = DummyRequest()
        request.matched_route = DummyRoute('JSON-RPC')
        if request_data is not None:
            request.body = json.dumps(request_data)
            request.content_length = len(request.body)

        return request
开发者ID:kabhinav,项目名称:pyramid_rpc,代码行数:9,代码来源:test_jsonrpc.py


示例7: add_observer

 def add_observer(self, cursor=None):
     obs = self.Observer(game=self)
     if cursor == self.cursor or cursor is None:
         self.observers.append(obs)
     else:
         msg = json.dumps(self.updates[cursor+1])
         obs.put(msg)
         obs.put(StopIteration)
     return obs
开发者ID:dhiraka,项目名称:tictactoe-1,代码行数:9,代码来源:model.py


示例8: serialize

 def serialize(self):
     tracking = {
         'events': self.events,
         'alias': self.user_id if self.alias else None,
         'identify': self.user_id if self.user_id else None
     }
     return {
         'api_token': self.api_token,
         'tracking': tracking,
         'tracking_json': json.dumps(tracking)
     }
开发者ID:dfee,项目名称:pyramid_analytics,代码行数:11,代码来源:helpers.py


示例9: jsonrpc_error_response

def jsonrpc_error_response(error, id=None):
    """ Marshal a Python Exception into a webob ``Response``
    object with a body that is a JSON string suitable for use as
    a JSON-RPC response with a content-type of ``application/json``
    and return the response."""

    body = json.dumps({"jsonrpc": "2.0", "id": id, "error": error.as_dict()})

    response = Response(body)
    response.content_type = "application/json"
    response.content_length = len(body)
    return response
开发者ID:aodag,项目名称:pyramid_rpc,代码行数:12,代码来源:jsonrpc.py


示例10: test_view_callable_cls_with_dict

 def test_view_callable_cls_with_dict(self):
     target = self._makeOne()
     view_callable = target(DummyView)
     request = testing.DummyRequest()
     params = {'jsonrpc':'2.0', 'method':'dummy_rpc', 
               'params':dict(a=3, b=4), 'id':'test'}
     body = json.dumps(params)
     request.json_body = params
     request.rpc_args = dict(a=3, b=4)
     context = object()
     result = view_callable(context, request)
     self.assertEqual(result, 7)
开发者ID:kabhinav,项目名称:pyramid_rpc,代码行数:12,代码来源:test_jsonrpc.py


示例11: test_view_callable_cls_with_invalid_args

    def test_view_callable_cls_with_invalid_args(self):
        from pyramid_rpc.jsonrpc import JsonRpcParamsInvalid

        target = self._makeOne()
        view_callable = target(DummyView)
        request = testing.DummyRequest()
        params = {'jsonrpc':'2.0', 'method':'dummy_rpc', 
                  'params':[], 'id':'test'}
        body = json.dumps(params)
        request.json_body = params
        request.rpc_args = []
        context = object()
        self.assertRaises(JsonRpcParamsInvalid, view_callable, context, request)
开发者ID:kabhinav,项目名称:pyramid_rpc,代码行数:13,代码来源:test_jsonrpc.py


示例12: view_calendar

def view_calendar(context, request):

    kotti_calendar_resources.need()
    locale_name = get_locale_name(request)
    if locale_name in fullcalendar_locales:
        fullcalendar_locales[locale_name].need()
    else:  # pragma: no cover (safety belt only, should never happen)
        fullcalendar_locales["en"].need()

    session = DBSession()
    now = datetime.datetime.now()
    query = session.query(Event).filter(Event.parent_id == context.id)
    future = or_(Event.start > now, Event.end > now)
    upcoming = query.filter(future).order_by(Event.start).all()
    past = query.filter(Event.start < now).order_by(desc(Event.start)).all()
    upcoming = [event for event in upcoming if
                has_permission('view', event, request)]
    past = [event for event in past if
            has_permission('view', event, request)]

    fmt = '%Y-%m-%d %H:%M:%S'
    fullcalendar_events = []
    for event in (upcoming + past):
        json_event = {
            'title': event.title,
            'url': resource_url(event, request),
            'start': event.start.strftime(fmt),
            'allDay': event.all_day,
            }
        if event.end:
            json_event['end'] = event.end.strftime(fmt)
        fullcalendar_events.append(json_event)

    fullcalendar_options = {
        'header': {
            'left': 'prev,next today',
            'center': 'title',
            'right': 'month,agendaWeek,agendaDay'
        },
        'eventSources': context.feeds,
        'weekends': context.weekends,
        'events': fullcalendar_events,
        }

    return {
        'api': template_api(context, request),
        'upcoming_events': upcoming,
        'past_events': past,
        'fullcalendar_options': json.dumps(fullcalendar_options),
        }
开发者ID:tonthon,项目名称:kotti_calendar,代码行数:50,代码来源:views.py


示例13: test_it_with_no_id

 def test_it_with_no_id(self):
     def view(request):
         return request.rpc_args[0]
     config = self.config
     config.include('pyramid_rpc.jsonrpc')
     config.add_jsonrpc_endpoint('rpc', '/api/jsonrpc')
     config.add_jsonrpc_method(view, endpoint='rpc', method='dummy')
     app = config.make_wsgi_app()
     app = TestApp(app)
     params = {'jsonrpc': '2.0', 'method': 'dummy', 'params': [2, 3]}
     resp = app.post('/api/jsonrpc', content_type='application/json',
                       params=json.dumps(params))
     self.assertEqual(resp.status_int, 204)
     self.assertEqual(resp.body, '')
开发者ID:kabhinav,项目名称:pyramid_rpc,代码行数:14,代码来源:test_jsonrpc.py


示例14: test_it_with_invalid_method

 def test_it_with_invalid_method(self):
     config = self.config
     config.include('pyramid_rpc.jsonrpc')
     config.add_jsonrpc_endpoint('rpc', '/api/jsonrpc')
     app = config.make_wsgi_app()
     app = TestApp(app)
     params = {'jsonrpc': '2.0', 'id': 5, 'method': 'foo', 'params': [2, 3]}
     resp = app.post('/api/jsonrpc', content_type='application/json',
                       params=json.dumps(params))
     self.assertEqual(resp.status_int, 200)
     self.assertEqual(resp.content_type, 'application/json')
     result = json.loads(resp.body)
     self.assertEqual(result['id'], 5)
     self.assertEqual(result['jsonrpc'], '2.0')
     self.assertEqual(result['error']['code'], -32601)
开发者ID:kabhinav,项目名称:pyramid_rpc,代码行数:15,代码来源:test_jsonrpc.py


示例15: search

def search(context, request):
    sr = get_search_results(context, request)
    artists, albums, tracks, criteria = sr["artists"], sr["albums"], sr["tracks"], sr["criteria"]
    return dict(results=json.dumps({
        "artists": render_artists(artists,
                                  request,
                                  context),
        "albums": render_albums(context,
                                request,
                                albums or [],
                                show_artist=True)["items"],
        "tracks": render_tracks(tracks,
                                request,
                                show_artist=True),
        "criteria": criteria}), criteria=criteria)
开发者ID:twillis,项目名称:spazzer,代码行数:15,代码来源:views.py


示例16: view

    def view(self):
        """ Default view for :class:`kotti_calendar.resources.Calendar`

        :result: Dictionary needed to render the template.
        :rtype: dict
        """

        kotti_calendar_resources.need()
        lang_all_js.need()

        return {
            'api': template_api(self.context, self.request),
            'upcoming_events': self.upcoming_events,
            'past_events': self.past_events,
            'fullcalendar_options': json.dumps(self.fullcalendar_options),
            'event_url': self.event_url,
            }
开发者ID:Kotti,项目名称:kotti_calendar,代码行数:17,代码来源:views.py


示例17: _render

    def _render(value, system):
        request = system.get("request")
        if request is not None:
            rpc_id = getattr(request, "rpc_id", None)
            response = request.response

            if rpc_id is None:
                response.status = 204
                del response.content_type
                return ""

            ct = response.content_type
            if ct == response.default_content_type:
                response.content_type = "application/json"

            out = {"jsonrpc": "2.0", "id": rpc_id, "result": value}
            return json.dumps(out)
开发者ID:aodag,项目名称:pyramid_rpc,代码行数:17,代码来源:jsonrpc.py


示例18: test_it

    def test_it(self):
        try:
            # Pyramid 1.1
            from pyramid.renderers import null_renderer
            renderer = null_renderer
        except ImportError:
            # Pyramid 1.0
            renderer = None
        from pyramid.config import Configurator
        from pyramid_rpc.jsonrpc import jsonrpc_endpoint
        from pyramid_rpc.jsonrpc import JsonRpcViewMapper
        config = Configurator()
        config.add_route('JSON-RPC', 'apis/rpc')
        config.add_view(jsonrpc_endpoint, route_name='JSON-RPC')
        def dummy_rpc(request, a, b):
            return a + b
        config.add_view(route_name='JSON-RPC', name='dummy_rpc',
                        view=dummy_rpc, mapper=JsonRpcViewMapper,
                        renderer=renderer)
        
        config.add_route('JSON-RPC-CLS', 'apis/rpc/cls')
        config.add_view(jsonrpc_endpoint, route_name='JSON-RPC-CLS')
        config.add_view(route_name='JSON-RPC-CLS', name='dummy_rpc',
                        view=DummyView, mapper=JsonRpcViewMapper,
                        renderer=renderer)

        app = config.make_wsgi_app()
        import webtest
        app = webtest.TestApp(app)
        params = {'jsonrpc': '2.0', 'method': 'dummy_rpc',
                  'params': [2, 3], 'id': 'test'}
        body = json.dumps(params)
        res = app.post('/apis/rpc', params=body,
                       content_type='application/json')
        data = json.loads(res.body)
        self.assertEqual(data['id'], 'test')
        self.assertEqual(data['jsonrpc'], '2.0')
        self.assertEqual(data['result'], 5)
        
        res = app.post('/apis/rpc/cls', params=body,
                       content_type='application/json')
        data = json.loads(res.body)
        self.assertEqual(data['id'], 'test')
        self.assertEqual(data['jsonrpc'], '2.0')
        self.assertEqual(data['result'], 5)
开发者ID:kabhinav,项目名称:pyramid_rpc,代码行数:45,代码来源:test_jsonrpc.py


示例19: _render

    def _render(value, system):
        request = system.get('request')
        if request is not None:
            rpc_id = getattr(request, 'rpc_id', None)
            if rpc_id is None:
                raise HTTPNoContent()

            response = request.response
            ct = response.content_type
            if ct == response.default_content_type:
                response.content_type = 'application/json'

            out = {
                'jsonrpc' : JSONRPC_VERSION,
                'id' : rpc_id,
                'result' : value,
            }
            return json.dumps(out)
开发者ID:kabhinav,项目名称:pyramid_rpc,代码行数:18,代码来源:jsonrpc.py


示例20: view_calendar

def view_calendar(context, request):

    kotti_calendar_resources.need()
    locale_name = get_locale_name(request)
    if locale_name in fullcalendar_locales:
        fullcalendar_locales[locale_name].need()
    else:  # pragma: no cover (safety belt only, should never happen)
        fullcalendar_locales["en"].need()

    session = DBSession()
    now = datetime.datetime.now()
    query = session.query(Event).filter(Event.parent_id == context.id)
    future = or_(Event.start > now, Event.end > now)
    upcoming = query.filter(future).order_by(Event.start).all()
    past = query.filter(Event.start < now).order_by(desc(Event.start)).all()
    upcoming = [event for event in upcoming if has_permission("view", event, request)]
    past = [event for event in past if has_permission("view", event, request)]

    fmt = "%Y-%m-%d %H:%M:%S"
    fullcalendar_events = []
    for event in upcoming + past:
        json_event = {
            "title": event.title,
            "url": resource_url(event, request),
            "start": event.start.strftime(fmt),
            "allDay": event.all_day,
        }
        if event.end:
            json_event["end"] = event.end.strftime(fmt)
        fullcalendar_events.append(json_event)

    fullcalendar_options = {
        "header": {"left": "prev,next today", "center": "title", "right": "month,agendaWeek,agendaDay"},
        "eventSources": context.feeds,
        "weekends": context.weekends,
        "events": fullcalendar_events,
    }

    return {
        "api": template_api(context, request),
        "upcoming_events": upcoming,
        "past_events": past,
        "fullcalendar_options": json.dumps(fullcalendar_options),
    }
开发者ID:geojeff,项目名称:kotti_calendar,代码行数:44,代码来源:views.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python config.Configurator类代码示例发布时间:2022-05-27
下一篇:
Python compat.NativeIO类代码示例发布时间: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