當前位置: 首頁>>代碼示例>>Python>>正文


Python Response.headers['content-type']方法代碼示例

本文整理匯總了Python中pylons.Response.headers['content-type']方法的典型用法代碼示例。如果您正苦於以下問題:Python Response.headers['content-type']方法的具體用法?Python Response.headers['content-type']怎麽用?Python Response.headers['content-type']使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pylons.Response的用法示例。


在下文中一共展示了Response.headers['content-type']方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: filter

# 需要導入模塊: from pylons import Response [as 別名]
# 或者: from pylons.Response import headers['content-type'] [as 別名]
 def filter(self, execution_func, prof_arg = None):
     # put thie imports here so the app doesn't choke if profiling
     # is not present (this is a debug-only feature anyway)
     import cProfile as profile
     from pstats import Stats
     from r2.lib.contrib import gprof2dot
     # profiling needs an actual file to dump to.  Everything else
     # can be mitigated with streams
     tmpfile = tempfile.NamedTemporaryFile()
     dotfile = StringIO()
     # simple cutoff validation
     try:
         cutoff = .01 if prof_arg is None else float(prof_arg)/100
     except ValueError:
         cutoff = .01
     try:
         # profile the code in the current context
         profile.runctx('execution_func()',
                        globals(), locals(), tmpfile.name)
         # parse the data
         parser = gprof2dot.PstatsParser(tmpfile.name)
         prof = parser.parse()
         # remove nodes and edges with less than cutoff work
         prof.prune(cutoff, cutoff)
         # make the dotfile
         dot = gprof2dot.DotWriter(dotfile)
         dot.graph(prof, gprof2dot.TEMPERATURE_COLORMAP)
         # convert the dotfile to PNG in local stdout
         proc = subprocess.Popen("dot -Tpng",
                                 shell = True,
                                 stdin =subprocess.PIPE,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
         out, error =  proc.communicate(input = dotfile.getvalue())
         # generate the response
         r = Response()
         r.status_code = 200
         r.headers['content-type'] = "image/png"
         r.content = out
         return r
     finally:
         tmpfile.close()
開發者ID:JediWatchman,項目名稱:reddit,代碼行數:44,代碼來源:middleware.py


注:本文中的pylons.Response.headers['content-type']方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。