debuggers.hg

view tools/python/xen/web/protocol.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 d781b9d08e80
line source
1 class Factory:
3 def __init__(self):
4 pass
6 def startedConnecting(self):
7 print 'ServerProtocolFactory>startedConnecting>'
8 pass
10 def doStart(self):
11 print 'ServerProtocolFactory>doStart>'
12 pass
14 def doStop(self):
15 print 'ServerProtocolFactory>doStop>'
16 pass
18 def buildProtocol(self, addr):
19 print 'ServerProtocolFactory>buildProtocol>', addr
20 return Protocol(self)
22 class ServerFactory(Factory):
23 pass
25 class ClientFactory(Factory):
26 pass
28 class Protocol:
30 factory = None
31 transport = None
32 connected = False
34 def __init__(self, factory):
35 self.factory = factory
37 def setTransport(self, transport):
38 self.transport = transport
39 self.connected = bool(transport)
41 def getTransport(self):
42 return self.transport
44 def connectionMade(self, addr):
45 print 'Protocol>connectionMade>', addr
46 pass
48 def connectionLost(self, reason=None):
49 print 'Protocol>connectionLost>', reason
50 pass
52 def dataReceived(self, data):
53 print 'Protocol>dataReceived>'
54 pass
56 def write(self, data):
57 if self.transport:
58 return self.transport.write(data)
59 else:
60 return 0
62 def read(self):
63 if self.transport:
64 return self.transport.read()
65 else:
66 return None
68 class TestClientFactory(Factory):
70 def buildProtocol(self, addr):
71 print 'TestClientProtocolFactory>buildProtocol>', addr
72 return TestClientProtocol(self)
74 class TestClientProtocol(Protocol):
76 def connectionMade(self, addr):
77 print 'TestProtocol>connectionMade>', addr
78 self.write("hello")
79 self.write("there")
81 class TestServerFactory(Factory):
83 def buildProtocol(self, addr):
84 print 'TestServerProtocolFactory>buildProtocol>', addr
85 return TestServerProtocol(self)
87 class TestServerProtocol(Protocol):
89 def dataReceived(self, data):
90 print 'TestServerProtocol>dataReceived>', len(data), data
91 #sys.exit(0)
92 import os
93 os._exit(0)