connectors/ConnectorBase.py
author Edouard Tisserant
Thu, 31 Jan 2019 14:10:06 +0100
changeset 2485 ef327451d067
parent 2465 47d3aea2be30
child 2487 6a4f9a061994
permissions -rw-r--r--
Add a debugger token to SetTraceVariables and GetTraceVariables to prevent crash an inconsistant data in case of multiple connections. Last connection now takes over existing connections's debug, and first connected IDE gets a wrning.
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# See COPYING file for copyrights details.

import md5

class ConnectorBase(object):

    #chuncksize = 16384
    chuncksize = 1024*1024
    def BlobFromFile(self, filepath): 
        s = md5.new()
        blobID = s.digest()  # empty md5, to support empty blob
        with open(filepath, "rb") as f:
            while True:
                chunk = f.read(self.chuncksize) 
                if len(chunk) == 0: return blobID
                blobID = self.AppendChunkToBlob(chunk, blobID)
                s.update(chunk)
                if blobID != s.digest(): return None