当前位置: 首页>>代码示例>>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 = 0.01 if prof_arg is None else float(prof_arg) / 100
        except ValueError:
            cutoff = 0.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:Julian,项目名称:reddit,代码行数:42,代码来源:middleware.py


注:本文中的pylons.Response.headers["content-type"]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。