
    wdf                         d Z ddlmZ ddlmZ  eg d          Z G d de          Z G d de	          Z
 G d	 d
 ee
e                    ZdS )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                   :    e Zd ZdZdZdZdZd Zed             Z	dS )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/<name>', 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 c                     t                      )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.
        )NotImplementedError)selfs    P/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/flask/views.pydispatch_requestzView.dispatch_requestE   s    
 "###    c                     fd| j         r(|_        | j        _        | j         D ]} |          | _        |_        | 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.
        c                  8     j         i } |j        | i |S )N)
view_classr   )argskwargsr   
class_argsclass_kwargsviews      r   r   zView.as_view.<locals>.viewW   s1    "4?J?,??D(4($9&999r   )
decorators__name__
__module__r   __doc__methodsprovide_automatic_options)clsnamer   r   	decoratorr   s     `` @r   as_viewzView.as_viewL   s    	: 	: 	: 	: 	: 	: 	: > 	' DM!nDO ^ ' '	 y {.{),)F&r   )
r   r    __qualname__r!   r"   r#   r   r   classmethodr'   r   r   r   r   r      s_         @ G !% J$ $ $   [  r   r   c                   "     e Zd ZdZ fdZ xZS )MethodViewTypezYMetaclass for :class:`MethodView` that determines what methods the view
    defines.
    c                 |   t          t          |                               |||           d|vrt                      }|D ]-}t	          |dd           r|                    |j                   .t          D ]9}t          | |          r'|	                    |
                                           :|r|| _        d S d S d S )Nr"   )superr+   __init__setgetattrupdater"   http_method_funcshasattraddupper)r$   r%   basesdr"   basekey	__class__s          r   r.   zMethodViewType.__init__t   s    nc""++D%;;;AeeG 1 14D11 1NN4<000( - -3$$ -KK		,,,  &%! & &r   )r   r    r(   r!   r.   __classcell__)r:   s   @r   r+   r+   o   sB         & & & & & & & & &r   r+   c                       e Zd ZdZd ZdS )
MethodViewa   A 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'))
    c                     t          | t          j                                        d           }|!t          j        dk    rt          | dd           }|J dt          j        z               ||i |S )NHEADr   zUnimplemented method %r)r0   r   methodlower)r   r   r   meths       r   r   zMethodView.dispatch_request   sv    tW^1133T:: <GNf444--D!:W^!KtT$V$$$r   N)r   r    r(   r!   r   r   r   r   r=   r=      s-         	% 	% 	% 	% 	%r   r=   N)r!   _compatr   globalsr   	frozensetr2   objectr   typer+   r=   r   r   r   <module>rH      s     $ # # # # #       IIII  
X X X X X6 X X Xv& & & & &T & & &6% % % % %55 % % % % %r   