X-Git-Url: https://code.grnet.gr/git/pithos/blobdiff_plain/fb0640327aaf0fb573ad04ad6ddc3fef3e57fd13..7301127c9709b99c41ca8d6a3702f3fd42f65a07:/pithos/api/util.py diff --git a/pithos/api/util.py b/pithos/api/util.py index d7ed7af..1ac568f 100644 --- a/pithos/api/util.py +++ b/pithos/api/util.py @@ -47,7 +47,9 @@ from django.utils.encoding import smart_unicode, smart_str from django.core.files.uploadhandler import FileUploadHandler from django.core.files.uploadedfile import UploadedFile -from pithos.api.compat import parse_http_date_safe, parse_http_date +from pithos.lib.compat import parse_http_date_safe, parse_http_date +from pithos.lib.hashmap import HashMap + from pithos.api.faults import (Fault, NotModified, BadRequest, Unauthorized, Forbidden, ItemNotFound, Conflict, LengthRequired, PreconditionFailed, RequestEntityTooLarge, RangeNotSatisfiable, ServiceUnavailable) @@ -197,7 +199,7 @@ def put_object_headers(response, meta, restricted=False): else: for k in ('Content-Encoding', 'Content-Disposition'): if k in meta: - response[k] = meta[k] + response[k] = smart_str(meta[k], strings_only=True) def update_manifest_meta(request, v_account, meta): """Update metadata if the object has an X-Object-Manifest.""" @@ -741,24 +743,9 @@ def put_object_block(request, hashmap, data, offset): def hashmap_hash(request, hashmap): """Produce the root hash, treating the hashmap as a Merkle-like tree.""" - def subhash(d): - h = hashlib.new(request.backend.hash_algorithm) - h.update(d) - return h.digest() - - if len(hashmap) == 0: - return hexlify(subhash('')) - if len(hashmap) == 1: - return hashmap[0] - - s = 2 - while s < len(hashmap): - s = s * 2 - h = [unhexlify(x) for x in hashmap] - h += [('\x00' * len(h[0]))] * (s - len(hashmap)) - while len(h) > 1: - h = [subhash(h[x] + h[x + 1]) for x in range(0, len(h), 2)] - return hexlify(h[0]) + map = HashMap(request.backend.block_size, request.backend.hash_algorithm) + map.extend([unhexlify(x) for x in hashmap]) + return hexlify(map.hash()) def update_request_headers(request): # Handle URL-encoded keys and values.