git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3py/trunk@67 830e0280-6d2a-0410-9c65-932aecc39d9d
Michal Ludvig authored on 2007/02/07 12:05:25... | ... |
@@ -5,8 +5,9 @@ |
5 | 5 |
|
6 | 6 |
import os, os.path |
7 | 7 |
import base64 |
8 |
+import md5 |
|
9 |
+import sha |
|
8 | 10 |
import hmac |
9 |
-import hashlib |
|
10 | 11 |
import httplib |
11 | 12 |
import logging |
12 | 13 |
from logging import debug, info, warning, error |
... | ... |
@@ -248,7 +249,7 @@ class S3(object): |
248 | 248 |
if response["status"] < 200 or response["status"] > 299: |
249 | 249 |
raise S3Error(response) |
250 | 250 |
|
251 |
- md5=hashlib.new("md5") |
|
251 |
+ md5_hash = md5.new() |
|
252 | 252 |
size_left = size_total = int(response["headers"]["content-length"]) |
253 | 253 |
while (size_left > 0): |
254 | 254 |
this_chunk = size_left > self.config.recv_chunk and self.config.recv_chunk or size_left |
... | ... |
@@ -256,14 +257,14 @@ class S3(object): |
256 | 256 |
data = http_response.read(this_chunk) |
257 | 257 |
debug("ReceiveFile: Writing %d bytes to file '%s'" % (len(data), file.name)) |
258 | 258 |
file.write(data) |
259 |
- md5.update(data) |
|
259 |
+ md5_hash.update(data) |
|
260 | 260 |
size_left -= len(data) |
261 | 261 |
info("Received %d bytes (%d %% of %d)" % ( |
262 | 262 |
(size_total - size_left), |
263 | 263 |
(size_total - size_left) * 100 / size_total, |
264 | 264 |
size_total)) |
265 | 265 |
conn.close() |
266 |
- response["md5"] = md5.hexdigest() |
|
266 |
+ response["md5"] = md5_hash.hexdigest() |
|
267 | 267 |
response["md5match"] = response["headers"]["etag"].find(response["md5"]) >= 0 |
268 | 268 |
debug("ReceiveFile: Computed MD5 = %s" % response["md5"]) |
269 | 269 |
if not response["md5match"]: |
... | ... |
@@ -282,7 +283,7 @@ class S3(object): |
282 | 282 |
h += header+":"+str(headers[header])+"\n" |
283 | 283 |
h += resource |
284 | 284 |
debug("SignHeaders: " + repr(h)) |
285 |
- return base64.encodestring(hmac.new(self.config.secret_key, h, hashlib.sha1).digest()).strip() |
|
285 |
+ return base64.encodestring(hmac.new(self.config.secret_key, h, sha).digest()).strip() |
|
286 | 286 |
|
287 | 287 |
def check_bucket_name(self, bucket): |
288 | 288 |
if re.compile("[^A-Za-z0-9\._-]").search(bucket): |