Esempio n. 1
0
 def render_PUT(self, request):
     """PUT corresponds to a create/update operation on a blob"""
     # process path and extract potential containers/fnm
     name, container_path, fullpath = parse_path(request.path)
     length = request.getHeader('Content-Length')
     if length is None:
         request.setResponseCode(411)
         return ''
     content = (request.content, int(length))
     # default values of mimetype and metadata
     mimetype = request.getHeader('Content-Type') if request.getHeader('Content-Type') is not None else 'text/plain'
     desired_backend = request.getHeader('desired_backend')
     if ((len(mimetype) == 2 and mimetype[1] == 'utf-8')):
         valueencoding = 'utf-8'
     else:
         valueencoding = 'base64'
     status, _ = blob.write(self.avatar, name, container_path, fullpath,
                            mimetype, {}, content, valueencoding,
                            desired_backend)
     request.setResponseCode(status)
     set_common_headers(request, False)
     return ''
Esempio n. 2
0
    def render_PUT(self, request):
        """PUT corresponds to a create/update operation on a blob"""
        # process path and extract potential containers/fnm
        name, container_path, fullpath = parse_path(request.path)

        length = int(request.getHeader('Content-Length'))
        request.content.seek(0, 0)
        # process json encoded request body
        body = json.loads(request.content.read(length))
        # default values of mimetype and metadata
        mimetype = body.get('mimetype', 'text/plain')
        metadata = body.get('metadata', {})
        desired_backend = (metadata.get('desired_backend') or
                           request.getHeader('desired_backend'))
        valueencoding = body.get('valuetransferencoding', 'utf-8')
        body_value = body.get('value', '')
        value = (body_value if valueencoding == 'utf-8' else
                                  base64.b64decode(body_value))
        content = (StringIO(value), len(value))
        status, uid = blob.write(self.avatar, name, container_path, fullpath,
                                 mimetype, metadata, content, valueencoding,
                                 desired_backend=desired_backend)
        request.setResponseCode(status)
        request.setHeader('Content-Type', CDMI_OBJECT)
        set_common_headers(request)
        if status == OK or status == CREATED:
            response_body = {
                             'completionStatus': 'Complete',
                             'mimetype': mimetype,
                             'metadata': metadata,
                             }
            # add common elements
            response_body.update(get_common_body(request, uid, fullpath))
            return json.dumps(response_body)
        else:
            # error state
            return ''