security/timing.py
def match_time(regex, regex_input, iterations: int = 2, timeout: int = config.timeout):
    """
    Determine how long a string takes to match
    """
    times = []
    compiled_regex = re.compile(regex)
    for _ in range(iterations):
        parent_conn, child_conn = multiprocessing.Pipe()
        p = multiprocessing.Process(target=do_match, args=((compiled_regex, regex_input, child_conn, )))
        p.start()
        p.join(timeout=timeout)
        if p.is_alive():
            time_taken = timeout
            # print("TIMEOUT:", regex_input)
            p.kill()
        else:
            time_taken = parent_conn.recv()
        times.append(time_taken)

    # print("difference in time", total_time1, total_time2, abs(total_time1 - total_time2))
    return statistics.mean(times)

    Determine how long a string takes to match
    
Determine how long a string takes to match
Determine how long a string takes to match
def match_time(regex, regex_input, iterations: int = 2, timeout: int = config.timeout):
    times = []
    compiled_regex = re.compile(regex)
    for _ in range(iterations):
        parent_conn, child_conn = multiprocessing.Pipe()
        p = multiprocessing.Process(target=do_match, args=((compiled_regex, regex_input, child_conn, )))
        p.start()
        p.join(timeout=timeout)
        if p.is_alive():
            time_taken = timeout
            p.kill()
        else:
            time_taken = parent_conn.recv()
        times.append(time_taken)
    return statistics.mean(times)
def match_time ( regex , regex_input , iterations : int = 2 , timeout : int = config . timeout ) : times = [ ] compiled_regex = re . compile ( regex ) for _ in range ( iterations ) : parent_conn , child_conn = multiprocessing . Pipe ( ) p = multiprocessing . Process ( target = do_match , args = ( ( compiled_regex , regex_input , child_conn , ) ) ) p . start ( ) p . join ( timeout = timeout ) if p . is_alive ( ) : time_taken = timeout p . kill ( ) else : time_taken = parent_conn . recv ( ) times . append ( time_taken ) return statistics . mean ( times )
Determine how long a string takes to match
Determine how long a string takes to match
"""
    Determine how long a string takes to match
    """ # print("TIMEOUT:", regex_input) # print("difference in time", total_time1, total_time2, abs(total_time1 - total_time2))
regex
regex_input
iterations
int
timeout
int