"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Tardis/Connection.py" between
Tardis-1.1.5.tar.gz and Tardis-1.2.1.tar.gz

About: Tardis is a system for making encrypted, incremental backups of filesystems.

Connection.py  (Tardis-1.1.5):Connection.py  (Tardis-1.2.1)
skipping to change at line 35 skipping to change at line 35
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
import socket import socket
import json import json
import time import time
import ssl import ssl
import queue
import Tardis import Tardis
import Tardis.Messages as Messages import Tardis.Messages as Messages
protocolVersion = "1.4" protocolVersion = "1.4"
headerString = "TARDIS " + protocolVersion headerString = "TARDIS " + protocolVersion
sslHeaderString = headerString + "/SSL" sslHeaderString = headerString + "/SSL"
class ConnectionException(Exception): class ConnectionException(Exception):
pass pass
skipping to change at line 126 skipping to change at line 127
def send(self, message, compress=True): def send(self, message, compress=True):
self.sender.sendMessage(message, compress) self.sender.sendMessage(message, compress)
self.stats['messagesSent'] += 1 self.stats['messagesSent'] += 1
def receive(self): def receive(self):
message = self.sender.recvMessage() message = self.sender.recvMessage()
self.stats['messagesRecvd'] += 1 self.stats['messagesRecvd'] += 1
return message return message
def close(self): def close(self, error=None):
self.send({"message" : "BYE" }) message = {"message": "BYE" }
if error:
message["error"] = error
self.send(message)
super(ProtocolConnection, self).close() super(ProtocolConnection, self).close()
def encode(self, string): def encode(self, string):
return self.sender.encode(string) return self.sender.encode(string)
def decode(self, string): def decode(self, string):
return self.sender.decode(string) return self.sender.decode(string)
_defaultVersion = Tardis.__buildversion__ or Tardis.__version__ _defaultVersion = Tardis.__buildversion__ or Tardis.__version__
skipping to change at line 157 skipping to change at line 161
ProtocolConnection.__init__(self, host, port, 'BSON', compress, timeout) ProtocolConnection.__init__(self, host, port, 'BSON', compress, timeout)
# Really, cons this up in the connection, but it needs access to the soc k parameter, so..... # Really, cons this up in the connection, but it needs access to the soc k parameter, so.....
self.sender = Messages.BsonMessages(self.sock, stats=self.stats, compres s=compress) self.sender = Messages.BsonMessages(self.sock, stats=self.stats, compres s=compress)
class MsgPackConnection(ProtocolConnection): class MsgPackConnection(ProtocolConnection):
def __init__(self, host, port, compress, timeout): def __init__(self, host, port, compress, timeout):
ProtocolConnection.__init__(self, host, port, 'MSGP', compress, timeout) ProtocolConnection.__init__(self, host, port, 'MSGP', compress, timeout)
# Really, cons this up in the connection, but it needs access to the soc k parameter, so..... # Really, cons this up in the connection, but it needs access to the soc k parameter, so.....
self.sender = Messages.MsgPackMessages(self.sock, stats=self.stats, comp ress=compress) self.sender = Messages.MsgPackMessages(self.sock, stats=self.stats, comp ress=compress)
class DirectConnection:
stats = { 'messagesRecvd': 0, 'messagesSent' : 0, 'bytesRecvd': 0, 'bytesSen
t': 0 }
serverStats = { 'messagesRecvd': 0, 'messagesSent' : 0, 'bytesRecvd': 0, 'by
tesSent': 0 }
def __init__(self, timeout):
self.timeout = timeout
self.toClientQueue = queue.SimpleQueue()
self.toServerQueue = queue.Queue(1024)
self.clientMessages = Messages.ObjectMessages(self.toClientQueue, self.t
oServerQueue, self.stats, timeout)
self.serverMessages = Messages.ObjectMessages(self.toServerQueue, self.t
oClientQueue)
self.sender = self.clientMessages
def send(self, message, compress=True):
self.sender.sendMessage(message, compress)
self.stats['messagesSent'] += 1
def receive(self):
message = self.sender.recvMessage()
self.stats['messagesRecvd'] += 1
return message
def close(self):
self.send({"message" : "BYE" })
def encode(self, string):
return self.sender.encode(string)
def decode(self, string):
return self.sender.decode(string)
def getStats(self):
return self.stats
if __name__ == "__main__": if __name__ == "__main__":
""" """
Test Code Test Code
"""
conn = JsonConnection("localhost", 9999, "HiMom") conn = JsonConnection("localhost", 9999, "HiMom")
print(conn.getSessionId()) print(conn.getSessionId())
conn.send({ 'x' : 1 }) conn.send({ 'x' : 1 })
print(conn.receive()) print(conn.receive())
conn.send({ 'y' : 2 }) conn.send({ 'y' : 2 })
print(conn.receive()) print(conn.receive())
conn.close() conn.close()
"""
conn = DirectConnection(None)
server = conn.serverMessages
conn.send({"a" : 1})
print(server.recvMessage())
server.sendMessage({"b": 2, "c": ['a', 'b', 'c']})
print(conn.receive())
 End of changes. 5 change blocks. 
3 lines changed or deleted 43 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)