twisted08-1 多级访问-httpserver
来源:互联网 发布:gx8.86编程软怎么安装 编辑:程序博客网 时间:2024/06/06 00:29
#coding=utf8from twisted.internet import reactorfrom twisted.web.server import Sitefrom twisted.web.resource import Resource, NoResourcefrom twisted.web.static import Filefrom calendar import calendarimport sysclass Calendar(Resource):def __init__(self, year):#必须要调用父类的构造函数,否则由于#self.children没有初始化,getChildWithDefault会出错,因为self.children是NoneResource.__init__(self)#super在这里不能使用,super只能用于python新类(从object派生),不能用于老类#super(Calendar,self).__init__()assert(isinstance(year, (int, long)))self.year = yeardef render_GET(self, request):return '<html><h1><pre>%s</pre></h1></html>' % calendar(self.year)def getChild(self, name,request):if name.isdigit() and int(name) > 1990:#递归处理下一个name的日历print 'next_name->',namereturn Calendar(int(name))else:return NoResource()class URL_Dispatcher(Resource):def getChild(self, name, request):#name不是URI,仅是名称,request.uri才是真正的URIif name == '/' or not name:return self#return ico resouceelif name == 'favicon.ico':return File('d:/down.png')#仅仅只能处理 http://localhost:8000/1995#不能处理http://localhost:8000/1995/1995 or http://localhost:8000/1995/1995/../../..#如果返回一个资源对象,将继续getChild往下递归访问,以'/'为分隔符elif name.isdigit() and int(name) > 1990:print 'name->:',namey = int(name)return Calendar(y)else:return NoResource()def render_GET(self, request):return '<html><h1>Calendar</h1></html>'if __name__ == '__main__':reload(sys)sys.setdefaultencoding('utf8')s = Site(URL_Dispatcher())reactor.listenTCP(8000,s)reactor.run()
0 0
- twisted08-1 多级访问-httpserver
- HttpServer
- httpserver
- 多级缓存访问
- HttpServer服务端测试模块-详解[5-1]
- 访问控制-代码的多级管理
- Codeigniter 框架多级目录访问问题
- 多级派生时的访问权限
- twisted08 分发动态处理的http服务器
- Java HttpServer
- Httpserver跳转
- java httpserver
- python HTTPServer
- iso httpServer
- HTTPServer入门
- HttpClient -- HttpServer
- HTTPServer细节
- Go:HttpServer
- iOS培训心得连载四
- hard link与symbolic link区别
- Foundation Kit (一)
- 最长公共子序列
- 机器视觉开源代码集合(转载)
- twisted08-1 多级访问-httpserver
- Hdu1009 贪心
- CS224d lecture 14札记
- 【POJ 1837】 Balance
- Hdu3363 贪心
- poj2442---Sequence
- android jni方法模拟高频按键点击
- HDOJ1160 Fat Mouse's Speed
- POJ 3903 Stock Exchange(LIS)