debuggers.hg

view tools/python/xen/web/static.py @ 4655:a838a908e38e

bitkeeper revision 1.1327.2.2 (4267a9b3MhPpljnjQ5IbfLdzcW2K3w)

Remove twisted from the HTTP server and replace with a
threaded server. Add classes to provide tcp and unix servers
using threads instead of twisted. Remove use of twisted from
the consoles, event server and HTTP resources

Signed-off-by: Mike Wray <mike.wray@hp.com>
author mjw@wray-m-3.hpl.hp.com
date Thu Apr 21 13:25:07 2005 +0000 (2005-04-21)
parents
children 369e382b2f81
line source
1 import os
3 from resource import Resource
5 class File(Resource):
7 isLeaf = True
9 def __init__(self, filename, defaultType=None):
10 if defaultType is None:
11 defaultType = "text/plain"
12 self.filename = filename
13 self.type = defaultType
14 self.encoding = None
16 def getFileSize(self):
17 try:
18 info = os.stat(self.filename)
19 return info.st_size
20 except:
21 return 0
23 def render(self, req):
24 if self.type:
25 req.setHeader('Content-Type', self.type)
26 if self.encoding:
27 rew.setHeader('Content-Encoding', self.encoding)
28 req.setHeader('Content-Length', self.getFileSize())
29 try:
30 io = file(self.filename, "r")
31 while True:
32 buf = io.read(1024)
33 if not buf:
34 break
35 req.write(buf)
36 except IOError:
37 pass
38 try:
39 if io:
40 io.close()
41 except:
42 pass
43 return ''