connectors/ConnectorBase.py
changeset 2540 fca79ca84272
parent 2492 7dd551ac2fa0
child 2542 a3ec35ee94e7
equal deleted inserted replaced
2539:bcadc7f465ee 2540:fca79ca84272
     2 # -*- coding: utf-8 -*-
     2 # -*- coding: utf-8 -*-
     3 
     3 
     4 # See COPYING file for copyrights details.
     4 # See COPYING file for copyrights details.
     5 
     5 
     6 from __future__ import absolute_import
     6 from __future__ import absolute_import
     7 import md5
     7 import hashlib
     8 
     8 
     9 
     9 
    10 class ConnectorBase(object):
    10 class ConnectorBase(object):
    11 
    11 
    12     chuncksize = 1024*1024
    12     chuncksize = 1024*1024
    13 
    13 
    14     def BlobFromFile(self, filepath, seed):
    14     def BlobFromFile(self, filepath, seed):
    15         s = md5.new()
    15         s = hashlib.new('md5')
    16         s.update(seed)
    16         s.update(seed)
    17         blobID = self.SeedBlob(seed)
    17         blobID = self.SeedBlob(seed)
    18         with open(filepath, "rb") as f:
    18         with open(filepath, "rb") as f:
    19             while blobID == s.digest():
    19             while blobID == s.digest():
    20                 chunk = f.read(self.chuncksize)
    20                 chunk = f.read(self.chuncksize)
    21                 if len(chunk) == 0:
    21                 if len(chunk) == 0:
    22                     return blobID
    22                     return blobID
    23                 blobID = self.AppendChunkToBlob(chunk, blobID)
    23                 blobID = self.AppendChunkToBlob(chunk, blobID)
    24                 s.update(chunk)
    24                 s.update(chunk)
       
    25