twisted04 使用twisted.web搭建简单文件服务器

来源:互联网 发布:淘宝云客服上班时间 编辑:程序博客网 时间:2024/05/05 06:19

默认的文件服务器,可以任意访问服务器上的URL

from twisted.internet import reactorfrom twisted.web.server import Sitefrom twisted.web.static import Fileresource = File('/var/www/mysite')factory = Site(resource)reactor.listenTCP(8000, factory)reactor.run()


改造之后的文件服务器,只能访问zip文件的URL,否则会提示资源不存在。

from twisted.internet import reactorfrom twisted.web.server import Sitefrom twisted.web.static import Fileclass MyResourceFile(File):def getChild(self, path, request):#print path,requestif not request.uri.endswith('.zip'):return File.childNotFoundreturn super(MyResourceFile, self).getChild(path, request)res = MyResourceFile('E:\\')f = Site(res)reactor.listenTCP(8000, f)reactor.run()



0 0