U
    •uÄc+  ã                	   @   sÊ  d dl Z d dlZd dlZd dlZd dlmZ zd dlmZ W n. ek
rj   edƒ edƒ e 	d¡ Y nX 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 ¡  ejdd�Zejddddd� ejdddddd� ejdddde j dd¡d� ejddddd� ejddd dd� ejd!d"ded#d d$� ejd%d&d'�Zej d(d)d*�Z!e!jd+e"d,d-� e!jd.d/d0d1� e!jd2d3d4d5d6� ej d7d8d*�Z#e#jd+e"d9d-� e#jd:d/d0d1� e#jd2d3d4d5d6� ej d;d<d*�Z$e$jd+e"d,d-� e$jd=ed d>d?� e$jd@e"d/dAdB� ej dCdDd*�Z%e%jd+e"d,d-� e%jd=ed d>d?� e%jdEe"dFdFdGgdHdI� dJdK„ Z&edLdM„ ƒZ'edNdO„ ƒZ(edPdQ„ ƒZ)edRdS„ ƒZ*dTdU„ Z+edVdW„ ƒZ,e-dXk�rÆe+ƒ  dS )Yé    N)Úcopy)Ú	Componentz.The 'wamp' command-line tool requires Twisted.z  pip install autobahn[twisted]é   )ÚDeferredÚinlineCallbacks)Úreact)ÚProcessProtocol)ÚApplicationError)ÚPublishOptions)ÚSubscribeOptionsZ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)Z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   Úcommandz®Takes 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                 C   s~   | j  d¡rd}n| j  d¡r$d}ntdƒ‚tƒ }| jr\| jsFtdƒ‚| j| j| jdœ|d< t|| j d	œg|rr|nd
| jd�S )zX
    Configure and return a Component instance according to the given
    `options`
    zws://Z	websocketzrs://Z	rawsocketz$URL should start with ws:// or rs://zRRequire --authid and --authrole if --private-key (or WAMP_PRIVATE_KEY) is provided)ÚauthidÚauthroleZprivkeyZ
cryptosign)r   ÚurlN)Ú
transportsÚauthenticationÚrealm)	r(   Ú
startswithÚ
ValueErrorÚdictZprivate_keyr&   r'   r   r+   )ÚoptionsÚkindr*   © r1   úT/var/www/html/BOARDBOSS/school/venv/lib/python3.8/site-packages/autobahn/__main__.pyÚ_create_componentÌ   s0    ÿÿý
þ
úr3   c                 c   sR   t |jƒ}tƒ }|jd k	r*dd„ |jD ƒ}|j|jf|ž|ŽV }td |¡ƒ d S )Nc                 S   s   i | ]\}}||“qS r1   r1   ©Ú.0ÚkÚvr1   r1   r2   Ú
<dictcomp>õ   s   ÿ zdo_call.<locals>.<dictcomp>z
result: {})Úlistr   r.   Úkeywordr   r   ÚprintÚformat)ÚreactorÚsessionr/   r   Zcall_kwargsÚresultsr1   r1   r2   Údo_callð   s    

þr@   c                 c   sP   t |jƒ}|jd kri ndd„ |jD ƒ}|j|jf|ždtdd�i|—ŽV  d S )Nc                 S   s   i | ]\}}||“qS r1   r1   r4   r1   r1   r2   r8     s   ÿ zdo_publish.<locals>.<dictcomp>r/   T)Zacknowledge)r9   r   r:   r   r   r
   )r=   r>   r/   r   Zpublish_kwargsr1   r1   r2   Ú
do_publishþ   s    
þÿþýürA   c                 #   s>   t ƒ ‰ ˆjg‰t‡ ‡‡‡fdd„ƒ}| |ˆj¡V  ˆ V  dS )z-
    run a command-line upon an RPC call
    c                  ?   s
  t d | |¡tjd� ttjƒ}d | ¡|d< t 	| ¡|d< d dd„ | 
¡ D ƒ¡|d< t 	|¡|d	< tj ˆjd
 ¡}ˆj} tƒ ‰ G ‡ fdd„dtƒ}|ƒ }ˆj||| |dd� ˆ V }|d
krÎt d |¡ƒ ˆd
 �rˆd
  d8  < ˆd
 d
k�rˆ d
ˆjd ¡ d S )Nzcalled: args={}, kwargs={}©Úfileú Z	WAMP_ARGSZWAMP_ARGS_JSONc                 s   s   | ]\}}d   ||¡V  qdS )z{}={}N)r<   r4   r1   r1   r2   Ú	<genexpr>  s     z.do_register.<locals>.called.<locals>.<genexpr>ZWAMP_KWARGSZWAMP_KWARGS_JSONr   c                       s(   e Zd Zdd„ Zdd„ Z‡ fdd„ZdS )z/do_register.<locals>.called.<locals>.DumpOutputc                 S   s   t j | d¡¡ d S ©NÚutf8)ÚsysÚstdoutÚwriteÚdecode©ÚselfÚdatar1   r1   r2   ÚoutReceived%  s    z;do_register.<locals>.called.<locals>.DumpOutput.outReceivedc                 S   s   t j | d¡¡ d S rF   )rH   ÚstderrrJ   rK   rL   r1   r1   r2   ÚerrReceived(  s    z;do_register.<locals>.called.<locals>.DumpOutput.errReceivedc                    s   ˆ   |jj¡ d S )N)ÚcallbackÚvalueZexitCode)rM   Úreason©Údoner1   r2   ÚprocessExited+  s    z=do_register.<locals>.called.<locals>.DumpOutput.processExitedN)Ú__name__Ú
__module__Ú__qualname__rO   rQ   rW   r1   rU   r1   r2   Ú
DumpOutput$  s   r[   Ú.)ÚenvÚpathzFailed with exit-code {}r   )r;   r<   rH   rP   r   ÚosÚenvironÚjoinÚjsonÚdumpsÚitemsr^   Úabspathr!   r   r   ZspawnProcessÚ	callLaterrR   )ÚargsÚkwr]   Úexer[   ÚprotoÚcode©Úall_doneÚ	countdownr/   r=   rU   r2   Úcalled  s2    

    ÿ
zdo_register.<locals>.calledN)r   Útimesr   r    r   )r=   r>   r/   ro   r1   rl   r2   Údo_register  s    #rq   c                 #   sH   t ƒ ‰ |jg‰t‡ ‡‡fdd„ƒ}|j||jt|jd�d�V  ˆ V  dS )z3
    print events (one line of JSON per event)
    c                     sL   t t | |dœ¡ƒ ˆd rHˆd  d8  < ˆd dkrHˆ dˆ jd ¡ d S )N)rg   Úkwargsr   r   )r;   rb   rc   rf   rR   )rg   rh   ©rm   rn   r=   r1   r2   Ú	publishedH  s    þÿzdo_subscribe.<locals>.published)Úmatch)r/   N)r   rp   r   r"   r   r   ru   )r=   r>   r/   rt   r1   rs   r2   Údo_subscribe?  s    rv   c                   C   s   t tƒ dS )zi
    This is a magic name for `python -m autobahn`, and specified as
    our entry_point in setup.py
    N)r   Ú
_real_mainr1   r1   r1   r2   Ú_mainY  s    rx   c                 #   sø   t  ¡ ‰tˆƒ}ˆjdkr,tdƒ t d¡ ˆjdkr”ˆjd }tj	 
|¡sjtd |¡tjd� t d¡ tj	 |¡s”td |¡tjd� t d¡ ttttd	œ}|ˆj ‰ dg‰|jt‡ ‡‡‡fd
d„ƒƒ}g ‰|j‡‡‡fdd„ƒ}| ˆ¡V  dS )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: {}rB   zExecutable not found: {})r   r    r"   r   c              
   3   s€   t d |j|j¡tjd� zˆ ˆ| ˆƒV  W nD tk
rp } z&t d |jd |j	¡¡ƒ dˆd< W 5 d }~X Y nX |  
¡ V  d S )Nz$connected: authrole={} authmethod={}rB   z
{}: {}
Ú é   r   )r;   r<   r'   Z
authmethodrH   rP   r	   Úerrorra   rg   Zleave)r>   ÚdetailsÚe)Ú
command_fnÚ	exit_coder/   r=   r1   r2   Ú_€  s    z_real_main.<locals>._c                    sN   t d |¡ƒ ˆ  |¡ ˆjdkrJtˆ ƒˆjkrJt d tˆ ƒ¡ƒ ˆ ¡  d S )Nzconnect failure: {}r   zToo many failures ({}). Exiting)r;   r<   r   Zmax_failuresÚlenÚstop)ÚcompÚfail)Úfailuresr/   r=   r1   r2   r€   �  s
    
)ÚtopÚ
parse_argsr3   r   r;   rH   Úexitr!   r_   r^   Úisabsr<   rP   Úexistsr@   rq   rv   rA   Zon_joinr   Zon_connectfailureÚstart)r=   Z	componentri   r   r€   r1   )r~   r   r…   r/   r=   r2   rw   a  s6    





ü
	rw   Ú__main__).r_   rH   Úargparserb   r   Zautobahn.twisted.componentr   ÚImportErrorr;   rˆ   Ztwisted.internet.deferr   r   Ztwisted.internet.taskr   Ztwisted.internet.protocolr   Zautobahn.wamp.exceptionr	   Zautobahn.wamp.typesr
   r   ZtxaioZuse_twistedÚArgumentParserr†   Úadd_argumentr`   ÚgetÚintÚadd_subparsersÚsubÚ
add_parserr   Ústrr   r    r"   r3   r@   rA   rq   rv   rx   rw   rX   r1   r1   r1   r2   Ú<module>   s@  ü ü üüü ûþþýýüþýýüþýüûþýüû	$


0

7
