def contentfilter(fsname, pattern):
 if (pattern is None):
  return True
 try:
  f = open(fsname)
  prog = re.compile(pattern)
  for line in f:
   if prog.match(line):
    f.close()
    return True
  f.close()
 except:
  pass
 return False

def contentfilter ( fsname , pattern ) : if ( pattern is None ) : return True try : f = open ( fsname ) prog = re . compile ( pattern ) for line in f : if prog . match ( line ) : f . close ( ) return True f . close ( ) except : pass return False
filter files which contain the given expression .