a
     ÑOc¡F  ã                   @   sˆ  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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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(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@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZW ddlXmYZY ddlZm[Z[ ddl\m]Z]m^Z^ ddl_m`Z`maZambZb ddlcmdZdmeZemfZf ddlgmhZhmiZimjZjmkZk ddllmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZz ddl{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ˆ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”m•Z•m–Z– dZ—zd dl˜m™Z™ W n eš�yè   eZ™Y n0 ee› Zœddddddde�de[e[jžeddddœeeee f eee›eœf  eeŸ ee› eeejeej f  e e ee™ ed eŸee e›eej¡ e¢ee¢ ee¢ ddœd d!„Z£ed" e j¤dd#œd$d%„Z¥ddddddde�de[e[jžeddddd&œeeee f eee›eœf  eeŸ ee› eeejeej f  e e ee™ ed eŸee e›eej¡ e¢ee¢ ee¢ ee j¤ dd'œd(d)„Z¦ee› dd*œd+d,„Z§e¨d-k�r„e§ej©dd… ƒ dS ).é    N)ÚArgumentParser)ÚIterable)Úimport_module)
ÚAnyÚ	AwaitableÚCallabler   ÚListÚOptionalÚSetÚTypeÚUnionÚcasté   )ÚAbstractAccessLogger)Ú	all_tasks)Úaccess_logger)ÚApplicationÚCleanupError)9ÚHTTPAcceptedÚHTTPBadGatewayÚHTTPBadRequestÚHTTPClientErrorÚHTTPConflictÚHTTPCreatedÚ	HTTPErrorÚHTTPExceptionÚHTTPExpectationFailedÚHTTPFailedDependencyÚHTTPForbiddenÚ	HTTPFoundÚHTTPGatewayTimeoutÚHTTPGoneÚHTTPInsufficientStorageÚHTTPInternalServerErrorÚHTTPLengthRequiredÚHTTPMethodNotAllowedÚHTTPMisdirectedRequestÚ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)Ú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)or   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/   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   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rn   ro   rp   rq   rm   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r€   Úrun_app)Ú
SSLContextg      N@g     ÀR@é€   T©Ú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).N)Úappr…   r†   r‡   rˆ   r‰   rŠ   r‹   rŒ   r�   rŽ   r�   r�   r‘   r’   r“   Úreturnc                Ã   s4  t  | ¡r| I d H } tt| ƒ} t| ||
|||d�}| ¡ I d H  g }�zØ|d ur¬t|ttt	t
fƒr‚| t||||||	||d�¡ qà|D ]"}| t||||||	||d�¡ q†n4|d u r¼|d u sÄ|d urà| t|||||	||d�¡ |d u�r<t|ttt	t
fƒ�r| t|||||	d�¡ n$|D ]}| t|||||	d�¡ �q|d u�r�t|tƒ�sl| t|||||	d�¡ n$|D ]}| t|||||	d�¡ �qp|D ]}| ¡ I d H  �q”|�rØtdd„ |jD ƒƒ}|d d |¡¡ƒ tjd	k�rötjd
k �röd}nd}t  |¡I d H  �qúW | ¡ I d H  n| ¡ I d H  0 d S )N)r‘   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 )N)ÚstrÚname)Ú.0Ús© rš   úB/var/www/html/gsl.tools/lib/python3.9/site-packages/aiohttp/web.pyÚ	<genexpr>¢  ó    z_run_app.<locals>.<genexpr>z6======== Running on {} ========
(Press CTRL+C to quit)z, Úwin32)é   é   r   i  )ÚasyncioÚiscoroutiner   r   ri   ÚsetupÚ
isinstancer–   ÚbytesÚ	bytearrayÚ
memoryviewÚappendrp   rq   r   ro   ÚstartÚsortedÚsitesÚformatÚjoinÚsysÚplatformÚversion_infoÚsleepÚcleanup)r”   r…   r†   r‡   rˆ   r‰   rŠ   r‹   rŒ   r�   rŽ   r�   r�   r‘   r’   r“   Úrunnerr«   ÚhÚpr™   ÚsiteÚnamesÚdelayrš   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•   c                C   s  |du rt  ¡ }| ¡ rT|rT|jdkrT|jtjkr>| tj¡ | 	¡ sT| 
t ¡ ¡ | t| |||||||||	|
|||||d�¡}zdzt  |¡ | |¡ W n ttfy²   Y n0 W t|h|ƒ tt|ƒ|ƒ | | ¡ ¡ | ¡  n2t|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À   rl   ÚKeyboardInterruptrÁ   r   Zshutdown_asyncgensÚclose)r”   r…   r†   r‡   rˆ   r‰   rŠ   r‹   rŒ   r�   rŽ   r�   r�   r‘   r’   r“   r»   Z	main_taskrš   rš   r›   r�   Î  sP    ðÿ

ý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®   Úargparser   Úcollections.abcr   Ú	importlibr   Útypingr   r   r   ZTypingIterabler   r	   r
   r   r   r   Úabcr   Zhelpersr   Úlogr   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+   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   Zweb_fileresponserM   Zweb_logrN   Zweb_middlewaresrO   rP   Zweb_protocolrQ   rR   rS   Zweb_requestrT   rU   rV   Zweb_responserW   rX   rY   rZ   Zweb_routedefr[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   Z
web_runnerri   rj   rk   rl   rm   rn   ro   rp   rq   Z
web_serverrr   Zweb_urldispatcherrs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   Zweb_wsr~   r   r€   Ú__all__Ússlr‚   rÞ   r–   ZHostSequencerŒ   Z
LOG_FORMATrÙ   ÚfloatÚLoggerÚboolr¹   ZAbstractEventLooprÁ   r�   rë   Ú__name__rÌ   rš   rš   rš   r›   Ú<module>   sÖ   0ì;@,4 
ïî 
þîí@=
