Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8951
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'subject:Does': 0.04; 'data:': 0.09; 'naturally': 0.09; 'none:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'output': 0.11; 'binary': 0.13; 'subject:file': 0.13; 'wrote:': 0.15; "'r')": 0.16; 'arguments:': 0.16; 'hex': 0.16; 'mode.': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'dance': 0.16; 'def': 0.16; 'digest': 0.19; 'file,': 0.22; 'function': 0.26; 'problem': 0.29; 'example': 0.30; 'match': 0.30; 'but...': 0.30; 'from:addr:web.de': 0.30; 'subject:support': 0.30; 'version': 0.30; 'subject:?': 0.31; 'usual': 0.32; 'break': 0.33; 'to:addr :python-list': 0.34; 'header:X-Complaints-To:1': 0.34; 'skip:o 20': 0.36; 'file': 0.36; 'open': 0.37; 'but': 0.37; 'received:org': 0.38; 'subject:: ': 0.38; 'two': 0.38; 'header :Mime-Version:1': 0.39; 'data': 0.39; 'version:': 0.39; 'to:addr:python.org': 0.39; 'did': 0.40; 'flow': 0.68; 'stream': 0.77; 'died.': 0.84; 'streams': 0.84; 'subject:mode': 0.84; 'ipad': 0.93; 'yours.': 0.96 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: Does hashlib support a file mode? |
| Date | Wed, 06 Jul 2011 18:26:09 +0200 |
| Organization | None |
| References | <453cc47b-b545-4bcf-91c0-2efe2aae37bd@v11g2000prn.googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p5084b154.dip.t-dialin.net |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.704.1309969573.1164.python-list@python.org> (permalink) |
| Lines | 50 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1309969573 news.xs4all.nl 21780 [2001:888:2000:d::a6]:56028 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:8951 |
Show key headers only | View raw
Phlip wrote:
> Tx, all!. But...
>
>> For example I use this function to copy a stream and return a SHA512 and
>> the output streams size:
>>
>> def write(self, in_handle, out_handle):
>> m = hashlib.sha512()
>> data = in_handle.read(4096)
>> while True:
>> if not data:
>> break
>> m.update(data)
>> out_handle.write(data)
>> data = in_handle.read(4096)
>> out_handle.flush()
>> return (m.hexdigest(), in_handle.tell())
>
> The operation was a success but the patient died.
>
> My version of that did not return the same hex digest as the md5sum
> version:
>
>
> def file_to_hash(path, m = hashlib.md5()):
>
> with open(path, 'r') as f:
>
> s = f.read(8192)
>
> while s:
> m.update(s)
> s = f.read(8192)
>
> return m.hexdigest()
>
> You'll notice it has the same control flow as yours.
>
> That number must eventually match an iPad's internal MD5 opinion of
> that file, after it copies up, so I naturally cannot continue working
> this problem until we see which of the two numbers the iPad likes!
- Open the file in binary mode.
- Do the usual dance for default arguments:
def file_to_hash(path, m=None):
if m is None:
m = hashlib.md5()
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Does hashlib support a file mode? Phlip <phlip2005@gmail.com> - 2011-07-06 08:59 -0700
Re: Does hashlib support a file mode? Peter Otten <__peter__@web.de> - 2011-07-06 18:26 +0200
Re: Does hashlib support a file mode? Phlip <phlip2005@gmail.com> - 2011-07-06 09:49 -0700
Re: Does hashlib support a file mode? Peter Otten <__peter__@web.de> - 2011-07-06 19:06 +0200
Re: Does hashlib support a file mode? Phlip <phlip2005@gmail.com> - 2011-07-06 10:38 -0700
Re: Does hashlib support a file mode? Andrew Berg <bahamutzero8825@gmail.com> - 2011-07-06 13:42 -0500
Re: Does hashlib support a file mode? Chris Torek <nospam@torek.net> - 2011-07-06 17:54 +0000
csiph-web