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
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:
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 = []
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:
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):
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'