<s> """<STR_LIT>""" <EOL> import logging <EOL> from contextlib import contextmanager <EOL> from functools import partial <EOL> from tornado import stack_context <EOL> from viewfinder . backend . base . context_local import ContextLocal <EOL> from viewfinder . backend . storage . server_log import UserOperationLogHandler <EOL> class OpContext ( ContextLocal ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( OpContext , self ) . __init__ ( ) <EOL> self . executing_op = None <EOL> @ contextmanager <EOL> def Enter ( self , op ) : <EOL> """<STR_LIT>""" <EOL> log_handler = None <EOL> log_context = None <EOL> try : <EOL> assert op is not None , '<STR_LIT>' <EOL> assert self . executing_op is None , '<STR_LIT>' <EOL> self . executing_op = op <EOL> if op . method is not None : <EOL> log_handler = UserOperationLogHandler ( op ) <EOL> log_handler . setLevel ( logging . INFO ) <EOL> log_context = log_handler . LoggingContext ( ) <EOL> log_context . __enter__ ( ) <EOL> yield <EOL> finally : <EOL> if log_context is not None : <EOL> log_context . __exit__ ( None , None , None ) <EOL> if log_handler is not None : <EOL> log_handler . close ( ) <EOL> self . executing_op = None <EOL> def EnterOpContext ( op ) : <EOL> """<STR_LIT>""" <EOL> @ contextmanager <EOL> def _ContextManager ( op ) : <EOL> with OpContext ( ) : <EOL> with OpContext . current ( ) . Enter ( op ) : <EOL> yield <EOL> return stack_context . StackContext ( partial ( _ContextManager , op ) ) </s>
