Revision 32a437b1 pithos/api/functions.py
b/pithos/api/functions.py | ||
---|---|---|
40 | 40 |
from django.template.loader import render_to_string |
41 | 41 |
from django.utils import simplejson as json |
42 | 42 |
from django.utils.http import parse_etags |
43 |
from xml.dom import minidom |
|
43 | 44 |
|
44 | 45 |
from pithos.api.faults import (Fault, NotModified, BadRequest, Unauthorized, ItemNotFound, Conflict, |
45 | 46 |
LengthRequired, PreconditionFailed, RangeNotSatisfiable, UnprocessableEntity) |
... | ... | |
622 | 623 |
if 'Content-Type' not in meta: |
623 | 624 |
raise LengthRequired('Missing Content-Type header') |
624 | 625 |
|
625 |
if request.serialization == 'json':
|
|
626 |
if request.serialization != 'text':
|
|
626 | 627 |
data = '' |
627 | 628 |
sock = raw_input_socket(request) |
628 | 629 |
for block in socket_read_iterator(sock, content_length, backend.block_size): |
629 | 630 |
data = '%s%s' % (data, block) |
630 |
d = json.loads(data) |
|
631 |
if not hasattr(d, '__getitem__'): |
|
632 |
raise BadRequest('Invalid data formating') |
|
633 |
try: |
|
634 |
hashmap = d['hashes'] |
|
635 |
size = d['bytes'] |
|
636 |
except KeyError: |
|
637 |
raise BadRequest('Invalid data formatting') |
|
631 |
|
|
632 |
if request.serialization == 'json': |
|
633 |
d = json.loads(data) |
|
634 |
if not hasattr(d, '__getitem__'): |
|
635 |
raise BadRequest('Invalid data formating') |
|
636 |
try: |
|
637 |
hashmap = d['hashes'] |
|
638 |
size = d['bytes'] |
|
639 |
except KeyError: |
|
640 |
raise BadRequest('Invalid data formatting') |
|
641 |
elif request.serialization == 'xml': |
|
642 |
try: |
|
643 |
xml = minidom.parseString(data) |
|
644 |
obj = xml.getElementsByTagName('object')[0] |
|
645 |
size = obj.attributes['bytes'].value |
|
646 |
|
|
647 |
hashes = xml.getElementsByTagName('hash') |
|
648 |
hashmap = [] |
|
649 |
for hash in hashes: |
|
650 |
hashmap.append(hash.firstChild.data) |
|
651 |
except Exception: |
|
652 |
raise BadRequest('Invalid data formatting') |
|
653 |
|
|
638 | 654 |
meta.update({'hash': hashmap_hash(hashmap)}) # Update ETag. |
639 |
elif request.serialization == 'xml': |
|
640 |
# TODO: Support xml. |
|
641 |
raise BadRequest('Format xml is not supported') |
|
642 | 655 |
else: |
643 | 656 |
md5 = hashlib.md5() |
644 | 657 |
size = 0 |
... | ... | |
724 | 737 |
# itemNotFound (404), |
725 | 738 |
# unauthorized (401), |
726 | 739 |
# badRequest (400) |
727 |
|
|
728 | 740 |
meta, permissions, public = get_object_headers(request) |
729 | 741 |
content_type = meta.get('Content-Type') |
730 | 742 |
if content_type: |
... | ... | |
816 | 828 |
content_length = -1 |
817 | 829 |
if request.META.get('HTTP_TRANSFER_ENCODING') != 'chunked': |
818 | 830 |
content_length = get_content_length(request) |
819 |
|
|
831 |
|
|
820 | 832 |
if length is None: |
821 | 833 |
length = content_length |
822 | 834 |
else: |
Also available in: Unified diff