Revision 02c0c3fa pithos/api/functions.py
b/pithos/api/functions.py | ||
---|---|---|
42 | 42 |
|
43 | 43 |
from pithos.api.faults import (Fault, NotModified, BadRequest, Unauthorized, ItemNotFound, Conflict, |
44 | 44 |
LengthRequired, PreconditionFailed, RangeNotSatisfiable, UnprocessableEntity) |
45 |
from pithos.api.util import (format_meta_key, printable_meta_dict, get_account_meta,
|
|
46 |
put_account_meta, get_container_meta, put_container_meta, get_object_meta, put_object_meta,
|
|
45 |
from pithos.api.util import (format_header_key, printable_header_dict, get_account_headers,
|
|
46 |
put_account_headers, get_container_headers, put_container_headers, get_object_headers, put_object_headers,
|
|
47 | 47 |
update_manifest_meta, update_sharing_meta, validate_modification_preconditions, |
48 | 48 |
validate_matching_preconditions, split_container_object_string, copy_or_move_object, |
49 | 49 |
get_int_parameter, get_content_length, get_content_range, get_sharing, raw_input_socket, |
... | ... | |
129 | 129 |
until = get_int_parameter(request, 'until') |
130 | 130 |
try: |
131 | 131 |
meta = backend.get_account_meta(request.user, v_account, until) |
132 |
groups = backend.get_account_groups(request.user, v_account) |
|
132 | 133 |
except NotAllowedError: |
133 | 134 |
raise Unauthorized('Access denied') |
134 | 135 |
|
135 | 136 |
response = HttpResponse(status=204) |
136 |
put_account_meta(response, meta)
|
|
137 |
put_account_headers(response, meta, groups)
|
|
137 | 138 |
return response |
138 | 139 |
|
139 | 140 |
@api_method('POST') |
... | ... | |
143 | 144 |
# unauthorized (401), |
144 | 145 |
# badRequest (400) |
145 | 146 |
|
146 |
meta = get_account_meta(request)
|
|
147 |
meta, groups = get_account_headers(request)
|
|
147 | 148 |
replace = True |
148 | 149 |
if 'update' in request.GET: |
149 |
replace = False |
|
150 |
replace = False |
|
151 |
if groups: |
|
152 |
try: |
|
153 |
backend.update_account_groups(request.user, v_account, groups, replace) |
|
154 |
except NotAllowedError: |
|
155 |
raise Unauthorized('Access denied') |
|
156 |
except ValueError: |
|
157 |
raise BadRequest('Invalid groups header') |
|
150 | 158 |
try: |
151 | 159 |
backend.update_account_meta(request.user, v_account, meta, replace) |
152 | 160 |
except NotAllowedError: |
... | ... | |
164 | 172 |
until = get_int_parameter(request, 'until') |
165 | 173 |
try: |
166 | 174 |
meta = backend.get_account_meta(request.user, v_account, until) |
175 |
groups = backend.get_account_groups(request.user, v_account) |
|
167 | 176 |
except NotAllowedError: |
168 | 177 |
raise Unauthorized('Access denied') |
169 | 178 |
|
170 | 179 |
validate_modification_preconditions(request, meta) |
171 | 180 |
|
172 | 181 |
response = HttpResponse() |
173 |
put_account_meta(response, meta)
|
|
182 |
put_account_headers(response, meta, groups)
|
|
174 | 183 |
|
175 | 184 |
marker = request.GET.get('marker') |
176 | 185 |
limit = request.GET.get('limit') |
... | ... | |
203 | 212 |
if x[1] is not None: |
204 | 213 |
try: |
205 | 214 |
meta = backend.get_container_meta(request.user, v_account, x[0], until) |
206 |
container_meta.append(printable_meta_dict(meta))
|
|
215 |
container_meta.append(printable_header_dict(meta))
|
|
207 | 216 |
except NotAllowedError: |
208 | 217 |
raise Unauthorized('Access denied') |
209 | 218 |
except NameError: |
... | ... | |
234 | 243 |
raise ItemNotFound('Container does not exist') |
235 | 244 |
|
236 | 245 |
response = HttpResponse(status=204) |
237 |
put_container_meta(response, meta)
|
|
246 |
put_container_headers(response, meta)
|
|
238 | 247 |
return response |
239 | 248 |
|
240 | 249 |
@api_method('PUT') |
... | ... | |
245 | 254 |
# unauthorized (401), |
246 | 255 |
# badRequest (400) |
247 | 256 |
|
248 |
meta = get_container_meta(request)
|
|
257 |
meta = get_container_headers(request)
|
|
249 | 258 |
|
250 | 259 |
try: |
251 | 260 |
backend.put_container(request.user, v_account, v_container) |
... | ... | |
273 | 282 |
# unauthorized (401), |
274 | 283 |
# badRequest (400) |
275 | 284 |
|
276 |
meta = get_container_meta(request)
|
|
285 |
meta = get_container_headers(request)
|
|
277 | 286 |
replace = True |
278 | 287 |
if 'update' in request.GET: |
279 | 288 |
replace = False |
... | ... | |
324 | 333 |
validate_modification_preconditions(request, meta) |
325 | 334 |
|
326 | 335 |
response = HttpResponse() |
327 |
put_container_meta(response, meta)
|
|
336 |
put_container_headers(response, meta)
|
|
328 | 337 |
|
329 | 338 |
path = request.GET.get('path') |
330 | 339 |
prefix = request.GET.get('prefix') |
... | ... | |
357 | 366 |
keys = request.GET.get('meta') |
358 | 367 |
if keys: |
359 | 368 |
keys = keys.split(',') |
360 |
keys = [format_meta_key('X-Object-Meta-' + x.strip()) for x in keys if x.strip() != '']
|
|
369 |
keys = [format_header_key('X-Object-Meta-' + x.strip()) for x in keys if x.strip() != '']
|
|
361 | 370 |
else: |
362 | 371 |
keys = [] |
363 | 372 |
|
... | ... | |
394 | 403 |
except NameError: |
395 | 404 |
pass |
396 | 405 |
update_sharing_meta(permissions, v_account, v_container, x[0], meta) |
397 |
object_meta.append(printable_meta_dict(meta))
|
|
406 |
object_meta.append(printable_header_dict(meta))
|
|
398 | 407 |
if request.serialization == 'xml': |
399 | 408 |
data = render_to_string('objects.xml', {'container': v_container, 'objects': object_meta}) |
400 | 409 |
elif request.serialization == 'json': |
... | ... | |
429 | 438 |
update_sharing_meta(permissions, v_account, v_container, v_object, meta) |
430 | 439 |
|
431 | 440 |
response = HttpResponse(status=200) |
432 |
put_object_meta(response, meta)
|
|
441 |
put_object_headers(response, meta)
|
|
433 | 442 |
return response |
434 | 443 |
|
435 | 444 |
@api_method('GET', format_allowed=True) |
... | ... | |
538 | 547 |
data = json.dumps(d) |
539 | 548 |
|
540 | 549 |
response = HttpResponse(data, status=200) |
541 |
put_object_meta(response, meta)
|
|
550 |
put_object_headers(response, meta)
|
|
542 | 551 |
response['Content-Length'] = len(data) |
543 | 552 |
return response |
544 | 553 |
|
... | ... | |
575 | 584 |
copy_or_move_object(request, v_account, src_container, src_name, v_container, v_object, move=False) |
576 | 585 |
return HttpResponse(status=201) |
577 | 586 |
|
578 |
meta = get_object_meta(request)
|
|
587 |
meta = get_object_headers(request)
|
|
579 | 588 |
permissions = get_sharing(request) |
580 | 589 |
content_length = -1 |
581 | 590 |
if request.META.get('HTTP_TRANSFER_ENCODING') != 'chunked': |
... | ... | |
660 | 669 |
# unauthorized (401), |
661 | 670 |
# badRequest (400) |
662 | 671 |
|
663 |
meta = get_object_meta(request)
|
|
672 |
meta = get_object_headers(request)
|
|
664 | 673 |
permissions = get_sharing(request) |
665 | 674 |
content_type = meta.get('Content-Type') |
666 | 675 |
if content_type: |
Also available in: Unified diff