a
    Nb<                     @   sn   d dl ZddlmZ ddlmZ ddl mZ eg dZG dd dZG d	d
 d
e	Z
G dd dee
dZdS )    N   )current_app)request)ResponseReturnValue)getpostheadoptionsdeleteputtracepatchc                   @   s|   e Zd ZU dZdZejeje  e	d< dZ
eje e	d< g Zejej e	d< edddZeeejejejd	d
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 f"Hello {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methodsprovide_automatic_options
decorators)returnc                 C   s
   t  dS )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)self r   H/var/www/html/diaryflask/venv/lib/python3.9/site-packages/flask/views.pydispatch_request>   s    zView.dispatch_request)name
class_argsclass_kwargsr   c                    sv   t jt jtd fdd| jrF|_| j_| jD ]}|q8| _|_| 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.
        argskwargsr   c                     s&   j  i }t|j| i |S )N)
view_classr   ensure_syncr   )r   r   r   r   r   viewr   r   r!   R   s    zView.as_view.<locals>.view)
tAnyr   r   __name__
__module__r   __doc__r   r   )clsr   r   r   	decoratorr   r    r   as_viewE   s    

zView.as_view)r$   r%   __qualname__r&   r   r"   OptionalListstr__annotations__r   boolr   Callabler   r   classmethodr#   r)   r   r   r   r   r      s   
 
r   c                       s    e Zd ZdZ fddZ  ZS )MethodViewTypezYMetaclass for :class:`MethodView` that determines what methods the view
    defines.
    c                    sp   t  ||| d|vrlt }|D ]}t|dd r"||j q"tD ]}t| |rD||	  qD|rl|| _d S )Nr   )
super__init__setgetattrupdater   http_method_funcshasattraddupper)r'   r   basesdr   basekey	__class__r   r   r4   o   s    
zMethodViewType.__init__)r$   r%   r*   r&   r4   __classcell__r   r   r@   r   r2   j   s   r2   c                   @   s&   e Zd ZdZejejedd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'))
    r   c                 O   s\   t | tj d }|d u r0tjdkr0t | dd }|d usHJ dtjt||i |S )NHEADr   zUnimplemented method )r6   r   methodlowerr   r   )r   r   r   methr   r   r   r      s
    zMethodView.dispatch_requestN)r$   r%   r*   r&   r"   r#   r   r   r   r   r   r   rC      s   rC   )	metaclass)typingr"   globalsr   r   r   	frozensetr8   r   typer2   rC   r   r   r   r   <module>   s   ]