o
    1 i                  	   @   s   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	 d dl
mZmZmZmZ d dlmZmZmZ eeZG dd de jZdd Z		dd
edededejjfddZdS )    N)Any)PathLikeRouteDefaiohttphdrs)CustomEncoderHTTPStatusCodeto_google_stylec                	   @   s   e Zd ZdZG dd dZeeejdd Z	eeejdd Z
eejdd	 Zeejd
d Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zededed ed!d"fd#d$Zd"S )%BaseRouteTablea  A base class to bind http route to a target instance. Subclass should implement
    the _register_route method. It should define how the handler interacts with
    _BindInfo.instance.

    Subclasses must declare their own _bind_map and _routes properties to avoid
    conflicts.
    c                   @   s   e Zd Zdd ZdS )zBaseRouteTable._BindInfoc                 C   s   || _ || _|| _d S N)filenamelinenoinstance)selfr   r   r    r   `/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/ray/dashboard/routes.py__init__   s   
z!BaseRouteTable._BindInfo.__init__N)__name__
__module____qualname__r   r   r   r   r   	_BindInfo   s    r   c                 C      d S r   r   clsr   r   r   	_bind_map       zBaseRouteTable._bind_mapc                 C   r   r   r   r   r   r   r   _routes&   r   zBaseRouteTable._routesc                 K   r   r   r   )r   methodpathkwargsr   r   r   _register_route,      zBaseRouteTable._register_routec                 C   r   r   r   )r   r   r   r   r   bind1   r!   zBaseRouteTable.bindc                 C   s   | j S r   )r   r   r   r   r   routes6   s   zBaseRouteTable.routesc                 C   sn   g }| j jD ]&}t|tr'|jj}|jj}| j| | j}|d ur&|	| q|	| qt
j }||_|S r   )r   Z_items
isinstancer   handler__route_method____route_path__r   r   appendr   webRouteTableDef)r   Zbound_itemsrZroute_methodZ
route_pathr   r#   r   r   r   bound_routes:   s   


zBaseRouteTable.bound_routesc                 K      | j tj|fi |S r   )r    r   Z	METH_HEADr   r   r   r   r   r   headJ      zBaseRouteTable.headc                 K   r-   r   )r    r   ZMETH_GETr.   r   r   r   getN   r0   zBaseRouteTable.getc                 K   r-   r   )r    r   Z	METH_POSTr.   r   r   r   postR   r0   zBaseRouteTable.postc                 K   r-   r   )r    r   ZMETH_PUTr.   r   r   r   putV   r0   zBaseRouteTable.putc                 K   r-   r   )r    r   Z
METH_PATCHr.   r   r   r   patchZ   r0   zBaseRouteTable.patchc                 K   r-   r   )r    r   ZMETH_DELETEr.   r   r   r   delete^   r0   zBaseRouteTable.deletec                 K   r-   r   )r    r   ZMETH_ANYr.   r   r   r   viewb   r0   zBaseRouteTable.viewprefixr   r   returnNc                 K   s   | j j||fi | d S r   )r   static)r   r7   r   r   r   r   r   r9   f   s   zBaseRouteTable.static)r   r   r   __doc__r   classmethodpropertyabcabstractmethodr   r   r    r"   r#   r,   r/   r1   r2   r3   r4   r5   r6   strr   r   r9   r   r   r   r   r
      sJ    








 r
   c                  C   s   G dd dt } | S )zU
    Return a method-based route table class, for in-process HeadModule objects.
    c                   @   s<   e Zd ZdZeeZej	
 Zedd Zedd ZdS )z4method_route_table_factory.<locals>.MethodRouteTablezA helper class to bind http route to class method. Each _BindInfo.instance
        is a class instance, and for an inbound request, we invoke the async handler
        method.c                    s    fdd}|S )Nc                    s   j  v rj    td d j d j jjjjd  t	dt
jjf fdd} j  < |_|_jjfi |S )NzDuplicated route path: z, previous one registered at :r8   c                     sR   z| d } j |I d H W S  ty(   td ttjt d Y S w )NzHandle %s %s failed.)status_codemessage)	r   	Exceptionlogger	exceptionrest_responser   INTERNAL_ERROR	traceback
format_exc)argsreq)	bind_infor%   r   r   r   r   _handler_route   s   
znmethod_route_table_factory.<locals>.MethodRouteTable._register_route.<locals>._wrapper.<locals>._handler_route)r   rD   r   r   r   __code__co_filenameco_firstlineno	functoolswrapsr   r)   Responser&   r'   r   Zroute)r%   rN   r   r   r   r   )rM   r%   r   _wrapperz   s$   zVmethod_route_table_factory.<locals>.MethodRouteTable._register_route.<locals>._wrapperr   )r   r   r   r   rV   r   rU   r   r    x   s   "zDmethod_route_table_factory.<locals>.MethodRouteTable._register_routec                 S   s>   dd }t ||}|D ]\}}|| j|jj |jj _qd S )Nc                 S   s"   t | rt| dot| dS dS )Nr&   r'   F)inspectismethodhasattr)or   r   r   	predicate   s
   
zLmethod_route_table_factory.<locals>.MethodRouteTable.bind.<locals>.predicate)rW   
getmembersr   __func__r&   r'   r   )r   r   r[   Zhandler_routes_hr   r   r   r"      s   z9method_route_table_factory.<locals>.MethodRouteTable.bindN)r   r   r   r:   collectionsdefaultdictdictr   r   r)   r*   r   r;   r    r"   r   r   r   r   MethodRouteTablep   s    


%rc   )r
   )rc   r   r   r   method_route_table_factoryk   s   =rd   TrB   rC   convert_google_styler8   c                 K   s\   t jddkrddi}ni }| tjk}tjj|||rt|n|dt	j
tjtd|| dS )a.  
    Args:
        status_code: HTTPStatusCode
            The HTTP status code of the response.
        message: str
            The message of the response.
        convert_google_style: bool
            Whether to convert the response to google style.

    Returns:
        aiohttp.web.Response
    ZRAY_DASHBOARD_DEV1zAccess-Control-Allow-Origin*)resultmsgdatar   )dumpsheadersstatus)osenvironr1   r   OKr   r)   Zjson_responser	   rR   partialjsonrk   r   )rB   rC   re   r   rl   successr   r   r   rG      s   

rG   )T)r=   r`   rR   rW   rr   loggingrn   rI   typingr   Zray.dashboard.optional_depsr   r   r   r   Zray.dashboard.utilsr   r   r	   	getLoggerr   rE   ABCr
   rd   r?   boolr)   rT   rG   r   r   r   r   <module>   s0    
ZH