def POST(self, req):
        """HTTP POST request handler."""
        error_response = \
            self.clean_acls(req) or check_metadata(req, 'container')
        if error_response:
            return error_response
        if not req.environ.get('swift_owner'):
            for key in self.app.swift_owner_headers:
                req.headers.pop(key, None)

        headers = self.generate_request_headers(req, transfer=True)
        clear_info_cache(self.app, req.environ,
                         self.account_name, self.container_name)

        storage = self.app.storage
        metadata = {}
        metadata.update(("user.%s" % k, v) for k, v in req.headers.iteritems()
                        if k.lower() in self.pass_through_headers or
                        is_sys_or_user_meta('container', k))

        try:
            storage.container_update(self.account_name, self.container_name,
                                     metadata, headers=headers)
            resp = HTTPNoContent(request=req)
        except exceptions.NoSuchContainer:
            resp = self.PUT(req)
        return resp
    def PUT(self, req):
        """HTTP PUT request handler."""
        error_response = \
            self.clean_acls(req) or check_metadata(req, 'container')
        if error_response:
            return error_response
        if not req.environ.get('swift_owner'):
            for key in self.app.swift_owner_headers:
                req.headers.pop(key, None)
        if len(self.container_name) > constraints.MAX_CONTAINER_NAME_LENGTH:
            resp = HTTPBadRequest(request=req)
            resp.body = 'Container name length of %d longer than %d' % \
                        (len(self.container_name),
                         constraints.MAX_CONTAINER_NAME_LENGTH)
            return resp
        container_count = self.account_info(self.account_name, req)

        clear_info_cache(self.app, req.environ,
                         self.account_name, self.container_name)

        storage = self.app.storage
        try:
            storage.container_create(self.account_name, self.container_name)
        except exceptions.OioException:
            return HTTPServerError(request=req)
        resp = HTTPCreated(request=req)
        return resp
 def DELETE(self, req):
     """HTTP DELETE request handler."""
     clear_info_cache(self.app, req.environ,
                      self.account_name, self.container_name)
     storage = self.app.storage
     try:
         storage.container_delete(self.account_name, self.container_name)
     except exceptions.ContainerNotEmpty:
         return HTTPConflict(request=req)
     except exceptions.NoSuchContainer:
         return HTTPNotFound(request=req)
     resp = HTTPNoContent(request=req)
     return resp
 def DELETE(self, req):
     """HTTP DELETE request handler."""
     # Extra safety in case someone typos a query string for an
     # account-level DELETE request that was really meant to be caught by
     # some middleware.
     if req.query_string:
         return HTTPBadRequest(request=req)
     if not self.app.allow_account_management:
         return HTTPMethodNotAllowed(
             request=req,
             headers={'Allow': ', '.join(self.allowed_methods)})
     headers = self.generate_request_headers(req)
     clear_info_cache(self.app, req.environ, self.account_name)
     # TODO delete account
     resp = HTTPNoContent(request=req)
     return resp
    def POST(self, req):
        """HTTP POST request handler."""
        if len(self.account_name) > constraints.MAX_ACCOUNT_NAME_LENGTH:
            resp = HTTPBadRequest(request=req)
            resp.body = 'Account name length of %d longer than %d' % \
                        (len(self.account_name),
                         constraints.MAX_ACCOUNT_NAME_LENGTH)
            return resp
        error_response = check_metadata(req, 'account')
        if error_response:
            return error_response

        clear_info_cache(self.app, req.environ, self.account_name)
        resp = self.get_account_post_resp(req)
        self.add_acls_from_sys_metadata(resp)
        return resp
    def PUT(self, req):
        """HTTP PUT request handler."""
        if not self.app.allow_account_management:
            return HTTPMethodNotAllowed(
                request=req,
                headers={'Allow': ', '.join(self.allowed_methods)})
        error_response = check_metadata(req, 'account')
        if error_response:
            return error_response
        if len(self.account_name) > constraints.MAX_ACCOUNT_NAME_LENGTH:
            resp = HTTPBadRequest(request=req)
            resp.body = 'Account name length of %d longer than %d' % \
                        (len(self.account_name),
                         constraints.MAX_ACCOUNT_NAME_LENGTH)
            return resp

        resp = self.get_account_put_resp(req)
        clear_info_cache(self.app, req.environ, self.account_name)
        self.add_acls_from_sys_metadata(resp)
        return resp