B
    5dm              	   @   sf   d dl Zddlm Z ddlmZ ddlmZ edddd	d
dddgZG dd dZ	G dd de	Z
dS )    N   )typing)current_app)requestgetpostheadoptionsdeleteputtracepatchc               @   s   e Zd ZU dZdZejejeje	   e
d< dZejeje  e
d< g Zejejej  e
d< dZeje e
d< ejdd	d
Zee	ejejejdddZdS )Viewa  Subclass this class and override :meth:`dispatch_request` to
    create a generic class-based view. Call :meth:`as_view` to create a
    view function that creates an instance of the class with the given
    arguments and calls its ``dispatch_request`` method with any URL
    variables.

    See :doc:`views` for a detailed guide.

    .. code-block:: python

        class Hello(View):
            init_every_request = False

            def dispatch_request(self, name):
                return f"Hello, {name}!"

        app.add_url_rule(
            "/hello/<name>", view_func=Hello.as_view("hello")
        )

    Set :attr:`methods` on the class to change what methods the view
    accepts.

    Set :attr:`decorators` on the class to apply a list of decorators to
    the generated view function. Decorators applied to the class itself
    will not be applied to the generated view function!

    Set :attr:`init_every_request` to ``False`` for efficiency, unless
    you need to store request-global data on ``self``.
    Nmethodsprovide_automatic_options
decoratorsTinit_every_request)returnc             C   s
   t  dS )zThe actual view function behavior. Subclasses must override
        this and return a valid response. Any variables from the URL
        rule are passed as keyword arguments.
        N)NotImplementedError)self r   //tmp/pip-unpacked-wheel-qgtjwo79/flask/views.pydispatch_requestK   s    zView.dispatch_request)name
class_argsclass_kwargsr   c                s   | j r$tjtjd fddn"|  tjtjdfdd| jrr|_| j_x| jD ]}|qbW | _|_| j	_	| j_| j
_
| j_S )af  Convert the class into a view function that can be registered
        for a route.

        By default, the generated view will create a new instance of the
        view class for every request and call its
        :meth:`dispatch_request` method. If the view class sets
        :attr:`init_every_request` to ``False``, the same instance will
        be used for every request.

        Except for ``name``, all other arguments passed to this method
        are forwarded to the view class ``__init__`` method.

        .. versionchanged:: 2.2
            Added the ``init_every_request`` class attribute.
        )kwargsr   c                 s   j  }t|jf | S )N)
view_classr   ensure_syncr   )r   r   )r   r   viewr   r   r   g   s    zView.as_view.<locals>.viewc                 s   t  jf | S )N)r   r   r   )r   )r   r   r   r   p   s    )r   tAnyftResponseReturnValuer   __name__
__module__r   __doc__r   r   )clsr   r   r   	decoratorr   )r   r   r   r   r   as_viewR   s     
zView.as_view)r$   r%   __qualname__r&   r   r    ClassVarOptional
Collectionstr__annotations__r   boolr   ListCallabler   r"   r#   r   classmethodr!   ZRouteCallabler)   r   r   r   r   r      s   

r   c                   s>   e Zd ZdZejdd fddZejejdddZ	  Z
S )
MethodViewa  Dispatches request methods to the corresponding instance methods.
    For example, if you implement a ``get`` method, it will be used to
    handle ``GET`` requests.

    This can be useful for defining a REST API.

    :attr:`methods` is automatically set based on the methods defined on
    the class.

    See :doc:`views` for a detailed guide.

    .. code-block:: python

        class CounterAPI(MethodView):
            def get(self):
                return str(session.get("counter", 0))

            def post(self):
                session["counter"] = session.get("counter", 0) + 1
                return redirect(url_for("counter"))

        app.add_url_rule(
            "/counter", view_func=CounterAPI.as_view("counter")
        )
    N)r   r   c                sz   t  jf | d| jkrvt }x&| jD ]}t|dd r&||j q&W x$tD ]}t	| |rL|
|  qLW |rv|| _d S )Nr   )super__init_subclass____dict__set	__bases__getattrupdater   http_method_funcshasattraddupper)r'   r   r   basekey)	__class__r   r   r6      s    


zMethodView.__init_subclass__c             K   sX   t | tj d }|d kr0tjdkr0t | dd }|d k	sHtdtjt|f |S )NHEADr   zUnimplemented method )r:   r   methodlowerAssertionErrorr   r   )r   r   methr   r   r   r      s
    zMethodView.dispatch_request)r$   r%   r*   r&   r    r!   r6   r"   r#   r   __classcell__r   r   )rB   r   r4      s   r4   )r   r     r"   globalsr   r   	frozensetr<   r   r4   r   r   r   r   <module>   s   z