Commit d971f7f5 authored by maruel@chromium.org's avatar maruel@chromium.org

Load hashlib when available and md5 otherwise.

Review URL: http://codereview.chromium.org/99235

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@15043 0039d316-1c4b-4281-b951-d872f2087c98
parent 66256354
...@@ -34,7 +34,6 @@ against by using the '--rev' option. ...@@ -34,7 +34,6 @@ against by using the '--rev' option.
import cookielib import cookielib
import getpass import getpass
import logging import logging
import md5
import mimetypes import mimetypes
import optparse import optparse
import os import os
...@@ -46,6 +45,14 @@ import urllib ...@@ -46,6 +45,14 @@ import urllib
import urllib2 import urllib2
import urlparse import urlparse
# Work-around for md5 module deprecation warning in python 2.5+:
try:
# Try to load hashlib (python 2.5+)
from hashlib import md5
except ImportError:
# If hashlib cannot be imported, load md5.new instead.
from md5 import new as md5
try: try:
import readline import readline
except ImportError: except ImportError:
...@@ -675,7 +682,7 @@ class VersionControlSystem(object): ...@@ -675,7 +682,7 @@ class VersionControlSystem(object):
(type, filename)) (type, filename))
file_too_large = True file_too_large = True
content = "" content = ""
checksum = md5.new(content).hexdigest() checksum = md5(content).hexdigest()
if options.verbose > 0 and not file_too_large: if options.verbose > 0 and not file_too_large:
print "Uploading %s file for %s" % (type, filename) print "Uploading %s file for %s" % (type, filename)
url = "/%d/upload_content/%d/%d" % (int(issue), int(patchset), file_id) url = "/%d/upload_content/%d/%d" % (int(issue), int(patchset), file_id)
...@@ -1313,7 +1320,7 @@ def RealMain(argv, data=None): ...@@ -1313,7 +1320,7 @@ def RealMain(argv, data=None):
base_hashes = "" base_hashes = ""
for file, info in files.iteritems(): for file, info in files.iteritems():
if not info[0] is None: if not info[0] is None:
checksum = md5.new(info[0]).hexdigest() checksum = md5(info[0]).hexdigest()
if base_hashes: if base_hashes:
base_hashes += "|" base_hashes += "|"
base_hashes += checksum + ":" + file base_hashes += checksum + ":" + file
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment