def match_file(pattern, filename):
    '''
    The function will match a pattern in a file and return
    a rex object, which will have all the matches found in the file.
    '''

    # Validate user data.

    if pattern is None:
        return None

    if os.stat(filename).st_size == 0:
        return None

    rexobj = REX(pattern, filename)

    rexpatstr = reformat_pattern(pattern)
    #print "rexpatstr: ", rexpatstr

    rexpat = re.compile(rexpatstr)
    rexobj.rex_patternstr = rexpatstr
    rexobj.rex_pattern = rexpat

    sfile = open(filename, 'r')
    data = sfile.read()
    sfile.close()

    line_count = 1
    for line in data.splitlines():
        mobj = rexpat.match(line)
        if mobj:
            populate_resobj(rexobj, mobj, line_count)

        line_count += 1

    return rexobj
def match_file ( pattern , filename ) : if pattern is None : return None if os . stat ( filename ) . st_size == 0 : return None rexobj = REX ( pattern , filename ) rexpatstr = reformat_pattern ( pattern ) rexpat = re . compile ( rexpatstr ) rexobj . rex_patternstr = rexpatstr rexobj . rex_pattern = rexpat sfile = open ( filename , 'r' ) data = sfile . read ( ) sfile . close ( ) line_count = 1 for line in data . splitlines ( ) : mobj = rexpat . match ( line ) if mobj : populate_resobj ( rexobj , mobj , line_count ) line_count += 1 return rexobj
The function will match a pattern in a file and return
    a rex object, which will have all the matches found in the file.