U
    ÒZjR  ã                	   @   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 )z·The 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   úN/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/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rn|ˆ_| jˆ_| jD ]}|ˆƒ‰q`| ˆ_|ˆ_| j	ˆ_	| jˆ_| j
ˆ_
| jˆ_ˆS )aK  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.

        The 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 r   )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")
        )
    Nr   c                    sr   t ƒ jf |Ž d| jkrntƒ }| jD ]}t|dd ƒr$| |j¡ q$tD ]}t	| |ƒrF| 
| ¡ ¡ qF|rn|| _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   r9   ¢   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$   r9   r%   r&   r   Ú__classcell__r   r   rE   r   r7   ‡   s   r7   )r   r#   Ú r%   Úglobalsr   r   Ú	frozensetr?   r   r7   r   r   r   r   Ú<module>   s   ÿz