a
    8öj¼E  ã                   @   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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#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/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` ddlambZb ddlcmdZd ddlemfZfmgZg ddlhmiZimjZjmkZk ddllmmZmmnZnmoZo ddlpmqZqmrZrmsZsmtZt ddlumvZvmwZwmxZxmyZymzZzm{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‡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 e�rd dl¡m¢Z¢ n*zd dl¡m¢Z¢ W n e£�y0   e¤Z¢Y n0 ej¥de`dd� ee¦ Z§ddddde¨ddddœ	ee#ee# f eee¦e§f  ee© ee!ee! df eeejeej f  ee¢ eed   e©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ededj®edddd*dd+œee#ee# f eee¦e§f  ee© ee!ee! df eeejeej f  e¯e¯ee¢ eed   e©ee e¦eej° eªeeª eeª eªee j¬ edd,œd-d.„Z±ee¦ dd/œd0d1„Z²e³d2k�rÜe²ej´dd… ƒ dS )3é    N)ÚArgumentParser)ÚIterable)Úsuppress)Úimport_module)ÚTYPE_CHECKINGÚAnyÚ	AwaitableÚCallabler   ÚListÚOptionalÚSetÚTypeÚUnionÚcasté   )Ú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   rQ   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   rN   rO   rP   rR   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   rm   rn   ro   rp   rq   rs   rt   ru   rv   rr   rw   rx   ry   rz   r{   r|   r}   r~   r   r€   r�   r‚   rƒ   r„   r…   Úrun_app)Ú
SSLContextÚignoreT)ÚcategoryÚappendé€   )	ÚhostÚportÚpathÚsockÚssl_contextÚprintÚbacklogÚreuse_addressÚ
reuse_port).N)ÚapprŒ   r�   rŽ   r�   r�   r‘   r’   r“   r”   ÚkwargsÚreturnc       	         Ë   sö  t  | ¡r| I d H } tt| ƒ} t| fi |
¤Ž}| ¡ I d H  g }�zž|d urœt|tƒrt| t	|||||||	d�¡ qÎ|D ] }| t	|||||||	d�¡ qxn2|d u r¬|d u s´|d urÎ| t	||||||	d�¡ |d u�r$t|tt
jfƒ�r| t||||d�¡ n"|D ]}| t||||d�¡ �q|d u�rtt|tƒ�sR| t||||d�¡ n"|D ]}| t||||d�¡ �qV|D ]}| ¡ I d H  �qx|�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 )	N)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œ   úJ/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/aiohttp/web.pyÚ	<genexpr>Ÿ  ó    z_run_app.<locals>.<genexpr>z6======== Running on {} ========
(Press CTRL+C to quit)z, i  )ÚasyncioÚiscoroutiner   r   rn   ÚsetupÚ
isinstancer˜   rŠ   ru   Úosr   rv   r   rt   ÚstartÚsortedÚsitesÚformatÚjoinÚsleepÚcleanup)r•   rŒ   r�   rŽ   r�   r�   r‘   r’   r“   r”   r–   Úrunnerr§   ÚhÚpr›   ÚsiteÚnamesrœ   rœ   r�   Ú_run_app1  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¹   g      N@g     ÀR@F)rŒ   r�   rŽ   r�   Úshutdown_timeoutÚkeepalive_timeoutr�   r‘   r’   Úaccess_log_classÚaccess_log_formatÚ
access_logÚhandle_signalsr“   r”   Úhandler_cancellationr³   )r•   rŒ   r�   rŽ   r�   rº   r»   r�   r‘   r’   r¼   r½   r¾   r¿   r“   r”   rÀ   r³   r–   r—   c                K   sê  |du rt  ¡ }| ¡ rT|rT|jdkrT|jtjkr>| tj¡ | 	¡ sT| 
t ¡ ¡ | t| f|||||||||	|
||||||dœ|¤Ž¡}zÄzt  |¡ | |¡ W n ttfy¼   Y n0 W zf| ¡  tt jƒ� | |¡ W d  ƒ n1 sô0    Y  W tt  |¡|ƒ | | ¡ ¡ | ¡  n(tt  |¡|ƒ | | ¡ ¡ | ¡  0 n”zh| ¡  tt jƒ� | |¡ W d  ƒ n1 �sˆ0    Y  W tt  |¡|ƒ | | ¡ ¡ | ¡  n(tt  |¡|ƒ | | ¡ ¡ | ¡  0 0 dS )zRun an app locallyNzaiohttp.access)rŒ   r�   rŽ   r�   rº   r»   r�   r‘   r’   r¼   r½   r¾   r¿   r“   r”   rÀ   )r    Znew_event_loopZ	get_debugr™   ÚlevelÚloggingÚNOTSETÚsetLevelÚDEBUGÚhasHandlersÚ
addHandlerÚStreamHandlerZcreate_taskr±   Zset_event_loopr¸   rq   ÚKeyboardInterruptr·   r   ZCancelledErrorr¹   Z	all_tasksZshutdown_asyncgensÚclose)r•   rŒ   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   s¤  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� |j�rh|jd u �rhd  }
}n|j�prd }
|j}|	|ƒ}t||
||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
--hostnamez0TCP/IP hostname to serve on (default: localhost))rÏ   Údefaultz-Pz--portz.TCP/IP port to serve on (default: %(default)r)i�  )rÏ   ÚtyperÑ   z-Uz--pathz_Unix file system path to serve on. Can be combined with hostname to serve on both Unix and TCP.)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Á   Ú	localhost)rŒ   r�   rŽ   zStopped
)r´   )r   Úadd_argumentÚintÚparse_known_argsrÎ   Ú	partitionÚerrorÚ
startswithr   ÚImportErrorÚgetattrÚAttributeErrorrŽ   ÚhasattrÚsocketrÂ   ÚbasicConfigrÅ   Úhostnamer�   r†   Úexit)rË   Z
arg_parserÚargsZ
extra_argvZmod_strÚ_Zfunc_strÚmoduleÚexÚfuncrŒ   r�   r•   rœ   rœ   r�   Úmain  sh    ÿúüûý


,ÿ
rê   Ú__main__)µr    rÂ   r¤   rá   ÚsysÚwarningsÚargparser   Úcollections.abcr   Ú
contextlibr   Ú	importlibr   Útypingr   r   r   r	   ZTypingIterabler
   r   r   r   r   r   Ú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.   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   Zweb_fileresponserR   Zweb_logrS   Zweb_middlewaresrT   rU   Zweb_protocolrV   rW   rX   Zweb_requestrY   rZ   r[   Zweb_responser\   r]   r^   r_   Zweb_routedefr`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   Z
web_runnerrn   ro   rp   rq   rr   rs   rt   ru   rv   Z
web_serverrw   Zweb_urldispatcherrx   ry   rz   r{   r|   r}   r~   r   r€   r�   r‚   Zweb_wsrƒ   r„   r…   Ú__all__Ússlr‡   rÝ   ÚobjectÚfilterwarningsr˜   ZHostSequencer‘   rØ   Úboolr±   ZAbstractEventLoopr¹   Z
LOG_FORMATÚfloatÚLoggerr†   rê   Ú__name__rË   rœ   rœ   rœ   r�   Ú<module>   sÒ   4ô=@,4 
õ
ó|
þí
ëHC
