a
    nJh?K                     @   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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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l#m$Z$ d	dl%m&Z&m'Z' d	dl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZc d	dldmeZe d	dlfmgZg d	dlhmiZimjZj d	dlkmlZlmmZmmnZn d	dlompZpmqZqmrZr d	dlsmtZtmuZumvZvmwZw d	dlxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZmZmZmZmZmZmZmZ d	dlmZmZmZmZmZmZmZmZmZ d	dlmZ d	dlmZmZmZmZmZmZmZmZmZmZmZ d	dlmZmZmZ dZzd dlmZ W n ey0   eZY n0 ejdecdd ee Zddddd d!ded"egegje"dddd#d$ee&ee& f eeeef  ee ee$ee$ df eeejeej f  eeee eed%  eee eeej eee ee edd&d'd(Zed) e jdd*d+d,Zddddd d!ded"egegje"dddd#dd-ee&ee& f eeeef  ee ee$ee$ df eeejeej f  eeee eed%  eee eeej eee ee eee j dd.d/d0Zee dd1d2d3Zed4kr eejd	d  dS )5    N)ArgumentParser)Iterable)suppress)partial)import_module)
Any	AwaitableCallabler   ListOptionalSetTypeUnioncast)WeakSet   )AbstractAccessLogger)AppKey)access_logger)PathLike)ApplicationCleanupError);HTTPAcceptedHTTPBadGatewayHTTPBadRequestHTTPClientErrorHTTPConflictHTTPCreated	HTTPErrorHTTPExceptionHTTPExpectationFailedHTTPFailedDependencyHTTPForbidden	HTTPFoundHTTPGatewayTimeoutHTTPGoneHTTPInsufficientStorageHTTPInternalServerErrorHTTPLengthRequiredHTTPMethodNotAllowedHTTPMisdirectedRequestHTTPMoveHTTPMovedPermanentlyHTTPMultipleChoices!HTTPNetworkAuthenticationRequiredHTTPNoContentHTTPNonAuthoritativeInformationHTTPNotAcceptableHTTPNotExtendedHTTPNotFoundHTTPNotImplementedHTTPNotModifiedHTTPOkHTTPPartialContentHTTPPaymentRequiredHTTPPermanentRedirectHTTPPreconditionFailedHTTPPreconditionRequiredHTTPProxyAuthenticationRequiredHTTPRedirectionHTTPRequestEntityTooLargeHTTPRequestHeaderFieldsTooLargeHTTPRequestRangeNotSatisfiableHTTPRequestTimeoutHTTPRequestURITooLongHTTPResetContentHTTPSeeOtherHTTPServerErrorHTTPServiceUnavailableHTTPSuccessfulHTTPTemporaryRedirectHTTPTooManyRequestsHTTPUnauthorizedHTTPUnavailableForLegalReasonsHTTPUnprocessableEntityHTTPUnsupportedMediaTypeHTTPUpgradeRequiredHTTPUseProxyHTTPVariantAlsoNegotiatesHTTPVersionNotSupportedNotAppKeyWarning)FileResponse)AccessLogger)
middlewarenormalize_path_middleware)PayloadAccessErrorRequestHandlerRequestPayloadError)BaseRequest	FileFieldRequest)ContentCodingResponseStreamResponsejson_response)AbstractRouteDefRouteDefRouteTableDef	StaticDefdeletegetheadoptionspatchpostputroutestaticview)		AppRunner
BaseRunnerBaseSiteGracefulExitNamedPipeSiteServerRunnerSockSiteTCPSiteUnixSite)Server)AbstractResourceAbstractRouteDynamicResourcePlainResourcePrefixedSubAppResourceResourceResourceRouteStaticResourceUrlDispatcherUrlMappingMatchInfoView)WebSocketReadyWebSocketResponse	WSMsgType)rr   r   r   rR   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rS   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rt   ru   rv   rw   rs   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   run_app)
SSLContextignoreT)categoryappendg      N@g     R@   Fhostportpathsockshutdown_timeoutkeepalive_timeoutssl_contextprintbacklogaccess_log_classaccess_log_format
access_loghandle_signalsreuse_address
reuse_porthandler_cancellation).N)appr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   returnc                   sJ  dt d d fdd}dd ddd t| r:| I d H } tt| } t| ||
|||||d}| I d H  tt }t	||||_
g }z|d urt|ttttfr|t|||||	||d	 n&|D ] }|t|||||	||d	 qn6|d u r|d u s|d ur"|t||||	||d
 |d urxt|ttjfrV|t||||	d n"|D ]}|t||||	d qZ|d urt|ts|t||||	d n"|D ]}|t||||	d q|D ]}| I d H  q|rtdd |jD }|dd| tdI d H  qW | I d H  n| I d H  0 d S )NzWeakSet[asyncio.Task[object]])starting_tasksr   r   c                    sd   t  }|d usJ | | tt j( t j | |dI d H  W d    n1 sV0    Y  d S )N)timeout)asynciocurrent_taskaddr   TimeoutErrorwait_for)r   r   t_wait =/var/www/shaz/venv/lib/python3.9/site-packages/aiohttp/web.pywaitC  s
    
z_run_app.<locals>.wait)excluder   c                    sF   t  }|d usJ | | t  |  }rBt |I d H  qd S N)r   r   r   	all_tasks
differencer   )r   r   tasksr   r   r   r   M  s
    
z_run_app.<locals>._wait)r   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   r   )r   r   c                 s   s   | ]}t |jV  qd S r   )strname).0sr   r   r   	<genexpr>      z_run_app.<locals>.<genexpr>z6======== Running on {} ========
(Press CTRL+C to quit)z, i  )floatr   iscoroutiner   r   ro   setupr   r   r   Zshutdown_callback
isinstancer   bytes	bytearray
memoryviewr   rv   osr   rw   r   ru   startsortedsitesformatjoinsleepcleanup)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   runnerr   r   hpr   sitenamesr   r   r   _run_app/  s    




		
	r   zasyncio.Task[Any])	to_cancelloopr   c                 C   sj   | sd S | D ]}|   q|tj| ddi | D ]0}| rBq4| d ur4|d| |d q4d S )NZreturn_exceptionsTz1unhandled exception during asyncio.run() shutdown)message	exceptiontask)cancelrun_until_completer   ZgatherZ	cancelledr   Zcall_exception_handler)r   r   r   r   r   r   _cancel_tasks  s    
r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   c                C   s$  |du rt  }| rT|rT|jdkrT|jtjkr>|tj |	 sT|
t  |t| |||||||||	|
||||||d}zfzt | || W n ttfy   Y n0 W t|h| tt || ||  |  n4t|h| tt || ||  |  0 dS )zRun an app locallyNzaiohttp.accessr   )r   Znew_event_loopZ	get_debugr   levelloggingNOTSETsetLevelDEBUGhasHandlers
addHandlerStreamHandlerZcreate_taskr   Zset_event_loopr   rr   KeyboardInterruptr   r   Zshutdown_asyncgensclose)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Z	main_taskr   r   r   r     sR    

r   )argvr   c              
   C   sx  t ddd}|jdddd |jdd	d
dd |jdddtdd |jdddd || \}}|jd\}}}|rz|s|d |dr|d zt|}W n: t	y } z"|d| d|  W Y d }~n
d }~0 0 zt
||}	W n* ty   |d|d| Y n0 |jd ur<ttds<|d tjtjd  |	|}
t|
|j|j|jd! |jd"d# d S )$Nzaiohttp.web Application serverzaiohttp.web)descriptionprog
entry_funczvCallable returning the `aiohttp.web.Application` instance to run. Should be specified in the 'module:function' syntax.z
entry-func)helpmetavarz-Hz
--hostnamez2TCP/IP hostname to serve on (default: %(default)r)	localhost)r   defaultz-Pz--portz.TCP/IP port to serve on (default: %(default)r)Z8080)r   typer   z-Uz--pathzjUnix file system path to serve on. Specifying a path will cause hostname and port arguments to be ignored.)r   :z,'entry-func' not in 'module:function' syntax.z#relative module names not supportedzunable to import z: zmodule z has no attribute AF_UNIXz=file system paths not supported by your operating environment)r   )r   r   r   zStopped
)r   )r   add_argumentintparse_known_argsr   	partitionerror
startswithr   ImportErrorgetattrAttributeErrorr   hasattrsocketr   basicConfigr   r   hostnamer   exit)r   Z
arg_parserargsZ
extra_argvZmod_str_Zfunc_strmoduleexfuncr   r   r   r   main*  s`    


,r   __main__)r   r   r   r   syswarningsargparser   collections.abcr   
contextlibr   	functoolsr   	importlibr   typingr   r   r	   ZTypingIterabler
   r   r   r   r   r   weakrefr   abcr   Zhelpersr   logr   Ztypedefsr   Zweb_appr   r   Zweb_exceptionsr   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   Zweb_fileresponserS   Zweb_logrT   Zweb_middlewaresrU   rV   Zweb_protocolrW   rX   rY   Zweb_requestrZ   r[   r\   Zweb_responser]   r^   r_   r`   Zweb_routedefra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   Z
web_runnerro   rp   rq   rr   rs   rt   ru   rv   rw   Z
web_serverrx   Zweb_urldispatcherry   rz   r{   r|   r}   r~   r   r   r   r   r   Zweb_wsr   r   r   __all__sslr   r   filterwarningsr   ZHostSequencer   Z
LOG_FORMATr   r   Loggerboolr   ZAbstractEventLoopr   r   r   __name__r   r   r   r   r   <module>   s   0=@,4 

 #

B=
