o
    m=8jG                  )   @   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	m
Z
mZmZ d dlmZ d dlmZ d dlmZmZmZ ddlmZ dd	lmZmZ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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z] ddl^m_Z_ ddl`maZa ddlbmcZcmdZd ddlemfZfmgZgmhZh ddlimjZjmkZkmlZl ddlmmnZnmoZompZpmqZqmrZr ddlsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZmZmZ ddlmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZ dZerd dlmZ nzd dlmZ W n ey   eZY nw ejde]dd ee Zdddddedddd	d e e	e  B d!eeB dB d"edB d#eee B dB d$ejeej B dB d%edB d&e
d' dB d(ed)edB d*edB d+ed,dfd-d.Zd/ed0 d1e jd,dfd2d3Zddddd4d5dedeaeajedddd6dd7d e e	e  B d!eeB dB d"edB d#eee B dB d$ejeej B dB d8ed9ed%edB d&e
d' dB d(ed:ee d;ed<ejdB d=ed)edB d*edB d>ed1e jdB d+ed,df(d?d@ZdAee d,dfdBdCZedDkreejdd  dS dS )E    N)ArgumentParser)	AwaitableCallableIterabler   )suppress)import_module)TYPE_CHECKINGAnycast   )AbstractAccessLogger)AppKey
RequestKeyResponseKey)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_bytes_response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)ur   r   r   rN   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   rQ   rR   rS   rT   rU   rV   rW   rX   r   rY   rZ   r[   r\   r]   r   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rq   rr   rs   rt   rp   ru   rv   rw   rx   ry   rz   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appr   r   r   r   r   r   ).Nr   r   r   kwargsreturnc       	            s  t | r| I d H } tt| } t| fi |
}| I d H  g }z|d urNt|tr:|t	|||||||	d n-|D ]}|t	|||||||	d q<n|d u rV|d u sZ|d urg|t	||||||	d |d urt|tt
jfr|t||||d n|D ]}|t||||d q|d urt|ts|t||||d n|D ]}|t||||d q|D ]	}| I d H  q|rtdd |jD }|dd| 	 t d	I d H  q| I d H  w )
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   R/home/nk/hobo-godmode/plappi-mvp/.venv/lib/python3.10/site-packages/aiohttp/web.py	<genexpr>  s    z_run_app.<locals>.<genexpr>z6======== Running on {} ========
(Press CTRL+C to quit)z, Ti  )asyncioiscoroutiner
   r   rl   setup
isinstancer   r   rs   osr   rt   r   rr   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_app)  s   



		
	r   	to_cancelzasyncio.Task[Any]loopc                 C   sj   | sd S | D ]}|   q|tj| ddi | D ]}| r!q| d ur2|d| |d qd S )Nreturn_exceptionsTz1unhandled exception during asyncio.run() shutdown)message	exceptiontask)cancelrun_until_completer   gather	cancelledr   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   c                K   s  |du rt  }| r*|r*|jdkr*|jtjkr|tj |	 s*|
t  |t| fi d|d|d|d|d|d|d	|d
|d|	d|
d|d|d|d|d|d||}zzt | || W n ttfy}   Y nw W zd| s|  tt j || W d   n41 sw   Y  W tt || ||  |  dS W tt || ||  |  dS W tt || ||  |  dS tt || ||  |  w zc| s2|  tt j || W d   n31 sw   Y  W tt || ||  |  w W tt || ||  |  w W tt || ||  |  w tt || ||  |  w )zRun an app locallyNzaiohttp.accessr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   new_event_loop	get_debugr   levelloggingNOTSETsetLevelDEBUGhasHandlers
addHandlerStreamHandlercreate_taskr   set_event_loopr   ro   KeyboardInterruptdoner   r   CancelledErrorr   	all_tasksshutdown_asyncgensclose)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	main_taskr   r   r   r     s   	

	

	 



r   argvc              
   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\}}}|r=|sB|d |drL|d zt|}W n t	yo } z|d| d|  W Y d }~nd }~ww zt
||}	W n ty   |d|d| Y nw |jd urttds|d tjtjd |jr|jd u rd  }
}n|jpd }
|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   
arg_parserargs
extra_argvmod_str_func_strmoduleexfuncr   r   r   r   r   r   main  sn   


"

r   __main__)r   r   r   r   syswarningsargparser   collections.abcr   r   r   TypingIterable
contextlibr   	importlibr   typingr   r	   r
   abcr   helpersr   r   r   logr   typedefsr   web_appr   r   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   rM   rN   web_fileresponserO   web_logrP   web_middlewaresrQ   rR   web_protocolrS   rT   rU   web_requestrV   rW   rX   web_responserY   rZ   r[   r\   r]   web_routedefr^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   
web_runnerrl   rm   rn   ro   rp   rq   rr   rs   rt   
web_serverru   web_urldispatcherrv   rw   rx   ry   rz   r{   r|   r}   r~   r   r   web_wsr   r   r   __all__sslr   r   objectfilterwarningsr   HostSequencer   r   boolr   setAbstractEventLoopr   
LOG_FORMATfloatr   Loggerr   listr   __name__r   r   r   r   r   <module>   s   =@,4 


	

{


	


Q
C