Gentoo Archives: gentoo-commits

From: "Zac Medico (zmedico)" <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r10854 - main/trunk/pym/portage
Date: Mon, 30 Jun 2008 03:18:14
Message-Id: E1KD9u5-0000pc-0C@stork.gentoo.org
1 Author: zmedico
2 Date: 2008-06-30 03:18:07 +0000 (Mon, 30 Jun 2008)
3 New Revision: 10854
4
5 Modified:
6 main/trunk/pym/portage/checksum.py
7 Log:
8 Avoid python-2.6 deprecation warnings for md5 and sha modules by trying
9 to import hashlib first and then falling back to the deprecated modules
10 if necessary. Thanks to ColdWind for reporting.
11
12
13 Modified: main/trunk/pym/portage/checksum.py
14 ===================================================================
15 --- main/trunk/pym/portage/checksum.py 2008-06-30 02:34:16 UTC (rev 10853)
16 +++ main/trunk/pym/portage/checksum.py 2008-06-30 03:18:07 UTC (rev 10854)
17 @@ -11,7 +11,6 @@
18 import portage.exception
19 import portage.process
20 import commands
21 -import md5, sha
22
23 #dict of all available hash functions
24 hashfunc_map = {}
25 @@ -46,9 +45,20 @@
26 # override earlier ones
27
28 # Use the internal modules as last fallback
29 -md5hash = _generate_hash_function("MD5", md5.new, origin="internal")
30 -sha1hash = _generate_hash_function("SHA1", sha.new, origin="internal")
31 +try:
32 + from hashlib import md5 as _new_md5
33 +except ImportError:
34 + from md5 import new as _new_md5
35
36 +md5hash = _generate_hash_function("MD5", _new_md5, origin="internal")
37 +
38 +try:
39 + from hashlib import sha1 as _new_sha1
40 +except ImportError:
41 + from sha import new as _new_sha1
42 +
43 +sha1hash = _generate_hash_function("SHA1", _new_sha1, origin="internal")
44 +
45 # Use pycrypto when available, prefer it over the internal fallbacks
46 try:
47 from Crypto.Hash import MD5, SHA, SHA256, RIPEMD
48
49 --
50 gentoo-commits@l.g.o mailing list