+
    ]f}  c                   s   R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
Ht R F  w  tt ]! ]4      ]! 4       ]&   K  	  ]P$                  R8X  d   ^ RIt	^ RIHtHt ^ RIHt  ! R R	]P2                  4      t ! R
 R]]4      t ! R R4      tR#   ] d    R]! 4       ]&   ]! R]: R]: 24        K  i ; i)ap  
Python WebSocket server base with support for "wss://" encryption.
Copyright 2011 Joel Martin
Copyright 2016 Pierre Ossman
Licensed under LGPL version 3 (see docs/LICENSE.LGPL-3)

You can make a cert/key with openssl using:
openssl req -new -x509 -days 365 -nodes -out self.pem -keyout self.pem
as taken from http://docs.python.org/dev/library/ssl.html#certificates

N)SimpleHTTPRequestHandlerzWARNING: no 'z
' module, Zwin32)WebSocketWantReadErrorWebSocketWantWriteError)WebSocketRequestHandlerMixInc                   s&   a  ] tR t^#t o R tRtV tR# )CompatibleWebSocketc                s    R V9   d   R # R# )Zbinary  )selfZ	protocols   &&@/usr/lib/python3.14/site-packages/websockify/websockifyserver.pyselect_subprotocolZ&CompatibleWebSocket.select_subprotocol$   s    y     r   N)__name__
__module____qualname____firstlineno__r
   __static_attributes____classdictcell____classdict__   @r	   r   r   #   s      r   r   c                   sX  a a ] tR t^,t oRtRtRt]t ! R R]	4      t
V 3R ltR tRR ltR	 tR
 tR tR R ltR tR!R ltRP)                  R4      3R ltRP)                  R4      3R ltV 3R ltR tV 3R ltV 3R ltR tR tR tV 3R ltV 3R ltV 3R lt R"V 3R llt!Rt"Vt#V ;t$# )#WebSockifyRequestHandlerav  
WebSocket Request Handler Class, derived from SimpleHTTPRequestHandler.
Must be sub-classed with new_websocket_client method definition.
The request handler can be configured by setting optional
attributes on the server object:

* only_upgrade: If true, SimpleHTTPRequestHandler will not be enabled,
  only websocket is allowed.
* verbose: If true, verbose logging is activated.
* daemon: Running as daemon, do not write to console etc
* record: Record raw frame data as JavaScript array into specified filename
* run_once: Handle a single request
* handler_id: A sequence number for this connection, appended to record filename
Z
WebSockifyzHTTP/1.1c                   s    ] tR t^BtRtR# )WebSockifyRequestHandler.CCloser   Nr   r   r   r   r   r   r   r	   CCloser   B       r   r   c                s  < \        VR R4      V n        \        VRR4      V n        \        VRR4      V n        \        VRR4      V n        \        VRR4      V n        RV n        \        VRR4      V n        \        VRR4      V n        \        VR	R4      V n	        \        VR
R4      V n
        \        VRR4      V n        \        VRR4      V n        V P                  f   \        P                  4       V n        \        SV `A  WV4       R# )only_upgradeFverbosedaemonrecordrun_onceN
handler_id	file_onlytrafficweb_auth
host_tokenlogger)getattrr   r   r   r   r   recr   r    r!   r"   r#   r$   WebSockifyServer
get_loggersuper__init__)r   ZreqZaddrserver	__class__s   &&&&r	   r*   Z!WebSockifyRequestHandler.__init__E   s    #FNEBvy%8fh6fh6
E:!&,> e<vy%8
E:!&,>fh5;;*557DKF+r   c                s    V P                   P                  V P                  ^ ,          : RV P                  4       : RW,          : 24       R# )    z - - [z] N)r$   Zinfoclient_addressZlog_date_time_string)r   formatargss   &&*r	   log_messageZ$WebSockifyRequestHandler.log_messageY   s6    T-@-@-C-CTE^E^E`bhbopqr   c                s    V P                   '       d@   \        P                  P                  V4       \        P                  P	                  4        R# R# )zShow traffic flow mode. N)r!   sysstdoutwriteZflush)r   Ztokenr   r	   print_trafficZ&WebSockifyRequestHandler.print_traffic`   s2    <<<JJU#JJ r   c                    RV P                   ,          pV P                  P                  ! \        P                  V: V: 2.VO5/ VB  R# )z'Output message with handler_id prefix. % 3d: N)r   r$   logloggingINFOr   msgr0   kwargsZprefix   &&*, r	   r<   ZWebSockifyRequestHandler.msgf   5    DOO+&<NtNvNr   c                r6   )Same as msg() but as debug. r7   N)r   r$   r8   r9   DEBUGr;   r>   r	   vmsgZWebSockifyRequestHandler.vmsgk   s5    DOO+'=OOOr   c                r6   )Same as msg() but as warning. r7   N)r   r$   r8   r9   WARNr;   r>   r	   warnZWebSockifyRequestHandler.warnp   r?   r   c                s   \        \        P                  ! 4       R,          4      V P                  ,
          pV'       d   V F  pV P                  '       dj   VP	                  R4      P                  R4      P	                  R4      P                  RR4      pV P                  P                  RP                  W$4      4       V P                  P                  V4       K  	  V P                  '       d\    V P                  P                  V P                  ^ ,          4       T P                  P                  ^ 4       T P                  R
4       Km  R#   \         d    T P                  R4        R	# i ; i)a  Encode and send WebSocket frames. Any frames already
queued will be sent first. If buf is not set then only queued
frames will be sent. Returns True if any frames could not be
fully sent, in which case the caller should call again when
the socket is ready.   latin1unicode_escapeascii'\'z'{{{0}{{{1}',
z<.TZ<F)inttime
start_timer&   decodeencodereplacer4   r/   
send_partsappendrequestZsendmsgr   r5   Zpop)r   bufstdeltabufbufstrs   &&   r	   send_framesZ$WebSockifyRequestHandler.send_framesx   s    TYY[%&8888 ZZ1889IJQQRYZbbcfhmnFHHNN#4#;#;F#KL&&s+  ooo$$T__Q%78 OO"s# + ""4(s   1,E E-,E-c                s   Rp. p\        \        P                  ! 4       R,          4      V P                  ,
          p  V P                  P	                  4       pTf2   RT P                  P                  RT P                  P                  /pY!3# T P                  R4       T P                  '       dj   TP                  R4      P                  R4      P                  R	4      P                  R
R4      pT P                  P                  RP                  Y54      4       TP                  T4       T P                  P!                  4       '       d   EK   Y!3#   \
         d    T P                  R4        Y!3# i ; i)zNReceive and decode WebSocket frames.

Returns:
    (bufs_list, closed_string)
FrF   z}.codereasonZ}rG   rH   rI   rJ   rK   z'}}{0}}}{1}',
)rL   rM   rN   rT   Zrecvmsgr   r5   Z
close_codeZclose_reasonr&   rO   rP   rQ   r4   r/   rS   Zpending)r   ZclosedrU   rV   rW   rX      &     r	   recv_framesZ$WebSockifyRequestHandler.recv_frames   s7    TYY[%&8ll**,
 { $,,"9"9"DLL$=$=?|#s#xxxH-445EFMMgV^^_bdij077GHKK<<''))|+ * ""4(& |+s   E E10E1r   c                sZ    V P                   P                  \        P                  W4       R# )z&Send a WebSocket orderly close frame. N)rT   ZshutdownsocketZ	SHUT_RDWR)r   rZ   r[      &&&r	   
send_closeZ#WebSockifyRequestHandler.send_close   s    f..=r   rI   c                <    V P                   P                  V4       R# )zSend a WebSocket pong frame. N)rT   Zpongr   Zdatar   r	   	send_pongZ"WebSockifyRequestHandler.send_pong       $r   c                ra   )zSend a WebSocket ping frame. N)rT   Zpingrb   r   r	   	send_pingZ"WebSockifyRequestHandler.send_ping   rd   r   c                sd   < V P                  4        V P                  4        \        SV `  4        R # N)validate_connectionauth_connectionr)   handle_upgrader   r,      &r	   ri   Z'WebSockifyRequestHandler.handle_upgrade   s&      " r   c                s   R V P                   n        . V n        RV n        \	        \
        P
                  ! 4       R,          4      V n        RpRp V P                  ^ ,          pV P                  ^,          pV'       d	   RV n	        MRV n	        V P                  RVV P                  4       V P                  R8w  d   V P                  R	WP                  4       V P                  '       d\   V P                  : R
V P                  : 2pV P                  RV4       \        VR4      V n        V P                  P!                  R4        V P#                  4        R#   \         d     Li ; i  T P$                   dQ    \&        P(                  ! 4       w  rEpT P+                  TP,                  ^ ,          TP,                  ^,          4        R# i ; i)TNrF   r   FzSSL/TLS (wss://)zPlain non-SSL (ws://)z%s: %s WebSocket connection/z%s: Path: '%s'.zopening record file: %szw+zvar VNC_frame_data = [
)r+   ws_connectionrR   	recv_partrL   rM   rN   r.   Z
IndexErrorstyper1   pathr   r   openr&   r4   new_websocket_clientr   r2   exc_infor`   r0   )r   Zclient_addrZis_sslZfname_excr\   r	   handle_websocketZ)WebSockifyRequestHandler.handle_websocket   sf   $(!diik$./ 	--a0K((+F +DJ0DJ6	%99-{IIF;;;#{{#0E6>E4(DHHHNN56	6%%'-  		. {{ 	6IAAOOCHHQK!5	6s%   &E E' E$#E$'AGGc                   < V P                   '       d   V P                  4        V P                  '       d   V P                  R 4       R# \        SV `  4        R# i  N)r"   rh   r   
send_errorr)   do_GETrj   rk   r	   r{   ZWebSockifyRequestHandler.do_GET   s:    ===  "OOC GNr   c                sl   < V P                   '       d   V P                  R 4       R# \        SV `  V4      # )i  N)r    rz   r)   list_directory)r   rq   r,   s   &&r	   r|   Z'WebSockifyRequestHandler.list_directory  s(    >>>OOC 7)$//r   c                s    \        R4      h)2Do something with a WebSockets client connection. zAWebSocketRequestHandler.new_websocket_client() must be overloaded)	Exceptionr      &r	   rs   Z-WebSockifyRequestHandler.new_websocket_client  s    [\\r   c                    R# )zBEnsure that the connection has a valid token, and set the target. Nr   r   r   r	   rg   Z,WebSockifyRequestHandler.validate_connection      r   c                r   )z*Ensure that the connection is authorized. Nr   r   r   r	   rh   Z(WebSockifyRequestHandler.auth_connection  r   r   c                rx   ry   )r"   rh   r   rz   r)   do_HEADrj   rk   r	   r   Z WebSockifyRequestHandler.do_HEAD  s:    ===  "OOC GOr   c                s   < V P                   '       d6   V P                   P                  R 4       V P                   P                  4        \        SV `  4        R# )z'EOF'];
N)r&   r4   closer)   finishrj   rk   r	   r   ZWebSockifyRequestHandler.finish  s4    888HHNN;'HHNNr   c                sl   < V P                   '       d   V P                  4        R # \        SV `  4        R # rf   )r   Zhandle_one_requestr)   handlerj   rk   r	   r   ZWebSockifyRequestHandler.handle"  s$     ===##%GNr   c                sN   < V P                   '       d   \        SV `	  W4       R # R # rf   )r   r)   log_request)r   rZ   Zsizer,   s   &&&r	   r   Z$WebSockifyRequestHandler.log_request+  s    <<<G+ r   )r   r    r   r#   r$   r   r&   r   ro   r   rR   rN   rp   r!   r   r"   rm   rf   )rF   r   )-r   )%r   r   r   r   __doc__Zserver_versionZprotocol_versionr   SocketClassr~   r   r*   r1   r5   r<   rB   rE   rY   r]   r`   rP   rc   re   ri   rw   r{   r|   rs   rg   rh   r   r   r   r   r   r   Z__classcell__)r,   r   s   @@r	   r   r   ,   s      "N!%K ,(rO
P
O:#J>  YYw/    YYw/  !(6T0], ,r   r   c                   s   a  ] tR tRt o RtRtRt ! R R]4      t ! R R]4      t	RR
 lt
]R 4       t]RR l4       t]RR l4       tR tR tR tR tR tR tR tR tR tR tR tR tR tR tRtV tR	# ) r'   i0  z[
WebSockets server class.
As an alternative, the standard library SocketServer can be used
zY<cross-domain-policy><allow-access-from domain="*" to-ports="*" /></cross-domain-policy>
Z	websocketc                       ] tR tRtRtR# )WebSockifyServer.EClosei:  r   Nr   r   r   r	   ECloser   :  r   r   r   c                   r   )WebSockifyServer.Terminatei=  r   Nr   r   r   r	   	Terminater   =  r   r   r   Nc                sv   Wn         W`n        W n        VV n        VV n        W0n        W@n        WPn        Wn        VV n	        VV n
        Wn        Wn        VV n        VV n        VV n        VV n        VV n        VV n        \&        P&                  ! 4       V n        R V n        ^V n        R V n        V P1                  4       V n        VV n        VV n        VV n        VV n        RV n        Wn        \@        PB                  PE                  V4      V n#        R;V n$        ;V n%        V n&        V'       d%   \@        PB                  PE                  V4      V n        V'       d%   \@        PB                  PE                  V4      V n$        V'       d%   \@        PB                  PE                  V4      V n%        V'       d%   \@        PB                  PE                  V4      V n&        V PH                  '       d!   \@        PN                  ! V PH                  4       V PH                  '       * V n(        \R        '       g   V P                  '       d   \U        R4      hV P                  '       d   \V        '       g   \U        R4      hV PY                  R4       V P                  R8w  d   V PY                  R4       MUV P                  R8w  d   V PY                  RV P                  4       M'V PY                  RV P
                  V P                  4       V PH                  '       dL   V P"                  '       d   V PY                  R	V PH                  4       MV PY                  R
V PH                  4       \R        '       dw   \@        PB                  P[                  V PF                  4      '       d6   V PY                  R4       V P                  '       d   V PY                  R4       M#V PY                  R4       MV PY                  R4       V P                  '       d   V PY                  R4       V PJ                  '       d   V PY                  RV PJ                  4       R# R# )FNr   z&No 'ssl' module and SSL-only specifiedz'Module 'resource' required to daemonizezWebSocket server settings:z   - Listen for inetd connectionsz  - Listen on unix socket %sz  - Listen on %s:%sz4  - Web server (no directory listings). Web root: %sz  - Web server. Web root: %sz  - SSL/TLS supportz   - Deny non-SSL/TLS connectionsz%  - No SSL/TLS support (no cert file)z(  - No SSL/TLS support (no 'ssl' module)z  - Backgrounding (daemon)z  - Recording to '%s.*').RequestHandlerClassr   	listen_fdunix_listenunix_listen_modelisten_hostlisten_portprefer_ipv6ssl_onlyssl_ciphersssl_optionsverify_clientr   r   timeoutidle_timeoutr!   r    r"   rM   launch_timern   r   terminatingr(   r$   tcp_keepalivetcp_keepcnttcp_keepidletcp_keepintvlkeykey_passwordosrq   Zabspathcertwebr   cafilechdirr   sslr~   resourcer<   exists)r   r   r   r   r   Zsource_is_ipv6r   r   r   r   r   r   r   r   r   r   r"   r    r   r   r   r!   r   r   r   r   r   r   r   r   s   &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&r	   r*   ZWebSockifyServer.__init__@  s    $7 #*#,#.#3#.#.#1#+#.#.#0#)#+#*#/#*#,#+#'99;#(#$#(#'??#4#0#.#/#0 ( GGOOD)	/1114;wws+DHwws+DH''//&1DK''//&1DK888HHTXX $L st}}}DEE;;;xxEFF 	-.>>T!HH78%HH3T5E5EFHH*$$d&6&68888~~~OQUQYQYZ7B3ww~~dii((./===HH?@@AHH?@;;;HH12;;;HH.< r   c                 s    \         P                  ! \        P                  : R \        P                  P
                  : 24      # r   )r9   Z	getLoggerr'   
log_prefixr,   r   r   r   r	   r(   ZWebSockifyServer.get_logger  s2      ''&&//"1 2 	2r   c                s   ^ pV R8X  d   Rp V'       d   V'       g   V'       g   \        R4      hV'       d   \        '       g   \        R4      hV'       g   V'       d   \        R4      hV'       g   V\        P                  ,          pV'       Eg3   \        P                  ! W^ \        P
                  \        P                  V4      pV'       g   \        RV ,          4      hVP                  R R7       V'       d   VP                  4        \        P                  ! V^ ,          ^ ,          V^ ,          ^,          4      pV'       d   VP                  \        P                  \        P                  ^4       V	'       d0   VP                  \        P                  \        P                  V	4       V
'       d0   VP                  \        P                  \        P                  V
4       V'       d0   VP                  \        P                  \        P                  V4       V'       d?   VP!                  V^ ,          ^,          4       V'       d   \        P#                  V4      pV# VP                  \        P                  \        P$                  ^4       VP'                  V^ ,          ^,          4       VP)                  ^d4        V# V'       d    \*        P,                  ! V4       \        P                  ! \        P0                  \        P
                  4      p\*        P2                  ! R	V,          4      p VP'                  V4       \*        P2                  ! V4       VP)                  ^d4       V# \        P                  ! \        P0                  \        P
                  4      pVP!                  V4       V#   \.         d     Li ; i  \*        P2                  ! T4       i ; i)
zResolve a host (and optional port) to an IPv4 or IPv6
address. Create a socket. Bind to it if listen is set,
otherwise connect to it. Return the socket.
r   NzConnect mode requires a portz6SSL socket requested but Python SSL module not loaded.z,SSL only supported in connect mode (for now)zCould not resolve host '%s'c                 s    V ^ ,          # )r-   r   )xr   r	   Z<lambda>Z)WebSockifyServer.socket.<locals>.<lambda>  s    QqTr   )r   i  )r~   r   r^   Z
AI_PASSIVEZgetaddrinfoSOCK_STREAMZIPPROTO_TCPZsortZreverseZ
setsockoptZ
SOL_SOCKETZSO_KEEPALIVEZSOL_TCPZTCP_KEEPCNTZTCP_KEEPIDLEZTCP_KEEPINTVLconnectwrap_socketZSO_REUSEADDRZbindZlistenr   ZunlinkZFileNotFoundErrorZAF_UNIXumask)hostZportr   r   unix_socketunix_socket_modeunix_socket_listenZuse_sslr   r   r   r   ZflagsZaddrssockZoldmasks   &&&&&&&&&&&&    r	   r^   ZWebSockifyServer.socket  s    2:DDK:;;33TUU7JKKF---E{&&t1f6H6H&&/E = DEEJJ>J*==q!eAhqk:D 1 163F3FJOOFNNF4F4F$/1OOFNNF4G4G$02 OOFNNF4H4H$13 U1Xa[)??40D. +  1 163F3FJ		%(1+&C & # "IIk* }}V^^V5G5GH((5+;#;<&IIk*HHW%C 
  }}V^^V5G5GH[) )  HHW%s   N3 3O 3O OOc                s   V f   . p \         P                  ! ^ 4       V'       d   \         P                  ! V4       M\         P                  ! R4       \         P                  ! \         P                  ! 4       4       \         P
                  ! \         P                  ! 4       4       \         P                  ! 4       ^ 8  d   \         P                  ! ^ 4       \         P                  ! 4        \         P                  ! 4       ^ 8  d   \         P                  ! ^ 4       \        P                  ! \        P                  \        P                  4       \        P                  ! \        P                  \        P                  4       \        P                  \        P                   4      ^,          pV\        P"                  8X  d   Rp\%        \'        V4      4       F"  p W09  d   \         P(                  ! V4       K"  K$  	  \         P4                  ! \         P6                  ! \         P8                  \         P:                  4      \,        P<                  P?                  4       4       \         P4                  ! \         P6                  ! \         P8                  \         P:                  4      \,        P@                  P?                  4       4       \         P4                  ! \         P6                  ! \         P8                  \         P:                  4      \,        PB                  P?                  4       4       R #   \*         d>    \,        P.                  ! 4       w  rEpTP0                  \0        P2                  8w  d   h  EK  i ; i)Nrl   i   )"r   r   r   ZsetgidZgetgidZsetuidZgetuidZforkZ_exitZsetsidsignalSIGTERMZSIG_IGNSIGINTr   Z	getrlimitZRLIMIT_NOFILEZRLIM_INFINITYZreversedZranger   OSErrorr2   rt   errnoZEBADFZdup2rr   ZdevnullZO_RDWRZstdinfilenor3   Zstderr)keepfdr   ZmaxfdZfdru   rv   s   &&    r	   	daemonizeZWebSockifyServer.daemonize  s    >F
HHUOHHSM
		"))+
		"))+ 779q="((1+
		779q="((1+ 	fnnfnn5fmmV^^4 ""8#9#9:1=H***CE5<(B3#HHRL $ ) 	

BII.		0@0@0BC


BII.

0A0A0CD


BII.

0A0A0CD  3LLN	99+U+3s   L((AM0/M0c                s   \         P                   ! V.. . ^4      ^ ,          pV'       g   V P                  R4      hVP                  R\        P                  4      pV'       g   V P                  R4      hV^ ,          R9   Ed   \
        '       g   V P                  R4      h\        P                  P                  V P                  4      '       g#   V P                  RV P                  ,          4      hRp \
        P                  \
        P                  P                  4      pV P                  e   VP                  V P                  4       V P                  Vn        VP#                  V P                  V P$                  V P&                  R7       V P(                  '       dU   \
        P*                  Vn        V P.                  '       d   VP1                  V P.                  R7       MVP3                  4        VP5                  VRR	7      pM%V PB                  '       d   V P                  R4      hTp\A        V4      ^8X  d   V^ ,          V^,          WQ8g  3pV PE                  WRV 4       V#   \
        P6                   d    \8        P:                  ! 4       w  rxpTP<                  ^ ,          \
        P>                  8X  dN   \A        TP<                  4      ^8  d#   T P                  TP<                  ^,          4      hT P                  R
4      hh i ; i)a  
do_handshake does the following:
- Peek at the first few bytes from the socket.
- If the connection is an HTTPS/SSL/TLS connection then SSL
  wrap the socket.
- Read from the (possibly wrapped) socket.
- If we have received a HTTP GET request and the webserver
  functionality is enabled, answer it, close the socket and
  return.
- Assume we have a WebSockets connection, parse the client
  handshake data.
- Send a WebSockets handshake server response.
- Return the socket for this WebSocket client.
r   i   z"SSL connection but no 'ssl' modulez!SSL connection but '%s' not foundN)ZcertfileZkeyfileZpassword)r   T)Zserver_sidezGot SSL_ERROR_EOFz*non-SSL connection received but disallowed)i   i   )#selectr   Zrecvr^   ZMSG_PEEKr   r   rq   r   r   Zcreate_default_contextZPurposeZCLIENT_AUTHr   Zset_ciphersr   ZoptionsZload_cert_chainr   r   r   ZCERT_REQUIREDZverify_moder   Zload_verify_locationsZset_default_verify_pathsr   ZSSLErrorr2   rt   r0   ZSSL_ERROR_EOFlenr   r   )	r   r   addressreadyZ	handshakeZretsockZcontextru   r   s	   &&&      r	   do_handshakeZWebSockifyServer.do_handshake  sU    tfb"a03++b/! IIdFOO4	 ++b/!q\Y&3kk"FGG77>>$)),,kk"E$(II#. / /G44S[[5L5LM##/''(8(89"&"2"2''DHHW[WhWh'i%%%*-*;*;G'{{{55T[[5I88:!--$( . * ]]]++JKK G
 w<1qz71:AG  48 3 << ,,.a66!9 1 11166{Q"kk!&&)44"kk*=>>s   4B*I% &I% A I% %B"Lc                b    V P                   P                  ! \        P                  .VO5/ VB  R# )zOutput message as info N)r$   r8   r9   r:   r   r0   r=      &*,r	   r<   ZWebSockifyServer.msgk       6t6v6r   c                r   )r@   N)r$   r8   r9   rA   r   r   r	   rB   ZWebSockifyServer.vmsgo  s     777r   c                r   )rC   N)r$   r8   r9   rD   r   r   r	   rE   ZWebSockifyServer.warns  r   r   c                s(    V P                  R4       R# )z Called after WebSockets startup zWebSockets server startedN)rB   r   r   r	   startedZWebSockifyServer.started{  s    		-.r   c                r   )z0Run periodically while waiting for connections. Nr   r   r   r	   pollZWebSockifyServer.poll  s     	r   c                sX    V P                   '       g   R V n         V P                  4       hR# )TN)r   r   r   r   r	   	terminateZWebSockifyServer.terminate  s(    #D..""  r   c                s0    \         P                  ! 4        R # rf   )multiprocessingactive_childrenr   sigstackr_   r	   multiprocessing_SIGCHLDZ(WebSockifyServer.multiprocessing_SIGCHLD  s     	'')r   c                s     \         P                  ! R\         P                  4      pV^ ,          '       dG   V P                  RV^ ,          ,          4       \         P                  ! R\         P                  4      pKU  R#   \         d     R# i ; i)i   zReaped child process %sNi)r   ZwaitpidZWNOHANGrB   r   )r   r   r   Zresults   &&& r	   fallback_SIGCHLDZ!WebSockifyServer.fallback_SIGCHLD  sg    	ZZBJJ/F))		3fQi?@B

3   		s   3A> AA> >BBc                &    V P                  4        R # rf   r   r   r_   r	   	do_SIGINTZWebSockifyServer.do_SIGINT       	r   c                r   rf   r   r   r_   r	   
do_SIGTERMZWebSockifyServer.do_SIGTERM  r   r   c                s   Rp  V P                  W4      pT'       d   Y18w  d   TP                  4        R# R# R#   T P                   de    \        P                  ! 4       w  rEpTP                  ^ ,          '       d1   T P                  T^ ,          : RTP                  ^ ,          : 24        L\        P                   d    h \         dQ    \        P                  ! 4       w  rEpT P                  R\        T4      ,          4       T P                  RRR7        ELi ; i  T'       d   Y18w  d   TP                  4        i i i ; i)r}   Nz: handler exception: %s	exceptionTrt   )r   r   r2   rt   r0   r<   r'   r   r~   strrB   r   )r   	startsockr   Zclientru   rv   s   &&&   r	   top_new_clientZWebSockifyServer.top_new_client  s     	6**9> &-  .v ;; CLLN	88A;;HHSXXa[AB#--  6LLN	03s8;<		+	56 &-  .vs;   : A2D,D  .D
DADD  DD   "Ec                s    . pV P                   P                  P                   FN  p\        V\        P
                  4      '       g   K%  VP                  VP                  P                  4       4       KP  	  V# )z]
Get file descriptors for the loggers.
They should not be closed when the process is forked.
)	r$   ZparentZhandlersZ
isinstancer9   ZFileHandlerrS   Zstreamr   )r   ZdescriptorsZhandlers   &  r	   
get_log_fdZWebSockifyServer.get_log_fd  sY    
 {{))22G'7#6#677""7>>#8#8#:; 3 r   c                s   V P                   R8w  d@   \        P                  ! V P                   \        P                  \        P                  4      pMV P
                  R8w  d+   V P                  RV P
                  V P                  RR7      pM_V P                  V P                  V P                  RV P                  V P                  V P                  V P                  V P                  R7      pV P                  '       dL   V P                  4       pVP!                  VP#                  4       4       V P%                  W P&                  R7       V P)                  4        \*        P,                  \*        P.                  ! \*        P,                  4      \*        P0                  \*        P.                  ! \*        P0                  4      /p\3        \*        RR4      e6   \*        P.                  ! \*        P4                  4      V\*        P4                  &   \*        P*                  ! \*        P,                  V P6                  4       \*        P*                  ! \*        P0                  V P8                  4       \3        \*        RR4      e0   \*        P*                  ! \*        P4                  V P:                  4       V P<                  p    Rp^ ;rg^ p\?        \@        PB                  ! 4       4      p\D        PD                  ! 4       V P<                  ,
          p	V PF                  '       dO   WPF                  8  d?   V PI                  RV PF                  ,          4        V'       Ed7   VPK                  4        EM$V PL                  '       d   ^ p
V^ 8X  d   \D        PD                  ! 4       V,
          p
M^ p
\D        PD                  ! 4       pWPL                  8  dF   V^ 8X  d?   V PI                  R	V PL                  ,          4        V'       Ed   VPK                  4        EM V PO                  4        \P        PP                  ! V.. . ^4      ^ ,          pW9   d2   VPS                  4       w  r\V P
                  R8w  d   V P
                  .pM V'       g   EK  VPK                  4        EK  V Pf                  '       d^   V Pi                  W\4       V Pj                  '       d:   V PI                  RV^ ,          ,          4        V'       d   VPK                  4        MMRV Pe                  RV^ ,          ,          4       \@        Pl                  ! V Ph                  W\3R7      pVPo                  4        V ;Pp                  ^,          un8        X'       d   TPK                  4        EK  EK  V Pe                  RV P                  V P                  4       VPK                  4        VP}                  4        F  w  pp\*        P*                  ! VV4       K  	  R#   T PT                   d    h \V         d    \X        PZ                  ! 4       w  rp\]        TR
4      '       d   TP^                  pM/\]        TR4      '       d   TP`                  ^ ,          pM	T^ ,          pT\^        Pb                  8X  d1   T Pe                  R4        T'       g   EK  TPK                  4        EK  h i ; i  T PT                  \r        \t        3 d    T PI                  R4       T Pf                  '       gQ   \@        PB                  ! 4       pT F5  pT PI                  RTPv                  ,          4       TPy                  4        K7  	   X'       g   EK  TPK                  4        EK  \V         dO    \X        PZ                  ! 4       ^,          pT PI                  R\{        T4      4       T Pe                  RRR7        ELYi ; i  X'       d   TPK                  4        i i ; i  T Pe                  RT P                  T P                  4       TPK                  4        TP}                  4        F  w  pp\*        P*                  ! TT4       K  	  i ; i)z
Daemonize if requested. Listen for for connections. Run
do_handshake() method for each connection. If the connection
is a WebSockets client then call new_websocket_client() method (which must
be overridden) for each new client connection.
NT)r   r   r   r   F)r   r   r   r   )r   r   SIGCHLDz!listener exit due to --timeout %sz&listener exit due to --idle-timeout %sr   r0   zIgnoring interrupted syscallz%s: exiting due to --run-oncez%s: new handler Process)Ztargetr0   zIn exitzTerminating child %sr   r   r   z!Closing socket listening at %s:%s)?r   r^   ZfromfdZAF_INETr   r   r   r   r   r   r   r   r   r   r   r   rS   r   r   r   r   r   r   Z	getsignalr   r%   r   r   r   r   r   r   r   r   rM   r   r<   r   r   r   r   Zacceptr   r~   r2   rt   Zhasattrr   r0   ZEINTRrB   r   r   rn   ZProcessZstartr   Z
SystemExitZKeyboardInterruptpidr   r   Zitems)r   Zlsockr   Zoriginal_signalsZlast_active_timer   r   ZerrZchild_countZtime_elapsedZ	idle_timer   r   ru   rv   ZpZchildrenZchildr   Zfuncs   &                   r	   start_serverZWebSockifyServer.start_server  s&    >>T!MM$..&..&BTBTUE%KKT,0,<,<151F1F37   9E
 KK 0 0$2B2BE $ 0 0.2.@.@,0,<,<-1->->.2.@.@   BE ;;;__&FMM%,,.)NN&N9 MM6++FMM:NNF,,V^^<
 69d+7/5/?/?/OV^^,fmmT^^4fnndoo6 69d+7MM&..$*F*FG++f	)[*V>$(	$%&' '*/*I*I*K&L'+yy{T5E5E'E<<<L<<,G HH%H&*ll&3 4!Z !y!)Y  ,,,()I*a/,0IIK:J,J	,-	3799; 0(+<+<<PQAQ $)Q.2.?.?*@ !A %@ !y!)& IIK$*MM5'2r1$Ea$HE$~5:\\^ 2	#'#3#3t#;040@0@.BG (h !y!)I  === //	C#111 $)H*1!**5 !6 %: !!)C  2
 !II&?'!*&LM / 7 7+/+>+>*3)=!?A GGI 1,& !!) ! II9&&(8(8:KKM .335	Tc4( 6y  $~~ "!( &(+IAA&sG44&)ii!(f!5!5&)hhqk&)!f"ekk1 $		*H I (N !y!)M !&&@ !NNJ8IJ 
+#}}}'6'F'F'HH)1 $)?%)))K L % 1 *2  !y!) % >!llnQ/!8#c(C		+	=> !!) ! II9&&(8(8:KKM .335	Tc4( 6s   3_" 6BZ; _" _" !Z; 3A6Z; *_" 2_" A'W/ -Z; /_" :_" Z; AZ; "_" )_" ;A,Z; '_" /Z8
BZ8Z; _" #_" 6Z88Z; ;>_:A_
_ _" _" )_2A_=_  __ __" "A*a)#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"   rn   )Nr   NFFr   r   NNFNFr   r   FFFr-   r-   FTNNNNr-   NN)NFFNNFFTNNN)Nrl   )r   r   r   r   r   Zpolicy_responser   r~   r   r   r*   Zstaticmethodr(   r^   r   r   r<   rB   rE   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   r'   r'   0  s     
 wOJ I _=J 2 2
 D DL $E $ELLd787/
#
*



2
S) S)r   r'   ))r   zTLS/SSL/wss is disabled)r   zdaemonizing is disabled)r   r   r2   rM   r   r   r^   r   r9   r   Zhttp.serverr    Zmodr<   Z
__import__ZglobalsZImportErrorZprintZplatformZmultiprocessing.reductionZwebsockify.websocketr   r   Zwebsockify.websocketserverr   r   r   r   r'   r   r   r	   <module>r      s   
 = < < <  0:HC:#C	#: <<7$ P C6BB A,;=U A,Hl) l)q  :	#sC89:s   B!B?>B?