o
    㥵i                     @  s   d dl mZ d dlmZ d dlmZmZmZmZ d dlm	Z
 ddlmZ ddlmZ dd	lmZ dddZG dd deZG dd dedZdS )    )annotations)
isfunction)TYPE_CHECKINGAnyCallableList)cast   )SyncViewType   )request)HttpResponsemethodstrreturn&Callable[[SyncViewType], SyncViewType]c                   s:   dkrddhnh dd  id fdd	}|S )z;
    Set the acceptable request method of the function
    GETHEADAllow, functionr
   r   c                   s:   t  std fdd}t|d  tt|S )Nz,`required_method` can only decorate functionc                    s8   t j v r| i |S t jdkrtdS tddS )NOPTIONSheaders  status_coder   )r   r   r   )argskwargs)allow_methodsr   r    B/home/ubuntu/.local/lib/python3.10/site-packages/kui/wsgi/views.pywrapper   s
   


z3required_method.<locals>.decorator.<locals>.wrapper
__method__)r   	TypeErrorsetattruppertyping_castr
   )r   r"   r   r   r   )r   r!   	decorator   s
   
z"required_method.<locals>.decoratorN)r   r
   r   r
   )join)r   r)   r    r(   r!   required_method   s   r+   c                      s   e Zd Zd fddZ  ZS )HttpViewMetar   r   kwdsr   c                   s   t  j|i |}| S N)super__call____impl__)selfr   r-   instance	__class__r    r!   r0   &   s   zHttpViewMeta.__call__)r   r   r-   r   r   r   )__name__
__module____qualname__r0   __classcell__r    r    r4   r!   r,   %   s    r,   c                   @  sN   e Zd ZU g dZerded< dddZdd	d
ZdddZe	dddZ
dS )HttpView)getpostputpatchdeleteheadoptionstracez	List[str]__methods__r   Nonec                   s    fdd j D  _d S )Nc                   s   g | ]}t  |r| qS r    )hasattrr&   ).0mclsr    r!   
<listcomp>;   s    z.HttpView.__init_subclass__.<locals>.<listcomp>)HTTP_METHOD_NAMESrC   rH   r    rH   r!   __init_subclass__:   s   zHttpView.__init_subclass__r   c                 C  s   t | tj | j}| S r.   )getattrr   r   lowerhttp_method_not_allowed)r2   handlerr    r    r!   r1   =   s   zHttpView.__impl__r   c                 C  s   t ddd| jidS )Nr   r   r   r   r   r*   rC   )r2   r    r    r!   rO   A   s   z HttpView.http_method_not_allowedc                 C  s   t dd| jidS )z8Handle responding to requests for the OPTIONS HTTP verb.r   r   r   rQ   rH   r    r    r!   rA   F   s   zHttpView.optionsN)r   rD   )r   r   )r   r   )r6   r7   r8   rK   r   __annotations__rL   r1   rO   classmethodrA   r    r    r    r!   r:   +   s   
 


r:   )	metaclassN)r   r   r   r   )
__future__r   inspectr   typingr   r   r   r   r   r'   routingr
   requestsr   	responsesr   r+   typer,   r:   r    r    r    r!   <module>   s    
