本文整理汇总了Python中webob.acceptparse.Accept.startswith方法的典型用法代码示例。如果您正苦于以下问题:Python Accept.startswith方法的具体用法?Python Accept.startswith怎么用?Python Accept.startswith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webob.acceptparse.Accept
的用法示例。
在下文中一共展示了Accept.startswith方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lookup_template_engine
# 需要导入模块: from webob.acceptparse import Accept [as 别名]
# 或者: from webob.acceptparse.Accept import startswith [as 别名]
def lookup_template_engine(self, tgl):
"""Return the template engine data.
Provides a convenience method to get the proper engine,
content_type, template, and exclude_names for a particular
tg_format (which is pulled off of the request headers).
"""
request = tgl.request
response = tgl.response
try:
render_custom_format = request._render_custom_format[self.controller]
except:
render_custom_format = self.render_custom_format
if render_custom_format:
(content_type, engine, template, exclude_names, render_params
) = self.custom_engines[render_custom_format]
else:
if self.default_engine:
content_type = self.default_engine
elif self.engines:
if request._response_type and request._response_type in self.engines:
accept_types = request._response_type
else:
accept_types = request.headers.get('accept', '*/*')
content_type = Accept(accept_types).best_match(self.engines_keys, self.engines_keys[0])
else:
content_type = 'text/html'
# check for overridden content type from the controller call
try:
controller_content_type = response.headers['Content-Type']
# make sure we handle content_types like 'text/html; charset=utf-8'
content_type = controller_content_type.split(';')[0]
except KeyError:
pass
# check for overridden templates
try:
cnt_override_mapping = request._override_mapping[self.controller]
engine, template, exclude_names, render_params = cnt_override_mapping[content_type.split(";")[0]]
except (AttributeError, KeyError):
(engine, template, exclude_names, render_params
) = self.engines.get(content_type, (None,) * 4)
if 'charset' not in content_type and (content_type.startswith('text')
or content_type in ('application/xhtml+xml',
'application/xml', 'application/json')):
content_type += '; charset=utf-8'
return content_type, engine, template, exclude_names, render_params