X-Git-Url: https://code.grnet.gr/git/pithos/blobdiff_plain/21a8a6ff7bf6409f3e853ecb768ba45915b37285..f9f15f9298274c5af6c94599bd46e663c73414b3:/pithos/api/util.py diff --git a/pithos/api/util.py b/pithos/api/util.py index 773ef40..cc486bd 100644 --- a/pithos/api/util.py +++ b/pithos/api/util.py @@ -35,7 +35,7 @@ from functools import wraps from time import time from traceback import format_exc from wsgiref.handlers import format_date_time -from binascii import hexlify +from binascii import hexlify, unhexlify from django.conf import settings from django.http import HttpResponse @@ -160,7 +160,9 @@ def put_object_headers(response, meta, restricted=False): response['X-Object-Version-Timestamp'] = http_date(int(meta['version_timestamp'])) for k in [x for x in meta.keys() if x.startswith('X-Object-Meta-')]: response[smart_str(k, strings_only=True)] = smart_str(meta[k], strings_only=True) - for k in ('Content-Encoding', 'Content-Disposition', 'X-Object-Manifest', 'X-Object-Sharing', 'X-Object-Shared-By', 'X-Object-Public'): + for k in ('Content-Encoding', 'Content-Disposition', 'X-Object-Manifest', + 'X-Object-Sharing', 'X-Object-Shared-By', 'X-Object-Allowed-To', + 'X-Object-Public'): if k in meta: response[k] = smart_str(meta[k], strings_only=True) else: @@ -189,10 +191,10 @@ def update_manifest_meta(request, v_account, meta): md5.update(hash) meta['hash'] = md5.hexdigest().lower() -def update_sharing_meta(permissions, v_account, v_container, v_object, meta): +def update_sharing_meta(request, permissions, v_account, v_container, v_object, meta): if permissions is None: return - perm_path, perms = permissions + allowed, perm_path, perms = permissions if len(perms) == 0: return ret = [] @@ -205,6 +207,8 @@ def update_sharing_meta(permissions, v_account, v_container, v_object, meta): meta['X-Object-Sharing'] = '; '.join(ret) if '/'.join((v_account, v_container, v_object)) != perm_path: meta['X-Object-Shared-By'] = perm_path + if request.user != v_account: + meta['X-Object-Allowed-To'] = allowed def update_public_meta(public, meta): if not public: @@ -672,13 +676,14 @@ def hashmap_hash(hashmap): return hexlify(subhash('')) if len(hashmap) == 1: return hashmap[0] + s = 2 while s < len(hashmap): s = s * 2 - h = hashmap + ([('\x00' * len(hashmap[0]))] * (s - len(hashmap))) - h = [subhash(h[x] + (h[x + 1] if x + 1 < len(h) else '')) for x in range(0, len(h), 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] if x + 1 < len(h) else '')) for x in range(0, len(h), 2)] + h = [subhash(h[x] + h[x + 1]) for x in range(0, len(h), 2)] return hexlify(h[0]) def update_response_headers(request, response): @@ -720,12 +725,12 @@ def request_serialization(request, format_allowed=False): elif format == 'xml': return 'xml' -# for item in request.META.get('HTTP_ACCEPT', '').split(','): -# accept, sep, rest = item.strip().partition(';') -# if accept == 'application/json': -# return 'json' -# elif accept == 'application/xml' or accept == 'text/xml': -# return 'xml' + for item in request.META.get('HTTP_ACCEPT', '').split(','): + accept, sep, rest = item.strip().partition(';') + if accept == 'application/json': + return 'json' + elif accept == 'application/xml' or accept == 'text/xml': + return 'xml' return 'text'