Patchwork [1,of,7,V3] util: move md5 back next to sha1 and allow to call it without an argument

login
register
mail settings
Submitter Mike Hommey
Date Oct. 16, 2014, 8:22 a.m.
Message ID <97135fb11cee697a17fb.1413447746@zenigata.glandium.org>
Download mbox | patch
Permalink /patch/6318/
State Accepted
Headers show

Comments

Mike Hommey - Oct. 16, 2014, 8:22 a.m.
# HG changeset patch
# User Mike Hommey <mh@glandium.org>
# Date 1411542047 -32400
#      Wed Sep 24 16:00:47 2014 +0900
# Node ID 97135fb11cee697a17fbc2409c730e2c5b0a1edc
# Parent  da2758c0aca04fe20fef2797f80c6079099afca5
util: move md5 back next to sha1 and allow to call it without an argument

This effectively backs out changeset 908c5906091b.

The API change is done so that both util.sha1 and util.md5 can be called the
same way. The function is moved in order to use it for md5 checksumming for
an upcoming bundle2 feature.

Patch

diff --git a/mercurial/keepalive.py b/mercurial/keepalive.py
--- a/mercurial/keepalive.py
+++ b/mercurial/keepalive.py
@@ -14,18 +14,16 @@ 
 
 # This file is part of urlgrabber, a high-level cross-protocol url-grabber
 # Copyright 2002-2004 Michael D. Stenner, Ryan Tomayko
 
 # Modified by Benoit Boissinot:
 #  - fix for digest auth (inspired from urllib2.py @ Python v2.4)
 # Modified by Dirkjan Ochtman:
 #  - import md5 function from a local util module
-# Modified by Martin Geisler:
-#  - moved md5 function from local util module to this module
 # Modified by Augie Fackler:
 #  - add safesend method and use it to prevent broken pipe errors
 #    on large POST requests
 
 """An HTTP handler for urllib2 that supports HTTP 1.1 and keepalive.
 
 >>> import urllib2
 >>> from keepalive import HTTPHandler
@@ -612,26 +610,18 @@  def error_handler(url):
             raise
         else:
             print "  status = %s, reason = %s" % (status, reason)
     HANDLE_ERRORS = orig
     hosts = keepalive_handler.open_connections()
     print "open connections:", hosts
     keepalive_handler.close_all()
 
-def md5(s):
-    try:
-        from hashlib import md5 as _md5
-    except ImportError:
-        from md5 import md5 as _md5
-    global md5
-    md5 = _md5
-    return _md5(s)
-
 def continuity(url):
+    from util import md5
     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()
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -103,16 +103,25 @@  def _fastsha1(s=''):
     if sys.version_info >= (2, 5):
         from hashlib import sha1 as _sha1
     else:
         from sha import sha as _sha1
     global _fastsha1, sha1
     _fastsha1 = sha1 = _sha1
     return _sha1(s)
 
+def md5(s=''):
+    try:
+        from hashlib import md5 as _md5
+    except ImportError:
+        from md5 import md5 as _md5
+    global md5
+    md5 = _md5
+    return _md5(s)
+
 try:
     buffer = buffer
 except NameError:
     if sys.version_info[0] < 3:
         def buffer(sliceable, offset=0):
             return sliceable[offset:]
     else:
         def buffer(sliceable, offset=0):