Revision 32a437b1

b/docs/source/devguide.rst
604 604

  
605 605
  {"block_hash": "sha1", "hashes": ["7295c41da03d7f916440b98e32c4a2a39351546c", ...], "block_size": 131072, "bytes": 242}
606 606

  
607
Example ``format=xml`` request:
608

  
609
::
610

  
611
  <?xml version="1.0" encoding="UTF-8"?>
612
  <object name="file" bytes="24223726" block_size="131072" block_hash="sha1">
613
    <hash>7295c41da03d7f916440b98e32c4a2a39351546c</hash>
614
    <hash>...</hash>
615
  </object>
607 616

  
608 617
==========================  ===============================
609 618
Reply Header Name           Value
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:
b/pithos/api/util.py
472 472
                    data = data[blocksize:]
473 473
                    yield ret
474 474
            sock.read(2) # CRLF
475
        # TODO: Raise something to note that maximum size is reached.
475
        raise BadRequest('Maximum size is reached')
476 476
    else:
477 477
        if length > MAX_UPLOAD_SIZE:
478
            # TODO: Raise something to note that maximum size is reached.
479
            pass
478
            raise BadRequest('Maximum size is reached')
480 479
        while length > 0:
481 480
            data = sock.read(min(length, blocksize))
482 481
            length -= len(data)

Also available in: Unified diff