def unauthenticated_userid(request):
    """
    Helper method for getting the `unauthenticated_userid` value from a
    request. For pyramid >= 1.5 `unauthenticated_userid` is an attribute
    on the request object. For older pyramid versions, before 1.5,
    `unauthenticated_userid` is a helper method in `pyramid.security`.
    """
    try:
        return request.unauthenticated_userid
    except AttributeError:
        try:
            from pyramid.security import unauthenticated_userid
            return unauthenticated_userid(request)
        except ImportError:
            return None
