def _filterwarnings(filters, quiet=False):
<EOL>frame = sys._getframe(<NUM_LIT:2>)<EOL>registry = frame.f_globals.get('<STR_LIT>')<EOL>if registry:<EOL><INDENT>registry.clear()<EOL><DEDENT>with warnings.catch_warnings(record=True) as w:<EOL><INDENT>sys.modules['<STR_LIT>'].simplefilter("<STR_LIT>")<EOL>yield WarningsRecorder(w)<EOL><DEDENT>reraise = [warning.message for warning in w]<EOL>missing = []<EOL>for msg, cat in filters:<EOL><INDENT>seen = False<EOL>for exc in reraise[:]:<EOL><INDENT>message = str(exc)<EOL>if (re.match(msg, message, re.I) and<EOL>issubclass(exc.__class__, cat)):<EOL><INDENT>seen = True<EOL>reraise.remove(exc)<EOL><DEDENT><DEDENT>if not seen and not quiet:<EOL><INDENT>missing.append((msg, cat.__name__))<EOL><DEDENT><DEDENT>if reraise:<EOL><INDENT>raise AssertionError("<STR_LIT>" % reraise[<NUM_LIT:0>])<EOL><DEDENT>if missing:<EOL><INDENT>raise AssertionError("<STR_LIT>" %<EOL>missing[<NUM_LIT:0>])<EOL><DEDENT>
Catch the warnings, then check if all the expected
    warnings have been raised and re-raise unexpected warnings.
    If 'quiet' is True, only re-raise the unexpected warnings.