@contextlib.contextmanager
def no_internet(verbose=False):
 already_disabled = INTERNET_OFF
 turn_off_internet(verbose=verbose)
 try:
  (yield)
 finally:
  if (not already_disabled):
   turn_on_internet(verbose=verbose)

@ contextlib . contextmanager def no_internet ( verbose = False ) : already_disabled = INTERNET_OFF turn_off_internet ( verbose = verbose ) try : ( yield ) finally : if ( not already_disabled ) : turn_on_internet ( verbose = verbose )
context manager to temporarily disable internet access .