def _bucket_response_put(self, request, body, region_name, bucket_name, querystring):
    if (not request.headers.get('Content-Length')):
        return (411, {}, 'Content-Length required')
    self._set_action('BUCKET', 'PUT', querystring)
    self._authenticate_and_authorize_s3_action()
    if ('object-lock' in querystring):
        body_decoded = body.decode()
        config = self._lock_config_from_xml(body_decoded)
        if (not self.backend.get_bucket(bucket_name).object_lock_enabled):
            raise BucketMustHaveLockeEnabled
        self.backend.put_object_lock_configuration(bucket_name, config.get('enabled'), config.get('mode'), config.get('days'), config.get('years'))
        return (200, {}, '')
    if ('versioning' in querystring):
        ver = re.search('<Status>([A-Za-z]+)</Status>', body.decode())
        if ver:
            self.backend.set_bucket_versioning(bucket_name, ver.group(1))
            template = self.response_template(S3_BUCKET_VERSIONING)
            return template.render(bucket_versioning_status=ver.group(1))
        else:
            return (404, {}, '')
    elif ('lifecycle' in querystring):
        rules = xmltodict.parse(body)['LifecycleConfiguration']['Rule']
        if (not isinstance(rules, list)):
            rules = [rules]
        self.backend.put_bucket_lifecycle(bucket_name, rules)
        return ''
    elif ('policy' in querystring):
        self.backend.put_bucket_policy(bucket_name, body)
        return 'True'
    elif ('acl' in querystring):
        acls = self._acl_from_headers(request.headers)
        if (not acls):
            acls = self._acl_from_xml(body)
        self.backend.put_bucket_acl(bucket_name, acls)
        return ''
    elif ('tagging' in querystring):
        tagging = self._bucket_tagging_from_xml(body)
        self.backend.put_bucket_tagging(bucket_name, tagging)
        return ''
    elif ('website' in querystring):
        self.backend.set_bucket_website_configuration(bucket_name, body)
        return ''
    elif ('cors' in querystring):
        try:
            self.backend.put_bucket_cors(bucket_name, self._cors_from_xml(body))
            return ''
        except KeyError:
            raise MalformedXML()
    elif ('logging' in querystring):
        try:
            self.backend.put_bucket_logging(bucket_name, self._logging_from_xml(body))
            return ''
        except KeyError:
            raise MalformedXML()
    elif ('notification' in querystring):
        try:
            self.backend.put_bucket_notification_configuration(bucket_name, self._notification_config_from_xml(body))
            return ''
        except KeyError:
            raise MalformedXML()
        except Exception as e:
            raise e
    elif ('accelerate' in querystring):
        try:
            accelerate_status = self._accelerate_config_from_xml(body)
            self.backend.put_bucket_accelerate_configuration(bucket_name, accelerate_status)
            return ''
        except KeyError:
            raise MalformedXML()
        except Exception as e:
            raise e
    elif ('publicAccessBlock' in querystring):
        pab_config = self._parse_pab_config(body)
        self.backend.put_bucket_public_access_block(bucket_name, pab_config['PublicAccessBlockConfiguration'])
        return ''
    elif ('encryption' in querystring):
        try:
            self.backend.put_bucket_encryption(bucket_name, self._encryption_config_from_xml(body))
            return ''
        except KeyError:
            raise MalformedXML()
        except Exception as e:
            raise e
    else:
        if ((region_name != DEFAULT_REGION_NAME) and (not self._body_contains_location_constraint(body))):
            raise IllegalLocationConstraintException()
        if body:
            if self._create_bucket_configuration_is_empty(body):
                raise MalformedXML()
            try:
                forced_region = xmltodict.parse(body)['CreateBucketConfiguration']['LocationConstraint']
                if (forced_region == DEFAULT_REGION_NAME):
                    raise S3ClientError('InvalidLocationConstraint', 'The specified location-constraint is not valid')
                else:
                    region_name = forced_region
            except KeyError:
                pass
        try:
            new_bucket = self.backend.create_bucket(bucket_name, region_name)
        except BucketAlreadyExists:
            new_bucket = self.backend.get_bucket(bucket_name)
            if ((new_bucket.region_name == DEFAULT_REGION_NAME) and (region_name == DEFAULT_REGION_NAME)):
                pass
            else:
                template = self.response_template(S3_DUPLICATE_BUCKET_ERROR)
                return (409, {}, template.render(bucket_name=bucket_name))
        if ('x-amz-acl' in request.headers):
            self.backend.put_bucket_acl(bucket_name, self._acl_from_headers(request.headers))
        if (request.headers.get('x-amz-bucket-object-lock-enabled', '').lower() == 'true'):
            new_bucket.object_lock_enabled = True
            new_bucket.versioning_status = 'Enabled'
        template = self.response_template(S3_BUCKET_CREATE_RESPONSE)
        return (200, {}, template.render(bucket=new_bucket))
def _bucket_response_put(self, request, body, region_name, bucket_name, querystring):
    if (not request.headers.get('Content-Length')):
        return (411, {}, 'Content-Length required')
    self._set_action('BUCKET', 'PUT', querystring)
    self._authenticate_and_authorize_s3_action()
    if ('object-lock' in querystring):
        body_decoded = body.decode()
        config = self._lock_config_from_xml(body_decoded)
        if (not self.backend.get_bucket(bucket_name).object_lock_enabled):
            raise BucketMustHaveLockeEnabled
        self.backend.put_object_lock_configuration(bucket_name, config.get('enabled'), config.get('mode'), config.get('days'), config.get('years'))
        return (200, {}, )
    if ('versioning' in querystring):
        ver = re.search('<Status>([A-Za-z]+)</Status>', body.decode())
        if ver:
            self.backend.set_bucket_versioning(bucket_name, ver.group(1))
            template = self.response_template(S3_BUCKET_VERSIONING)
            return template.render(bucket_versioning_status=ver.group(1))
        else:
            return (404, {}, )
    elif ('lifecycle' in querystring):
        rules = xmltodict.parse(body)['LifecycleConfiguration']['Rule']
        if (not isinstance(rules, list)):
            rules = [rules]
        self.backend.put_bucket_lifecycle(bucket_name, rules)
        return 
    elif ('policy' in querystring):
        self.backend.put_bucket_policy(bucket_name, body)
        return 'True'
    elif ('acl' in querystring):
        acls = self._acl_from_headers(request.headers)
        if (not acls):
            acls = self._acl_from_xml(body)
        self.backend.put_bucket_acl(bucket_name, acls)
        return 
    elif ('tagging' in querystring):
        tagging = self._bucket_tagging_from_xml(body)
        self.backend.put_bucket_tagging(bucket_name, tagging)
        return 
    elif ('website' in querystring):
        self.backend.set_bucket_website_configuration(bucket_name, body)
        return 
    elif ('cors' in querystring):
        try:
            self.backend.put_bucket_cors(bucket_name, self._cors_from_xml(body))
            return 
        except KeyError:
            raise MalformedXML()
    elif ('logging' in querystring):
        try:
            self.backend.put_bucket_logging(bucket_name, self._logging_from_xml(body))
            return 
        except KeyError:
            raise MalformedXML()
    elif ('notification' in querystring):
        try:
            self.backend.put_bucket_notification_configuration(bucket_name, self._notification_config_from_xml(body))
            return 
        except KeyError:
            raise MalformedXML()
        except Exception as e:
            raise e
    elif ('accelerate' in querystring):
        try:
            accelerate_status = self._accelerate_config_from_xml(body)
            self.backend.put_bucket_accelerate_configuration(bucket_name, accelerate_status)
            return 
        except KeyError:
            raise MalformedXML()
        except Exception as e:
            raise e
    elif ('publicAccessBlock' in querystring):
        pab_config = self._parse_pab_config(body)
        self.backend.put_bucket_public_access_block(bucket_name, pab_config['PublicAccessBlockConfiguration'])
        return 
    elif ('encryption' in querystring):
        try:
            self.backend.put_bucket_encryption(bucket_name, self._encryption_config_from_xml(body))
            return 
        except KeyError:
            raise MalformedXML()
        except Exception as e:
            raise e
    else:
        if ((region_name != DEFAULT_REGION_NAME) and (not self._body_contains_location_constraint(body))):
            raise IllegalLocationConstraintException()
        if body:
            if self._create_bucket_configuration_is_empty(body):
                raise MalformedXML()
            try:
                forced_region = xmltodict.parse(body)['CreateBucketConfiguration']['LocationConstraint']
                if (forced_region == DEFAULT_REGION_NAME):
                    raise S3ClientError('InvalidLocationConstraint', 'The specified location-constraint is not valid')
                else:
                    region_name = forced_region
            except KeyError:
                pass
        try:
            new_bucket = self.backend.create_bucket(bucket_name, region_name)
        except BucketAlreadyExists:
            new_bucket = self.backend.get_bucket(bucket_name)
            if ((new_bucket.region_name == DEFAULT_REGION_NAME) and (region_name == DEFAULT_REGION_NAME)):
                pass
            else:
                template = self.response_template(S3_DUPLICATE_BUCKET_ERROR)
                return (409, {}, template.render(bucket_name=bucket_name))
        if ('x-amz-acl' in request.headers):
            self.backend.put_bucket_acl(bucket_name, self._acl_from_headers(request.headers))
        if (request.headers.get('x-amz-bucket-object-lock-enabled', ).lower() == 'true'):
            new_bucket.object_lock_enabled = True
            new_bucket.versioning_status = 'Enabled'
        template = self.response_template(S3_BUCKET_CREATE_RESPONSE)
        return (200, {}, template.render(bucket=new_bucket))