HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /lib/python3/dist-packages/serial/urlhandler/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/serial/urlhandler/__pycache__/protocol_socket.cpython-311.pyc
�

Ȧ^_�7���ddlmZddlZddlZddlZddlZddlZ	ddlZn#e$r	ddl	m
ZYnwxYwddlmZm
Z
mZmZmZmZejejejejd�ZdZGd�de��Zedkr�ddlZed	��Zej�d
�e����ej�d��e�d��e���ej�d
�e� d������e�!��dSdS)�)�absolute_importN)�
SerialBase�SerialException�to_bytes�PortNotOpenError�SerialTimeoutException�Timeout)�debug�info�warning�error�c���eZdZdZdZd�Zd�Zd�Zd�Ze	d���Z
dd	�Zd
�Zd�Z
d�Zdd�Zd�Zd�Zd�Ze	d���Ze	d���Ze	d���Ze	d���Zd�ZdS)�Serialz-Serial port implementation for plain sockets.)�2�K�n����i,iXi�ii`	i�i�%iKi�i�i�c��d|_|j�td���|jrtd���	t	j|�|j��t���|_	nA#t$r4}d|_	td�|j|�����d}~wwxYw|j	�d��|�
��d|_|js|���|js|���|���|���dS)zx        Open port with current settings. This may throw a SerialException
        if the port cannot be opened.
        Nz.Port must be configured before it can be used.zPort is already open.)�timeoutzCould not open port {}: {}FT)�logger�_portr�is_open�socket�create_connection�from_url�portstr�POLL_TIMEOUT�_socket�	Exception�format�setblocking�_reconfigure_port�_dsrdtr�_update_dtr_state�_rtscts�_update_rts_state�reset_input_buffer�reset_output_buffer)�self�msgs  �C/usr/lib/python3/dist-packages/serial/urlhandler/protocol_socket.py�openzSerial.open3sJ��
����:��!�"R�S�S�S��<�	;�!�"9�:�:�:�	Z�!�3�D�M�M�$�,�4O�4O�Ye�f�f�f�D�L�L���	Z�	Z�	Z��D�L�!�">�"E�"E�d�l�TW�"X�"X�Y�Y�Y�����	Z����	
�� � ��'�'�'�	
��� � � �����|�	%��"�"�$�$�$��|�	%��"�"�$�$�$����!�!�!�� � �"�"�"�"�"s�8A.�.
B,�8/B'�'B,c�x�|j�td���|jr|j�d��dSdS)zz        Set communication parameters on opened port. For the socket://
        protocol all settings are ignored!
        NzCan only operate on open portsz!ignored port configuration change)r!rrr�r,s r.r%zSerial._reconfigure_portQsO��
�<��!�"B�C�C�C��;�	B��K���@�A�A�A�A�A�	B�	B�c��|jrq|jrM	|j�tj��|j���n#YnxYwd|_d|_t
jd��dSdS)z
Close portNFg333333�?)rr!�shutdownr�	SHUT_RDWR�close�time�sleepr1s r.r6zSerial.close[s����<�	��|�
$���L�)�)�&�*:�;�;�;��L�&�&�(�(�(�(����D����#��� �D�L��J�s�O�O�O�O�O�	�	s�=A�Ac���tj|��}|jdkr'td�|j�����	tj|jd�����D]�\}}|dkrrtj	��tj
d��|_|j�t|d��|j�d���}td�|�����d|jcxkrd	ksntd
���n4#t$r'}td�|�����d}~wwxYw|j|jfS)
z(extract host and port from an URL stringrzexpected a string in the form "socket://<host>:<port>[?logging={debug|info|warning|error}]": not starting with socket:// ({!r})T�loggingzpySerial.socketrzenabled loggingzunknown option: {!r}izport not in range 0...65535z_expected a string in the form "socket://<host>:<port>[?logging={debug|info|warning|error}]": {}N)�urlparse�urlsplit�schemerr#�parse_qs�query�itemsr:�basicConfig�	getLoggerr�setLevel�
LOGGER_LEVELSr
�
ValueError�port�hostname)r,�url�parts�option�values�es      r.rzSerial.from_urljs����!�#�&�&���<�8�#�#�!�5�5;�V�E�L�5I�5I�K�K�
K�	_�"*�"3�E�K��"F�"F�"L�"L�"N�"N�
L�
L�����Y�&�&��'�)�)�)�")�"3�4E�"F�"F�D�K��K�(�(��v�a�y�)A�B�B�B��K�%�%�&7�8�8�8�8�$�%;�%B�%B�6�%J�%J�K�K�K���
�*�*�*�*�U�*�*�*�*� �!>�?�?�?�+���	_�	_�	_�!�T�TZ�TZ�[\�T]�T]�_�_�
_�����	_����
���
�+�+s�C.D7�7
E(�"E#�#E(c��|jst���tj|jgggd��\}}}t	|��S)z9Return the number of bytes currently in the input buffer.r)rr�selectr!�len)r,�lr�lw�lxs    r.�
in_waitingzSerial.in_waiting�sF���|�	%�"�$�$�$��]�D�L�>�2�r�1�=�=�
��B���2�w�w�r2�c��|jst���t��}t|j��}t|��|k�r�	t
j|jggg|�����\}}}|s�ny|j�	|t|��z
��}|std���|�|��n�#t$rl}|j
tjtjtjtjtjfvr"td�|�����Yd}~n�d}~wtjt*jf$rm}|dtjtjtjtjtjfvr"td�|�����Yd}~nd}~wwxYw|���rnt|��|k���t/|��S)z�        Read size bytes from the serial port. If a timeout is set it may
        return less characters as requested. With no timeout it will block
        until the requested number of bytes is read.
        zsocket disconnected�read failed: {}Nr)rr�	bytearrayr	�_timeoutrOrNr!�	time_left�recvr�extend�OSError�errno�EAGAIN�EALREADY�EWOULDBLOCK�EINPROGRESS�EINTRr#r
r�expired�bytes)r,�size�readr�ready�_�bufrLs        r.rfzSerial.read�s����|�	%�"�$�$�$��{�{���$�-�(�(���$�i�i�$���
G�$�m�T�\�N�B��G�DU�DU�DW�DW�X�X���q�!�
����l�'�'��s�4�y�y�(8�9�9���A�)�*?�@�@�@����C� � � � ���
G�
G�
G��7�5�<����AR�TY�Te�gl�gr�"s�s�s�)�*;�*B�*B�1�*E�*E�F�F�F�t�s�s�s�s������L�&�,�/�
G�
G�
G��Q�4���e�n�e�>O�QV�Qb�di�do�p�p�p�)�*;�*B�*B�1�*E�*E�F�F�F�q�p�p�p�p�����	
G������� � �
��9�$�i�i�$���:�T�{�{�s-�
5C�AC�
G�A"E�G�$A#G�Gc��|jst���t|��}t|��x}}t	|j��}|dk�r	|j�|��}|jr|S|j	sh|�
��rtd���tjg|jgg|�
����\}}}|std���nH|�
���J�tjg|jggd��\}}}|std���||d�}||z}n�#t$r�t$rl}	|	jt jt jt jt jt jfvr"td�|	�����Yd}	~	n�d}	~	wtj$rm}	|	dt jt jt jt jt jfvr"td�|	�����Yd}	~	nd}	~	wwxYw|js#|�
��rtd���|dk��|t|��z
S)z�        Output the given byte string over the serial port. Can block if the
        connection is blocked. May raise SerialException if the connection is
        closed.
        rz
Write timeoutNzwrite failed (select)zwrite failed: {})rrrrOr	�_write_timeoutr!�send�is_non_blocking�is_infinitercrrNrYrr\r]r^r_r`rarbr#r
)
r,�data�d�tx_len�lengthr�nrhrgrLs
          r.�writezSerial.write�s����|�	%�"�$�$�$��T�N�N���a�&�&� ����$�-�.�.���q�j�j�#
H��L�%�%�a�(�(���*�G��H� �,�
G����(�(�F�4�_�E�E�E�"(�-��T�\�N�B��HY�HY�H[�H[�"\�"\�K�A�u�a� �F�4�_�E�E�E�F�#�,�,�.�.�6�6�6�"(�-��T�\�N�B��"M�"M�K�A�u�a� �G�-�.E�F�F�F��a�b�b�E���!�����"�
�
�
���
H�
H�
H��7�5�<����AR�TY�Te�gl�gr�"s�s�s�)�*<�*C�*C�A�*F�*F�G�G�G�t�s�s�s�s������<�
H�
H�
H��Q�4���e�n�e�>O�QV�Qb�di�do�p�p�p�)�*<�*C�*C�A�*F�*F�G�G�G�q�p�p�p�p�����	
H�����*�
>�w���/@�/@�
>�,�_�=�=�=�M�q�j�j�N��A����s-�"D<�5CD<�<H6�A"F7�7H6�	A#H1�1H6c��|jst���d}|�rCtj|jgggd��\}}}	|r|j�d��}n�#t
$rl}|jtjtjtj	tj
tjfvr"td�
|�����Yd}~n�d}~wtjtjf$rm}|dtjtjtj	tj
tjfvr"td�
|�����Yd}~nd}~wwxYw|��AdSdS)z9Clear input buffer, discarding all that is in the buffer.TrirVN)rrrNr!rZr\r]r^r_r`rarbrr#r
r)r,rgrhrLs    r.r*zSerial.reset_input_buffer�s����|�	%�"�$�$�$����	G� �-�����B��B�B�K�E�1�a�
G��4� �L�-�-�d�3�3�E����
G�
G�
G��7�5�<����AR�TY�Te�gl�gr�"s�s�s�)�*;�*B�*B�1�*E�*E�F�F�F�t�s�s�s�s������L�&�,�/�
G�
G�
G��Q�4���e�n�e�>O�QV�Qb�di�do�p�p�p�)�*;�*B�*B�1�*E�*E�F�F�F�q�p�p�p�p�����	
G�����	G�	G�	G�	G�	Gs%�A�
E�$A"C�E�)A#E�Ec�v�|jst���|jr|j�d��dSdS)zs        Clear output buffer, aborting the current output and
        discarding all that is in the buffer.
        zignored reset_output_bufferN�rrrrr1s r.r+zSerial.reset_output_buffersK��
�|�	%�"�$�$�$��;�	<��K���:�;�;�;�;�;�	<�	<r2��?c��|jst���|jr/|j�d�|����dSdS)za        Send break condition. Timed, returns to idle state after given
        duration.
        zignored send_break({!r})N)rrrrr#)r,�durations  r.�
send_breakzSerial.send_breaks\��
�|�	%�"�$�$�$��;�	J��K���7�>�>�x�H�H�I�I�I�I�I�	J�	Jr2c�|�|jr4|j�d�|j����dSdS)zJSet break: Controls TXD. When active, to transmitting is
        possible.z!ignored _update_break_state({!r})N)rrr#�_break_stater1s r.�_update_break_statezSerial._update_break_statesI���;�	\��K���@�G�G��HY�Z�Z�[�[�[�[�[�	\�	\r2c�|�|jr4|j�d�|j����dSdS)z)Set terminal status line: Request To Sendzignored _update_rts_state({!r})N)rrr#�
_rts_stater1s r.r)zSerial._update_rts_state%�F���;�	X��K���>�E�E�d�o�V�V�W�W�W�W�W�	X�	Xr2c�|�|jr4|j�d�|j����dSdS)z-Set terminal status line: Data Terminal Readyzignored _update_dtr_state({!r})N)rrr#�
_dtr_stater1s r.r'zSerial._update_dtr_state*r�r2c�r�|jst���|jr|j�d��dS)z(Read terminal status line: Clear To Sendzreturning dummy for ctsTrwr1s r.�ctsz
Serial.cts/�@���|�	%�"�$�$�$��;�	8��K���6�7�7�7��tr2c�r�|jst���|jr|j�d��dS)z)Read terminal status line: Data Set Readyzreturning dummy for dsrTrwr1s r.�dsrz
Serial.dsr8r�r2c�r�|jst���|jr|j�d��dS)z)Read terminal status line: Ring Indicatorzreturning dummy for riFrwr1s r.�riz	Serial.riAs@���|�	%�"�$�$�$��;�	7��K���5�6�6�6��ur2c�r�|jst���|jr|j�d��dS)z)Read terminal status line: Carrier Detectzreturning dummy for cd)Trwr1s r.�cdz	Serial.cdJr�r2c�4�|j���S)z@Get the file handle of the underlying socket for use with select)r!�filenor1s r.r�z
Serial.filenoVs���|�"�"�$�$�$r2N)rT)rx)�__name__�
__module__�__qualname__�__doc__�	BAUDRATESr/r%r6r�propertyrSrfrtr*r+r{r~r)r'r�r�r�r�r��r2r.rr-s�������7�7�4�I�#�#�#�<B�B�B�
�
�
�,�,�,�:����X��'�'�'�'�R3�3�3�jG�G�G�2<�<�<�J�J�J�J�\�\�\�X�X�X�
X�X�X�
����X������X������X������X��%�%�%�%�%r2r�__main__zsocket://localhost:7000z{}
z	write...
shello
z	read: {}
)"�
__future__rr]r:rNrr7r;�ImportError�urllib.parse�parse�serial.serialutilrrrrrr	�DEBUG�INFO�WARNING�ERRORrDr rr��sys�s�stdoutrtr#�flushrfr6r�r2r.�<module>r�s���&'�&�&�&�&�&���������
�
�
�
�
�
�
�
�����$��O�O�O�O���$�$�$�#�#�#�#�#�#�#�#�$����6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�
�]��L���
�]�	��
���k%�k%�k%�k%�k%�Z�k%�k%�k%�`	�z����J�J�J���(�)�)�A��J���V�]�]�1�%�%�&�&�&��J���\�"�"�"��G�G�J�����G�G�I�I�I��J���\�(�(�������3�3�4�4�4��G�G�I�I�I�I�I��s�!�/�/