human
Complete this python program:
def find_and_assign_anonymous_cart(queryset=Cart.objects.all()):
assistant
#Here is the Python code you requested.

    """Assign cart from cookie to request user
    :type request: django.http.HttpRequest
    """
    def get_cart(view):
        @wraps(view)
        def func(request, *args, **kwargs):
            response = view(request, *args, **kwargs)
            token = request.get_signed_cookie(COOKIE_NAME, default=None)
            if (not token_is_valid(token)):
                return response
            cart = get_anonymous_cart_from_token(token=token, cart_queryset=queryset)
            if (cart is None):
                return response
            if request.user.is_authenticated():
                with transaction.atomic():
                    cart.change_user(request.user)
                    carts_to_close = Cart.objects.open().filter(user=request.user)
                    carts_to_close = carts_to_close.exclude(token=token)
                    carts_to_close.update(status=CartStatus.CANCELED, last_status_change=now())
                response.delete_cookie(COOKIE_NAME)
            return response
        return func
    return get_cart