o
    NK&h                     @  s   d dl mZ d dl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 d dlmZ d dlmZmZmZmZmZmZ d d	lmZ d d
lmZmZ erRd dlmZ dZG dd dZG dd dZdS )    )annotationsN)suppress)import_module)
isfunction)Path)
SSLContext)TYPE_CHECKINGAnyCallableOptionalUnioncast)process_to_context)MkcertCreatorTrustmeCreatorSanicappc                   @  s0   e Zd ZdZ					ddddZdddZdS )	AppLoadera\  A helper to load application instances.

    Generally used by the worker to load the application instance.

    See [Dynamic Applications](/en/guide/deployment/app-loader) for information on when you may need to use this.

    Args:
        module_input (str): The module to load the application from.
        as_factory (bool): Whether the application is a factory.
        as_simple (bool): Whether the application is a simple server.
        args (Any): Arguments to pass to the application factory.
        factory (Callable[[], SanicApp]): A callable that returns a Sanic application instance.
     FNmodule_inputstr
as_factorybool	as_simpleargsr	   factory Optional[Callable[[], SanicApp]]returnNonec           	      C  s   || _ d| _d| _|| _|| _|| _|| _t | _	|rQd|v r"dnd}||v rSd|vrUd|vrW|
|d\}}|| _|| _| jdrYd| _| jd d	 | _d S d S d S d S d S d S )
Nr   :.\/   z()T)r   module_nameapp_namer   r   r   r   osgetcwdcwdrsplitendswith)	selfr   r   r   r   r   	delimiterr&   r'    r/   F/var/www/html/venv/lib/python3.10/site-packages/sanic/worker/loader.py__init__&   s0   
zAppLoader.__init__SanicAppc                 C  s  t j| j}|tjvrtj| | jr|  S ddlm} ddl	m
} t| j}| js;| rAd| jv s;d| jv rA||}|S d}| jsR| jsR| j| _t| _d}t| j}t|| jd }|sk|rktd| j d	| jsrt|rz|| j}W n ty   | }Y nw t|j}t||s| jrt| jd
rtt t| j}	t|	dd }W d    n1 sw   Y  |sd| d| jj d}
t|
|S )Nr   r   )create_simple_serverr"   r#   FTz`Looks like you only supplied a module name. Sanic tried to locate an application instance named z:app, but was unable to locate an application instance. Please provide a path to a global instance of Sanic(), or a callable that will return a Sanic() application instance.targetr   z#Module is not a Sanic app, it is a z
  Perhaps you meant z:app?) r(   pathabspathr*   sysappendr   	sanic.appr   sanic.simpler3   r   r   r   is_dirr&   r'   DEFAULT_APP_NAMEr   getattr
ValueErrorr   r   r   	TypeErrortype__name__
isinstancehasattrr   ModuleNotFoundErrorr4   )r-   module_pathr   r3   
maybe_pathr   implied_app_namemoduleapp_type_namemaybe_modulemessager/   r/   r0   loadE   sj   

)





zAppLoader.load)r   FFNN)r   r   r   r   r   r   r   r	   r   r   r   r   )r   r2   )rA   
__module____qualname____doc__r1   rL   r/   r/   r/   r0   r      s    r   c                   @  s*   e Zd ZeedZdddZddd	Zd
S )
CertLoader)mkcerttrustmessl_data?Optional[Union[SSLContext, dict[str, Union[str, os.PathLike]]]]c                 C  s   || _ d | _|rt|tsd S tt|d}| j|| _|s"d S | js,td| |d | _	|d | _
tt|d | _d S )NcreatorzUnknown certificate creator: keycert	localhost)	_ssl_data_creator_classrB   dictr   r   get	_creatorsRuntimeError_key_cert
_localhost)r-   rS   creator_namer/   r/   r0   r1      s   

zCertLoader.__init__r   r2   c                 C  s.   | j st| jS |  || j| j}|| jS )N)rZ   r   rY   r_   r`   generate_certra   )r-   r   rU   r/   r/   r0   rL      s   
zCertLoader.loadN)rS   rT   )r   r2   )rA   rM   rN   r   r   r]   r1   rL   r/   r/   r/   r0   rP      s    
rP   ) 
__future__r   r(   r7   
contextlibr   	importlibr   inspectr   pathlibr   sslr   typingr   r	   r
   r   r   r   sanic.http.tls.contextr   sanic.http.tls.creatorsr   r   sanicr   r2   r<   r   rP   r/   r/   r/   r0   <module>   s      j