U a @snddlZddlmZddlmZeddddd d d d gZGd ddZGdddeZ Gdddee dZ dS)N)request)ResponseReturnValuegetpostheadoptionsdeleteputtracepatchc@s|eZdZUdZdZejejee d<dZ eje e d<gZ ejej e d<edddZeeejejej d d d ZdS) ViewaAlternative way to use view functions. A subclass has to implement :meth:`dispatch_request` which is called with the view arguments from the URL routing system. If :attr:`methods` is provided the methods do not have to be passed to the :meth:`~flask.Flask.add_url_rule` method explicitly:: class MyView(View): methods = ['GET'] def dispatch_request(self, name): return f"Hello {name}!" app.add_url_rule('/hello/', view_func=MyView.as_view('myview')) When you want to decorate a pluggable view you will have to either do that when the view function is created (by wrapping the return value of :meth:`as_view`) or you can use the :attr:`decorators` attribute:: class SecretView(View): methods = ['GET'] decorators = [superuser_required] def dispatch_request(self): ... The decorators stored in the decorators list are applied one after another when the view function is created. Note that you can *not* use the class based decorators since those would decorate the view class and not the generated view function! Nmethodsprovide_automatic_options decorators)returncCs tdS)zSubclasses have to override this method to implement the actual view function code. This method is called with all the arguments from the URL rule. N)NotImplementedError)selfrLC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-e702oxwa\flask\views.pydispatch_request=szView.dispatch_request)name class_args class_kwargsrcsvtjtjtdfdd |jrF|_|j_|jD] }|q8|_|_|j_|j_|j_|j _ S)aConverts the class into an actual view function that can be used with the routing system. Internally this generates a function on the fly which will instantiate the :class:`View` on each request and call the :meth:`dispatch_request` method on it. The arguments passed to :meth:`as_view` are forwarded to the constructor of the class. argskwargsrcsj}|j||S)N) view_classr)rrrrrviewrrrQs zView.as_view..view) tAnyrr__name__ __module__r__doc__rr)clsrrr decoratorrrras_viewDs   z View.as_view)r"r# __qualname__r$rr OptionalListstr__annotations__rboolrCallablerr classmethodr!r'rrrrr s   r cs eZdZdZfddZZS)MethodViewTypezYMetaclass for :class:`MethodView` that determines what methods the view defines. cspt|||d|krlt}|D]}t|ddr"||jq"tD]}t||rD|| qD|rl||_dS)Nr) super__init__setgetattrupdaterhttp_method_funcshasattraddupper)r%rbasesdrbasekey __class__rrr2ns  zMethodViewType.__init__)r"r#r(r$r2 __classcell__rrr>rr0isr0c@s&eZdZdZejejedddZdS) MethodViewaA class-based view that dispatches request methods to the corresponding class methods. For example, if you implement a ``get`` method, it will be used to handle ``GET`` requests. :: class CounterAPI(MethodView): def get(self): return session.get('counter', 0) def post(self): session['counter'] = session.get('counter', 0) + 1 return 'OK' app.add_url_rule('/counter', view_func=CounterAPI.as_view('counter')) rcOsRt|tjd}|dkr0tjdkr0t|dd}|dk sHtdtj|||S)NHEADrzUnimplemented method )r4rmethodlowerAssertionError)rrrmethrrrrs  zMethodView.dispatch_requestN)r"r#r(r$r r!rrrrrrrAsrA) metaclass) typingr globalsrr frozensetr6r typer0rArrrrs  ]