本文整理匯總了Python中webob.acceptparse.Accept.split方法的典型用法代碼示例。如果您正苦於以下問題:Python Accept.split方法的具體用法?Python Accept.split怎麽用?Python Accept.split使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類webob.acceptparse.Accept
的用法示例。
在下文中一共展示了Accept.split方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: lookup_template_engine
# 需要導入模塊: from webob.acceptparse import Accept [as 別名]
# 或者: from webob.acceptparse.Accept import split [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