code: def redirect_warnings(capture=True, logger='py.warnings'):
      
      global _warnings_showwarning
      if capture:
          assert _warnings_showwarning is None
          _warnings_showwarning = warnings.showwarning
          # `warnings.showwarning` must be a function, a generic
          # callable object is not accepted ...
          warnings.showwarning = _WarningsLogger(logger, format_warning_oneline).__call__
      else:
          assert _warnings_showwarning is not None
          warnings.showwarning = _warnings_showwarning
          _warnings_showwarning = None
docs: If capture is true, redirect all warnings to the logging package.
      If capture is False, ensure that warnings are not redirected to logging
      but to their original destinations.