本文整理汇总了Python中pyramid.config.Configurator.add_renderer方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.add_renderer方法的具体用法?Python Configurator.add_renderer怎么用?Python Configurator.add_renderer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.add_renderer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_renderer [as 别名]
def main():
default_log_config(debug=True)
import logging
log = logging.getLogger(__name__)
try:
if len(sys.argv) == 2:
config = parse_conf(sys.argv[1])
else:
config = parse_conf('uploader.yml')
config = config_schema.validate(config)
from pyramid.config import Configurator
from pyramid.renderers import JSON
from ivr.common.utils import CustomJSONEncoder
pyramid_config = Configurator()
pyramid_config.add_renderer(None, JSON(indent=4, check_circular=True, cls=CustomJSONEncoder))
if config.get('fs_path'):
from fs import FSUploadService
upload_service = FSUploadService(config['fs_path'])
pyramid_config.registry.upload_service = upload_service
else:
raise Exception('No valid upload serivce given')
pyramid_config.add_route('preview_upload', 'api/ivc/v1/projects/{project_name}/devices/{login_code}/channels/{channel}/upload_preview')
pyramid_config.add_view(upload_view, route_name='preview_upload', request_method='POST')
upload_server = WSGIServer(config['listen'], pyramid_config.make_wsgi_app())
gevent.joinall(map(gevent.spawn, (upload_server.serve_forever, )))
log.info("Quit")
except Exception:
log.exception('Failed to start preview image uploader')
示例2: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_renderer [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
settings['db'] = {'host':'localhost', 'port': 27017}
session_factory = session_factory_from_settings(settings)
config = Configurator(settings=settings,session_factory=session_factory)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_renderer('jsonp', JSONP(param_name = 'callback'))
config.add_route('home', '/')
config.add_route('home_jiang', '/home')
config.add_route('index', '/index')
config.add_route('preview', '/i/{short_url}')
config.add_route('img', '/html/img/{filename}')
config.add_route('test', '/test')
config.add_route('create', '/create')
config.add_route('get_info', '/get_info')
config.add_route('pull', '/pull')
config.add_route('tencent', '/qq')
config.add_route('login', '/login')
config.add_route('site_view', '/site_view')
config.add_route('register', '/register')
config.add_route('qqlogin', '/qqlogin')
config.scan()
return config.make_wsgi_app()
示例3: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_renderer [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
setup_logging(global_config['__file__'])
config.add_renderer('jsonp', JSONP(param_name='callback'))
config.add_renderer('ujson', factory='app.renderers.UjsonRenderer')
config.add_static_view('static', 'static', cache_max_age=3600)
# initialise a connection to mongo on startup and store the client
# in the registry which will be injected into each request
conf = appConfig(config.registry.settings.get('app.config'))
config.registry.app_config = conf.app_config
config.registry.app_config['mongodb']['client'] = init_mongodb_connection(config.registry.app_config['mongodb'])
config.add_route('home', '/')
config.add_route('health-check', '/health-check')
config.add_route('network-stats', '/stats/{code}/{explore}')
config.add_route('network-build', '/network/{code}/{explore}')
config.add_route('network-build-status', '/network/{code}/{explore}/status')
config.add_route('entity-data', '/entity/{code}/data')
config.add_route('entity-build', '/entity/{code}/{id}')
config.add_route('entity-build-status', '/entity/{code}/{id}/status')
config.add_route('convert-graph', '/convert/{code}')
config.scan()
return config.make_wsgi_app()
示例4: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_renderer [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
# Update the settings with the current app root path
settings["app_root"] = abspath(dirname(dirname(__file__)))
initialize_sql(settings)
authn_policy = AuthTktAuthenticationPolicy(settings.get("auth.secret"), callback=UserMgr.auth_groupfinder)
authz_policy = ACLAuthorizationPolicy()
config = Configurator(
settings=settings,
root_factory="bookie.RootFactory",
authentication_policy=authn_policy,
authorization_policy=authz_policy,
)
config.set_request_factory(RequestWithUserAttribute)
config = build_routes(config)
config.add_static_view("static", "bookie:static")
config.add_renderer("jsonp", JSONP(param_name="callback"))
config.scan("bookie.views")
return config.make_wsgi_app()
示例5: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_renderer [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.add_renderer('json')
config.scan()
return config.make_wsgi_app()
示例6: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_renderer [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
# Initialize database
pyramid_sqla.add_engine(settings, prefix='sqlalchemy.',
convert_unicode=True)
# Configure Beaker sessions
session_factory = pyramid_beaker.session_factory_from_settings(settings)
config.set_session_factory(session_factory)
# Configure renderers
config.add_renderer('.html', 'pyramid.mako_templating.renderer_factory')
config.add_subscriber('simpledemo.subscribers.add_renderer_globals',
'pyramid.events.BeforeRender')
# Set up routes and views
config.add_handler('home', '/', 'simpledemo.handlers:MainHandler',
action='index')
config.add_handler('main', '/{action}', 'simpledemo.handlers:MainHandler',
path_info=r'/(?!favicon\.ico|robots\.txt|w3c)')
add_static_route(config, 'simpledemo', 'static', cache_max_age=3600)
return config.make_wsgi_app()
示例7: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_renderer [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
config = Configurator(settings=settings)
config.add_renderer('.mustache', 'pubssite.renderers.pystache_renderer_factory')
config.add_renderer('pubs_json', 'pubssite.renderers.PubsJSONRenderer')
config.add_static_view('static', 'static', cache_max_age=3600)
# TODO: change login to / after auth setup
config.add_route('home', '/')
config.add_route('login', '/login')
# Citation routes
config.add_route('citation_by_id', '/citation/{id:[0-9]+(,[0-9]+)*}')
config.add_route('citations_by_owner', '/citation/owner/{owner:.*}')
config.add_route('citations_by_collection', '/collection/citations/{id:\d+}')
config.add_route('citation_delete', '/citation/delete/{id:\d+}')
# TODO: Let's try to find a regex to make sure we're getting JSON objects
# sent to these next two
config.add_route('citation_update', '/citation/')
#config.add_route('citation_add', '/citation/')
# Collection routes
config.add_route('collection_by_id', 'collection/{id:\d+}')
config.add_route('collections_by_owner', '/collection/owner/{owner:.*}')
config.add_route('collection_delete', '/collection/delete/{id:\d+}')
config.scan()
return config.make_wsgi_app()
示例8: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_renderer [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
settings["g"] = g = Globals(**settings)
config = Configurator(settings=settings
, root_factory=WebsiteRootContext
, session_factory = session_factory_from_settings(settings)
, authentication_policy= Security()
, authorization_policy= ACLAuthorizationPolicy()
, default_permission='view'
)
request.extend_request_traversal(config)
config.add_directive('add_mako_renderer', pyramid_mako.add_mako_renderer)
config.add_mako_renderer(".html")
config.add_mako_renderer(".xml")
config.add_renderer('json', jsonRenderer)
def _(request, string):
return string
config.add_request_method(_, '_')
config.add_subscriber(add_renderer_variables, 'pyramid.events.BeforeRender')
config.include("ufostart.handlers")
config.include("ufostart.admin")
config.scan()
return config.make_wsgi_app()
示例9: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_renderer [as 别名]
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()
示例10: make_app
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_renderer [as 别名]
def make_app():
""" This function returns a Pyramid WSGI application.
"""
# config = Configurator(root_factory=Root)
settings = {}
settings['mako.directories'] = os.path.join(__here__, 'templates')
config = Configurator( root_factory=Root, settings=settings )
config.add_renderer('.jinja2', pyramid_jinja2.Jinja2Renderer)
#config.add_view(views.my_view,
# context=Root,
#renderer='mytemplate.jinja2')
config.add_route( "home", "/home" )
config.add_view( views.home_view, route_name="home", renderer="main.mako" )
config.add_static_view(name='static',
path=os.path.join(__here__, 'static'))
config.add_route('zodiac', '/zodiac')
config.add_view(views.zodiac_view, route_name='zodiac', renderer='zodiac.mako')
config.add_route('resultat', '/resultat')
config.add_view(views.zodiac_view, route_name='resultat', renderer='res.mako')
config.add_route('guestView', '/guestView')
config.add_view(views.guestView_view, route_name='guestView', renderer='guestView.mako')
return config.make_wsgi_app()
示例11: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_renderer [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.add_renderer('.html', mako_factory)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('new', '/')
config.add_route('quiz', '/user/{username}/account/{account_type}')
config.add_route('posting', '/posting')
config.add_route('notloggedin', '/notloggedin')
config.add_route('loginerror', '/loginerror')
config.add_route('saranghae100', '/saranghae100')
# MongoDB Setting
db_url = urlparse(settings['mongo_uri'])
conn = pymongo.Connection(host=db_url.hostname, port=db_url.port)
config.registry.settings['db_conn'] = conn
def add_mongo_db(event):
settings = event.request.registry.settings
db = settings['db_conn'][db_url.path[1:]]
if db_url.username and db_url.password:
db.authenticate(db_url.username, db_url.password)
event.request.db = db
config.add_subscriber(add_mongo_db, NewRequest)
config.scan()
return config.make_wsgi_app()
示例12: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_renderer [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
# add html renderer (chameleon based)
config.add_renderer(name='.html', factory='p_started.renderer.AppDistRendererFactory')
production_config = asbool(settings.get('PRODUCTION', 'false'))
production_config = asbool(settings.get('PRODUCTION', 'false'))
production = os.environ.get('PRODUCTION', production_config)
minify_config = settings.get('minify', 'app')
minify = os.environ.get('minify', minify_config)
config.include('pyramid_chameleon')
# static views
# See also config.override_asset if you want to avoid minify
config.add_static_view('scripts', 'p_started:webapp/%s/scripts' % minify, cache_max_age=3600)
config.add_static_view('styles', 'p_started:webapp/%s/styles' % minify, cache_max_age=3600)
config.add_static_view('images', 'p_started:webapp/%s/images' % minify, cache_max_age=3600)
if not production:
# we expose the bower_components dir just for development deployments, not good for production
config.add_static_view('bower_components', 'p_started:webapp/%s/bower_components' % minify, cache_max_age=3600)
else:
config.add_static_view('fonts', 'p_started:webapp/%s/fonts' % minify, cache_max_age=3600)
# routes
config.add_route('home', '/')
config.scan()
return config.make_wsgi_app()
示例13: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_renderer [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.include('pyramid_mako')
config.include('.db')
config.add_renderer('json', MongoJSONRenderer)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('kensaku', '/kensaku')
config.add_route('promo', '/promo/{ref_tag}/{ref_id}')
config.add_route('upromo', '/promo/{id}')
config.add_route('suggest', '/sg')
# set familiar url standart API
config.add_route('results', '/api/v1/result')
config.add_route('valid', '/api/v1/valid')
config.add_route('rest', '/api/v1/rest')
# set inspeksi data
config.add_route('testrails', '/api/v1/test_rails')
config.add_route('results_build', '/api/beta/result')
config.add_route('valid_build', '/api/beta/valid')
config.add_route('kensaku_build', '/kensaku-beta')
config.scan()
return config.make_wsgi_app()
示例14: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_renderer [as 别名]
def main(global_config, **settings):
""" This function returns a WSGI application.
"""
config = Configurator(settings=settings)
config.add_renderer('utf8_json', JSON(ensure_ascii=False))
add_view(config)
# MongoDB
def add_mongo_db(event):
settings = event.request.registry.settings
url = settings['mongodb.url']
db_name = settings['mongodb.db_name']
db = settings['mongodb_conn'][db_name]
event.request.db = db
db_uri = settings['mongodb.url']
MongoDB = pymongo.Connection
if 'pyramid_debugtoolbar' in set(settings.values()):
class MongoDB(pymongo.Connection):
def __html__(self):
return 'MongoDB: <b>{}></b>'.format(self)
conn = MongoDB(db_uri)
config.registry.settings['mongodb_conn'] = conn
config.add_subscriber(add_mongo_db, NewRequest)
config.scan('albumapp')
return config.make_wsgi_app()
示例15: create_api
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_renderer [as 别名]
def create_api(global_config, **settings):
settings = get_settings(global_config, **settings)
config = Configurator(settings=settings)
config.set_authentication_policy(remote_authn)
config.set_authorization_policy(acl_authz)
config.set_root_factory('h.api.resources.create_root')
config.add_renderer('json', JSON(indent=4))
config.add_subscriber('h.api.subscribers.set_user_from_oauth',
'pyramid.events.ContextFound')
config.add_tween('h.api.tweens.auth_token')
config.include('h.features')
config.include('h.auth')
config.include('h.api.db')
config.include('h.api.views')
if config.registry.feature('queue'):
config.include('h.queue')
config.include('h.api.queue')
app = config.make_wsgi_app()
app = permit_cors(app,
allow_headers=('Authorization',
'X-Annotator-Auth-Token'),
allow_methods=('HEAD', 'GET', 'POST', 'PUT', 'DELETE'))
return app