'Handle HTTP PUT request.'

@public
@timing_stats()
def PUT(self, req):

    (drive, part, account, container) = split_and_validate_path(req, 3, 4)
    if (self.mount_check and (not check_mount(self.root, drive))):
        return HTTPInsufficientStorage(drive=drive, request=req)
    if container:
        if ('x-timestamp' not in req.headers):
            timestamp = Timestamp.now()
        else:
            timestamp = valid_timestamp(req)
        pending_timeout = None
        container_policy_index = req.headers.get('X-Backend-Storage-Policy-Index', 0)
        if ('x-trans-id' in req.headers):
            pending_timeout = 3
        broker = self._get_account_broker(drive, part, account, pending_timeout=pending_timeout)
        if (account.startswith(self.auto_create_account_prefix) and (not os.path.exists(broker.db_file))):
            try:
                broker.initialize(timestamp.internal)
            except DatabaseAlreadyExists:
                pass
        if ((req.headers.get('x-account-override-deleted', 'no').lower() != 'yes') and broker.is_deleted()):
            return HTTPNotFound(request=req)
        broker.put_container(container, req.headers['x-put-timestamp'], req.headers['x-delete-timestamp'], req.headers['x-object-count'], req.headers['x-bytes-used'], container_policy_index)
        if (req.headers['x-delete-timestamp'] > req.headers['x-put-timestamp']):
            return HTTPNoContent(request=req)
        else:
            return HTTPCreated(request=req)
    else:
        timestamp = valid_timestamp(req)
        broker = self._get_account_broker(drive, part, account)
        if (not os.path.exists(broker.db_file)):
            try:
                broker.initialize(timestamp.internal)
                created = True
            except DatabaseAlreadyExists:
                created = False
        elif broker.is_status_deleted():
            return self._deleted_response(broker, req, HTTPForbidden, body='Recently    deleted')
        else:
            created = broker.is_deleted()
            broker.update_put_timestamp(timestamp.internal)
            if broker.is_deleted():
                return HTTPConflict(request=req)
        metadata = {}
        metadata.update(((key, (value, timestamp.internal)) for (key, value) in req.headers.items() if is_sys_or_user_meta('account', key)))
        if metadata:
            broker.update_metadata(metadata, validate_metadata=True)
        if created:
            return HTTPCreated(request=req)
        else:
            return HTTPAccepted(request=req)
