o
    èó·i+  ã                	   @   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y4   edƒ edƒ e 	d¡ Y nw 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�rde+ƒ  dS 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s#tdƒ‚| j| j| jdœ|d< t|| j d	œg|r9|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   úWC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\autobahn/__main__.pyÚ_create_componentÌ   s0   ÿÿ
ýþ
úr3   c                 c   sZ   � t |jƒ}tƒ }|jd urdd„ |jD ƒ}|j|jg|¢R i |¤ŽV }td |¡ƒ d S )Nc                 S   ó   i | ]\}}||“qS r1   r1   ©Ú.0ÚkÚvr1   r1   r2   Ú
<dictcomp>õ   ó    ÿÿ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   €

þrB   c                 c   sT   � t |jƒ}|jd u ri ndd„ |jD ƒ}|j|jg|¢R dtdd�i|¤ŽV  d S )Nc                 S   r4   r1   r1   r5   r1   r1   r2   r9     r:   zdo_publish.<locals>.<dictcomp>r/   T)Zacknowledge)r;   r   r<   r   r   r
   )r?   r@   r/   r   Zpublish_kwargsr1   r1   r2   Ú
do_publishþ   s   €
þÿþýürC   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rht d |¡ƒ ˆd
 r„ˆd
  d8  < ˆd
 d
kr†ˆ d
ˆjd ¡ d S d S d S )Nzcalled: args={}, kwargs={}©Úfileú Z	WAMP_ARGSZWAMP_ARGS_JSONc                 s   s    � | ]\}}d   ||¡V  qdS )z{}={}N)r>   r5   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   ó   t j | d¡¡ d S ©NÚutf8)ÚsysÚstdoutÚwriteÚdecode©ÚselfÚdatar1   r1   r2   ÚoutReceived%  ó   z;do_register.<locals>.called.<locals>.DumpOutput.outReceivedc                 S   rH   rI   )rK   ÚstderrrM   rN   rO   r1   r1   r2   ÚerrReceived(  rS   z;do_register.<locals>.called.<locals>.DumpOutput.errReceivedc                    s   ˆ   |jj¡ d S )N)ÚcallbackÚvalueZexitCode)rP   Úreason©Údoner1   r2   ÚprocessExited+  s   z=do_register.<locals>.called.<locals>.DumpOutput.processExitedN)Ú__name__Ú
__module__Ú__qualname__rR   rU   r[   r1   rY   r1   r2   Ú
DumpOutput$  s    r_   Ú.)ÚenvÚpathzFailed with exit-code {}r   )r=   r>   rK   rT   r   ÚosÚenvironÚjoinÚjsonÚdumpsÚitemsrb   Úabspathr!   r   r   ZspawnProcessÚ	callLaterrV   )ÚargsÚkwra   Úexer_   ÚprotoÚcode©Úall_doneÚ	countdownr/   r?   rY   r2   Úcalled  s0   €


ÿýzdo_register.<locals>.calledN)r   Útimesr   r    r   )r?   r@   r/   rs   r1   rp   r2   Údo_register  s   €#
ru   c                 #   sJ   � 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                     sT   t t | |dœ¡ƒ ˆd r&ˆd  d8  < ˆd dkr(ˆ dˆ jd ¡ d S d S d S )N)rk   Úkwargsr   r   )r=   rf   rg   rj   rV   )rk   rl   ©rq   rr   r?   r1   r2   Ú	publishedH  s   þÿýzdo_subscribe.<locals>.published)Úmatch)r/   N)r   rt   r   r"   r   r   ry   )r?   r@   r/   rx   r1   rw   r2   Údo_subscribe?  s   €
rz   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   r|   c                 #   sú   � t  ¡ ‰tˆƒ}ˆjdu rtdƒ t d¡ ˆjdkrKˆjd }tj	 
|¡s6td |¡tjd� t d¡ tj	 |¡sKt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: {}rD   zExecutable not found: {})r   r    r"   r   c              
   3   s„   � t d |j|j¡tjd� z	ˆ ˆ| ˆƒV  W n# ty: } zt d |jd |j	¡¡ƒ dˆd< W Y d }~nd }~ww |  
¡ V  d S )Nz$connected: authrole={} authmethod={}rD   z
{}: {}
Ú é   r   )r=   r>   r'   Z
authmethodrK   rT   r	   Úerrorre   rk   Zleave)r@   ÚdetailsÚe)Ú
command_fnÚ	exit_coder/   r?   r1   r2   Ú_€  s   €€þz_real_main.<locals>._c                    sV   t d |¡ƒ ˆ  |¡ ˆjdkr'tˆ ƒˆjkr)t d tˆ ƒ¡ƒ ˆ ¡  d S d S d S )Nzconnect failure: {}r   zToo many failures ({}). Exiting)r=   r>   r   Zmax_failuresÚlenÚstop)ÚcompZfail)Úfailuresr/   r?   r1   r2   r„   �  s   
þ)ÚtopÚ
parse_argsr3   r   r=   rK   Úexitr!   rc   rb   Úisabsr>   rT   ÚexistsrB   ru   rz   rC   Zon_joinr   Zon_connectfailureÚstart)r?   Ú	componentrm   r   r„   r1   )r‚   rƒ   rˆ   r/   r?   r2   r{   a  s8   €





ü
	r{   Ú__main__).rc   rK   Úargparserf   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_argumentrd   ÚgetÚintZadd_subparsersÚsubZ
add_parserr   Ústrr   r    r"   r3   rB   rC   ru   rz   r|   r{   r\   r1   r1   r1   r2   Ú<module>   s@  ýüüüüüûþþýýüþýýüþýüûþýüû	$


0


7
ÿ