aboutsummaryrefslogtreecommitdiffstats
path: root/tools/python/xen/sv/HTMLBase.py
blob: d0fca13a980a4f6f9cad87ee0b56d38d7fe33305 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from xen.sv.util import *

class HTMLBase:

    isLeaf = True
 
    def __init__( self ):
        pass

    def render_POST( self, request ):
        self.perform( request )
        return self.render_GET( request )
        
    def render_GET( self, request ):
        pass
    
    def write_BODY( self, request ):
        pass
        
    def write_TOP( self, request ):
        pass
    
    def write_BOTTOM( self, request ):
        pass
    
    def get_op_method(self, op):
        """Get the method for an operation.
        For operation 'foo' looks for 'op_foo'.

        op	operation name
        returns method or None
        """
        op_method_name = 'op_' + op
        return getattr(self, op_method_name, None)
        
    def perform(self, req):
        """General operation handler for posted operations.
        For operation 'foo' looks for a method op_foo and calls
        it with op_foo(req). Replies with code 500 if op_foo
        is not found.

        The method must return a list when req.use_sxp is true
        and an HTML string otherwise (or list).
        Methods may also return a Deferred (for incomplete processing).

        req	request
        """
        op = req.args.get('op')
        if not op is None and len(op) == 1:
            op = op[0]
            op_method = self.get_op_method(op)
            if op_method:
                op_method( req )