o
    ).hd  ã                   @   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/supernova/superenvnew/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   sb   | j }t|d| ¡ ƒ}t||dƒj}|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_docstringr   r   r   Úget_descriptionH   s   ÿzViewInspector.get_descriptionc                 C   s°   dd„ |  ¡ D ƒ}d}ddi}|D ]!}| j |¡r(| d¡\}}}	|	 ¡ ||< q||  d| 7  < qtj}
||v r@||  ¡ S ||
v rR|
| |v rR||
|   ¡ S |d  ¡ S )Nc                 S   s   g | ]}|‘qS r   r   )Ú.0Úliner   r   r   Ú
<listcomp>[   s    z:ViewInspector._get_description_section.<locals>.<listcomp>Ú ú:Ú
)Ú
splitlinesÚheader_regexÚmatchÚ	partitionÚstripr   ÚSCHEMA_COERCE_METHOD_NAMES)r
   r   ÚheaderÚdescriptionÚlinesÚcurrent_sectionÚsectionsr&   Ú	separatorÚleadÚcoerce_method_namesr   r   r   r   Z   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   Ú
isinstancerA   r   ÚDEFAULT_SCHEMA_CLASSÚ
issubclassr   r   )r
   r   r   ÚresultÚinspector_classÚ	inspector©Ú	__class__r   r   r   r   s   
ÿzDefaultSchema.__get__)r9   r:   r;   r   r   Ú__classcell__r   r   rI   r   rA   p   s    rA   )r   r<   Úweakrefr   Údjango.utils.encodingr   Úrest_framework.settingsr   Úrest_framework.utilsr   r   rA   r   r   r   r   Ú<module>   s    a