comparison mercurial/util.py @ 6470:ac0bcd951c2c

python 2.6 compatibility: compatibility wrappers for hash functions
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Fri, 04 Apr 2008 22:36:40 +0200
parents ed9b07a97587
children 4f7feeb6d6ee
comparison
equal deleted inserted replaced
6469:fb502719c75c 6470:ac0bcd951c2c
14 14
15 from i18n import _ 15 from i18n import _
16 import cStringIO, errno, getpass, re, shutil, sys, tempfile 16 import cStringIO, errno, getpass, re, shutil, sys, tempfile
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
20 # Python compatibility
19 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
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)
25 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:
29 # On darwin, getpreferredencoding ignores the locale environment and 55 # On darwin, getpreferredencoding ignores the locale environment and