#NEWLINE# @ classmethod #NEWLINE# @ contextmanager #NEWLINE# def global_instance( cls , cmdline_args , allow_override = False ) : #NEWLINE# #INDENT# '\n        Meant to be used as a context manager.\n        ' #NEWLINE# orig_value = cls . _instance #NEWLINE# assert ( ( orig_value is None ) or allow_override ) #NEWLINE# new_value = None #NEWLINE# try : #NEWLINE# #INDENT# new_value = CmdlineParser ( cmdline_args ) #NEWLINE# cls . _instance = new_value #NEWLINE# ( yield new_value ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# assert ( cls . _instance is new_value ) #NEWLINE# cls . _instance = orig_value