Mercurial > hg-stable
comparison hgext/largefiles/lfutil.py @ 36150:6426878f7f0f
py3: use hex(hasher.digest())
.hexdigest() returns a system str. .digest() consistently returns
bytes.
Differential Revision: https://phab.mercurial-scm.org/D2159
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 11 Feb 2018 16:29:35 -0800 |
parents | be4481d6222e |
children | 164306d3f4b4 |
comparison
equal
deleted
inserted
replaced
36149:b44a47214122 | 36150:6426878f7f0f |
---|---|
13 import hashlib | 13 import hashlib |
14 import os | 14 import os |
15 import stat | 15 import stat |
16 | 16 |
17 from mercurial.i18n import _ | 17 from mercurial.i18n import _ |
18 from mercurial.node import hex | |
18 | 19 |
19 from mercurial import ( | 20 from mercurial import ( |
20 dirstate, | 21 dirstate, |
21 encoding, | 22 encoding, |
22 error, | 23 error, |
369 computing the SHA-1 hash of the data along the way. Return the hash.''' | 370 computing the SHA-1 hash of the data along the way. Return the hash.''' |
370 hasher = hashlib.sha1('') | 371 hasher = hashlib.sha1('') |
371 for data in instream: | 372 for data in instream: |
372 hasher.update(data) | 373 hasher.update(data) |
373 outfile.write(data) | 374 outfile.write(data) |
374 return hasher.hexdigest() | 375 return hex(hasher.digest()) |
375 | 376 |
376 def hashfile(file): | 377 def hashfile(file): |
377 if not os.path.exists(file): | 378 if not os.path.exists(file): |
378 return '' | 379 return '' |
379 with open(file, 'rb') as fd: | 380 with open(file, 'rb') as fd: |
402 """hexsha1 returns the hex-encoded sha1 sum of the data in the file-like | 403 """hexsha1 returns the hex-encoded sha1 sum of the data in the file-like |
403 object data""" | 404 object data""" |
404 h = hashlib.sha1() | 405 h = hashlib.sha1() |
405 for chunk in util.filechunkiter(fileobj): | 406 for chunk in util.filechunkiter(fileobj): |
406 h.update(chunk) | 407 h.update(chunk) |
407 return h.hexdigest() | 408 return hex(h.digest()) |
408 | 409 |
409 def httpsendfile(ui, filename): | 410 def httpsendfile(ui, filename): |
410 return httpconnection.httpsendfile(ui, filename, 'rb') | 411 return httpconnection.httpsendfile(ui, filename, 'rb') |
411 | 412 |
412 def unixpath(path): | 413 def unixpath(path): |