Patchwork keepalive: fix how md5 is used

login
register
mail settings
Submitter Mike Hommey
Date Sept. 24, 2014, 6:56 a.m.
Message ID <bc01442c6e030eee52c5.1411541797@zenigata.glandium.org>
Download mbox | patch
Permalink /patch/5955/
State Accepted
Headers show

Comments

Mike Hommey - Sept. 24, 2014, 6:56 a.m.
# HG changeset patch
# User Mike Hommey <mh@glandium.org>
# Date 1411541560 -32400
#      Wed Sep 24 15:52:40 2014 +0900
# Node ID bc01442c6e030eee52c5f5524a28a50b1c25a4a6
# Parent  80ffdeecf26b373db4fd4a4bf26d548d456fa7b6
keepalive: fix how md5 is used

The code in keepalive dates from when it was importing the md5 module directly
and uses md5.new. Since then, what 'md5' means has been changed from an import
of the md5 module to being a function using the right module between hashlib
and md5, so the md5.new idiom doesn't work anymore.
Mike Hommey - Sept. 24, 2014, 7:04 a.m.
On Wed, Sep 24, 2014 at 03:56:37PM +0900, Mike Hommey wrote:
> # HG changeset patch
> # User Mike Hommey <mh@glandium.org>
> # Date 1411541560 -32400
> #      Wed Sep 24 15:52:40 2014 +0900
> # Node ID bc01442c6e030eee52c5f5524a28a50b1c25a4a6
> # Parent  80ffdeecf26b373db4fd4a4bf26d548d456fa7b6
> keepalive: fix how md5 is used
> 
> The code in keepalive dates from when it was importing the md5 module directly
> and uses md5.new. Since then, what 'md5' means has been changed from an import
> of the md5 module to being a function using the right module between hashlib
> and md5, so the md5.new idiom doesn't work anymore.

Note that considering how long this has been broken, this could also be
considered dead code and simply removed.

Mike
Mike Hommey - Sept. 24, 2014, 7:08 a.m.
On Wed, Sep 24, 2014 at 04:04:46PM +0900, Mike Hommey wrote:
> On Wed, Sep 24, 2014 at 03:56:37PM +0900, Mike Hommey wrote:
> > # HG changeset patch
> > # User Mike Hommey <mh@glandium.org>
> > # Date 1411541560 -32400
> > #      Wed Sep 24 15:52:40 2014 +0900
> > # Node ID bc01442c6e030eee52c5f5524a28a50b1c25a4a6
> > # Parent  80ffdeecf26b373db4fd4a4bf26d548d456fa7b6
> > keepalive: fix how md5 is used
> > 
> > The code in keepalive dates from when it was importing the md5 module directly
> > and uses md5.new. Since then, what 'md5' means has been changed from an import
> > of the md5 module to being a function using the right module between hashlib
> > and md5, so the md5.new idiom doesn't work anymore.
> 
> Note that considering how long this has been broken, this could also be
> considered dead code and simply removed.

For the record, this has been broken since changeset ac0bcd951c2c, 6.5 years
ago.

Mike
Augie Fackler - Sept. 24, 2014, 2:05 p.m.
On Wed, Sep 24, 2014 at 03:56:37PM +0900, Mike Hommey wrote:
> # HG changeset patch
> # User Mike Hommey <mh@glandium.org>
> # Date 1411541560 -32400
> #      Wed Sep 24 15:52:40 2014 +0900
> # Node ID bc01442c6e030eee52c5f5524a28a50b1c25a4a6
> # Parent  80ffdeecf26b373db4fd4a4bf26d548d456fa7b6
> keepalive: fix how md5 is used

Queued for stable, though you're probably right that this is dead code.

>
> The code in keepalive dates from when it was importing the md5 module directly
> and uses md5.new. Since then, what 'md5' means has been changed from an import
> of the md5 module to being a function using the right module between hashlib
> and md5, so the md5.new idiom doesn't work anymore.
>
> diff --git a/mercurial/keepalive.py b/mercurial/keepalive.py
> --- a/mercurial/keepalive.py
> +++ b/mercurial/keepalive.py
> @@ -630,38 +630,38 @@ def continuity(url):
>      format = '%25s: %s'
>
>      # first fetch the file with the normal http handler
>      opener = urllib2.build_opener()
>      urllib2.install_opener(opener)
>      fo = urllib2.urlopen(url)
>      foo = fo.read()
>      fo.close()
> -    m = md5.new(foo)
> +    m = md5(foo)
>      print format % ('normal urllib', m.hexdigest())
>
>      # now install the keepalive handler and try again
>      opener = urllib2.build_opener(HTTPHandler())
>      urllib2.install_opener(opener)
>
>      fo = urllib2.urlopen(url)
>      foo = fo.read()
>      fo.close()
> -    m = md5.new(foo)
> +    m = md5(foo)
>      print format % ('keepalive read', m.hexdigest())
>
>      fo = urllib2.urlopen(url)
>      foo = ''
>      while True:
>          f = fo.readline()
>          if f:
>              foo = foo + f
>          else: break
>      fo.close()
> -    m = md5.new(foo)
> +    m = md5(foo)
>      print format % ('keepalive readline', m.hexdigest())
>
>  def comp(N, url):
>      print '  making %i connections to:\n  %s' % (N, url)
>
>      sys.stdout.write('  first using the normal urllib handlers')
>      # first use normal opener
>      opener = urllib2.build_opener()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/keepalive.py b/mercurial/keepalive.py
--- a/mercurial/keepalive.py
+++ b/mercurial/keepalive.py
@@ -630,38 +630,38 @@  def continuity(url):
     format = '%25s: %s'
 
     # first fetch the file with the normal http handler
     opener = urllib2.build_opener()
     urllib2.install_opener(opener)
     fo = urllib2.urlopen(url)
     foo = fo.read()
     fo.close()
-    m = md5.new(foo)
+    m = md5(foo)
     print format % ('normal urllib', m.hexdigest())
 
     # now install the keepalive handler and try again
     opener = urllib2.build_opener(HTTPHandler())
     urllib2.install_opener(opener)
 
     fo = urllib2.urlopen(url)
     foo = fo.read()
     fo.close()
-    m = md5.new(foo)
+    m = md5(foo)
     print format % ('keepalive read', m.hexdigest())
 
     fo = urllib2.urlopen(url)
     foo = ''
     while True:
         f = fo.readline()
         if f:
             foo = foo + f
         else: break
     fo.close()
-    m = md5.new(foo)
+    m = md5(foo)
     print format % ('keepalive readline', m.hexdigest())
 
 def comp(N, url):
     print '  making %i connections to:\n  %s' % (N, url)
 
     sys.stdout.write('  first using the normal urllib handlers')
     # first use normal opener
     opener = urllib2.build_opener()