name : protocol_spy.cpython-39.pyc
a

��WW@#�@s�ddlZddlZddlZzddlZWneyBddlmZYn0dd�Zdd�ZGdd�de	�Z
Gdd	�d	e	�ZGd
d�dej�Ze
dkr�ed�Zd
e_ee�dS)�Nccs�d}t�|�D]d}d�t|��d|kr2dkr@nn
|�d�ndfV|d7}|dkr`d	Vq|d
krdVd}q|dkr�|d
kr�|d7}|dkr�d	VdVq|dVd
S)z�    yield tuples of hex and ASCII display in multiples of 16. Includes a
    space after 8 bytes and (None, None) after 16 bytes and at the end.
    rz{:02X} � ��ascii�.��)� ��)NN)z   rN)�serialZ	iterbytes�format�ord�decode)�data�n�b�r�B/usr/lib/python3.9/site-packages/serial/urlhandler/protocol_spy.py�sixteen"s 6rccs|g}g}d}t|�D]b\}}|durb|d�d�|�d�|�g�fV|dd�=|dd�=|d7}q|�|�|�|�qdS)z yield lines with hexdump of datarNrr	r
)r�join�append)r�valuesr�offset�h�arrr�hexdump9s 



rc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�	FormatRawz&Forward only RX and TX data to output.cCs||_||_d|_d|_dS)N��)�output�color�rx_color�tx_color��selfrr rrr�__init__LszFormatRaw.__init__cCs.|jr|j�|j�|j�|�|j��dS)zshow received dataN)r r�writer!�flush�r$rrrr�rxRszFormatRaw.rxcCs.|jr|j�|j�|j�|�|j��dS)zshow transmitted dataN)r rr&r"r'r(rrr�txYszFormatRaw.txcCsdS)z(do not) show control callsNr�r$�name�valuerrr�control`szFormatRaw.controlN)�__name__�
__module__�__qualname__�__doc__r%r)r*r.rrrrrIs
rc@s:eZdZdZdd�Zddd�Zdd�Zd	d
�Zdd�Zd
S)�
FormatHexdumpax    Create a hex dump of RX ad TX data, show when control lines are read or
    written.

    output example::

        000000.000 Q-RX flushInput
        000002.469 RTS  inactive
        000002.773 RTS  active
        000003.001 TX   48 45 4C 4C 4F                                    HELLO
        000003.102 RX   48 45 4C 4C 4F                                    HELLO

    cCs,t��|_||_||_d|_d|_d|_dS)Nrrz)�time�
start_timerr r!r"�
control_colorr#rrrr%ts
zFormatHexdump.__init__r	cCs&|j�d�||||��|j��dS)Nz{:010.3f} {:4} {}{}
)rr&rr')r$Z	timestampZlabelr-Zvalue2rrr�
write_line|szFormatHexdump.write_linecCsh|jr|j�|j�|rLt|�D](\}}|�t��|jdd�|�|�q n|�t��|jdd�dS)zshow received data as hex dumpZRX�{:04X}  z<empty>N)	r rr&r!rr7r4r5r�r$rr�rowrrrr)�s$zFormatHexdump.rxcCsJ|jr|j�|j�t|�D](\}}|�t��|jdd�|�|�qdS)z!show transmitted data as hex dumpZTXr8N)	r rr&r"rr7r4r5rr9rrrr*�szFormatHexdump.txcCs0|jr|j�|j�|�t��|j||�dS)zshow control callsN)r rr&r6r7r4r5r+rrrr.�szFormatHexdump.controlN)r	)	r/r0r1r2r%r7r)r*r.rrrrr3es

r3csTeZdZdZ�fdd�Zejjjdd��Zdd�Z	�fdd	�Z
d,�fdd�	Zeejd
�rd�fdd�Z
eejd�r|�fdd�Ze�fdd��Z�fdd�Z�fdd�Z�fdd�Zd-�fdd�	Zejjjdd��Zejjjd d!��Zejjjd"d#��Zejjj�fd$d%��Zejjj�fd&d'��Zejjj�fd(d)��Zejjj�fd*d+��Z�ZS).�Serialzc    Inherit the native Serial port implementation and wrap all the methods and
    attributes.
    cs&tt|�j|i|��d|_d|_dS)NF)�superr;r%�	formatter�show_all)r$�args�kwargs��	__class__rrr%�szSerial.__init__cCs"|durtjj�||�|��dS�N)rr;�port�__set__�from_url)r$r-rrrrD�szSerial.portc	
Cs�t�|�}|jdkr&t�d�|j���t}d}tj}zrt�	|j
d���D]Z\}}|dkrht|dd�}qH|dkrvd}qH|d	kr�t
}qH|d
kr�d|_qHtd�|���qHWn4ty�}zt�d�|���WYd
}~n
d
}~00|||�|_d�|j|jg�S)z(extract host and port from an URL stringZspyzmexpected a string in the form "spy://port[?option[=value][&option[=value]]]": not starting with spy:// ({!r})FT�filer�wr �raw�allzunknown option: {!r}zPexpected a string in the form "spy://port[?option[=value][&option[=value]]]": {}Nr	)�urlparse�urlsplit�schemerZSerialExceptionrr3�sys�stderr�parse_qs�query�items�openrr>�
ValueErrorr=r�netloc�path)	r$�url�partsr=r r�optionr�errrrF�s:

����zSerial.from_urlcs|j�|�tt|��|�SrC)r=r*r<r;r&)r$r*rArrr&�szSerial.writercs*tt|��|�}|s|jr&|j�|�|SrC)r<r;�readr>r=r))r$�sizer)rArrr[�s
zSerial.read�cancel_readcs |j�dd�tt|���dS)N�Q-RXr])r=r.r<r;r]�r$rArrr]�szSerial.cancel_read�cancel_writecs |j�dd�tt|���dS)N�Q-TXr`)r=r.r<r;r`r_rArrr`�szSerial.cancel_writecs*tt|�j}|jr&|j�dd�|��|S)Nr^zin_waiting -> {})r<r;�
in_waitingr>r=r.r)r$rrArrrb�szSerial.in_waitingcs |j�dd�tt|���dS)Nrar')r=r.r<r;r'r_rArrr'�szSerial.flushcs |j�dd�tt|���dS)Nr^�reset_input_buffer)r=r.r<r;rcr_rArrrc�szSerial.reset_input_buffercs |j�dd�tt|���dS)Nra�reset_output_buffer)r=r.r<r;rdr_rArrrd�szSerial.reset_output_buffer��?cs(|j�dd�|��tt|��|�dS)N�BRKzsend_break {}s)r=r.rr<r;�
send_break)r$ZdurationrArrrg�szSerial.send_breakcCs*|j�d|rdnd�tjj�||�dS)Nrf�active�inactive)r=r.rr;�break_conditionrE�r$�levelrrrrj�szSerial.break_conditioncCs*|j�d|rdnd�tjj�||�dS)NZRTSrhri)r=r.rr;�rtsrErkrrrrm�sz
Serial.rtscCs*|j�d|rdnd�tjj�||�dS)NZDTRrhri)r=r.rr;�dtrrErkrrrrn�sz
Serial.dtrcs&tt|�j}|j�d|rdnd�|S)NZCTSrhri)r<r;�ctsr=r.rkrArrrosz
Serial.ctscs&tt|�j}|j�d|rdnd�|S)NZDSRrhri)r<r;�dsrr=r.rkrArrrpsz
Serial.dsrcs&tt|�j}|j�d|rdnd�|S)NZRIrhri)r<r;�rir=r.rkrArrrqsz	Serial.rics&tt|�j}|j�d|rdnd�|S)NZCDrhri)r<r;�cdr=r.rkrArrrrsz	Serial.cd)r)re)r/r0r1r2r%rr;rD�setterrFr&r[�hasattrr]r`�propertyrbr'rcrdrgrjrmrnro�getterrprqrr�
__classcell__rrrArr;�s>



r;�__main__zspy:///dev/ttyS0)rNr4rrK�ImportError�urllib.parse�parserr�objectrr3r;r/ZserrD�printrrrr�<module>s 3

© 2025 Cubjrnet7