##// END OF EJS Templates
python 2.6 compatibility: compatibility wrappers for hash functions
Dirkjan Ochtman -
r6470:ac0bcd95 default
parent child Browse files
Show More
@@ -19,6 +19,8 b''
19
19
20 # Modified by Benoit Boissinot:
20 # Modified by Benoit Boissinot:
21 # - fix for digest auth (inspired from urllib2.py @ Python v2.4)
21 # - fix for digest auth (inspired from urllib2.py @ Python v2.4)
22 # Modified by Dirkjan Ochtman:
23 # - import md5 function from a local util module
22
24
23 """An HTTP handler for urllib2 that supports HTTP 1.1 and keepalive.
25 """An HTTP handler for urllib2 that supports HTTP 1.1 and keepalive.
24
26
@@ -450,7 +452,7 b' def error_handler(url):'
450 keepalive_handler.close_all()
452 keepalive_handler.close_all()
451
453
452 def continuity(url):
454 def continuity(url):
453 import md5
455 from util import md5
454 format = '%25s: %s'
456 format = '%25s: %s'
455
457
456 # first fetch the file with the normal http handler
458 # first fetch the file with the normal http handler
@@ -6,7 +6,7 b''
6 # of the GNU General Public License, incorporated herein by reference.
6 # of the GNU General Public License, incorporated herein by reference.
7
7
8 from i18n import _
8 from i18n import _
9 import bdiff, mpatch, re, struct, util, md5
9 import bdiff, mpatch, re, struct, util
10
10
11 def splitnewlines(text):
11 def splitnewlines(text):
12 '''like str.splitlines, but only split on newlines.'''
12 '''like str.splitlines, but only split on newlines.'''
@@ -80,7 +80,7 b' def unidiff(a, ad, b, bd, fn1, fn2, r=No'
80 if not opts.text and (util.binary(a) or util.binary(b)):
80 if not opts.text and (util.binary(a) or util.binary(b)):
81 def h(v):
81 def h(v):
82 # md5 is used instead of sha1 because md5 is supposedly faster
82 # md5 is used instead of sha1 because md5 is supposedly faster
83 return md5.new(v).digest()
83 return util.md5(v).digest()
84 if a and b and len(a) == len(b) and h(a) == h(b):
84 if a and b and len(a) == len(b) and h(a) == h(b):
85 return ""
85 return ""
86 l = ['Binary file %s has changed\n' % fn1]
86 l = ['Binary file %s has changed\n' % fn1]
@@ -9,7 +9,7 b''
9 from i18n import _
9 from i18n import _
10 from node import hex, nullid, short
10 from node import hex, nullid, short
11 import base85, cmdutil, mdiff, util, context, revlog, diffhelpers, copies
11 import base85, cmdutil, mdiff, util, context, revlog, diffhelpers, copies
12 import cStringIO, email.Parser, os, popen2, re, sha, errno
12 import cStringIO, email.Parser, os, popen2, re, errno
13 import sys, tempfile, zlib
13 import sys, tempfile, zlib
14
14
15 class PatchError(Exception):
15 class PatchError(Exception):
@@ -1120,7 +1120,7 b' def b85diff(to, tn):'
1120 if not text:
1120 if not text:
1121 return '0' * 40
1121 return '0' * 40
1122 l = len(text)
1122 l = len(text)
1123 s = sha.new('blob %d\0' % l)
1123 s = util.sha1('blob %d\0' % l)
1124 s.update(text)
1124 s.update(text)
1125 return s.hexdigest()
1125 return s.hexdigest()
1126
1126
@@ -13,13 +13,13 b' of the GNU General Public License, incor'
13 from node import bin, hex, nullid, nullrev, short
13 from node import bin, hex, nullid, nullrev, short
14 from i18n import _
14 from i18n import _
15 import changegroup, errno, ancestor, mdiff
15 import changegroup, errno, ancestor, mdiff
16 import sha, struct, util, zlib
16 import struct, util, zlib
17
17
18 _pack = struct.pack
18 _pack = struct.pack
19 _unpack = struct.unpack
19 _unpack = struct.unpack
20 _compress = zlib.compress
20 _compress = zlib.compress
21 _decompress = zlib.decompress
21 _decompress = zlib.decompress
22 _sha = sha.new
22 _sha = util.sha1
23
23
24 # revlog flags
24 # revlog flags
25 REVLOGV0 = 0
25 REVLOGV0 = 0
@@ -17,12 +17,38 b' import cStringIO, errno, getpass, re, sh'
17 import os, stat, threading, time, calendar, ConfigParser, locale, glob, osutil
17 import os, stat, threading, time, calendar, ConfigParser, locale, glob, osutil
18 import urlparse
18 import urlparse
19
19
20 # Python compatibility
21
20 try:
22 try:
21 set = set
23 set = set
22 frozenset = frozenset
24 frozenset = frozenset
23 except NameError:
25 except NameError:
24 from sets import Set as set, ImmutableSet as frozenset
26 from sets import Set as set, ImmutableSet as frozenset
25
27
28 _md5 = None
29 def md5(s):
30 global _md5
31 if _md5 is None:
32 try:
33 import hashlib
34 _md5 = hashlib.md5
35 except ImportError:
36 import md5
37 _md5 = md5.md5
38 return _md5(s)
39
40 _sha1 = None
41 def sha1(s):
42 global _sha1
43 if _sha1 is None:
44 try:
45 import hashlib
46 _sha1 = hashlib.sha1
47 except ImportError:
48 import sha
49 _sha1 = sha.sha
50 return _sha1(s)
51
26 try:
52 try:
27 _encoding = os.environ.get("HGENCODING")
53 _encoding = os.environ.get("HGENCODING")
28 if sys.platform == 'darwin' and not _encoding:
54 if sys.platform == 'darwin' and not _encoding:
@@ -7,7 +7,11 b''
7 # GPL-compatible.
7 # GPL-compatible.
8
8
9 import sys
9 import sys
10 import md5
10
11 try:
12 from hashlib import md5
13 except ImportError:
14 from md5 import md5
11
15
12 for filename in sys.argv[1:]:
16 for filename in sys.argv[1:]:
13 try:
17 try:
@@ -16,7 +20,7 b' for filename in sys.argv[1:]:'
16 sys.stderr.write('%s: Can\'t open: %s\n' % (filename, msg))
20 sys.stderr.write('%s: Can\'t open: %s\n' % (filename, msg))
17 sys.exit(1)
21 sys.exit(1)
18
22
19 m = md5.new()
23 m = md5()
20 try:
24 try:
21 while 1:
25 while 1:
22 data = fp.read(8192)
26 data = fp.read(8192)
General Comments 0
You need to be logged in to leave comments. Login now