o
    >h                     @   s^   d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 G dd dZ
G d	d
 d
e
ZdS )zb
inspectors.py   # Per-endpoint view introspection

See schemas.__init__.py for package overview.
    N)WeakKeyDictionary)	smart_str)api_settings)
formattingc                   @   sj   e Zd ZdZedZdd Zdd Zdd Z	e
d	d
 Zejdd
 Zejdd
 Zdd Zdd ZdS )ViewInspectorz[
    Descriptor class on APIView.

    Provide subclass for per-view schema generation
    z^[a-zA-Z][0-9A-Za-z_]*:c                 C   s   t  | _d S N)r   instance_schemasself r   /var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/rest_framework/schemas/inspectors.py__init__   s   zViewInspector.__init__c                 C   s   || j v r
| j | S || _| S )a%  
        Enables `ViewInspector` as a Python _Descriptor_.

        This is how `view.schema` knows about `view`.

        `__get__` is called when the descriptor is accessed on the owner.
        (That will be when view.schema is called in our case.)

        `owner` is always the owner class. (An APIView, or subclass for us.)
        `instance` is the view instance or `None` if accessed from the class,
        rather than an instance.

        See: https://docs.python.org/3/howto/descriptor.html for info on
        descriptor usage.
        r   view)r
   instanceownerr   r   r   __get__   s   

zViewInspector.__get__c                 C   s    || j |< |d ur||_d S d S r   r   )r
   r   otherr   r   r   __set__2   s   

zViewInspector.__set__c                 C   s   | j dus	J d| j S )zView property.NzvSchema generation REQUIRES a view instance. (Hint: you accessed `schema` from the view class rather than an instance.)_viewr	   r   r   r   r   7   s   zViewInspector.viewc                 C   s
   || _ d S r   r   )r
   valuer   r   r   r   @      
c                 C   s
   d | _ d S r   r   r	   r   r   r   r   D   r   c                 C   sj   | j }t|d| }t||d}|j}|r&|r&| || tt|S | |t|d| | S )z
        Determine a path description.

        This will be based on the method docstring if one exists,
        or else the class docstring.
        actionN)	r   getattrlower__doc___get_description_sectionr   dedentr   get_view_description)r
   pathmethodr   method_namemethod_funcmethod_docstringr   r   r   get_descriptionH   s   zViewInspector.get_descriptionc                 C   s   |  }d}ddi}|D ]!}| j|r#|d\}}}	|	 ||< q||  d| 7  < qtj}
||v r;||  S ||
v rM|
| |v rM||
|   S |d  S )N :
)
splitlinesheader_regexmatch	partitionstripr   SCHEMA_COERCE_METHOD_NAMES)r
   r   headerdescriptionlinescurrent_sectionsectionsline	separatorleadcoerce_method_namesr   r   r   r   [   s   z&ViewInspector._get_description_sectionN)__name__
__module____qualname__r   recompiler*   r   r   r   propertyr   setterdeleterr%   r   r   r   r   r   r      s    



r   c                       s    e Zd ZdZ fddZ  ZS )DefaultSchemaz?Allows overriding AutoSchema using DEFAULT_SCHEMA_CLASS settingc                    sD   t  ||}t|ts|S tj}t|tsJ d| }||_|S )NzTDEFAULT_SCHEMA_CLASS must be set to a ViewInspector (usually an AutoSchema) subclass)	superr   
isinstancer@   r   DEFAULT_SCHEMA_CLASS
issubclassr   r   )r
   r   r   resultinspector_class	inspector	__class__r   r   r   s   s   
zDefaultSchema.__get__)r8   r9   r:   r   r   __classcell__r   r   rH   r   r@   q   s    r@   )r   r;   weakrefr   django.utils.encodingr   rest_framework.settingsr   rest_framework.utilsr   r   r@   r   r   r   r   <module>   s    b