debuggers.hg

view tools/python/xen/web/SrvBase.py @ 4672:d781b9d08e80

bitkeeper revision 1.1327.2.4 (426918a34Af7gihN8mTkq-P3KrAZXg)

Remove twisted from save/migrate handling.
This needs to use threads, so add thread support for
http server requests.

Signed-off-by: Mike Wray <mike.wray@hp.com>
author mjw@wray-m-3.hpl.hp.com
date Fri Apr 22 15:30:43 2005 +0000 (2005-04-22)
parents a838a908e38e
children 369e382b2f81
line source
1 # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
3 import types
6 from xen.xend import sxp
7 from xen.xend import PrettyPrint
8 from xen.xend.Args import ArgError
9 from xen.xend.XendError import XendError
10 from xen.xend.XendLogging import log
12 import resource
13 import http
14 import httpserver
15 import defer
17 def uri_pathlist(p):
18 """Split a path into a list.
19 p path
20 return list of path elements
21 """
22 l = []
23 for x in p.split('/'):
24 if x == '': continue
25 l.append(x)
26 return l
28 class SrvBase(resource.Resource):
29 """Base class for services.
30 """
33 def use_sxp(self, req):
34 return req.useSxp()
36 def get_op_method(self, op):
37 """Get the method for an operation.
38 For operation 'foo' looks for 'op_foo'.
40 op operation name
41 returns method or None
42 """
43 op_method_name = 'op_' + op
44 return getattr(self, op_method_name, None)
46 def perform(self, req):
47 """General operation handler for posted operations.
48 For operation 'foo' looks for a method op_foo and calls
49 it with op_foo(op, req). Replies with code 500 if op_foo
50 is not found.
52 The method must return a list when req.use_sxp is true
53 and an HTML string otherwise (or list).
54 Methods may also return a ThreadRequest (for incomplete processing).
56 req request
57 """
58 op = req.args.get('op')
59 if op is None or len(op) != 1:
60 req.setResponseCode(http.NOT_ACCEPTABLE, "Invalid request")
61 return ''
62 op = op[0]
63 op_method = self.get_op_method(op)
64 if op_method is None:
65 req.setResponseCode(http.NOT_IMPLEMENTED, "Operation not implemented: " + op)
66 req.setHeader("Content-Type", "text/plain")
67 req.write("Operation not implemented: " + op)
68 return ''
69 else:
70 return op_method(op, req)
72 def print_path(self, req):
73 """Print the path with hyperlinks.
74 """
75 req.printPath()