def get_checksum(content, encoding='utf8', block_size=8192):
 md = hashlib.md5()
 def safe_update(txt):
  try:
   md.update(txt)
  except UnicodeEncodeError:
   md.update(txt.encode(encoding))
 try:
  isfile = os.path.isfile(content)
 except TypeError:
  isfile = False
 if isfile:
  with open(content, 'rb') as ff:
   txt = ff.read(block_size)
   while txt:
    safe_update(txt)
    txt = ff.read(block_size)
 elif hasattr(content, 'read'):
  pos = content.tell()
  content.seek(0)
  txt = content.read(block_size)
  while txt:
   safe_update(txt)
   txt = content.read(block_size)
  content.seek(pos)
 else:
  safe_update(content)
 return md.hexdigest()

def get_checksum ( content , encoding = 'utf8' , block_size = 8192 ) : md = hashlib . md5 ( ) def safe_update ( txt ) : try : md . update ( txt ) except UnicodeEncodeError : md . update ( txt . encode ( encoding ) ) try : isfile = os . path . isfile ( content ) except TypeError : isfile = False if isfile : with open ( content , 'rb' ) as ff : txt = ff . read ( block_size ) while txt : safe_update ( txt ) txt = ff . read ( block_size ) elif hasattr ( content , 'read' ) : pos = content . tell ( ) content . seek ( 0 ) txt = content . read ( block_size ) while txt : safe_update ( txt ) txt = content . read ( block_size ) content . seek ( pos ) else : safe_update ( content ) return md . hexdigest ( )
returns the md5 checksum in hex for the given content .