#NEWLINE# def api_view( http_method_names = None ) : #NEWLINE# #INDENT# '\n    Decorator that converts a function-based view into an APIView subclass.\n    Takes a list of allowed methods for the view as an argument.\n    ' #NEWLINE# http_method_names = ( [ 'GET' ] if ( decorator is None ) else http_method_names ) #NEWLINE# def decorator( func ) : #NEWLINE# #INDENT# WrappedAPIView = type ( ( ( six . PY3 and 'WrappedAPIView' ) or b'WrappedAPIView' ) , ( APIView , ) , { #NEWLINE# #INDENT# '__doc__' : func . __doc__ , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert ( not isinstance ( http_method_names , types . FunctionType ) ) , '@api_view missing list of allowed HTTP methods' #NEWLINE# assert isinstance ( http_method_names , ( list , tuple ) ) , ( '@api_view expected a list of strings, received %s' % type ( http_method_names ) . __name__ ) #NEWLINE# allowed_methods = ( set ( http_method_names ) | set ( ( 'options' , ) ) ) #NEWLINE# WrappedAPIView . http_method_names = [ method . lower ( ) for method in allowed_methods ] #NEWLINE# def handler( self , * args , **kwargs ) : #NEWLINE# #INDENT# return func ( * args , ** kwargs ) #NEWLINE# #UNINDENT# for method in http_method_names : #NEWLINE# #INDENT# setattr ( WrappedAPIView , method . lower ( ) , handler ) #NEWLINE# #UNINDENT# WrappedAPIView . __name__ = func . __name__ #NEWLINE# WrappedAPIView . renderer_classes = getattr ( func , 'renderer_classes' , APIView . renderer_classes ) #NEWLINE# WrappedAPIView . parser_classes = getattr ( func , 'parser_classes' , APIView . parser_classes ) #NEWLINE# WrappedAPIView . authentication_classes = getattr ( func , 'authentication_classes' , APIView . authentication_classes ) #NEWLINE# WrappedAPIView . throttle_classes = getattr ( func , 'throttle_classes' , APIView . throttle_classes ) #NEWLINE# WrappedAPIView . permission_classes = getattr ( func , 'permission_classes' , APIView . permission_classes ) #NEWLINE# return WrappedAPIView . as_view ( ) #NEWLINE# #UNINDENT# return decorator