Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8961

Re: Does hashlib support a file mode?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'ubuntu': 0.04; 'instance': 0.05; '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; 'binary': 0.13; 'subject:file': 0.13; 'wrote:': 0.15; '"right"': 0.16; "'rb')": 0.16; 'arguments:': 0.16; 'combined.': 0.16; 'die,': 0.16; 'hacks': 0.16; 'length,': 0.16; 'mode.': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'dance': 0.16; 'def': 0.16; 'meant': 0.17; 'string': 0.26; 'function': 0.26; 'tried': 0.27; "i'm": 0.27; 'version,': 0.28; 'correct': 0.29; "didn't": 0.29; 'not.': 0.30; 'from:addr:web.de': 0.30; 'subject:support': 0.30; 'subject:?': 0.31; 'usual': 0.32; 'to:addr:python-list': 0.34; 'header:X-Complaints-To:1': 0.34; 'implies': 0.35; 'legacy': 0.35; 'core': 0.36; 'explain': 0.36; 'file': 0.36; 'open': 0.37; 'but': 0.37; 'using': 0.37; 'received:org': 0.38; 'subject:: ': 0.38; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'might': 0.39; 'did': 0.40; 'give': 0.60; 'your': 0.60; 'number.': 0.63; 'defensive': 0.84; 'huh?': 0.84; 'subject:mode': 0.84; 'appeared': 0.91; 'bless': 0.91; 'does?': 0.91
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 19:06:13 +0200
Organization None
References <453cc47b-b545-4bcf-91c0-2efe2aae37bd@v11g2000prn.googlegroups.com> <mailman.704.1309969573.1164.python-list@python.org> <b317226a-8008-4177-aaa6-3fdc30125eea@e20g2000prf.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p5084b5d1.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.709.1309971973.1164.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1309971973 news.xs4all.nl 21849 [2001:888:2000:d::a6]:52657
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:8961

Show key headers only | View raw


Phlip wrote:

>> - Open the file in binary mode.
> 
> I had tried open(path, 'rb') and it didn't change the "wrong" number.
> 
> And I added --binary to my evil md5sum version, and it didn't change
> the "right" number!
> 
> Gods bless those legacy hacks that will never die, huh? But I'm using
> Ubuntu (inside VMWare, on Win7, on a Core i7, because I rule), so that
> might explain why "binary mode" is a no-op.

Indeed. That part was a defensive measure mostly meant to make your function 
Windows-proof.

>> - Do the usual dance for default arguments:
>> def file_to_hash(path, m=None):
>> if m is None:
>> m = hashlib.md5()
> 
> Not sure why if that's what the defaulter does? I did indeed get an
> MD5-style string of what casually appeared to be the right length, so
> that implies the defaulter is not to blame...

The first call will give you the correct checksum, the second: not. As the 
default md5 instance remembers the state from the previous function call 
you'll get the checksum of both files combined. 

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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