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

Python renderers.JSON类代码示例

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

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



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

示例1: main

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine

    config = Configurator(settings=settings)
    json_renderer = JSON()

    def dataframe_adapter(df, request):
        return df.to_dict(orient="records")

    json_renderer.add_adapter(DataFrame, dataframe_adapter)
    config.add_renderer('json', json_renderer)

    config.include('pyramid_jinja2')
    config.include('pyramid_tm')

    config.add_static_view('static', 'static', cache_max_age=3600)

    config.add_route('home', '/')
    config.add_route('about', '/about')
    config.add_route('search', '/search/{name}')
    config.add_route('dropdown', '/dropdown/{namekey}')

    config.scan()

    return config.make_wsgi_app()
开发者ID:jay-tyler,项目名称:data-petting-zoo,代码行数:29,代码来源:__init__.py


示例2: main

def main(global_config, **settings):
    config = Configurator(settings=settings)
    config.include('pyramid_chameleon')

    config.registry.db = DatabaseClient()
    config.registry.dvr = DVR()
    
    def db(request):
        return config.registry.db

    def dvr(request):
        return config.registry.dvr

    config.add_request_method(db, 'db', reify=True)
    config.add_request_method(dvr, 'dvr', reify=True)
    
    json_renderer = JSON()
    def datetime_adapter(obj, request):
        return obj.isoformat()
    json_renderer.add_adapter(datetime.datetime, datetime_adapter)
    json_renderer.add_adapter(datetime.date, datetime_adapter)
    config.add_renderer('json', json_renderer)
    
    config.add_route('index', '/')
    config.add_route('recordings', 'recordings')
    config.add_route('recording', 'recording/{id}')
    config.add_route('delete_recording', 'delete_recording/{id}')
    config.add_route('skip_recording', 'skip_recording/{id}')
    config.add_route('enable_recording', 'enable_recording/{id}')
    config.add_route('season_passes', 'season_passes')
    config.add_route('add_season_pass', 'add_season_pass')
    config.add_route('search', 'search')
    config.scan('.views')
    return config.make_wsgi_app()
开发者ID:dcheckoway,项目名称:peaver,代码行数:34,代码来源:__init__.py


示例3: main

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    settings['sqlalchemy.url'] = settings['cn.dialect'] + quote_plus(settings['sqlalchemy.url'])
    engine = engine_from_config(settings, 'sqlalchemy.')
    dbConfig['url'] = settings['sqlalchemy.url']
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.create_all(engine)
    Base.metadata.reflect(views=True, extend_existing=False)

    config = Configurator(settings=settings)
    # Add renderer for datetime objects
    json_renderer = JSON()
    json_renderer.add_adapter(datetime, datetime_adapter)
    json_renderer.add_adapter(Decimal, decimal_adapter)
    config.add_renderer('json', json_renderer)

    # Set up authentication and authorization
    includeme(config)
    config.set_root_factory(SecurityRoot)


    # Set the default permission level to 'read'
    config.set_default_permission('read')
    config.include('pyramid_tm')
    add_routes(config)
    config.scan()
    return config.make_wsgi_app()
开发者ID:gerald13,项目名称:NsPortal,代码行数:29,代码来源:__init__.py


示例4: main

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine

    config = Configurator(settings=settings)
    config.include('cornice')
    config.include('pyramid_mako')

    json_renderer = JSON()
    def datetime_adapter(obj, request):
        return obj.strftime('%Y-%m-%d %H:%M:%S')
    json_renderer.add_adapter(datetime.datetime, datetime_adapter)

    def dictable_adapter(obj, request):
        return obj.asdict()
    json_renderer.add_adapter(DictableModel, dictable_adapter)

    config.add_renderer('json', json_renderer)

    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/')
    config.scan()
    return config.make_wsgi_app()
开发者ID:sebthauvette,项目名称:test,代码行数:26,代码来源:__init__.py


示例5: main

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(settings=settings)

    json_renderer = JSON()

    def datetime_adapter(obj, request):
        return obj.isoformat()

    json_renderer.add_adapter(datetime, datetime_adapter)
    config.add_renderer('json', json_renderer)

    config.include('pyramid_jinja2')
    config.include('.models')
    config.include('.routes')
    config.set_authentication_policy(MixedTokenAuthenticationPolicy())
    config.set_authorization_policy(
        AlwaysPassAuthenticatedAuthorizationPolicy()
    )

    enabled_registration_modules = settings.get(
        'pydiditpyramidgateway.enabled_registration_modules'
    )
    if enabled_registration_modules is not None:
        enabled_registration_modules = config.maybe_dotted(
            enabled_registration_modules.split(',')
        )
        for module in enabled_registration_modules:
            config.include(module)

    config.scan()
    pydiditbackend.initialize(json.loads(settings['backend_settings']))
    return config.make_wsgi_app()
开发者ID:adamlincoln,项目名称:PydiditPyramidGateway,代码行数:34,代码来源:__init__.py


示例6: main

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application. """


    config = Configurator(settings=settings)

    #set up beaker session
    session_factory = session_factory_from_settings(settings)
    config.set_session_factory(session_factory)


    # add security tweens
 #   config.add_tween('aws_demo.tweens.clickjacking.clickjacking_factory')
 #   config.add_tween('aws_demo.tweens.secure_headers.secure_headers_factory')

    config.registry['mailer'] = Mailer.from_settings(settings=settings)

    # modify the built in json renderer to serialize dates properly
    json_date_renderer = JSON()
    json_date_renderer.add_adapter(datetime.datetime, new_datetime_adapter)
    
    # set .html renderer to allow mako templating
    config.add_renderer('.html', 'pyramid.mako_templating.renderer_factory')
    config.add_renderer('.htm', 'pyramid.mako_templating.renderer_factory')
    config.add_renderer('json', json_date_renderer)
    
    config.add_static_view('static', 'static', cache_max_age=3600)

    # login / registration
    config.add_route('index_view', '/')


    config.scan()
    return config.make_wsgi_app()
开发者ID:k-wiens,项目名称:Blah,代码行数:34,代码来源:__init__.py


示例7: includeme

def includeme(config):
    ''' Pyramid includeme '''
    json_renderer = JSON(indent=4)

    json_renderer.add_adapter(datetime.datetime, datetime_adapter)
    json_renderer.add_adapter(datetime.date, datetime_adapter)

    config.add_renderer('json', json_renderer)
开发者ID:silenius,项目名称:amnesia,代码行数:8,代码来源:json.py


示例8: main

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    settings['sqlalchemy.url'] = settings['cn.dialect'] + quote_plus(settings['sqlalchemy.url'])
    engine = engine_from_config(settings, 'sqlalchemy.')
    dbConfig['url'] = settings['sqlalchemy.url']

    """ Configuration de la connexion à la BDD """
    # DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.create_all(engine)
    Base.metadata.reflect(views=True)

    """ Configuration du serveur pyramid"""
    config = Configurator(settings=settings)
    # Add renderer for datetime objects
    json_renderer = JSON()
    json_renderer.add_adapter(datetime, datetime_adapter)
    json_renderer.add_adapter(date, date_adapter)
    json_renderer.add_adapter(Decimal, decimal_adapter)
    json_renderer.add_adapter(bytes, bytes_adapter)
    config.add_renderer('json', json_renderer)
    config.registry.dbmaker = scoped_session(sessionmaker(bind=engine))
    config.add_request_method(db, name='dbsession', reify=True)
    # Set up authentication and authorization

    config.set_root_factory(SecurityRoot)
    config.add_subscriber(add_cors_headers_response_callback, NewRequest)

    # Set the default permission level to 'read'
    config.set_default_permission('read')
    config.include('pyramid_tm')
    add_routes(config)
    config.scan()
    return config.make_wsgi_app()
开发者ID:NaturalSolutions,项目名称:notification,代码行数:35,代码来源:__init__.py


示例9: includeme

def includeme(config):
    """
    RPC loader for Pyramid
    """
    global _do_xmlrpc, _do_jsonrpc
    cfg = config.registry.settings
    _do_xmlrpc = asbool(cfg.get('netprofile.rpc.xmlrpc', True))
    _do_jsonrpc = asbool(cfg.get('netprofile.rpc.jsonrpc', True))

    if _do_xmlrpc:
        config.include('pyramid_rpc.xmlrpc')
        config.add_xmlrpc_endpoint('api.xmlrpc', '/api/xmlrpc')
    if _do_jsonrpc:
        config.include('pyramid_rpc.jsonrpc')
        renderer = JSON()

        def _json_datetime(obj, req):
            if obj.tzinfo is None:
                obj = obj.replace(tzinfo=tzlocal())
            return obj.isoformat()

        renderer.add_adapter(dt.datetime, _json_datetime)
        renderer.add_adapter(dt.date, lambda obj, req: obj.isoformat())
        renderer.add_adapter(dt.time, lambda obj, req: obj.isoformat())
        renderer.add_adapter(ipaddress.IPv4Address, lambda obj, req: int(obj))
        renderer.add_adapter(decimal.Decimal, lambda obj, req: str(obj))
        config.add_renderer('jsonrpc', renderer)
        config.add_jsonrpc_endpoint('api.jsonrpc', '/api/jsonrpc',
                                    default_renderer='jsonrpc')

    config.scan()
开发者ID:unikmhz,项目名称:npui,代码行数:31,代码来源:rpc.py


示例10: main

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    init_model()

    session_factory = session_factory_from_settings(settings)
    if 'localization' not in settings:
        settings['localization'] = 'id_ID.UTF-8'
    locale.setlocale(locale.LC_ALL, settings['localization'])        
    if 'timezone' not in settings:
        settings['timezone'] = DefaultTimeZone
    config = Configurator(settings=settings,
                          root_factory='reklame.models.RootFactory',
                          session_factory=session_factory)
    config.include('pyramid_beaker')                          
    config.include('pyramid_chameleon')

    authn_policy = AuthTktAuthenticationPolicy('sosecret',
                    callback=group_finder, hashalg='sha512')
    authz_policy = ACLAuthorizationPolicy()                          
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)
    config.add_request_method(get_user, 'user', reify=True)
    config.add_request_method(get_title, 'title', reify=True)
    config.add_notfound_view(RemoveSlashNotFoundViewFactory())        
                          
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view('deform_static', 'deform:static')
    config.add_static_view('files', settings['static_files'])    
    ############################################################################
    config.include('pyramid_rpc.jsonrpc') # JSON RPC
    json_renderer = JSON()
    json_renderer.add_adapter(datetime.datetime, lambda v, request: v.isoformat())
    json_renderer.add_adapter(datetime.date, lambda v, request: v.isoformat())
    config.add_renderer('myjson', json_renderer)
    config.add_jsonrpc_endpoint('ws_reklame', '/ws/reklame', default_renderer="myjson")       
    ############################################################################
 
    routes = DBSession.query(Route.kode, Route.path, Route.nama).all()
    for route in routes:
        config.add_route(route.kode, route.path)
        if route.nama:
            titles[route.kode] = ' - '.join([main_title, route.nama])     
            
    
    config.scan()
    
    app = config.make_wsgi_app()
    from paste.translogger import TransLogger
    app = TransLogger(app, setup_console_handler=False)    
    return app
开发者ID:aagusti,项目名称:opensipkd-reklame,代码行数:54,代码来源:__init__.py


示例11: patch_json_renderer

def patch_json_renderer():
    """ Returns a patched JSON renderer capable of serializing custom
    objects.
    """

    def datetime_adapter(obj, request):
        return int(obj.strftime('%s'))

    renderer = JSON()
    renderer.add_adapter(datetime.datetime, datetime_adapter)

    return renderer
开发者ID:kanemathers,项目名称:gitdeployed,代码行数:12,代码来源:__init__.py


示例12: includeme

def includeme(config):
    json_renderer = JSON()

    def datetime_adapter(obj, request):
        return obj.isoformat()
    json_renderer.add_adapter(datetime.datetime, datetime_adapter)

    def uuid_adapter(obj, request):
        return str(obj)
    json_renderer.add_adapter(uuid.UUID, uuid_adapter)

    config.add_renderer('json', json_renderer)
开发者ID:cdunklau,项目名称:alexandria,代码行数:12,代码来源:renderer.py


示例13: main

def main(global_config, **settings):
    """ 
    This function returns a Pyramid WSGI application.
    """
    config = Configurator(settings=settings)
    config.add_static_view('static', 'static', cache_max_age=3600)

    # Use jinja2 as templating language
    config.include('pyramid_jinja2')

    # Add a datetime json renderer adapter.
    # This snippet comes from:
    # http://docs.pylonsproject.org/projects/pyramid/en/master/narr/renderers.html#using-the-add-adapter-method-of-a-custom-json-renderer
    json_renderer = JSON()
    def datetime_adapter(obj, request):
        return obj.isoformat()
    json_renderer.add_adapter(datetime.datetime, datetime_adapter)
    config.add_renderer('json', json_renderer)

    # (route_name, URL)
    config.add_route('upcoming_events', 'api/v1.0/events')
    config.add_route('home_page', '/')
    config.add_route('events_view', 'events')
    config.add_route('update_building_alias', 'api/v1.0/update_building_alias')
    config.scan()

    # db_url is stored in .ini files 
    db_url = urlparse(settings['mongo_uri'])

    # The registry "maps resource types to views, as well as housing 
    # other application-specific component registrations"
    config.registry.db = MongoClient(
            host=db_url.hostname
    )

    # TODO figure out what these do. Taken from Pyramid/mongo tutorial here:
    # http://pyramid-cookbook.readthedocs.org/en/latest/database/mongodb.html
    def add_db(request):
      db = config.registry.db[db_url.path[1:]]
      if db_url.username and db_url.password:
        print('authenitacintg?')
        db.authenticate(db_url.username, db_url.password)
      return db

    def add_fs(request):
      print('adding_fs??')
      return GridFS(request.db)

    config.add_request_method(add_db, 'db', reify=True)
    config.add_request_method(add_fs, 'fs', reify=True)

    return config.make_wsgi_app()
开发者ID:CarlTour,项目名称:CarlTourBackEnd,代码行数:52,代码来源:__init__.py


示例14: main

def main(global_config, **settings):
    engine = engine_from_config(settings, 'sqlalchemy.')
    session_factory = sessionmaker(bind=engine)
    settings['db.session_factory'] = session_factory

    config = Configurator(
        settings=settings,
        request_factory=RequestWithDB
    )

    json_renderer = JSON()
    json_renderer.add_adapter(datetime.date, date_adapter)
    json_renderer.add_adapter(decimal.Decimal, decimal_adapter)
    config.add_renderer('json', json_renderer)

    config.add_static_view('static', 'static', cache_max_age=0)

    # GET    /api/exploracaos      = Return all exploracaos
    # POST   /api/exploracaos      = Create a new exploracao, 'exp_id' in body
    # GET    /api/exploracaos/{id} = Return individual exploracao
    # PUT    /api/exploracaos/{id} = Update exploracao
    # DELETE /api/exploracaos/{id} = Delete exploracao
    config.add_route('exploracaos',     '/api/exploracaos')
    config.add_route('exploracaos_id',  '/api/exploracaos/{id}')

    # GET    /api/utentes      = Return all utentes
    # POST   /api/utentes      = Create a new utente, 'nome' in body
    # GET    /api/utentes/{id} = Return individual utente
    # PUT    /api/utentes/{id} = Update utente
    # DELETE /api/utentes/{id} = Delete utente
    config.add_route('utentes', '/api/utentes')
    config.add_route('utentes_id', '/api/utentes/{id}')

    # GET    /api/cultivos      = Return all cultivos
    # PUT    /api/utentes/{id} = Update cultivo
    config.add_route('cultivos', '/api/cultivos')
    config.add_route('cultivos_id', '/api/cultivos/{id}')

    # GET    /api/settings      = Return all settings
    # PUT    /api/settings/{property} = Update property
    config.add_route('settings', '/api/settings')
    config.add_route('settings_property', '/api/settings/{property}')

    # GET /domains = Return all domains (utentes included)
    config.add_route('domains', '/api/domains')

    # GET /api/base/fountains = Return a GeoJSON
    # POST /api/base/fountains = DELETE the table and insert the features in the zip
    config.add_route('base_fountains', '/api/base/fountains')

    config.scan()
    return config.make_wsgi_app()
开发者ID:iCarto,项目名称:utentes-api,代码行数:52,代码来源:__init__.py


示例15: make_app

def make_app(settings):
    config = Configurator(settings=settings)
    config.include("app.routes")

    # override: json renderer
    json_renderer = JSON()

    def datetime_adapter(obj, request):
        return obj.isoformat()
    json_renderer.add_adapter(datetime.datetime, datetime_adapter)
    config.add_renderer('json', json_renderer)

    return config.make_wsgi_app()
开发者ID:podhmo,项目名称:individual-sandbox,代码行数:13,代码来源:__init__.py


示例16: custom_json_renderer

def custom_json_renderer():
    """
    Return a custom json renderer that can deal with some datetime objects.
    """
    def datetime_adapter(obj, request):
        return obj.isoformat()

    def time_adapter(obj, request):
        return str(obj)

    json_renderer = JSON()
    json_renderer.add_adapter(datetime.datetime, datetime_adapter)
    json_renderer.add_adapter(datetime.time, time_adapter)
    return json_renderer
开发者ID:martinstein,项目名称:json-example,代码行数:14,代码来源:jsonhelpers.py


示例17: main

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(settings=settings)
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_route('custom_object', '/custom_object.json')

    json_third_party = JSON()
    json_third_party.add_adapter(ThirdPartyObject, third_party_adapter)
    config.add_renderer('json_third_party', json_third_party)
    config.add_route('third_party', '/third_party.json')

    config.scan()
    return config.make_wsgi_app()
开发者ID:wwitzel3,项目名称:pieceofpy,代码行数:15,代码来源:__init__.py


示例18: setUp

 def setUp(self):
     from pyramid.renderers import JSON
     json_renderer = JSON()
     settings = {
         'pyramlson.apidef_path': os.path.join(DATA_DIR, 'test-api.raml'),
         'pyramlson.debug': 'true',
         'pyramlson.arguments_transformation_callback': inflection.underscore,
         'pyramlson.convert_parameters': 'true'
     }
     self.config = testing.setUp(settings=settings)
     self.config.include('pyramlson')
     json_renderer.add_adapter(datetime, datetime_adapter)
     self.config.add_renderer('json', json_renderer)
     self.config.scan('.resource')
     from webtest import TestApp
     self.testapp = TestApp(self.config.make_wsgi_app())
开发者ID:jenner,项目名称:pyramlson,代码行数:16,代码来源:test_resource.py


示例19: main

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(settings=settings)
    config.include('pyramid_sqlalchemy')
    json_renderer = JSON()

    def datetime_adapter(obj, request):
        return obj.isoformat()

    json_renderer.add_adapter(datetime.datetime, datetime_adapter)
    config.add_renderer('json', json_renderer)
    initialization.initialize(config)

    config.scan()
    app = config.make_wsgi_app()
    return install_middlewares(app, settings)
开发者ID:marplatense,项目名称:test_cliquet,代码行数:17,代码来源:__init__.py


示例20: main

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(settings=settings)
    config.add_translation_dirs('locale/')

    # Custom JSON renderer
    json_renderer = JSON()
    def datetime_adapter(obj, request):
        return obj.isoformat()
    json_renderer.add_adapter(datetime.datetime, datetime_adapter)

    def objectid_adapter(obj, request):
        return unicode(obj)
    json_renderer.add_adapter(bson.objectid.ObjectId, objectid_adapter)

    config.add_renderer('json', json_renderer)

    config.include('pyramid_jinja2')
    config.add_renderer('.html', 'pyramid_jinja2.renderer_factory')
    config.add_jinja2_search_path("billwatcher:templates")

    config.add_static_view('static', 'billwatcher:static',
                           cache_max_age=3600)

    db_url = urlparse(settings['mongo_uri'])
    config.registry.db = pymongo.Connection(
        host=db_url.hostname,
        port=db_url.port
    )

    def add_db(request):
        db = config.registry.db[db_url.path[1:]]
        if db_url.username and db_url.password:
            db.authenticate(db_url.username, db_url.password)
        return db

    def add_fs(request):
        return GridFS(request.db)

    config.add_request_method(add_db, 'db', reify=True)
    config.add_request_method(add_fs, 'fs', reify=True)
        
    config.include('billwatcher.views.views_include')
    config.scan()
    return config.make_wsgi_app()
开发者ID:sweemeng,项目名称:BillWatcher-2.0,代码行数:46,代码来源:__init__.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python request.apply_request_extensions函数代码示例发布时间:2022-05-27
下一篇:
Python renderers.render_to_response函数代码示例发布时间: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