
    h+              
          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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Z ej.                           ej0                  d      Zej5                  dddd       ej5                  ddddd       ej5                  dddde j6                  j9                  dd             ej5                  dddd       ej5                  ddd d       ej5                  d!d"ded#d $       ej=                  d%d&'      ZejA                  d(d)*      Z!e!j5                  d+e"d,-       e!j5                  d.d/d01       e!j5                  d2d3d4d56       ejA                  d7d8*      Z#e#j5                  d+e"d9-       e#j5                  d:d/d01       e#j5                  d2d3d4d56       ejA                  d;d<*      Z$e$j5                  d+e"d,-       e$j5                  d=ed d>?       e$j5                  d@e"d/dAB       ejA                  dCdD*      Z%e%j5                  d+e"d,-       e%j5                  d=ed d>?       e%j5                  dEe"dFdFdGgdHI       dJ Z&edK        Z'edL        Z(edM        Z)edN        Z*dO Z+edP        Z,e-dQk(  r e+        yy# e$ r&  ed        ed        ej                  d       Y w xY w)R    N)copy)	Componentz.The 'wamp' command-line tool requires Twisted.z  pip install autobahn[twisted]   )DeferredinlineCallbacks)react)ProcessProtocol)ApplicationError)PublishOptions)SubscribeOptionswamp)progz--urlstorezLA WAMP URL to connect to, like ws://127.0.0.1:8080/ws or rs://localhost:1234T)actionhelprequiredz--realmz-rzThe realm to joindefault)r   r   r   z--private-keyz-kzCHex-encoded private key (via WAMP_PRIVATE_KEY if not provided here)WAMP_PRIVATE_KEYz--authidz$The authid to use, if authenticatingz
--authrolez"The role to use, if authenticatingz--max-failuresz-mz%Failures before giving up (0 forever))r   typer   r   subcommandssubcommand_name)titledestcallz&Do a WAMP call() and print any results)r   urizA WAMP URI to call)r   r   	call_args*z,All additional arguments are positional args)nargsr   z	--keyword   appendz.Specify a keyword argument to send: name value)r   r   r   publishz/Do a WAMP publish() with the given args, kwargszA WAMP URI to publishpublish_argsregisterz2Do a WAMP register() and run a command when calledz--timesz=Listen for this number of events, then exit. Default: forever)r   r   r   commandzTakes one or more args: the executable to call, and any positional arguments. As well, the following environment variables are set: WAMP_ARGS, WAMP_KWARGS and _JSON variants.)r   r   r   	subscribez:Do a WAMP subscribe() and print one line of JSON per eventz--matchexactprefixz4Massed in the SubscribeOptions, how to match the URI)r   r   choicesr   c                    | j                   j                  d      rd}n)| j                   j                  d      rd}nt        d      t               }| j                  r>| j
                  st        d      | j
                  | j                  | j                  d|d<   t        || j                   d	g|r|nd
| j                        S )zX
    Configure and return a Component instance according to the given
    `options`
    zws://	websocketzrs://	rawsocketz$URL should start with ws:// or rs://zRRequire --authid and --authrole if --private-key (or WAMP_PRIVATE_KEY) is provided)authidauthroleprivkey
cryptosign)r   urlN)
transportsauthenticationrealm)	r0   
startswith
ValueErrordictprivate_keyr,   r-   r   r3   )optionskindr2   s      M/var/www/Befach/backend/env/lib/python3.12/site-packages/autobahn/__main__.py_create_componentr;      s    
 {{g&				(2
 	
 VN~~d  nn((**(
|$ ;;
  *8~Tmm     c              #   $  K   t        |j                        }t               }|j                  |j                  D ci c]  \  }}||
 }}} |j                  |j
                  g|i |}t        dj                  |             y c c}}w w)Nz
result: {})listr   r6   keywordr   r   printformat)reactorsessionr8   r   call_kwargskvresultss           r:   do_callrH      s     W&&'I&K"  
1 qD
 

 !GLLHyHKHHG	,

g
&'
s   ;BB

ABc              #      K   t        |j                        }|j                  i n|j                  D ci c]  \  }}||
 c}}} |j                  |j                  g|dt        d      i| y c c}}w w)Nr8   T)acknowledge)r>   r"   r?   r!   r   r   )rB   rC   r8   r"   rE   rF   publish_kwargss          r:   
do_publishrL      s     ,,-L"??2ROO9Aq 	
19N
 '//	 40 	 9s   3A;A59A;c              #       K   t               j                  gt         fd       }|j                  |j                          yw)z-
    run a command-line upon an RPC call
    c               ?   
  K   t        dj                  | |      t        j                         t	        t
        j                        }dj                  |       |d<   t        j                  |       |d<   dj                  d |j                         D              |d<   t        j                  |      |d<   t
        j                  j                  
j                  d	         }
j                  } t                G fd
dt              } |       }j!                  ||| |d       }|d	k7  rt        dj                  |             	d	   r4	d	xx   dz  cc<   	d	   d	k  rj#                  d	j$                  d        y y y w)Nzcalled: args={}, kwargs={}file 	WAMP_ARGSWAMP_ARGS_JSONc              3   F   K   | ]  \  }}d j                  ||        yw)z{}={}N)rA   ).0rE   rF   s      r:   	<genexpr>z.do_register.<locals>.called.<locals>.<genexpr>  s     %Rtq!gnnQ&:%Rs   !WAMP_KWARGSWAMP_KWARGS_JSONr   c                   $    e Zd Zd Zd Z fdZy)/do_register.<locals>.called.<locals>.DumpOutputc                 `    t         j                  j                  |j                  d             y Nutf8)sysstdoutwritedecodeselfdatas     r:   outReceivedz;do_register.<locals>.called.<locals>.DumpOutput.outReceived%      

  V!45r<   c                 `    t         j                  j                  |j                  d             y r\   )r^   stderrr`   ra   rb   s     r:   errReceivedz;do_register.<locals>.called.<locals>.DumpOutput.errReceived(  rf   r<   c                 P    j                  |j                  j                         y )N)callbackvalueexitCode)rc   reasondones     r:   processExitedz=do_register.<locals>.called.<locals>.DumpOutput.processExited+  s    fll334r<   N)__name__
__module____qualname__re   ri   rp   )ro   s   r:   
DumpOutputrZ   $  s    665r<   rt   .)envpathzFailed with exit-code {}r   )r@   rA   r^   rh   r   osenvironjoinjsondumpsitemsrw   abspathr$   r   r	   spawnProcess	callLaterrk   )argskwrv   exert   protocodero   all_done	countdownr8   rB   s          @r:   calledzdo_register.<locals>.called  sN    *11$;#**M2::88D>K $

4 0 XX%Rrxxz%RRM"&**R.ggoogooa01z	5 	5 3#C 	 	
 z19,33D9:Q<aLAL|q !!!X%6%6= ! s   E?FN)r   timesr   r#   r   )rB   rC   r8   r   r   r   s   ` ` @@r:   do_registerr     sL      zHI!> !>F 

67;;
//
Ns   AAc              #       K   t               |j                  gt         fd       }|j                  ||j                  t        |j                                yw)z3
    print events (one line of JSON per event)
    c                      t        t        j                  | |d             d   r4dxx   dz  cc<   d   dk  rj                  dj                  d        y y y )N)r   kwargsr   r   )r@   r{   r|   r   rk   )r   r   r   r   rB   s     r:   	publishedzdo_subscribe.<locals>.publishedH  sg    JJ 	
 Q<aLAL|q !!!X%6%6= ! r<   )match)r8   N)r   r   r   r%   r   r   r   )rB   rC   r8   r   r   r   s   `   @@r:   do_subscriber   ?  s]      zHI
> 
> 

Iw{{<LSZS`S`<a

bb
Ns   A!A&c                  "    t        t               y)zi
    This is a magic name for `python -m autobahn`, and specified as
    our entry_point in setup.py
    N)r   
_real_main r<   r:   _mainr   Y  s    
 
*r<   c              #   H   K   t         j                         t              }j                   t	        d       t        j                  d       j                  dk(  rˉj                  d   }t        j                  j                  |      s?t	        dj                  |      t
        j                         t        j                  d       t        j                  j                  |      s?t	        dj                  |      t
        j                         t        j                  d       t        t        t         t"        d	}|j                     dg|j$                  t&         fd
              }g |j(                   fd       }|j+                          yw)zJ
    Sanity check options, create a connection and run our subcommand
    NzMust select a subcommandr   r#   r   z/Full path to the executable required. Found: {}rO   zExecutable not found: {})r   r#   r%   r!   c           	   3   |  K   t        dj                  |j                  |j                        t        j
                         	  |        | j                          y # t        $ rM}t        dj                  |j                  dj                  |j                                     dd<   Y d }~dd }~ww xY ww)Nz$connected: authrole={} authmethod={}rO   z
{}: {}
    r   )r@   rA   r-   
authmethodr^   rh   r
   errorrz   r   leave)rC   detailse
command_fn	exit_coder8   rB   s      r:   _z_real_main.<locals>._  s      	4;;G<L<LgN`N`ahkhrhrs	Wgw77 mmo   	,%%aggrwwqvv?@IaL	s1   A B<A# B<#	B9,AB4/B<4B99B<c                    t        dj                  |             j                  |       j                  dkD  rMt	              j                  kD  r4t        dj                  t	                           j                          y y y )Nzconnect failure: {}r   zToo many failures ({}). Exiting)r@   rA   r    max_failureslenstop)compfailfailuresr8   rB   s     r:   r   z_real_main.<locals>._  sl    #**401!#H8L8L(L3::3x=IJLLN )M#r<   )top
parse_argsr;   r   r@   r^   exitr$   rx   rw   isabsrA   rh   existsrH   r   r   rL   on_joinr   on_connectfailurestart)	rB   	componentr   r   r   r   r   r   r8   s	   `    @@@@r:   r   r   a  sF    
 nnG!'*I&()*,ooa ww}}S!CJJ3OVYV`V`aHHQKww~~c",33C8szzJHHQK !	K W445JI   H   ! //'
""s   FF"__main__).rx   r^   argparser{   r   autobahn.twisted.componentr   ImportErrorr@   r   twisted.internet.deferr   r   twisted.internet.taskr   twisted.internet.protocolr	   autobahn.wamp.exceptionr
   autobahn.wamp.typesr   r   txaiouse_twistedArgumentParserr   add_argumentry   getintadd_subparserssub
add_parserr   strr!   r#   r%   r;   rH   rL   r   r   r   r   rq   r   r<   r:   <module>r      s  < 
 
   4 = ' 5 4 . 0      h6*   	W	     t		     T	NJJNN-t4	     	/	     	-	     d		0   

	   ~~
	1     			  
   
	7  
   
	9	   ..	:     			   
   
	7  
   
	9	   >>	=   	  			  
 	  		H	   	  	
	5  	 NN	E  	 
  			  
 
  		H	   
  	h	?  !H 
( 
(   - -`  2 3# 3#n z	G g  	
:;	
+,CHHQKs   J 'KK