Improve formatting and documentation (pylint)
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
#!/usr/bin/env python
|
||||
# vim: ts=8 sts=4 sw=4 expandtab
|
||||
# Author: Douglas Clowes (dcl@ansto.gov.au) 2014-04-24
|
||||
""" SICS proxy client for use by unit testing modules
|
||||
|
||||
This class provides for connection to a running SICS instance,
|
||||
including login.
|
||||
It also provides wrapping of transactions and accumulation
|
||||
of a full response with deferred handling and callback
|
||||
"""
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor, defer
|
||||
from twisted.internet.task import LoopingCall
|
||||
@@ -20,6 +27,8 @@ class SicsProtocol(Protocol):
|
||||
self.login = 0
|
||||
self.login_deferred = defer.Deferred()
|
||||
self.command_deferred = None
|
||||
self.command = None
|
||||
self.line_list = []
|
||||
|
||||
def lineReceived(self, line):
|
||||
if self.login == 0:
|
||||
@@ -48,12 +57,14 @@ class SicsProtocol(Protocol):
|
||||
|
||||
def connectionMade(self):
|
||||
if self.verbose:
|
||||
print "connectionMade", self.transport.getHost(), self.transport.getPeer()
|
||||
print "connectionMade",
|
||||
print self.transport.getHost(),
|
||||
print self.transport.getPeer()
|
||||
self.login = 0
|
||||
self.port = self.transport.getHost().port
|
||||
MyConnections[self.port] = self
|
||||
if self.verbose:
|
||||
print "MyConnections:",MyConnections
|
||||
print "MyConnections:", MyConnections
|
||||
|
||||
def connectionLost(self, reason):
|
||||
if self.verbose:
|
||||
@@ -62,14 +73,13 @@ class SicsProtocol(Protocol):
|
||||
self.login = 0
|
||||
self.port = None
|
||||
if self.verbose:
|
||||
print "MyConnections:",MyConnections
|
||||
print "MyConnections:", MyConnections
|
||||
|
||||
def loginComplete(self, line):
|
||||
if self.verbose:
|
||||
print "LoginComplete"
|
||||
self.login_deferred.callback(line)
|
||||
self.factory.call_callbacks(None)
|
||||
pass
|
||||
|
||||
def sendLine(self, m):
|
||||
if self.verbose:
|
||||
@@ -106,24 +116,28 @@ class SICSClientFactory(ReconnectingClientFactory):
|
||||
if self.verbose:
|
||||
print 'Connected to:', addr
|
||||
self.resetDelay()
|
||||
p = SicsProtocol()
|
||||
my_proto = SicsProtocol()
|
||||
if self.verbose:
|
||||
p.verbose = True
|
||||
p.factory = self
|
||||
p.delimiter = '\n'
|
||||
self.device = p
|
||||
return p
|
||||
my_proto.verbose = True
|
||||
my_proto.factory = self
|
||||
my_proto.delimiter = '\n'
|
||||
self.device = my_proto
|
||||
return my_proto
|
||||
|
||||
def clientConnectionLost(self, connector, reason):
|
||||
if self.verbose:
|
||||
print 'Lost connection', connector.getDestination().port,'Reason:', reason
|
||||
print 'Lost connection',
|
||||
print connector.getDestination().port,
|
||||
print 'Reason:', reason
|
||||
self.device = None
|
||||
ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
|
||||
ReconnectingClientFactory.clientConnectionLost(self,
|
||||
connector, reason)
|
||||
|
||||
def clientConnectionFailed(self, connector, reason):
|
||||
if self.verbose:
|
||||
print 'Connection failed. Reason:', reason
|
||||
ReconnectingClientFactory.clientConnectionFailed(self, connector,reason)
|
||||
ReconnectingClientFactory.clientConnectionFailed(self,
|
||||
connector, reason)
|
||||
|
||||
def sendMessage(self, m):
|
||||
if self.device:
|
||||
@@ -147,7 +161,7 @@ class SICSClientFactory(ReconnectingClientFactory):
|
||||
for cb in self.callbacks:
|
||||
cb(self, data)
|
||||
|
||||
if __name__ == "__main__":
|
||||
def main_program():
|
||||
Verbose = False
|
||||
def cbf(server, data):
|
||||
if Verbose:
|
||||
@@ -168,10 +182,12 @@ if __name__ == "__main__":
|
||||
if Verbose:
|
||||
factory.verbose = True
|
||||
factory.add_callback(cbf)
|
||||
connector = reactor.connectTCP("localhost", 60003, factory)
|
||||
my_connector = reactor.connectTCP("localhost", 60003, factory)
|
||||
if True:
|
||||
print "Factory:", dir(factory)
|
||||
print "Destination:", connector.getDestination()
|
||||
print "Connector:", dir(connector)
|
||||
print "Destination:", my_connector.getDestination()
|
||||
print "Connector:", dir(my_connector)
|
||||
reactor.run()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main_program()
|
||||
|
||||
Reference in New Issue
Block a user