-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverboseprotocols.py
43 lines (32 loc) · 1.87 KB
/
verboseprotocols.py
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
"""
Extended, more verbose ClientFactory and ReconnectingClientFactory
Extended versions print info on startedConnecting, clientConnectionLost, clientConnectionFailed
"""
from twisted.internet import reactor, protocol
def format_reason(reason):
""" formats reason helper function """
return reason.getErrorMessage()
class ClientFactory (protocol.ClientFactory):
""" Verbose version of ClientFactory """
def startedConnecting(self, connector):
print
print '[SSHClient-ClientFactory] Connecting..'
return protocol.ClientFactory.startedConnecting(self, connector)
def clientConnectionLost(self, connector, reason):
print '[SSHClient-ClientFactory] Lost connection. Reason:', format_reason(reason)
return protocol.ClientFactory.clientConnectionLost(self, connector, reason)
def clientConnectionFailed(self, connector, reason):
print '[SSHClient-ClientFactory] Connection failed. Reason:', format_reason(reason)
return protocol.ClientFactory.clientConnectionFailed(self, connector, reason)
class ReconnectingClientFactory (protocol.ReconnectingClientFactory):
""" Verbose version of ReconnectingClientFactory """
def startedConnecting(self, connector):
print
print '[SSHClient-ClientFactory] Connecting..'
return protocol.ReconnectingClientFactory.startedConnecting(self, connector)
def clientConnectionLost(self, connector, reason):
print '[SSHClient-ClientFactory] Lost connection. Reason:', format_reason(reason)
return protocol.ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
def clientConnectionFailed(self, connector, reason):
print '[SSHClient-ClientFactory] Connection failed. Reason:', format_reason(reason)
return protocol.ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)