Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Unified Diff: static/upload.py

Issue 92159: Work around for md5 module deprecation warning in python 2.5+ (Closed) Base URL: http://rietveld.googlecode.com/svn/trunk/
Patch Set: '' Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: static/upload.py
===================================================================
--- static/upload.py (revision 412)
+++ static/upload.py (working copy)
@@ -33,8 +33,14 @@
import cookielib
import getpass
+# Work-around for md5 module deprecation warning in python 2.5+:
+try:
+ import hashlib # Try to load hashlib (python 2.5+)
+except ImportError: # If it cannot be imported, set it to None
+ hashlib = None
import logging
-import md5
+if not hashlib: # If hashlib was not imported, then this is python 2.4: use md5
+ import md5
import mimetypes
import optparse
import os
@@ -674,7 +680,10 @@
(type, filename))
file_too_large = True
content = ""
- checksum = md5.new(content).hexdigest()
+ if hashlib: # python 2.5+ uses hashlib
+ checksum = hashlib.md5(content).hexdigest()
+ else: # python 2.4- uses md5
+ checksum = md5.new(content).hexdigest()
if options.verbose > 0 and not file_too_large:
print "Uploading %s file for %s" % (type, filename)
url = "/%d/upload_content/%d/%d" % (int(issue), int(patchset), file_id)
@@ -1326,7 +1335,10 @@
base_hashes = ""
for file, info in files.iteritems():
if not info[0] is None:
- checksum = md5.new(info[0]).hexdigest()
+ if hashlib: # python 2.5+ uses hashlib
+ checksum = hashlib.md5(info[0]).hexdigest()
+ else: # python 2.4- uses md5
+ checksum = md5.new(info[0]).hexdigest()
if base_hashes:
base_hashes += "|"
base_hashes += checksum + ":" + file
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698