<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> from functools import update_wrapper <EOL> from django . utils . decorators import classonlymethod <EOL> from django . views . decorators . csrf import csrf_exempt <EOL> from rest_framework import generics , mixins , views <EOL> class ViewSetMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> @ classonlymethod <EOL> def as_view ( cls , actions = None , ** initkwargs ) : <EOL> """<STR_LIT>""" <EOL> cls . suffix = None <EOL> if not actions : <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> for key in initkwargs : <EOL> if key in cls . http_method_names : <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( key , cls . __name__ ) ) <EOL> if not hasattr ( cls , key ) : <EOL> raise TypeError ( "<STR_LIT>" % ( <EOL> cls . __name__ , key ) ) <EOL> def view ( request , * args , ** kwargs ) : <EOL> self = cls ( ** initkwargs ) <EOL> self . action_map = actions <EOL> for method , action in actions . items ( ) : <EOL> handler = getattr ( self , action ) <EOL> setattr ( self , method , handler ) <EOL> if hasattr ( self , '<STR_LIT>' ) and not hasattr ( self , '<STR_LIT>' ) : <EOL> self . head = self . get <EOL> return self . dispatch ( request , * args , ** kwargs ) <EOL> update_wrapper ( view , cls , updated = ( ) ) <EOL> update_wrapper ( view , cls . dispatch , assigned = ( ) ) <EOL> view . cls = cls <EOL> view . suffix = initkwargs . get ( '<STR_LIT>' , None ) <EOL> return csrf_exempt ( view ) <EOL> def initialize_request ( self , request , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> request = super ( ViewSetMixin , self ) . initialize_request ( request , * args , ** kwargs ) <EOL> method = request . method . lower ( ) <EOL> if method == '<STR_LIT>' : <EOL> self . action = '<STR_LIT>' <EOL> else : <EOL> self . action = self . action_map . get ( method ) <EOL> return request <EOL> class ViewSet ( ViewSetMixin , views . APIView ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class GenericViewSet ( ViewSetMixin , generics . GenericAPIView ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class ReadOnlyModelViewSet ( mixins . RetrieveModelMixin , <EOL> mixins . ListModelMixin , <EOL> GenericViewSet ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class ModelViewSet ( mixins . CreateModelMixin , <EOL> mixins . RetrieveModelMixin , <EOL> mixins . UpdateModelMixin , <EOL> mixins . DestroyModelMixin , <EOL> mixins . ListModelMixin , <EOL> GenericViewSet ) : <EOL> """<STR_LIT>""" <EOL> pass </s>
