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


Python renderers.JSON类代码示例

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


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


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