{"block_hash": "sha1", "hashes": ["7295c41da03d7f916440b98e32c4a2a39351546c", ...], "block_size": 131072, "bytes": 242}
+Example ``format=xml`` request:
+
+::
+
+ <?xml version="1.0" encoding="UTF-8"?>
+ <object name="file" bytes="24223726" block_size="131072" block_hash="sha1">
+ <hash>7295c41da03d7f916440b98e32c4a2a39351546c</hash>
+ <hash>...</hash>
+ </object>
========================== ===============================
Reply Header Name Value
from django.template.loader import render_to_string
from django.utils import simplejson as json
from django.utils.http import parse_etags
+from xml.dom import minidom
from pithos.api.faults import (Fault, NotModified, BadRequest, Unauthorized, ItemNotFound, Conflict,
LengthRequired, PreconditionFailed, RangeNotSatisfiable, UnprocessableEntity)
if 'Content-Type' not in meta:
raise LengthRequired('Missing Content-Type header')
- if request.serialization == 'json':
+ if request.serialization != 'text':
data = ''
sock = raw_input_socket(request)
for block in socket_read_iterator(sock, content_length, backend.block_size):
data = '%s%s' % (data, block)
- d = json.loads(data)
- if not hasattr(d, '__getitem__'):
- raise BadRequest('Invalid data formating')
- try:
- hashmap = d['hashes']
- size = d['bytes']
- except KeyError:
- raise BadRequest('Invalid data formatting')
+
+ if request.serialization == 'json':
+ d = json.loads(data)
+ if not hasattr(d, '__getitem__'):
+ raise BadRequest('Invalid data formating')
+ try:
+ hashmap = d['hashes']
+ size = d['bytes']
+ except KeyError:
+ raise BadRequest('Invalid data formatting')
+ elif request.serialization == 'xml':
+ try:
+ xml = minidom.parseString(data)
+ obj = xml.getElementsByTagName('object')[0]
+ size = obj.attributes['bytes'].value
+
+ hashes = xml.getElementsByTagName('hash')
+ hashmap = []
+ for hash in hashes:
+ hashmap.append(hash.firstChild.data)
+ except Exception:
+ raise BadRequest('Invalid data formatting')
+
meta.update({'hash': hashmap_hash(hashmap)}) # Update ETag.
- elif request.serialization == 'xml':
- # TODO: Support xml.
- raise BadRequest('Format xml is not supported')
else:
md5 = hashlib.md5()
size = 0
# itemNotFound (404),
# unauthorized (401),
# badRequest (400)
-
meta, permissions, public = get_object_headers(request)
content_type = meta.get('Content-Type')
if content_type:
content_length = -1
if request.META.get('HTTP_TRANSFER_ENCODING') != 'chunked':
content_length = get_content_length(request)
-
+
if length is None:
length = content_length
else: