Format: application/x-python-code
⬇ Download File (5.4 KB)
   1  o
   2  
   3  D'h2�@s�ddlmZddlZddlmZddlmZddlmZej	dej
   4  dejfd	�Ze
   5  gd
   6  ��ZGdd�d�ZGd
   7  d�de�ZdS)�)�annotationsN�)�typing)�current_app)�request�F.)�bound)�get�post�head�options�delete�put�trace�patchc@sZeZdZUdZdZded<dZded<gZded<d	Zd
   8  ed<ddd�Z	e
   9  ddd��ZdS)�ViewaSubclass this class and override :meth:`dispatch_request` to
  10      create a generic class-based view. Call :meth:`as_view` to create a
  11      view function that creates an instance of the class with the given
  12      arguments and calls its ``dispatch_request`` method with any URL
  13      variables.
  14  
  15      See :doc:`views` for a detailed guide.
  16  
  17      .. code-block:: python
  18  
  19          class Hello(View):
  20              init_every_request = False
  21  
  22              def dispatch_request(self, name):
  23                  return f"Hello, {name}!"
  24  
  25          app.add_url_rule(
  26              "/hello/<name>", view_func=Hello.as_view("hello")
  27          )
  28  
  29      Set :attr:`methods` on the class to change what methods the view
  30      accepts.
  31  
  32      Set :attr:`decorators` on the class to apply a list of decorators to
  33      the generated view function. Decorators applied to the class itself
  34      will not be applied to the generated view function!
  35  
  36      Set :attr:`init_every_request` to ``False`` for efficiency, unless
  37      you need to store request-global data on ``self``.
  38      Nz$t.ClassVar[t.Collection[str] | None]�methodszt.ClassVar[bool | None]�provide_automatic_optionsz(t.ClassVar[list[t.Callable[..., t.Any]]]�
  39  decoratorsTzt.ClassVar[bool]�init_every_request�return�ft.ResponseReturnValuecCst��)z�The actual view function behavior. Subclasses must override
  40          this and return a valid response. Any variables from the URL
  41          rule are passed as keyword arguments.
  42          )�NotImplementedError��self�r�AC:\Users\shubh\Videos\agent\nova\Lib\site-packages\flask/views.py�dispatch_requestNszView.dispatch_request�name�str�
  43  class_args�t.Any�class_kwargs�ft.RouteCallablecs�|jr
  44  d	���fdd��n|�i����d	�fdd��|jr/|�_|j�_|jD]}|���q(|�_|�_|j�_|j�_|j�_|j�_�S)
  45  afConvert the class into a view function that can be registered
  46          for a route.
  47  
  48          By default, the generated view will create a new instance of the
  49          view class for every request and call its
  50          :meth:`dispatch_request` method. If the view class sets
  51          :attr:`init_every_request` to ``False``, the same instance will
  52          be used for every request.
  53  
  54          Except for ``name``, all other arguments passed to this method
  55          are forwarded to the view class ``__init__`` method.
  56  
  57          .. versionchanged:: 2.2
  58              Added the ``init_every_request`` class attribute.
  59          �kwargsr!rrcs&�j�i���}t�|j�di|��S�Nr)�
  60  view_classr�ensure_syncr)r$r)r r"�viewrrr(js��zView.as_view.<locals>.viewcst��j�di|��Sr%)rr'r)r$rrrr(ssN�r$r!rr)rr�__name__�
  61  __module__r&�__doc__rr)�clsrr r"�	decoratorr)r r"rr(r�as_viewUs 
  62  
  63  zView.as_view)rr)rrr r!r"r!rr#)r*r+�__qualname__r,r�__annotations__rrrr�classmethodr/rrrrrs
  64  "
  65  rcs,eZdZdZd�fdd�Zdd	d
  66  �Z�ZS)
  67  �
  68  MethodViewa�Dispatches request methods to the corresponding instance methods.
  69      For example, if you implement a ``get`` method, it will be used to
  70      handle ``GET`` requests.
  71  
  72      This can be useful for defining a REST API.
  73  
  74      :attr:`methods` is automatically set based on the methods defined on
  75      the class.
  76  
  77      See :doc:`views` for a detailed guide.
  78  
  79      .. code-block:: python
  80  
  81          class CounterAPI(MethodView):
  82              def get(self):
  83                  return str(session.get("counter", 0))
  84  
  85              def post(self):
  86                  session["counter"] = session.get("counter", 0) + 1
  87                  return redirect(url_for("counter"))
  88  
  89          app.add_url_rule(
  90              "/counter", view_func=CounterAPI.as_view("counter")
  91          )
  92      r$r!r�Nonecs~t�jdi|��d|jvr;t�}|jD]}t|dd�r"|�|j�qtD]}t	||�r3|�
  93  |���q%|r=||_dSdSdS)Nrr)�super�__init_subclass__�__dict__�set�	__bases__�getattr�updater�http_method_funcs�hasattr�add�upper)r-r$r�base�key��	__class__rrr6�s
  94  
  95  �
  96  �
  97  �zMethodView.__init_subclass__rcKs\t|tj��d�}|durtjdkrt|dd�}|dus$Jdtj����t�|�di|��S)N�HEADr	zUnimplemented method r)r:r�method�lowerrr')rr$�methrrrr�s
  98  zMethodView.dispatch_request)r$r!rr4r))r*r+r0r,r6r�
  99  __classcell__rrrBrr3�sr3)�
 100  __future__rr�t��ft�globalsrr�TypeVar�Callable�Anyr�	frozensetr<rr3rrrr�<module>s�z