human
Can you provide a the Python code you requested given the following:
Complete the below
def _scipy_kraft_burrows_nousek(N, B, CL):

    ''''Upper limit on a poisson count rate
    The implementation is based on Kraft, Burrows and Nousek
    `ApJ 374, 344 (1991) <http://adsabs.harvard.edu/abs/1991ApJ...374..344K>`_.
    The XMM-Newton upper limit server uses the same formalism.
    Parameters
    N : int
    Total observed count number
    B : float
    Background count rate (assumed to be known with negligible error
    from a large background area).
    CL : float
    Confidence level (number between 0 and 1)
    Returns
    S : source count limit
    Notes
    Requires `scipy`. This implementation will cause Overflow Errors for about
    N > 100 (the exact limit depends on details of how scipy was compiled).
    See `~astropy.stats.mpmath_poisson_upper_limit` for an implementation that
    is slower, but can deal with arbitrarily high numbers since it is based on
    the `mpmath <http://mpmath.org/>`_ library.'
    '''
assistant
#Here is the Python code you requested.
    from scipy.optimize import brentq
    from scipy.integrate import quad
    from math import exp
    def eqn8(N, B):
        n = np.arange((N + 1), dtype=np.float64)
        factorial_n = np.ones(n.shape, dtype=np.float64)
        np.cumprod(n[1:], out=factorial_n[1:])
        return (1.0 / (exp((- B)) * np.sum((np.power(B, n) / factorial_n))))
    eqn8_res = eqn8(N, B)
    factorial_N = float(math.factorial(N))
    def eqn7(S, N, B):
        SpB = (S + B)
        return (eqn8_res * ((exp((- SpB)) * (SpB ** N)) / factorial_N))
    def eqn9_left(S_min, S_max, N, B):
        return quad(eqn7, S_min, S_max, args=(N, B), limit=500)
    def find_s_min(S_max, N, B):
        u'\n                                Kraft,    Burrows    and    Nousek    suggest    to    integrate    from    N-B    in    both\n                                directions    at    once,    so    that    S_min    and    S_max    move    similarly    (see\n                                the    article    for    details).    Here,    this    is    implemented    differently:\n                                Treat    S_max    as    the    optimization    parameters    in    func    and    then\n                                calculate    the    matching    s_min    that    has    has    eqn7(S_max)    =\n                                eqn7(S_min)    here.\n                                '
        y_S_max = eqn7(S_max, N, B)
        if (eqn7(0, N, B) >= y_S_max):
            return 0.0
        else:
            return brentq((lambda x: (eqn7(x, N, B) - y_S_max)), 0, (N - B))
    def func(s):
        s_min = find_s_min(s, N, B)
        out = eqn9_left(s_min, s, N, B)
        return (out[0] - CL)
    S_max = brentq(func, (N - B), 100)
    S_min = find_s_min(S_max, N, B)
    return (S_min, S_max)