当前位置: 首页>>代码示例>>Python>>正文


Python IRequest.write方法代码示例

本文整理汇总了Python中nevow.inevow.IRequest.write方法的典型用法代码示例。如果您正苦于以下问题:Python IRequest.write方法的具体用法?Python IRequest.write怎么用?Python IRequest.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nevow.inevow.IRequest的用法示例。


在下文中一共展示了IRequest.write方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ManifestStreamer

# 需要导入模块: from nevow.inevow import IRequest [as 别名]
# 或者: from nevow.inevow.IRequest import write [as 别名]
class ManifestStreamer(dirnode.DeepStats):
    implements(IPushProducer)

    def __init__(self, ctx, origin):
        dirnode.DeepStats.__init__(self, origin)
        self.req = IRequest(ctx)

    def setMonitor(self, monitor):
        self.monitor = monitor
    def pauseProducing(self):
        pass
    def resumeProducing(self):
        pass
    def stopProducing(self):
        self.monitor.cancel()

    def add_node(self, node, path):
        dirnode.DeepStats.add_node(self, node, path)
        d = {"path": path,
             "cap": node.get_uri()}

        if IDirectoryNode.providedBy(node):
            d["type"] = "directory"
        elif IFileNode.providedBy(node):
            d["type"] = "file"
        else:
            d["type"] = "unknown"

        v = node.get_verify_cap()
        if v:
            v = v.to_string()
        d["verifycap"] = v or ""

        r = node.get_repair_cap()
        if r:
            r = r.to_string()
        d["repaircap"] = r or ""

        si = node.get_storage_index()
        if si:
            si = base32.b2a(si)
        d["storage-index"] = si or ""

        j = simplejson.dumps(d, ensure_ascii=True)
        assert "\n" not in j
        self.req.write(j+"\n")

    def finish(self):
        stats = dirnode.DeepStats.get_results(self)
        d = {"type": "stats",
             "stats": stats,
             }
        j = simplejson.dumps(d, ensure_ascii=True)
        assert "\n" not in j
        self.req.write(j+"\n")
        return ""
开发者ID:david415,项目名称:tahoe-lafs,代码行数:58,代码来源:directory.py

示例2: simple

# 需要导入模块: from nevow.inevow import IRequest [as 别名]
# 或者: from nevow.inevow.IRequest import write [as 别名]
 def simple(self, ctx, text, code=http.BAD_REQUEST):
     req = IRequest(ctx)
     req.setResponseCode(code)
     #req.responseHeaders.setRawHeaders("content-encoding", [])
     #req.responseHeaders.setRawHeaders("content-disposition", [])
     req.setHeader("content-type", "text/plain;charset=utf-8")
     if isinstance(text, unicode):
         text = text.encode("utf-8")
     req.setHeader("content-length", str(len(text)))
     req.write(text)
     # TODO: consider putting the requested URL here
     req.finishRequest(False)
开发者ID:gnusosa,项目名称:tahoe-lafs,代码行数:14,代码来源:common.py

示例3: DeepCheckStreamer

# 需要导入模块: from nevow.inevow import IRequest [as 别名]
# 或者: from nevow.inevow.IRequest import write [as 别名]
class DeepCheckStreamer(dirnode.DeepStats):

    def __init__(self, ctx, origin, verify, repair, add_lease):
        dirnode.DeepStats.__init__(self, origin)
        self.req = IRequest(ctx)
        self.verify = verify
        self.repair = repair
        self.add_lease = add_lease

    def setMonitor(self, monitor):
        self.monitor = monitor
    def pauseProducing(self):
        pass
    def resumeProducing(self):
        pass
    def stopProducing(self):
        self.monitor.cancel()

    def add_node(self, node, path):
        dirnode.DeepStats.add_node(self, node, path)
        data = {"path": path,
                "cap": node.get_uri()}

        if IDirectoryNode.providedBy(node):
            data["type"] = "directory"
        elif IFileNode.providedBy(node):
            data["type"] = "file"
        else:
            data["type"] = "unknown"

        v = node.get_verify_cap()
        if v:
            v = v.to_string()
        data["verifycap"] = v or ""

        r = node.get_repair_cap()
        if r:
            r = r.to_string()
        data["repaircap"] = r or ""

        si = node.get_storage_index()
        if si:
            si = base32.b2a(si)
        data["storage-index"] = si or ""

        if self.repair:
            d = node.check_and_repair(self.monitor, self.verify, self.add_lease)
            d.addCallback(self.add_check_and_repair, data)
        else:
            d = node.check(self.monitor, self.verify, self.add_lease)
            d.addCallback(self.add_check, data)
        d.addCallback(self.write_line)
        return d

    def add_check_and_repair(self, crr, data):
        data["check-and-repair-results"] = json_check_and_repair_results(crr)
        return data

    def add_check(self, cr, data):
        data["check-results"] = json_check_results(cr)
        return data

    def write_line(self, data):
        j = json.dumps(data, ensure_ascii=True)
        assert "\n" not in j
        self.req.write(j+"\n")

    def finish(self):
        stats = dirnode.DeepStats.get_results(self)
        d = {"type": "stats",
             "stats": stats,
             }
        j = json.dumps(d, ensure_ascii=True)
        assert "\n" not in j
        self.req.write(j+"\n")
        return ""
开发者ID:LeastAuthority,项目名称:tahoe-lafs,代码行数:78,代码来源:directory.py


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