<s> "<STR_LIT>" <EOL> from functools import wraps , update_wrapper , WRAPPER_ASSIGNMENTS <EOL> class classonlymethod ( classmethod ) : <EOL> def __get__ ( self , instance , owner ) : <EOL> if instance is not None : <EOL> raise AttributeError ( "<STR_LIT>" ) <EOL> return super ( classonlymethod , self ) . __get__ ( instance , owner ) <EOL> def method_decorator ( decorator ) : <EOL> """<STR_LIT>""" <EOL> def _dec ( func ) : <EOL> def _wrapper ( self , * args , ** kwargs ) : <EOL> @ decorator <EOL> def bound_func ( * args2 , ** kwargs2 ) : <EOL> return func ( self , * args2 , ** kwargs2 ) <EOL> return bound_func ( * args , ** kwargs ) <EOL> @ decorator <EOL> def dummy ( * args , ** kwargs ) : <EOL> pass <EOL> update_wrapper ( _wrapper , dummy ) <EOL> update_wrapper ( _wrapper , func ) <EOL> return _wrapper <EOL> update_wrapper ( _dec , decorator ) <EOL> _dec . __name__ = '<STR_LIT>' % decorator . __name__ <EOL> return _dec <EOL> def decorator_from_middleware_with_args ( middleware_class ) : <EOL> """<STR_LIT>""" <EOL> return make_middleware_decorator ( middleware_class ) <EOL> def decorator_from_middleware ( middleware_class ) : <EOL> """<STR_LIT>""" <EOL> return make_middleware_decorator ( middleware_class ) ( ) <EOL> def available_attrs ( fn ) : <EOL> """<STR_LIT>""" <EOL> return tuple ( a for a in WRAPPER_ASSIGNMENTS if hasattr ( fn , a ) ) <EOL> def make_middleware_decorator ( middleware_class ) : <EOL> def _make_decorator ( * m_args , ** m_kwargs ) : <EOL> middleware = middleware_class ( * m_args , ** m_kwargs ) <EOL> def _decorator ( view_func ) : <EOL> @ wraps ( view_func , assigned = available_attrs ( view_func ) ) <EOL> def _wrapped_view ( request , * args , ** kwargs ) : <EOL> if hasattr ( middleware , '<STR_LIT>' ) : <EOL> result = middleware . process_request ( request ) <EOL> if result is not None : <EOL> return result <EOL> if hasattr ( middleware , '<STR_LIT>' ) : <EOL> result = middleware . process_view ( request , view_func , args , kwargs ) <EOL> if result is not None : <EOL> return result <EOL> try : <EOL> response = view_func ( request , * args , ** kwargs ) <EOL> except Exception as e : <EOL> if hasattr ( middleware , '<STR_LIT>' ) : <EOL> result = middleware . process_exception ( request , e ) <EOL> if result is not None : <EOL> return result <EOL> raise <EOL> if hasattr ( response , '<STR_LIT>' ) and callable ( response . render ) : <EOL> if hasattr ( middleware , '<STR_LIT>' ) : <EOL> response = middleware . process_template_response ( request , response ) <EOL> if hasattr ( middleware , '<STR_LIT>' ) : <EOL> callback = lambda response : middleware . process_response ( request , response ) <EOL> response . add_post_render_callback ( callback ) <EOL> else : <EOL> if hasattr ( middleware , '<STR_LIT>' ) : <EOL> return middleware . process_response ( request , response ) <EOL> return response <EOL> return _wrapped_view <EOL> return _decorator <EOL> return _make_decorator </s>
