def set_id(self, data):
"""
Set ID of document. To allow multiple files with the same path, the
digest of supplied data (e.g. first 4KB) is appended to the doc ID.
:param data: Data to append to docuemnt path.
:type data: Anything digestable by hashlib.
"""
digest = hashlib.md5()
digest.update(self.path.encode('utf-8'))
if isinstance(data, unicode):
data = data.encode('utf-8')
digest.update(data)
self.docid = digest.hexdigest()
评论列表
文章目录