Commit 25f5177b authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis Committed by Christos Stavrakakis
Browse files

PEP8 style fixes

parent abf7848e
......@@ -40,7 +40,6 @@ from django.utils.http import parse_etags
from django.utils.encoding import smart_str
from django.views.decorators.csrf import csrf_exempt
from django.conf import settings
from snf_django.lib.astakos import get_uuids as _get_uuids
from snf_django.lib import api
......@@ -57,7 +56,7 @@ from pithos.api.util import (
get_content_range, socket_read_iterator, SaveToBackendHandler,
object_data_response, put_object_block, hashmap_md5, simple_list_response,
api_method, is_uuid,
retrieve_uuid, retrieve_displayname, retrieve_uuids, retrieve_displaynames,
retrieve_uuid, retrieve_uuids, retrieve_displaynames,
get_pithos_usage
)
......@@ -146,7 +145,8 @@ def container_demux(request, v_account, v_container):
@csrf_exempt
def object_demux(request, v_account, v_container, v_object):
# Helper to avoid placing the token in the URL when loading objects from a browser.
# Helper to avoid placing the token in the URL
# when loading objects from a browser.
if TRANSLATE_UUIDS:
if not is_uuid(v_account):
uuids = get_uuids([v_account])
......@@ -165,7 +165,8 @@ def object_demux(request, v_account, v_container, v_object):
elif request.method == 'MOVE':
return object_move(request, v_account, v_container, v_object)
elif request.method == 'POST':
if request.META.get('CONTENT_TYPE', '').startswith('multipart/form-data'):
if request.META.get(
'CONTENT_TYPE', '').startswith('multipart/form-data'):
return object_write_form(request, v_account, v_container, v_object)
return object_update(request, v_account, v_container, v_object)
elif request.method == 'DELETE':
......@@ -214,7 +215,7 @@ def account_list(request):
if request.serialization == 'text':
if TRANSLATE_UUIDS:
accounts = retrieve_displaynames(
getattr(request, 'token', None), accounts)
getattr(request, 'token', None), accounts)
if len(accounts) == 0:
# The cloudfiles python bindings expect 200 if json/xml.
response.status_code = 204
......@@ -247,7 +248,7 @@ def account_list(request):
if TRANSLATE_UUIDS:
uuids = list(d['name'] for d in account_meta)
catalog = retrieve_displaynames(
getattr(request, 'token', None), uuids, return_dict=True)
getattr(request, 'token', None), uuids, return_dict=True)
for meta in account_meta:
meta['name'] = catalog.get(meta.get('name'))
......@@ -279,7 +280,7 @@ def account_meta(request, v_account):
if TRANSLATE_UUIDS:
for k in groups:
groups[k] = retrieve_displaynames(
getattr(request, 'token', None), groups[k])
getattr(request, 'token', None), groups[k])
policy = request.backend.get_account_policy(
request.user_uniq, v_account, external_quota=usage)
except NotAllowedError:
......@@ -304,12 +305,12 @@ def account_update(request, v_account):
if TRANSLATE_UUIDS:
try:
groups[k] = retrieve_uuids(
getattr(request, 'token', None),
groups[k],
fail_silently=False)
getattr(request, 'token', None),
groups[k],
fail_silently=False)
except ItemNotExists, e:
raise faults.BadRequest(
'Bad X-Account-Group header value: %s' % e)
'Bad X-Account-Group header value: %s' % e)
else:
try:
retrieve_displaynames(
......@@ -318,7 +319,7 @@ def account_update(request, v_account):
fail_silently=False)
except ItemNotExists, e:
raise faults.BadRequest(
'Bad X-Account-Group header value: %s' % e)
'Bad X-Account-Group header value: %s' % e)
replace = True
if 'update' in request.GET:
replace = False
......@@ -437,8 +438,10 @@ def container_meta(request, v_account, v_container):
try:
meta = request.backend.get_container_meta(request.user_uniq, v_account,
v_container, 'pithos', until)
meta['object_meta'] = request.backend.list_container_meta(request.user_uniq,
v_account, v_container, 'pithos', until)
meta['object_meta'] = \
request.backend.list_container_meta(request.user_uniq,
v_account, v_container,
'pithos', until)
policy = request.backend.get_container_policy(
request.user_uniq, v_account,
v_container)
......@@ -489,7 +492,8 @@ def container_create(request, v_account, v_container):
if meta:
try:
request.backend.update_container_meta(request.user_uniq, v_account,
v_container, 'pithos', meta, replace=False)
v_container, 'pithos',
meta, replace=False)
except NotAllowedError:
raise faults.Forbidden('Not allowed')
except ItemNotExists:
......@@ -524,7 +528,8 @@ def container_update(request, v_account, v_container):
if meta or replace:
try:
request.backend.update_container_meta(request.user_uniq, v_account,
v_container, 'pithos', meta, replace)
v_container, 'pithos',
meta, replace)
except NotAllowedError:
raise faults.Forbidden('Not allowed')
except ItemNotExists:
......@@ -536,11 +541,14 @@ def container_update(request, v_account, v_container):
request.META.get('CONTENT_LENGTH', 0))
content_type = request.META.get('CONTENT_TYPE')
hashmap = []
if content_type and content_type == 'application/octet-stream' and content_length != 0:
if (content_type
and content_type == 'application/octet-stream'
and content_length != 0):
for data in socket_read_iterator(request, content_length,
request.backend.block_size):
# TODO: Raise 408 (Request Timeout) if this takes too long.
# TODO: Raise 499 (Client Disconnect) if a length is defined and we stop before getting this much data.
# TODO: Raise 499 (Client Disconnect) if a length is defined
# and we stop before getting this much data.
hashmap.append(request.backend.put_block(data))
response = HttpResponse(status=202)
......@@ -590,8 +598,10 @@ def object_list(request, v_account, v_container):
try:
meta = request.backend.get_container_meta(request.user_uniq, v_account,
v_container, 'pithos', until)
meta['object_meta'] = request.backend.list_container_meta(request.user_uniq,
v_account, v_container, 'pithos', until)
meta['object_meta'] = \
request.backend.list_container_meta(request.user_uniq,
v_account, v_container,
'pithos', until)
policy = request.backend.get_container_policy(
request.user_uniq, v_account,
v_container)
......@@ -679,16 +689,17 @@ def object_list(request, v_account, v_container):
if until is None:
name = '/'.join((v_account, v_container, ''))
name_idx = len(name)
for x in request.backend.list_object_permissions(request.user_uniq,
v_account, v_container, prefix):
for x in request.backend.list_object_permissions(
request.user_uniq, v_account, v_container, prefix):
# filter out objects which are not under the container
if name != x[:name_idx]:
continue
object = x[name_idx:]
object_permissions[object] = request.backend.get_object_permissions(
request.user_uniq, v_account, v_container, object)
object_permissions[object] = \
request.backend.get_object_permissions(
request.user_uniq, v_account, v_container, object)
if public_granted:
for k, v in request.backend.list_object_public(
......@@ -706,7 +717,7 @@ def object_list(request, v_account, v_container):
modified_by = meta.get('modified_by')
if modified_by:
l = retrieve_displaynames(
getattr(request, 'token', None), [meta['modified_by']])
getattr(request, 'token', None), [meta['modified_by']])
if l is not None and len(l) == 1:
meta['modified_by'] = l[0]
......@@ -757,7 +768,8 @@ def object_meta(request, v_account, v_container, v_object):
version = request.GET.get('version')
try:
meta = request.backend.get_object_meta(request.user_uniq, v_account,
v_container, v_object, 'pithos', version)
v_container, v_object,
'pithos', version)
if version is None:
permissions = request.backend.get_object_permissions(
request.user_uniq,
......@@ -833,7 +845,8 @@ def object_read(request, v_account, v_container, v_object):
try:
meta = request.backend.get_object_meta(request.user_uniq, v_account,
v_container, v_object, 'pithos', version)
v_container, v_object,
'pithos', version)
if version is None:
permissions = request.backend.get_object_permissions(
request.user_uniq,
......@@ -888,8 +901,10 @@ def object_read(request, v_account, v_container, v_object):
try:
for x in objects:
s, h = request.backend.get_object_hashmap(request.user_uniq,
v_account, src_container, x[0], x[1])
s, h = \
request.backend.get_object_hashmap(request.user_uniq,
v_account, src_container,
x[0], x[1])
sizes.append(s)
hashmaps.append(h)
except NotAllowedError:
......@@ -929,7 +944,7 @@ def object_read(request, v_account, v_container, v_object):
response = HttpResponse(data, status=200)
put_object_headers(
response, meta, token=getattr(request, 'token', None))
response, meta, token=getattr(request, 'token', None))
response['Content-Length'] = len(data)
return response
......@@ -951,7 +966,8 @@ def object_write(request, v_account, v_container, v_object):
# requestentitytoolarge (413)
# Evaluate conditions.
if request.META.get('HTTP_IF_MATCH') or request.META.get('HTTP_IF_NONE_MATCH'):
if (request.META.get('HTTP_IF_MATCH')
or request.META.get('HTTP_IF_NONE_MATCH')):
try:
meta = request.backend.get_object_meta(
request.user_uniq, v_account,
......@@ -988,7 +1004,8 @@ def object_write(request, v_account, v_container, v_object):
raise faults.BadRequest('Invalid X-Move-From header')
version_id = copy_or_move_object(
request, src_account, src_container, src_name,
v_account, v_container, v_object, move=True, delimiter=delimiter)
v_account, v_container, v_object,
move=True, delimiter=delimiter)
else:
try:
src_container, src_name = split_container_object_string(
......@@ -997,7 +1014,8 @@ def object_write(request, v_account, v_container, v_object):
raise faults.BadRequest('Invalid X-Copy-From header')
version_id = copy_or_move_object(
request, src_account, src_container, src_name,
v_account, v_container, v_object, move=False, delimiter=delimiter)
v_account, v_container, v_object,
move=False, delimiter=delimiter)
response = HttpResponse(status=201)
response['X-Object-Version'] = version_id
return response
......@@ -1049,7 +1067,8 @@ def object_write(request, v_account, v_container, v_object):
for data in socket_read_iterator(request, content_length,
request.backend.block_size):
# TODO: Raise 408 (Request Timeout) if this takes too long.
# TODO: Raise 499 (Client Disconnect) if a length is defined and we stop before getting this much data.
# TODO: Raise 499 (Client Disconnect) if a length is defined
# and we stop before getting this much data.
size += len(data)
hashmap.append(request.backend.put_block(data))
md5.update(data)
......@@ -1060,9 +1079,13 @@ def object_write(request, v_account, v_container, v_object):
raise faults.UnprocessableEntity('Object ETag does not match')
try:
version_id = request.backend.update_object_hashmap(request.user_uniq,
v_account, v_container, v_object, size, content_type,
hashmap, checksum, 'pithos', meta, True, permissions)
version_id = \
request.backend.update_object_hashmap(request.user_uniq,
v_account, v_container,
v_object, size, content_type,
hashmap, checksum,
'pithos', meta, True,
permissions)
except NotAllowedError:
raise faults.Forbidden('Not allowed')
except IndexError, e:
......@@ -1081,7 +1104,9 @@ def object_write(request, v_account, v_container, v_object):
checksum = hashmap_md5(request.backend, hashmap, size)
try:
request.backend.update_object_checksum(request.user_uniq,
v_account, v_container, v_object, version_id, checksum)
v_account, v_container,
v_object, version_id,
checksum)
except NotAllowedError:
raise faults.Forbidden('Not allowed')
if public is not None:
......@@ -1116,9 +1141,13 @@ def object_write_form(request, v_account, v_container, v_object):
checksum = file.etag
try:
version_id = request.backend.update_object_hashmap(request.user_uniq,
v_account, v_container, v_object, file.size, file.content_type,
file.hashmap, checksum, 'pithos', {}, True)
version_id = \
request.backend.update_object_hashmap(request.user_uniq,
v_account, v_container,
v_object, file.size,
file.content_type,
file.hashmap, checksum,
'pithos', {}, True)
except NotAllowedError:
raise faults.Forbidden('Not allowed')
except ItemNotExists:
......@@ -1154,7 +1183,8 @@ def object_copy(request, v_account, v_container, v_object):
raise faults.BadRequest('Invalid Destination header')
# Evaluate conditions.
if request.META.get('HTTP_IF_MATCH') or request.META.get('HTTP_IF_NONE_MATCH'):
if (request.META.get('HTTP_IF_MATCH')
or request.META.get('HTTP_IF_NONE_MATCH')):
src_version = request.META.get('HTTP_X_SOURCE_VERSION')
try:
meta = request.backend.get_object_meta(
......@@ -1169,7 +1199,8 @@ def object_copy(request, v_account, v_container, v_object):
delimiter = request.GET.get('delimiter')
version_id = copy_or_move_object(request, v_account, v_container, v_object,
dest_account, dest_container, dest_name, move=False, delimiter=delimiter)
dest_account, dest_container, dest_name,
move=False, delimiter=delimiter)
response = HttpResponse(status=201)
response['X-Object-Version'] = version_id
return response
......@@ -1196,7 +1227,8 @@ def object_move(request, v_account, v_container, v_object):
raise faults.BadRequest('Invalid Destination header')
# Evaluate conditions.
if request.META.get('HTTP_IF_MATCH') or request.META.get('HTTP_IF_NONE_MATCH'):
if (request.META.get('HTTP_IF_MATCH')
or request.META.get('HTTP_IF_NONE_MATCH')):
try:
meta = request.backend.get_object_meta(
request.user_uniq, v_account,
......@@ -1210,7 +1242,8 @@ def object_move(request, v_account, v_container, v_object):
delimiter = request.GET.get('delimiter')
version_id = copy_or_move_object(request, v_account, v_container, v_object,
dest_account, dest_container, dest_name, move=True, delimiter=delimiter)
dest_account, dest_container, dest_name,
move=True, delimiter=delimiter)
response = HttpResponse(status=201)
response['X-Object-Version'] = version_id
return response
......@@ -1237,7 +1270,8 @@ def object_update(request, v_account, v_container, v_object):
raise faults.ItemNotFound('Object does not exist')
# Evaluate conditions.
if request.META.get('HTTP_IF_MATCH') or request.META.get('HTTP_IF_NONE_MATCH'):
if (request.META.get('HTTP_IF_MATCH')
or request.META.get('HTTP_IF_NONE_MATCH')):
validate_matching_preconditions(request, prev_meta)
replace = True
......@@ -1246,14 +1280,17 @@ def object_update(request, v_account, v_container, v_object):
# A Content-Type or X-Source-Object header indicates data updates.
src_object = request.META.get('HTTP_X_SOURCE_OBJECT')
if (not content_type or content_type != 'application/octet-stream') and not src_object:
if ((not content_type or content_type != 'application/octet-stream')
and not src_object):
response = HttpResponse(status=202)
# Do permissions first, as it may fail easier.
if permissions is not None:
try:
request.backend.update_object_permissions(request.user_uniq,
v_account, v_container, v_object, permissions)
v_account,
v_container, v_object,
permissions)
except NotAllowedError:
raise faults.Forbidden('Not allowed')
except ItemNotExists:
......@@ -1293,8 +1330,9 @@ def object_update(request, v_account, v_container, v_object):
raise faults.RangeNotSatisfiable('Invalid Content-Range header')
try:
size, hashmap = request.backend.get_object_hashmap(request.user_uniq,
v_account, v_container, v_object)
size, hashmap = \
request.backend.get_object_hashmap(request.user_uniq,
v_account, v_container, v_object)
except NotAllowedError:
raise faults.Forbidden('Not allowed')
except ItemNotExists:
......@@ -1304,7 +1342,8 @@ def object_update(request, v_account, v_container, v_object):
if offset is None:
offset = size
elif offset > size:
raise faults.RangeNotSatisfiable('Supplied offset is beyond object limits')
raise faults.RangeNotSatisfiable(
'Supplied offset is beyond object limits')
if src_object:
src_account = request.META.get('HTTP_X_SOURCE_ACCOUNT')
if not src_account:
......@@ -1323,7 +1362,8 @@ def object_update(request, v_account, v_container, v_object):
if length is None:
length = src_size
elif length > src_size:
raise faults.BadRequest('Object length is smaller than range length')
raise faults.BadRequest(
'Object length is smaller than range length')
else:
# Require either a Content-Length, or 'chunked' Transfer-Encoding.
content_length = -1
......@@ -1337,8 +1377,11 @@ def object_update(request, v_account, v_container, v_object):
# TODO: Get up to length bytes in chunks.
length = content_length
elif length != content_length:
raise faults.BadRequest('Content length does not match range length')
if total is not None and (total != size or offset >= size or (length > 0 and offset + length >= size)):
raise faults.BadRequest(
'Content length does not match range length')
if (total is not None
and (total != size or offset >= size
or (length > 0 and offset + length >= size))):
raise faults.RangeNotSatisfiable(
'Supplied range will change provided object limits')
......@@ -1384,7 +1427,8 @@ def object_update(request, v_account, v_container, v_object):
for d in socket_read_iterator(request, length,
request.backend.block_size):
# TODO: Raise 408 (Request Timeout) if this takes too long.
# TODO: Raise 499 (Client Disconnect) if a length is defined and we stop before getting this much data.
# TODO: Raise 499 (Client Disconnect) if a length is defined
# and we stop before getting this much data.
data += d
bytes = put_object_block(request, hashmap, data, offset)
offset += bytes
......@@ -1400,10 +1444,13 @@ def object_update(request, v_account, v_container, v_object):
checksum = hashmap_md5(
request.backend, hashmap, size) if UPDATE_MD5 else ''
try:
version_id = request.backend.update_object_hashmap(request.user_uniq,
v_account, v_container, v_object, size, prev_meta[
'type'],
hashmap, checksum, 'pithos', meta, replace, permissions)
version_id = \
request.backend.update_object_hashmap(request.user_uniq,
v_account, v_container,
v_object, size,
prev_meta['type'],
hashmap, checksum, 'pithos',
meta, replace, permissions)
except NotAllowedError:
raise faults.Forbidden('Not allowed')
except ItemNotExists:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment