本文整理汇总了Python中pyramid.config.Configurator.register_adapter方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.register_adapter方法的具体用法?Python Configurator.register_adapter怎么用?Python Configurator.register_adapter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.register_adapter方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import register_adapter [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
convert = lambda spec: ''.join(c if i == 0 else c + c for i, c in enumerate(spec))
filename_pattern = re.compile('(?P<spec>(c|d|s|f|t)[0-9a-f]{3})\.png')
icons = []
for name in sorted(
[fn.name for fn in
Path(__file__).parent.joinpath('static', 'icons').glob('*.png')]):
m = filename_pattern.match(name)
if m:
icons.append(Icon(convert(m.group('spec'))))
config = Configurator(settings=settings)
config.include('clldmpg')
config.registry.registerUtility(map_marker, IMapMarker)
config.registry.registerUtility(icons, IIconList)
config.register_adapter(adapter_factory(
'parameter/detail_tab.mako',
mimetype='application/vnd.clld.tab',
send_mimetype="text/plain",
extension='tab',
name='tab-separated values'), IParameter)
#config.register_resource('construction', models.sailsUnit, IUnit, with_index=True)
config.register_resource('construction', models.sailsConstruction, IConstruction, with_index=True)
#config.register_adapter(adapter_factory('family/detail_html.mako'), IFamily)
return config.make_wsgi_app()
示例2: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import register_adapter [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.registry.registerUtility(link_attrs, interfaces.ILinkAttrs)
config.include('clldmpg')
config.include('clld_glottologfamily_plugin')
config.registry.registerUtility(MyMapMarker(), interfaces.IMapMarker)
config.add_page('submit')
config.add_page('help')
config.register_menu(
('dataset', partial(menu_item, 'dataset', label='Home')),
('contributions', partial(menu_item, 'contributions')),
('parameters', partial(menu_item, 'parameters')),
('sentences', partial(menu_item, 'sentences')),
('help', lambda ctx, rq: (rq.route_url('help'), u'Help')),
)
config.add_settings(
home_comp=['submit', 'contributors', 'languages'] +
config.get_settings()['home_comp'])
for cls in [md.BibTex, md.ReferenceManager]:
for if_ in [interfaces.IRepresentation, interfaces.IMetadata]:
config.register_adapter(cls, interfaces.IContribution, if_, name=cls.mimetype)
return config.make_wsgi_app()
示例3: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import register_adapter [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
convert = lambda spec: ''.join(c if i == 0 else c + c for i, c in enumerate(spec))
filename_pattern = re.compile('(?P<spec>(c|d|s|f|t)[0-9a-f]{3})\.png')
icons = {}
for fname in sorted(Path(__file__).parent.joinpath('static', 'icons').iterdir()):
m = filename_pattern.match(fname.name)
if m:
icons[m.group('spec')] = convert(m.group('spec'))
settings['icons'] = icons
config = Configurator(settings=settings)
config.include('clldmpg')
config.include('clld_glottologfamily_plugin')
config.registry.registerUtility(NtsMapMarker(), IMapMarker)
config.register_menu(
('dataset', partial(menu_item, 'dataset', label='Home')),
('parameters', partial(menu_item, 'parameters', label='Features')),
('languages', partial(menu_item, 'languages')),
('sources', partial(menu_item, 'sources')),
('designers', partial(menu_item, 'contributions', label="Contributors")),
)
config.register_adapter(adapter_factory(
'parameter/detail_tab.mako',
mimetype='application/vnd.clld.tab',
send_mimetype="text/plain",
extension='tab',
name='tab-separated values'), IParameter)
return config.make_wsgi_app()
示例4: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import register_adapter [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
convert = lambda spec: ''.join(c if i == 0 else c + c for i, c in enumerate(spec))
filename_pattern = re.compile('(?P<spec>(c|d|s|f|t)[0-9a-f]{3})\.png')
icons = []
for name in sorted(
path(__file__).dirname().joinpath('static', 'icons').files()
):
m = filename_pattern.match(name.splitall()[-1])
if m:
icons.append(Icon(convert(m.group('spec'))))
config = Configurator(settings=settings)
config.include('clldmpg')
config.registry.registerUtility(map_marker, IMapMarker)
config.registry.registerUtility(icons, IIconList)
config.register_adapter(adapter_factory(
'parameter/detail_tab.mako',
mimetype='application/vnd.clld.tab',
send_mimetype="text/plain",
extension='tab',
name='tab-separated values'), IParameter)
return config.make_wsgi_app()
示例5: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import register_adapter [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.include('clldmpg')
config.registry.registerUtility(LanguageByFamilyMapMarker(), interfaces.IMapMarker)
config.registry.registerUtility(link_attrs, interfaces.ILinkAttrs)
config.register_adapter(adapter_factory(
'contribution/detail_tab.mako',
mimetype='application/vnd.clld.tab',
send_mimetype="text/plain",
extension='tab',
name='tab-separated values'), interfaces.IContribution)
return config.make_wsgi_app()
示例6: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import register_adapter [as 别名]
def main(global_config, **settings):
"""called when bootstrapping a pyramid app using clld/tests/test.ini."""
class IF(Interface):
pass
settings['mako.directories'] = ['clld:web/templates']
config = Configurator(settings=settings)
config.include('clld.web.app')
config.registry.registerUtility(MapMarker(), interfaces.IMapMarker)
config.register_staticresource('css', 'clld:web/static/notexisting.css')
config.register_staticresource('js', 'clld:web/static/notexisting.js')
config.register_adapter(Representation, Mock, name='test')
config.register_menu(('home', lambda ctx, req: (req.resource_url(req.dataset), 'tt')))
return config.make_wsgi_app()
示例7: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import register_adapter [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
settings['route_patterns'] = {'walss': '/wals', 'wals': '/wals/{id:[^/\.]+}'}
config = Configurator(settings=settings)
config.include('clldmpg')
config.registry.registerUtility(ApicsCtxFactoryQuery(), ICtxFactoryQuery)
config.registry.registerUtility(ApicsMapMarker(), IMapMarker)
config.registry.registerUtility(link_attrs, ILinkAttrs)
config.register_menu(
('dataset', partial(menu_item, 'dataset', label='Home')),
('contributions', partial(menu_item, 'contributions')),
('parameters', partial(menu_item, 'parameters')),
('apics_wals', lambda ctx, rq: (rq.route_url('walss'), u'WALS\u2013APiCS')),
('surveys', partial(menu_item, 'surveys')),
('sentences', partial(menu_item, 'sentences')),
('sources', partial(menu_item, 'sources')),
('contributors', partial(menu_item, 'contributors')),
)
config.register_adapter(
{
"base": Representation,
"mimetype": 'application/vnd.clld.chapter+html',
"send_mimetype": "text/html",
"extension": 'chapter.html',
"template": 'parameter/chapter_html.mako',
},
IParameter,
name="application/vnd.clld.chapter+html")
config.register_download(CsvDump(
common.Language, 'apics', description="Languages as CSV"))
config.register_download(N3Dump(
common.Language, 'apics', description="Languages as RDF"))
config.register_download(Download(
common.Source, 'apics', ext='bib', description="Sources as BibTeX"))
config.register_resource('wals', Wals, IWals, with_index=True)
config.register_resource('survey', Survey, ISurvey, with_index=True)
config.register_adapters([(
ISurvey,
Representation,
'application/vnd.clld.md+xml',
'md.html',
'md_html.mako',
{'rel': 'describedby'})])
return config.make_wsgi_app()
示例8: get_configurator
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import register_adapter [as 别名]
def get_configurator(pkg, *utilities, **kw):
"""
.. seealso:: https://groups.google.com/d/msg/pylons-discuss/Od6qIGaLV6A/3mXVBQ13zWQJ
"""
kw.setdefault('package', pkg)
routes = kw.pop('routes', [])
config = Configurator(**kw)
for name, pattern in routes:
config.add_route(name, pattern)
config.set_request_factory(ClldRequest)
config.registry.registerUtility(CtxFactoryQuery(), interfaces.ICtxFactoryQuery)
config.registry.registerUtility(OlacConfig(), interfaces.IOlacConfig)
# initialize the db connection
engine = engine_from_config(config.registry.settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
config.add_settings({'pyramid.default_locale_name': 'en'})
if 'clld.files' in config.registry.settings:
# deployment-specific location of static data files
abspath = path(config.registry.settings['clld.files']).abspath()
config.add_settings({'clld.files': abspath})
config.add_static_view('files', abspath)
# event subscribers:
config.add_subscriber(add_localizer, events.NewRequest)
config.add_subscriber(init_map, events.ContextFound)
config.add_subscriber(
partial(add_renderer_globals, maybe_import('%s.util' % config.package_name)),
events.BeforeRender)
#
# make it easy to register custom functionality
#
for name, func in {
'register_datatable': partial(register_cls, interfaces.IDataTable),
'register_map': partial(register_cls, interfaces.IMap),
'register_menu': register_menu,
'register_resource': register_resource,
'register_adapter': register_adapter,
'register_download': register_download,
'add_route_and_view': add_route_and_view,
'add_settings_from_file': add_settings_from_file,
}.items():
config.add_directive(name, func)
#
# routes and views
#
config.add_static_view('clld-static', 'clld:web/static')
config.add_static_view('static', '%s:static' % config.package_name)
config.add_route_and_view('legal', '/legal', lambda r: {}, renderer='legal.mako')
config.add_route_and_view('download', '/download', lambda r: {}, renderer='download.mako')
config.add_route_and_view('contact', '/contact', lambda r: {}, renderer='contact.mako')
config.add_route_and_view('_js', '/_js', js, http_cache=3600)
# add some maintenance hatches
config.add_route_and_view('_raise', '/_raise', _raise)
config.add_route_and_view('_ping', '/_ping', _ping, renderer='json')
# sitemap support:
config.add_route_and_view('robots', '/robots.txt', robots)
config.add_route_and_view('sitemapindex', '/sitemap.xml', sitemapindex)
config.add_route_and_view('sitemap', '/sitemap.{rsc}.{n}.xml', sitemap)
config.add_route('google-site-verification', 'googlebbc8f4da1abdc58b.html')
config.add_view(
lambda r: Response('google-site-verification: googlebbc8f4da1abdc58b.html'),
route_name='google-site-verification')
config.add_route_and_view('unapi', '/unapi', unapi)
config.add_route_and_view('olac', '/olac', olac)
for rsc in RESOURCES:
name, model = rsc.name, rsc.model
factory = partial(ctx_factory, model, 'index')
config.add_route_and_view(rsc.plural, '/%s' % rsc.plural, index_view, factory=factory)
config.register_datatable(
rsc.plural, getattr(datatables, rsc.plural.capitalize(), DataTable))
config.register_adapter(
getattr(excel, rsc.plural.capitalize(), excel.ExcelAdapter), rsc.interface)
kw = dict(factory=partial(ctx_factory, model, 'rsc'))
if model == common.Dataset:
pattern = '/'
kw['alt_route_pattern'] = '/void.{ext}'
else:
pattern = '/%s/{id:[^/\.]+}' % rsc.plural
config.add_route_and_view(name, pattern, resource_view, **kw)
# maps
config.register_map('languages', Map)
config.register_map('language', LanguageMap)
config.register_map('parameter', ParameterMap)
#.........这里部分代码省略.........
示例9: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import register_adapter [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
settings.update(CFG)
settings['navbar.inverse'] = True
settings['route_patterns'] = {
'languages': '/glottolog/language',
'language': '/resource/languoid/id/{id:[^/\.]+}',
'source': '/resource/reference/id/{id:[^/\.]+}',
'sources': '/langdoc',
#'provider': '/langdoc/langdocinformation#provider-{id}',
'providers': '/langdoc/langdocinformation',
}
settings['sitemaps'] = ['language', 'source']
config = Configurator(settings=settings)
#
# Note: The following routes must be registered before including the clld web app,
# because they are special cases of a more general route pattern registered there.
#
config.add_route('languoid.xhtml', '/resource/languoid/id/{id:[^/\.]+}.xhtml')
config.add_route('reference.xhtml', '/resource/reference/id/{id:[^/\.]+}.xhtml')
config.include('clldmpg')
config.registry.registerUtility(GLCtxFactoryQuery(), ICtxFactoryQuery)
config.register_menu(
#('dataset', partial(menu_item, 'dataset', label='Home')),
('languages', partial(menu_item, 'languages', label='Languages')),
('families', partial(menu_item, 'glottolog.families', label='Families')),
('search', partial(menu_item, 'glottolog.languages', label='Language Search')),
('sources', partial(menu_item, 'sources', label='References')),
('query', partial(menu_item, 'langdoc.complexquery', label='Reference Search')),
('about', partial(menu_item, 'about', label='About')),
)
config.register_resource('provider', models.Provider, IProvider, with_index=True)
config.register_adapter(
adapter_factory('provider/index_html.mako', base=Index), IProvider)
config.add_view(views.redirect_languoid_xhtml, route_name='languoid.xhtml')
config.add_view(views.redirect_reference_xhtml, route_name='reference.xhtml')
config.add_route_and_view('news', '/news', views.news, renderer='news.mako')
config.add_route_and_view(
'glottolog.meta',
'/glottolog/glottologinformation',
views.glottologmeta,
renderer='glottologmeta.mako')
config.add_route_and_view(
'glottolog.families',
'/glottolog/family',
views.families,
renderer='families.mako')
config.add_route_and_view(
'glottolog.iso',
'/resource/languoid/iso/{id:[^/\.]+}',
views.iso)
config.add_route_and_view(
'glottolog.languages',
'/glottolog',
views.languages,
renderer='language/search_html.mako')
config.add_route_and_view(
'glottolog.childnodes',
'/db/getchildlects',
views.childnodes,
renderer='json')
config.add_route_and_view(
'langdoc.complexquery',
'/langdoc/complexquery',
views.langdoccomplexquery,
renderer='langdoccomplexquery.mako')
for name in 'credits glossary cite downloads contact'.split():
pp = '/' if name == 'credits' else '/meta/'
config.add_route_and_view(
'home.' + name,
pp + name,
getattr(views, name),
renderer=name + '.mako')
config.register_download(adapters.LanguoidCsvDump(
models.Languoid, 'glottolog3', description="Languoids as CSV"))
config.register_download(adapters.LanguoidN3Dump(
Language, 'glottolog3', description="Languoids as RDF"))
config.register_download(Download(
Source, 'glottolog3', ext='bib', description="References as BibTeX"))
config.register_download(N3Dump(
Source, 'glottolog3', description="References as RDF"))
config.add_route('langdocstatus', '/langdoc/status')
config.add_route('langdocstatus.browser', '/langdoc/status/browser')
config.add_route(
'langdocstatus.languages', '/langdoc/status/languages-{ed:[0-9]}-{sdt:[0-9]}')
config.scan('glottolog3.langdocstatus')
config.register_datatable('providers', Providers)
return config.make_wsgi_app()
示例10: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import register_adapter [as 别名]
def main(global_config, **settings):
"""return a Pyramid WSGI application."""
settings['route_patterns'] = {
'languages': '/languoid',
'language': '/languoid/lect/wals_code_{id:[^/\.]+}',
'source': '/refdb/record/{id:[^/\.]+}',
'sources': '/refdb',
'familys': '/languoid/family',
'family': '/languoid/family/{id:[^/\.]+}',
'genus': '/languoid/genus/{id:[^/\.]+}',
'parameters': '/feature',
'parameter': '/feature/{id:[^/\.]+}',
'sentences': '/example',
'sentence': '/example/{id:[^/\.]+}',
'contributions': '/chapter',
'contribution': '/chapter/{id:[^/\.]+}',
'countrys': '/country',
'country': '/country/{id:[^/\.]+}',
'contributors': '/author',
'contributor': '/author/{id:[^/\.]+}',
'legal': '/about/legal',
'olac': '/languoid/oai',
'credits': '/about/credits',
}
filename_pattern = re.compile('(?P<spec>(c|d|s|f|t)[0-9a-f]{3})\.png')
icons = []
for name in sorted(
path(__file__).dirname().joinpath('static', 'icons').files()
):
m = filename_pattern.match(name.splitall()[-1])
if m:
icons.append(WalsIcon(m.group('spec')))
config = Configurator(**dict(settings=settings))
config.include('clldmpg')
for utility, interface in [
(WalsCtxFactoryQuery(), ICtxFactoryQuery),
(map_marker, IMapMarker),
(Blog(settings), IBlog),
(icons, IIconList),
]:
config.registry.registerUtility(utility, interface)
config.register_resource('family', Family, IFamily, with_index=True)
config.register_resource('genus', Genus, IGenus, with_index=True)
config.register_resource('country', Country, ICountry)
config.add_route(
'sample_alt', '/languoid/samples/{count}.{ext}', factory=sample_factory)
config.add_route(
'sample', '/languoid/samples/{count}', factory=sample_factory)
for spec in [
dict(
template='parameter/detail_tab.mako',
mimetype='application/vnd.clld.tab',
send_mimetype="text/plain",
extension='tab',
name='tab-separated values'),
dict(
template='parameter/detail_xml.mako',
mimetype='application/vnd.clld.xml',
send_mimetype="application/xml",
extension='xml',
name='WALS XML',
__doc__="Custom XML format."),
dict(
template='parameter/detail_georss.mako',
mimetype='application/vnd.clld.georss+xml',
send_mimetype="application/rdf+xml",
extension='georss',
name="GeoRSS",
__doc__="RSS with location information "
"(http://en.wikipedia.org/wiki/GeoRSS)."),
dict(
template='parameter/detail_kml.mako',
mimetype='application/vnd.google-earth.kml+xml',
send_mimetype="application/xml",
extension='kml',
name='KML',
__doc__="Keyhole Markup Language"),
]:
config.register_adapter(spec, IParameter)
config.add_route('feature_info', '/feature-info/{id}')
config.add_route('genealogy', '/languoid/genealogy')
config.add_301(
'/index',
lambda req: req.route_url('dataset'))
config.add_301(
'/.{ext}',
lambda req: req.route_url('dataset_alt', ext=req.matchdict['ext']))
config.add_301(
'/example/{fid}/all',
lambda req: req.route_url('parameter', id=req.matchdict['fid']))
config.add_301(
'/example/all/wals_code_{lid}',
lambda req: req.route_url(
'sentences', _query=dict(language=req.matchdict['lid'])))
#.........这里部分代码省略.........