U ).ó_ªã @sndZddlmZddlmZedddddd d d gƒZGd d „d eƒZGdd„de ƒZ Gdd„dee eƒƒZ dS)z¦ flask.views ~~~~~~~~~~~ This module provides class-based views inspired by the ones in Django. :copyright: 2010 Pallets :license: BSD-3-Clause é)Úwith_metaclass)ÚrequestÚgetÚpostÚheadÚoptionsÚdeleteÚputÚtraceÚpatchc@s0eZdZdZdZdZdZdd„Zedd„ƒZ dS)ÚViewa©Alternative 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 'Hello %s!' % 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! N©cCs tƒ‚dS)z­Subclasses 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)Úselfr r úšC:\Users\Miouzora\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\flask/views.pyÚdispatch_requestEszView.dispatch_requestcsh‡‡‡fdd„‰|jr8|ˆ_|jˆ_|jD] }|ˆƒ‰q*|ˆ_|ˆ_|jˆ_|jˆ_|jˆ_|jˆ_ˆS)a€Converts 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. csˆjˆˆŽ}|j||ŽS)N)Ú view_classr)ÚargsÚkwargsr©Ú class_argsÚ class_kwargsÚviewr rrWs zView.as_view..view)Ú decoratorsÚ__name__Ú __module__rÚ__doc__ÚmethodsÚprovide_automatic_options)ÚclsÚnamerrÚ decoratorr rrÚas_viewLs   z View.as_view) rrÚ __qualname__rrrrrÚ classmethodr"r r r rr s  r cs eZdZdZ‡fdd„Z‡ZS)ÚMethodViewTypezYMetaclass for :class:`MethodView` that determines what methods the view defines. csttt|ƒ |||¡d|krptƒ}|D]}t|ddƒr&| |j¡q&tD]}t||ƒrH|  |  ¡¡qH|rp||_dS)Nr) Úsuperr%Ú__init__ÚsetÚgetattrÚupdaterÚhttp_method_funcsÚhasattrÚaddÚupper)rr ÚbasesÚdrÚbaseÚkey©Ú __class__r rr'ts  zMethodViewType.__init__)rrr#rr'Ú __classcell__r r r3rr%osr%c@seZdZdZdd„ZdS)Ú 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')) cOsPt|tj ¡dƒ}|dkr0tjdkr0t|ddƒ}|dk sFtdtjƒ‚|||ŽS)NÚHEADrzUnimplemented method %r)r)rÚmethodÚlowerÚAssertionError)rrrÚmethr r rršs  zMethodView.dispatch_requestN)rrr#rrr r r rr6Šsr6N) rÚ_compatrÚglobalsrÚ frozensetr+Úobjectr Útyper%r6r r r rÚs  ÿ[