本文整理汇总了Python中trac.web.chrome.Chrome.get方法的典型用法代码示例。如果您正苦于以下问题:Python Chrome.get方法的具体用法?Python Chrome.get怎么用?Python Chrome.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.web.chrome.Chrome
的用法示例。
在下文中一共展示了Chrome.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_error
# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import get [as 别名]
def send_error(self, exc_info, template='error.html',
content_type='text/html', status=500, env=None, data={}):
try:
if template.endswith('.cs') and self.hdf: # FIXME: remove this
if self.args.has_key('hdfdump'):
self.perm.require('TRAC_ADMIN')
content_type = 'text/plain'
data = str(self.hdf)
else:
data = self.hdf.render(template)
if template.endswith('.html'):
if env:
from trac.web.chrome import Chrome
try:
data = Chrome(env).render_template(self, template,
data, 'text/html')
except Exception:
# second chance rendering, in "safe" mode
data['trac_error_rendering'] = True
data = Chrome(env).render_template(self, template,
data, 'text/html')
else:
content_type = 'text/plain'
data = '%s\n\n%s: %s' % (data.get('title'),
data.get('type'),
data.get('message'))
except: # failed to render
data = get_last_traceback()
content_type = 'text/plain'
if isinstance(data, unicode):
data = data.encode('utf-8')
self.send_response(status)
self._outheaders = []
self.send_header('Cache-Control', 'must-revalidate')
self.send_header('Expires', 'Fri, 01 Jan 1999 00:00:00 GMT')
self.send_header('Content-Type', content_type + ';charset=utf-8')
self.send_header('Content-Length', len(data))
self._send_cookie_headers()
self._write = self._start_response(self._status, self._outheaders,
exc_info)
if self.method != 'HEAD':
self.write(data)
raise RequestDone
示例2: send_error
# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import get [as 别名]
def send_error(self, exc_info, template="error.html", content_type="text/html", status=500, env=None, data={}):
try:
if template.endswith(".cs") and self.hdf: # FIXME: remove this
if self.args.has_key("hdfdump"):
self.perm.require("TRAC_ADMIN")
content_type = "text/plain"
data = str(self.hdf)
else:
data = self.hdf.render(template)
if template.endswith(".html"):
if env:
from trac.web.chrome import Chrome
try:
data = Chrome(env).render_template(self, template, data, "text/html")
except Exception:
# second chance rendering, in "safe" mode
data["trac_error_rendering"] = True
data = Chrome(env).render_template(self, template, data, "text/html")
else:
content_type = "text/plain"
data = "%s\n\n%s: %s" % (data.get("title"), data.get("type"), data.get("message"))
except: # failed to render
data = get_last_traceback()
content_type = "text/plain"
if isinstance(data, unicode):
data = data.encode("utf-8")
self.send_response(status)
self._outheaders = []
self.send_header("Cache-Control", "must-revalidate")
self.send_header("Expires", "Fri, 01 Jan 1999 00:00:00 GMT")
self.send_header("Content-Type", content_type + ";charset=utf-8")
self.send_header("Content-Length", len(data))
self._send_cookie_headers()
self._write = self._start_response(self._status, self._outheaders, exc_info)
if self.method != "HEAD":
self.write(data)
raise RequestDone