Current File : //proc/self/root/usr/lib/python3/dist-packages/serial/__pycache__/rfc2217.cpython-312.pyc
�

=}`e������ddlmZddlZddlZddlZddlZddlZ	ddlZ	ddlZddl
Z
ddlmZmZmZmZmZmZej*ej,ej.ej0d�ZdZdZdZdZd	Zd
ZdZ dZ!d
Z"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5dZ6d Z7d!Z8d"Z9d#Z:d$Z;d%Z<d&Z=d'Z>d(Z?d)Z@d*ZAd+ZBd,ZCd-ZDd.ZEd/ZFe/e;e0e<e1e=e2e>e3e?e4e@e5eAe6eBe7eCe8eDe9eEe:eFiZGdZHdZIdZJdZKdZLdZMdZNdZOdZPd ZQd!ZRd"ZSd#ZTd0ZUd1ZVd2ZWd3ZXd4ZYd5ZZd6Z[d7Z\d8Z]d9Z^d:Z_d;Z`d<Zad=Zbd>Zcd7Zdd8Zed9Zfd:Zgd;Zhd<Zid=Zjd>ZkdZldZmdZne
j�d>e
j�d=e
j�d?e
j�d<e
j�d@iZteudA�etj��D��Zwe
j�d>e
j�d?e
j�d=iZ{eudB�e{j��D��Z|dZ}d>Z~d=ZdCZ�dDZ�dEZ�dFZ�GdG�dHe��Z�GdI�dJe��Z�GdK�dLe�Z�GdM�dNe��Z�e�dOk(r�ddl�Z�e�dPdQ�Z�e��j�jdR�je���e��j�jdS�e��jdT�e��j�e��j�jdU�je��j!d@���e��j#�yy#e$r
ddl	m
ZY���wxYw#e$rddlZY���wxYw)V�)�absolute_importN)�
SerialBase�SerialException�to_bytes�	iterbytes�PortNotOpenError�Timeout)�debug�info�warning�error��������������������������������s������,�������	�
���e�f�g�h�i�j�k�l�m�n�o�p�
��������@� �������c#�*K�|]\}}||f���
y�w�N���.0�k�vs   �0/usr/lib/python3/dist-packages/serial/rfc2217.py�	<genexpr>rQ�s����!P�T�Q��1�a�&�!P���c#�*K�|]\}}||f���
y�wrJrKrLs   rPrQrQ�s����"R�d�a��A�q�6�"R�rR�	REQUESTED�ACTIVE�INACTIVE�REALLY_INACTIVEc�&�eZdZdZ	dd�Zd�Zd�Zy)�TelnetOptionz@Manage a single telnet option, keeps track of DO/DONT WILL/WONT.Nc
��||_||_||_||_||_||_||_||_d|_|	|_	y)a;        Initialize option.
        :param connection: connection used to transmit answers
        :param name: a readable name for debug outputs
        :param send_yes: what to send when option is to be enabled.
        :param send_no: what to send when option is to be disabled.
        :param ack_yes: what to expect when remote agrees on option.
        :param ack_no: what to expect when remote disagrees on option.
        :param initial_state: options initialized with REQUESTED are tried to
            be enabled on startup. use INACTIVE for all others.
        FN)
�
connection�name�option�send_yes�send_no�ack_yes�ack_no�state�active�activation_callback)
�selfr[r\r]r^r_r`ra�
initial_staterds
          rP�__init__zTelnetOption.__init__�sK��%�����	���� ��
����������"��
����#6�� �c�&�dj|��S)zString for debug outputsz{o.name}:{o.active}({o.state}))�o��format�res rP�__repr__zTelnetOption.__repr__s��/�6�6��6�>�>rhc��||jk(�r$|jtur/t|_d|_|j
��|j�y|jtury|jtur_t|_|jj|j|j�d|_|j
�n|j�y|jtur1|jj|j|j�ytdj|���yy||jk(r�|jturt|_d|_y|jturCt|_|jj|j|j�d|_y|jtury|jturytdj|���y)zo        A DO/DONT/WILL/WONT was received for this option, update state and
        answer when needed.
        TNzoption in illegal state {!r}F)r`rbrTrUrcrdrVr[�telnet_send_optionr^r]rWr_�
ValueErrorrlra�re�commands  rP�process_incomingzTelnetOption.process_incomings���
�d�l�l�"��z�z�Y�&�#��
�"����+�+�7��,�,�.����v�%�����x�'�#��
����2�2�4�=�=�$�+�+�N�"����+�+�7��,�,�.�����.����2�2�4�<�<����M� �!?�!F�!F�t�!L�M�M�8�8�����
#��z�z�Y�&�%��
�#������v�%�%��
����2�2�4�<�<����M�#������x�'������.�� �!?�!F�!F�t�!L�M�M�$rhrJ)�__name__�
__module__�__qualname__�__doc__rgrnrtrKrhrPrYrY�s��J�=A�7�0?�$NrhrYc�H�eZdZdZd	d�Zd�Zd�Zd�Zee�Z	d
d�Z
d�Zy)�TelnetSubnegotiationz�    A object to handle subnegotiation of options. In this case actually
    sub-sub options for RFC 2217. It is used to track com port options.
    Nc�h�|�|}||_||_||_d|_||_t
|_yrJ)r[r\r]�value�
ack_optionrVrb)rer[r\r]r}s     rPrgzTelnetSubnegotiation.__init__9s7�����J�$�����	������
�$�����
rhc�&�dj|��S)zString for debug outputs.z{sn.name}:{sn.state})�snrkrms rPrnzTelnetSubnegotiation.__repr__Cs��%�,�,��,�5�5rhc�H�||_t|_|jj	|j
|j�|jjrJ|jjjdj|j|j��yy)z�        Request a change of the value. a request is sent to the server. if
        the client needs to know if the change is performed he has to check the
        state of this object.
        zSB Requesting {} -> {!r}N)
r|rTrbr[�rfc2217_send_subnegotiationr]�loggerr
rlr\)rer|s  rP�setzTelnetSubnegotiation.setGsq����
���
����3�3�D�K�K����L��?�?�!�!��O�O�"�"�(�(�)C�)J�)J�4�9�9�VZ�V`�V`�)a�b�"rhc��|jtk(r$tdj|j���|jt
k(S)z{        Check if answer from server has been received. when server rejects
        the change, raise a ValueError.
        z%remote rejected value for option {!r})rbrWrqrlr\rUrms rP�is_readyzTelnetSubnegotiation.is_readySs:��
�:�:��(��D�K�K�D�I�I�V�W�W��z�z�V�#�#rhc���t|�}|j�s7tjd�|j	�ry|j�s�7tdj
|j���)z�        Wait until the subnegotiation has been acknowledged or timeout. It
        can also throw a value error when the answer from the server does not
        match the value sent.
        皙�����?z%timeout while waiting for option {!r}N)r	�expired�time�sleepr�rrlr\)re�timeout�
timeout_timers   rP�waitzTelnetSubnegotiation.wait^s`�� ��(�
��'�'�)��J�J�t���}�}��� �'�'�)�
"�"I�"P�"P�QU�QZ�QZ�"[�\�\rhc�>�|j|dt|j�k(rt|_nt|_|j
jrK|j
jjdj|j||j��yy)z�        Check an incoming subnegotiation block. The parameter already has
        cut off the header like sub option number and com port option value.
        NzSB Answer {} -> {!r} -> {})
r|�lenrUrbrWr[r�r
rlr\)re�	suboptions  rP�check_answerz!TelnetSubnegotiation.check_answerlsv��
�:�:��#3�C��
�
�O�4�4��D�J�)�D�J��?�?�!�!��O�O�"�"�(�(�)E�)L�)L�T�Y�Y�Xa�cg�cm�cm�)n�o�"rhrJ)rG)rurvrwrxrgrnr�r��propertyrcr�r�rKrhrPrzrz3s4���
�6�
c�$��h�
�F�]�prhrzc�2��eZdZdZdZ�fd�Zd�Zd�Zd�Zd�Z	e
d��Zd!d	�Zd
�Z
d�Zd�Zd
�Zd�Zd�Ze
d��Ze
d��Ze
d��Ze
d��Ze
d��Zej0d��Zd�Zd�Zd�Zd�Zd�Zd�Zd"d�Zd�Z d�Z!d�Z"d �Z#�xZ$S)#�Serialz<Serial port implementation for RFC 2217 remote serial ports.)�2�K�n����i,iXi�ii`	i�i�%iKi�i���c���d|_d|_d|_d|_t	d�|_d|_d|_d|_d|_	d|_
d|_d|_d|_
d|_d|_t!t"|�J|i|��y)Nr���FrG)�_thread�_socket�
_linestate�_modemstater	�_modemstate_timeout�_remote_suspend_flow�_write_lockr��_ignore_set_control_answer�_poll_modem_state�_network_timeout�_telnet_options�_rfc2217_port_settings�_rfc2217_options�_read_buffer�superr�rg)re�args�kwargs�	__class__s   �rPrgzSerial.__init__�s����������������#*�2�;�� �$)��!�������*/��'�!&��� !���#���&*��#� $��� ���
�f�d�$�d�5�f�5rhc�
�d|_d|_d|_d|_|j�td��|jrtd��	tj|j|j�d��|_|jjtjtjd�t#j"�|_t'j(�|_t-|d
t.t0t2t4t6t8�t-|dt:t0t2t4t6t<�g}t-|dt>t4t6t0t2t<�t-|d
t@t0t2t4t6t<�t-|dt@t4t6t0t2t<�t-|dt.t4t6t0t2t8�t-|dt:t4t6t0t2t<�g|z|_!tE|dtFtH�tE|dtJtL�tE|dtNtP�tE|dtRtT�d�|_+tE|dtXtZ�tE|dt\t^�d�|_0|j`jc|jV�d|_2d|_3tid�|_5d|_6d|_t'jn|jp��|_9|jrjud�|jrjwdj!|j��|jrjy�	|jBD];}|jzt<us�|j}|j~|j���=ti|j�}|j��sLt�j�d�t�d�|D��t�d �|D��k(rn+|j��s�Ltd!j!|���|jr4|jj�d"j!|jB��|j��|j�s|j��|j�s|j��|j��|j��y#t$r1}d|_td	j!|j|���d}~wwxYw#|j���xYw)#zx        Open port with current settings. This may throw a SerialException
        if the port cannot be opened.
        NFrGz.Port must be configured before it can be used.zPort is already open.rH)r�rFzCould not open port {}: {}�	we-BINARY�
we-RFC2217�ECHO�we-SGA�they-SGA�they-BINARY�they-RFC2217�baudrate�datasize�parity�stopsize)r�r�r�r��purge�control)r�r�rr�T)�targetz&pySerial RFC 2217 reader thread for {}r�c3�4K�|]}|j���y�wrJ�rc�rMrjs  rPrQzSerial.open.<locals>.<genexpr>�s����;�A�q�x�x�;���c3�BK�|]}|jtk7���y�wrJ)rbrVr�s  rPrQzSerial.open.<locals>.<genexpr>�s����Br�[\�1�7�7�h�CV�Br�s�z;Remote does not seem to support RFC2217 or BINARY mode {!r}zNegotiated options: {})Nr�r�r�r��_portr�is_open�socket�create_connection�from_url�portstrr��
setsockopt�IPPROTO_TCP�TCP_NODELAY�	Exceptionrl�Queuer��	threading�Lockr�rY�BINARY�WILL�WONT�DO�DONTrV�COM_PORT_OPTIONrTr��SGAr�rz�SET_BAUDRATE�SERVER_SET_BAUDRATE�SET_DATASIZE�SERVER_SET_DATASIZE�
SET_PARITY�SERVER_SET_PARITY�SET_STOPSIZE�SERVER_SET_STOPSIZEr��
PURGE_DATA�SERVER_PURGE_DATA�SET_CONTROL�SERVER_SET_CONTROLr��updater�r�r	r�r��Thread�_telnet_read_loopr��	setDaemon�setName�startrbrpr^r]r�r�r��sumr�_reconfigure_port�_dsrdtr�_update_dtr_state�_rtscts�_update_rts_state�reset_input_buffer�reset_output_buffer�close)re�msg�mandadory_optionsr]r�s     rP�openzSerial.open�s��
���*/��'�!&��� !����:�:��!�"R�S�S��<�<�!�"9�:�:�	Z�!�3�3�D�M�M�$�,�,�4O�YZ�[�D�L��L�L�#�#�F�$6�$6��8J�8J�A�N�"�K�K�M���%�>�>�+���
��{�F�D�$��D�(�S���|�_�d�D�"�d�T]�^�
��
��v�t�R��t�T�9�M���x��d�D�"�d�I�N���z�3��D�$��i�P���}�f�b�$��d�H�U���~���D�$�PT�V_�`� 
�
�
 ���-�T�:�|�M`�a�,�T�:�|�M`�a�,�T�8�z�M^�_�,�T�:�|�M`�a�	'
��#�-�T�7�z�M^�_�,�T�9�{�M_�`�!
���	
���$�$�T�%@�%@�A�������#*�2�;�� �$)��!���� �'�'�t�/E�/E�F��������t�$������E�L�L�T�Z�Z�X�Y�������	��.�.�
L���<�<�9�,��+�+�F�O�O�V�]�]�K�
L��d�3�3�4�G��o�o�'��
�
�4� ��;�):�;�;�s�Br�`q�Br�?r�r���o�o�'�
&�Q�X�X�Yj�k�m�m��{�{���� � �!9�!@�!@��AU�AU�!V�W�
�"�"�$��<�<��&�&�(��<�<��&�&�(��#�#�%��$�$�&��Y�	Z��D�L�!�">�"E�"E�d�l�l�TW�"X�Y�Y��	Z��Z	��J�J�L��s3�A.T�!U�'BU�CU�	T=�,T8�8T=�Uc���|j�td��|j�td��d|jcxkrdks&ntdj
|j���|jdjtjd|j��|jd	jtjd
|j��|jdjtjd
t|j��|jdjtjd
t|j��|jj!�}|j"r*|j"j%d
j
|��t'|j(�}|j+�sEt-j.d�t1d�|D��t3|�k(rn+|j+�s�Etdj
|���|j"r*|j"j5dj
|��|j6r|j8rtd��|j6r|j;t<�y|j8r|j;t>�y|j;t@�y)z,Set communication parameters on opened port.NzCan only operate on open portsz(write_timeout is currently not supportedrlzinvalid baudrate: {!r}r��!Ir��!Br�r�zNegotiating settings: {}r�c3�4K�|]}|j���y�wrJr�r�s  rPrQz+Serial._reconfigure_port.<locals>.<genexpr>s����+��1�8�8�+�r�z7Remote does not accept parameter change (RFC2217): {!r}zNegotiated settings: {}z-xonxoff and rtscts together are not supported)!r�r�_write_timeout�NotImplementedError�	_baudraterqrlr�r��struct�pack�	_bytesize�RFC2217_PARITY_MAP�_parity�RFC2217_STOPBIT_MAP�	_stopbits�valuesr�r
r	r�r�r�r�r�r�rr��_xonxoff�rfc2217_set_control�SET_CONTROL_USE_HW_FLOW_CONTROL�SET_CONTROL_USE_SW_FLOW_CONTROL�SET_CONTROL_USE_NO_FLOW_CONTROL)re�itemsr�s   rPr�zSerial._reconfigure_port�s,���<�<��!�"B�C�C�
���*�%�&P�Q�Q�
�4�>�>�+�G�+��5�<�<�T�^�^�L�M�M��#�#�J�/�3�3�F�K�K��t�~�~�4V�W��#�#�J�/�3�3�F�K�K��t�~�~�4V�W��#�#�H�-�1�1�&�+�+�e�EW�X\�Xd�Xd�Ee�2f�g��#�#�J�/�3�3�F�K�K��GZ�[_�[i�[i�Gj�4k�l��+�+�2�2�4���;�;��K�K���8�?�?��F�G��$�/�/�0���/�/�#��J�J�t���+�U�+�+�s�5�z�9���/�/�#�
"�"[�"b�"b�ch�"i�j�j��;�;��K�K���6�=�=�e�D�E��<�<�D�M�M��L�M�M�
�\�\��$�$�%D�E�
�]�]��$�$�%D�E��$�$�%D�Erhc�T�d|_|jrD	|jjtj�|jj�|jr7|jjd�d|_tjd�d|_y#Y�OxYw)z
Close portF�N�333333�?)
r�r��shutdownr��	SHUT_RDWRr�r��joinr�r�rms rPr�zSerial.closes{������<�<�
����%�%�f�&6�&6�7����"�"�$��<�<��L�L���a� ��D�L��J�J�s�O�����
��s�AB#�#B'c�`�tj|�}|jdk7r$tdj	|j���	tj
|jd�j�D]�\}}|dk(rotj�tjd�|_|jjt|d�|jjd��z|dk(rd|_��|d	k(rd|_��|d
k(rt#|d�|_��t'dj	|���d|j(cxkrdkst'd
��t'd
��	|j*|j(fS#t&$r}tdj	|���d}~wwxYw)zu        extract host and port from an URL string, other settings are extracted
        an stored in instance
        �rfc2217zqexpected a string in the form "rfc2217://<host>:<port>[?option[&option...]]": not starting with rfc2217:// ({!r})T�loggingzpySerial.rfc2217rzenabled logging�ign_set_control�
poll_modemr�zunknown option: {!r}izport not in range 0...65535zPexpected a string in the form "rfc2217://<host>:<port>[?option[&option...]]": {}N)�urlparse�urlsplit�schemerrl�parse_qs�queryr
r�basicConfig�	getLoggerr��setLevel�
LOGGER_LEVELSr
r�r��floatr�rq�port�hostname)re�url�partsr]r�es      rPr�zSerial.from_url0s���
�!�!�#�&���<�<�9�$�!�6�6<�f�U�\�\�6J�L�
L�	P�"*�"3�"3�E�K�K��"F�"L�"L�"N�

L�����Y�&��'�'�)�")�"3�"3�4F�"G�D�K��K�K�(�(��v�a�y�)A�B��K�K�%�%�&7�8��0�0�6:�D�3��|�+�-1�D�*��y�(�,1�&��)�,<�D�)�$�%;�%B�%B�6�%J�K�K�

L���
�
�*�U�*� �!>�?�?�+� �!>�?�?�+�����
�
�+�+��	�	P�!�E�EK�V�A�Y�P�
P��	P�s�
D"F�	F-�F(�(F-c�b�|js
t��|jj�S)z9Return the number of bytes currently in the input buffer.)r�rr��qsizerms rP�
in_waitingzSerial.in_waitingUs)���|�|�"�$�$�� � �&�&�(�(rhc��|js
t��t�}	t|j�}t|�|kr�|j�|jj�std��|jjd|j��}|�t|�S||z
}|j�rnt|�|kr��t|�S#tj$r
Yt|�SwxYw)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.
        z&connection failed (reader thread died)T)r�r�	bytearrayr	�_timeoutr�r��is_aliverr��get�	time_left�bytesr�r��Empty)re�size�datar��bufs     rP�readzSerial.read\s����|�|�"�$�$��{��	��d�m�m�,�G��d�)�d�"��<�<�'�t�|�|�/D�/D�/F�)�*R�S�S��'�'�+�+�D�'�2C�2C�2E�F���;� ��;�&������?�?�$���d�)�d�"��T�{����{�{�	���T�{��	�s�B
C�-$C�C=�<C=c��|js
t��|j5	|jj	t|�j
tt��	ddd�t|�S#tj$r}tdj|���d}~wwxYw#1swYt|�SxYw)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.
        z$connection failed (socket error): {}N)r�rr�r��sendallr�replace�IAC�IAC_DOUBLEDr�r
rrlr�)rer1r$s   rP�writezSerial.writets����|�|�"�$�$�
�
�
�	X�
X����$�$�X�d�^�%;�%;�C��%M�N�	X�
�4�y����<�<�
X�%�&L�&S�&S�TU�&V�W�W��
X��	X�
�4�y��s(�B*�<A5�5B'�B"�"B'�'B*�*B=c��|js
t��|jt�|jj�r7|jj
d�|jj�r�6yy)z9Clear input buffer, discarding all that is in the buffer.FN)r�r�rfc2217_send_purge�PURGE_RECEIVE_BUFFERr�r&r,rms rPr�zSerial.reset_input_buffer�s[���|�|�"�$�$���� 4�5����%�%�'����!�!�%�(����%�%�'rhc�Z�|js
t��|jt�y)zs        Clear output buffer, aborting the current output and
        discarding all that is in the buffer.
        N)r�rr;�PURGE_TRANSMIT_BUFFERrms rPr�zSerial.reset_output_buffer�s#��
�|�|�"�$�$���� 5�6rhc�&�|js
t��|jr8|jjdj	|j
rdnd��|j
r|j
t�y|j
t�y)z[        Set break: Controls TXD. When active, to transmitting is
        possible.
        zset BREAK to {}rc�inactiveN)	r�rr�rrl�_break_stater�SET_CONTROL_BREAK_ON�SET_CONTROL_BREAK_OFFrms rP�_update_break_statezSerial._update_break_state�sk��
�|�|�"�$�$��;�;��K�K���.�5�5�$�BS�BS�h�Yc�d�e�����$�$�%9�:��$�$�%:�;rhc�&�|js
t��|jr8|jjdj	|j
rdnd��|j
r|j
t�y|j
t�y)z*Set terminal status line: Request To Send.z
set RTS to {}rcr@N)	r�rr�rrl�
_rts_stater�SET_CONTROL_RTS_ON�SET_CONTROL_RTS_OFFrms rPr�zSerial._update_rts_state��d���|�|�"�$�$��;�;��K�K���_�3�3����H�U_�`�a��?�?��$�$�%7�8��$�$�%8�9rhc�&�|js
t��|jr8|jjdj	|j
rdnd��|j
r|j
t�y|j
t�y)z.Set terminal status line: Data Terminal Ready.z
set DTR to {}rcr@N)	r�rr�rrl�
_dtr_stater�SET_CONTROL_DTR_ON�SET_CONTROL_DTR_OFFrms rPr�zSerial._update_dtr_state�rIrhc�n�|js
t��t|j�tz�S)z)Read terminal status line: Clear To Send.)r�r�bool�get_modem_state�MODEMSTATE_MASK_CTSrms rP�ctsz
Serial.cts��.���|�|�"�$�$��D�(�(�*�-@�@�A�Arhc�n�|js
t��t|j�tz�S)z*Read terminal status line: Data Set Ready.)r�rrOrP�MODEMSTATE_MASK_DSRrms rP�dsrz
Serial.dsr�rSrhc�n�|js
t��t|j�tz�S)z*Read terminal status line: Ring Indicator.)r�rrOrP�MODEMSTATE_MASK_RIrms rP�riz	Serial.ri��.���|�|�"�$�$��D�(�(�*�-?�?�@�@rhc�n�|js
t��t|j�tz�S)z*Read terminal status line: Carrier Detect.)r�rrOrP�MODEMSTATE_MASK_CDrms rP�cdz	Serial.cd�rZrhc��|jS)z Get the current timeout setting.)r*rms rPr�zSerial.timeout�s���}�}�rhc��|�%	|dz|dkrtdj|���||_y#t$rtdj|���wxYw)zChange timeout setting.NrFzNot a valid timeout: {!r}r)�	TypeErrorrqrlr*�rer�s  rPr�zSerial.timeout�sh����
N��!����{� �!<�!C�!C�G�!L�M�M���
��	�
N� �!<�!C�!C�G�!L�M�M�
N�s	�0�$Ac���t}d}	|j�r	|jjd�}|s|jjd��nDt|�D�]'}|tk(r4|tk(rt}�|�||z
}�%|jj|��A|tk(r�|tk(r2|�
|tz
}n|jjt�t}��|tk(rt!�}t}��|t"k(r#|j%t'|��d}t}��|t(t*t,t.fvr	|}t0}��|j3|�t}��|t0k(s��|j5|�t}��*|jr��|jr|jjd�yy#tj
$rY���tj$r[}|jr*|jjdj|��|jjd�Yd}~��d}~wwxYw#|jr|jjd�wwxYw)zRead loop for the socket.Niz!socket error in reader thread: {}zread thread terminated)�M_NORMALr�r��recvr�r�r
r�r
rlr��putrr7�
M_IAC_SEEN�SBr)�SE�_telnet_process_subnegotiationr.r�r�r�r��M_NEGOTIATE�_telnet_process_command�_telnet_negotiate_option)re�moder�r1r$�byte�telnet_commands       rPr�zSerial._telnet_read_loop�s�����	�<	<��,�,���<�<�,�,�T�2�D���%�%�)�)�$�/��%�d�O�((�D��x�'��3�;�#-�D� )�4� )�T� 1�	� $� 1� 1� 5� 5�d� ;���+��3�;� )�4� )�S� 0�	� $� 1� 1� 5� 5�c� :�#+�D�!�R�Z�(1��I�#+�D�!�R�Z� �?�?��i�@P�Q�(,�I�#+�D�!�b�$��d�%;�;�-1�N�#.�D�!�8�8��>�#+�D���,��5�5�n�d�K�'��Q((�!�,�,�t�{�{����!�!�":�;���o�~�~����|�|���{�{����)�)�*M�*T�*T�UV�*W�X��%�%�)�)�$�/�����f�{�{����!�!�":�;��sG�
I�F?�D8I�-'I�?I�I�I�'AH=�8I�=I�I�*I/c�r�|jr+|jjdj|��yy�z1Process commands other than DO, DONT, WILL, WONT.zignoring Telnet command: {!r}N�r�rrlrrs  rPrkzSerial._telnet_process_command/�.���;�;��K�K��� ?� F� F�w� O�P�rhc�T�d}|jD]%}|j|k(s�|j|�d}�'|sp|tk(s	|tk(r]|j|tk(rtnt|�|jr+|jjdj|��yyyy�z&Process incoming DO, DONT, WILL, WONT.FTzrejected Telnet option: {!r}N�r�r]rtr�r�rpr�r�r�rrl�rersr]�known�items     rPrlzSerial._telnet_negotiate_option5������(�(�	�D��{�{�f�$��%�%�g�.���	���$��'�R�-��'�'��D���d�V�T��;�;��K�K�'�'�(F�(M�(M�f�(U�V��#0�rhc���|ddtk(�r�|ddtk(rct|�dk\rUt|dd�|_|j
�rn|j
j
dj|j��y
|ddtk(r}t|�dk\rot|dd�|_	|j
r4|j
j
dj|j��|jjd�y
|ddtk(rd|_
y
|ddtk(rd	|_
y
|jj!�D]3}|j"|ddk(s�|j%t'|dd
��y
|j
r+|j
j)dj|��y
y
y
|j
r+|j
j)dj|��y
y
)
�;Process subnegotiation, the data between IAC SB and IAC SE.rrFrErGzNOTIFY_LINESTATE: {}�NOTIFY_MODEMSTATE: {}r
TFNzignoring COM_PORT_OPTION: {!r}zignoring subnegotiation: {!r})r��SERVER_NOTIFY_LINESTATEr��ordr�r�rrl�SERVER_NOTIFY_MODEMSTATEr�r��restart�FLOWCONTROL_SUSPENDr��FLOWCONTROL_RESUMEr�rr}r�r.r)rer�rys   rPriz%Serial._telnet_process_subnegotiationHs����Q�q�>�_�,���1�~�!8�8�S��^�q�=P�"%�i��!�n�"5����;�;��K�K�$�$�%;�%B�%B�4�?�?�%S�T��1�Q��#;�;��I��RS�@S�#&�y��1�~�#6�� ��;�;��K�K�$�$�%<�%C�%C�D�DT�DT�%U�V��(�(�0�0��5��1�Q��#6�6�,0��)��1�Q��#5�5�,1��)� �1�1�8�8�:�`�D����)�A�a�.�8��)�)�%�	�!�"�
�*>�?��	`��{�{����+�+�,L�,S�,S�T]�,^�_�#�'�,�{�{����#�#�$C�$J�$J�9�$U�V�rhc�|�|j5|jj|�ddd�y#1swYyxYw)zGinternal socket write with no data escaping. used to send telnet stuff.N)r�r�r5)rer1s  rP�_internal_raw_writezSerial._internal_raw_writehs2��
�
�
�	'��L�L� � ��&�	'�	'�	'�s�2�;c�:�|jt|z|z�y�zSend DO, DONT, WILL, WONT.N)r�r7�re�actionr]s   rPrpzSerial.telnet_send_optionms��� � ��v���!6�7rhc��|jtt�}|jttzt
z|z|ztztz�y)z%Subnegotiation of RFC2217 parameters.N)r6r7r8r�rgr�rh�rer]r|s   rPr�z"Serial.rfc2217_send_subnegotiationqs>���
�
�c�;�/��� � ��r��O�!;�f�!D�u�!L�s�!R�UW�!W�Xrhc�z�|jd}|j|�|j|j�y)z~        Send purge request to the remote.
        (PURGE_RECEIVE_BUFFER / PURGE_TRANSMIT_BUFFER / PURGE_BOTH_BUFFERS)
        r�N)r�r�r�r��rer|rys   rPr;zSerial.rfc2217_send_purgevs1��
�$�$�W�-��������	�	�$�'�'�(rhc��|jd}|j|�|jrtjd�y|j|j�y)z)transmit change of control line to remoter�g�������?N)r�r�r�r�r�r�r�r�s   rPrzSerial.rfc2217_set_controlsE���$�$�Y�/��������*�*�
�J�J�s�O��I�I�d�+�+�,rhc��y)z`        check if server is ready to receive data. block for some time when
        not.
        NrKrms rP�rfc2217_flow_server_readyz Serial.rfc2217_flow_server_ready�s�rhc�t�|jr�|jj�r�|jr|jj	d�|jt�t|j�}|j�sAtjd�|jj�sn8|j�s�A|jr|jjd�|j�3|jr|jj	d�|jStd��)z�        get last modem state (cached value. If value is "old", request a new
        one. This cache helps that we don't issue to many requests when e.g. all
        status lines, one after the other is queried by the user (CTS, DSR
        etc.)
        zpolling modem stater�zpoll for modem state failedzusing cached modem statez!remote sends no NOTIFY_MODEMSTATE)r�r�r�r�r
r��NOTIFY_MODEMSTATEr	r�r�r�rr�rras  rPrPzSerial.get_modem_state�s����!�!�d�&>�&>�&F�&F�&H��{�{����!�!�"7�8��,�,�->�?��d�3�3�4�G��o�o�'��
�
�4� ��/�/�7�7�9���o�o�'��;�;��K�K�'�'�(E�F�
���'��{�{����!�!�"<�=��#�#�#�"�"E�F�Frh)rF�rh)%rurvrwrx�	BAUDRATESrgr�r�r�r�r�r'r3r9r�r�rDr�r�rRrVrYr]r��setterr�rkrlrir�rpr�r;rr�rP�
__classcell__)r�s@rPr�r�zs%���F�4�I�6�$_�B*F�X�"!,�J�)��)��0
�)�7�<�	:�	:��B��B��B��B��A��A��A��A�����
�^�^�	 ��	 � @<�HQ�W�&W�@'�
8�Y�
)�
-��!Grhr�c�R�eZdZdZd
d�Zd�Zd�Zdd�Zdd�Zd�Z	d	�Z
d
�Zd�Zd�Z
y)�PortManagerz�    This class manages the state of Telnet and RFC 2217. It needs a serial
    instance and a connection to work with. Connection is expected to implement
    a (thread safe) write function, that writes the string to the network.
    Nc���||_||_||_d|_t|_d|_d|_d|_d|_	d|_
t|dttttt t"�t|dt$tttt t"�t|dt$tt ttt&�t|dt(tttt t&�t|dt(tt ttt"�t|d	t*tttt t"|j,�	t|d
t*tt ttt&|j,�	g|_|jr|jj1d�|j.D];}|j2t"us�|j5|j6|j8��=y)NF�rr�r�r�r�r�r�r�z*requesting initial Telnet/RFC 2217 options)�serialr[r��_client_is_rfc2217rcrmr�ro�modemstate_mask�last_modemstate�
linstate_maskrYr�r�r�r�r�rTr�rVr�r��
_client_okr�r
rbrpr^r])re�serial_portr[r�r]s     rPrgzPortManager.__init__�sc��!���$������"'�����	����"��� #���#������
��v�t�T�4��T�9�M���x��d�D�"�d�I�N���z�3��D�$��h�O���{�F�D�$��D�(�S���}�f�b�$��d�I�V���|�_�d�D�"�d�T]�_c�_n�_n�o���~���D�$�PT�V^�`d�`o�`o�p� 
����;�;��K�K���J�K��*�*�	H�F��|�|�y�(��'�'�������G�	Hrhc��d|_|jr|jjd�|jd��y)a        callback of telnet option. It gets called when option is activated.
        This one here is used to detect when the client agrees on RFC 2217. A
        flag is set so that other functions like check_modem_lines know if the
        client is OK.
        Tzclient accepts RFC 2217��force_notificationN)r�r�r�check_modem_linesrms rPr�zPortManager._client_ok�s9��#'����;�;��K�K���6�7�	
���$��7rhc�N�|jjt|z|z�yr�)r[r9r7r�s   rPrpzPortManager.telnet_send_option�s�������c�F�l�V�3�4rhc��|jtt�}|jj	tt
ztz|z|ztztz�y)z&Subnegotiation of RFC 2217 parameters.N)r6r7r8r[r9rgr�rhr�s   rPr�z'PortManager.rfc2217_send_subnegotiation�sB���
�
�c�;�/�������c�B�h��8�6�A�E�I�C�O�RT�T�Urhc���|jjxrt|jjxrtz|jj
xrtz|jjxrtz}||jxsdz}|tzr	|tz}|tzr	|tz}|tzr	|tz}|tzr	|tz}||jk7s|r�|jr||jzs|rc|j!t"t%||jzg��|j&r*|j&j)dj+|��|dz|_	yy)z�        read control lines from serial port and compare the last value sent to remote.
        send updates on changes.
        rr}��N)r�rRrQrVrUrYrXr]r\r��MODEMSTATE_MASK_CTS_CHANGE�MODEMSTATE_MASK_DSR_CHANGE�MODEMSTATE_MASK_RI_CHANGE�MODEMSTATE_MASK_CD_CHANGEr�r�r�r�rr�rrl)rer��
modemstate�deltass    rPr�zPortManager.check_modem_linessU���[�[�_�_�
4�!4�
�[�[�_�_�
4�!4�
6�
�[�[�^�^�
2� 2�
4��[�[�^�^�
2� 2�
4�	��t�3�3�8�q�9���'�'��4�4�J��'�'��4�4�J��&�&��3�3�J��&�&��3�3�J���-�-�-�1C��'�'�Z�$�:N�:N�-N�Tf��0�0�,��j�4�+?�+?�?�@�A�C��;�;��K�K�$�$�%<�%C�%C�J�%O�P�$.��#4�D� �2Drhc#�hK�t|�D] }|tk(rt��t���|���"y�w)z�        This generator function is for the user. All outgoing data has to be
        properly escaped, so that no IAC character in the data stream messes up
        the Telnet state machine in the server.

        socket.sendall(escape(data))
        N)rr7�rer1rns   rP�escapezPortManager.escape(s1�����d�O�	�D��s�{��	��	��
�	�s�02c#�@K�t|�D�]�}|jtk(r<|tk(rt|_�,|j
�|xj
|z
c_�N|���S|jtk(r�|tk(r2|j
�|xj
|z
c_n|��t|_��|tk(rt�|_t|_��|tk(r8|jt|j
��d|_t|_��|ttttfvr||_t |_��2|j#|�t|_��P|jt k(s��e|j%|j|�t|_���y�w)a�        Handle a bunch of incoming bytes. This is a generator. It will yield
        all characters not of interest for Telnet/RFC 2217.

        The idea is that the reader thread pushes data from the socket through
        this filter:

        for byte in filter(socket.recv(1024)):
            # do things like CR/LF conversion/whatever
            # and write data to the serial port
            serial.write(byte)

        (socket error handling code left as exercise for the reader)
        N)rrmrcr7rfr�rgr)rhrir.r�r�r�r�rorjrkrlr�s   rP�filterzPortManager.filter9s1�����d�O�(	%�D��y�y�H�$��3�;� *�D�I��~�~�1����$�.��"�
����j�(��3�;��~�~�1����$�.��"�
� (�D�I��R�Z�%.�[�D�N� (�D�I��R�Z��7�7��d�n�n�8M�N�%)�D�N� (�D�I��b�$��d�3�3�*.�D�'� +�D�I��0�0��6� (�D�I����k�)��-�-�d�.A�.A�4�H�$��	�Q(	%�s�E/F�3+Fc�r�|jr+|jjdj|��yyrqrrrrs  rPrkz#PortManager._telnet_process_commandtrsrhc�T�d}|jD]%}|j|k(s�|j|�d}�'|sp|tk(s	|tk(r]|j|tk(rtnt|�|jr+|jjdj|��yyyyrurvrws     rPrlz$PortManager._telnet_negotiate_optionzrzrhc	��|ddtk(�r|jr*|jjdj|��|ddtk(r�|j
j}	tjd|dd�\}|dk7r||j
_|jrD|jjdj|rdnd	|j
j��	|jttjd|j
j��y|ddtk(r�|j
j }	tjd|dd
�\}|dk7r||j
_|jrD|jjdj|rdnd	|j
j ��	|jt"tjd|j
j ��y|ddt$k(r�|j
j&}	tjd|dd
�d}|dk7rt(||j
_|jrD|jjdj|rdnd	|j
j&��	|jt*tjdt,|j
j&��y|ddt.k(r�|j
j0}	tjd|dd
�d}|dk7rt2||j
_|jrD|jjdj|rdnd	|j
j0��	|jt4tjdt6|j
j0��y|ddt8k(�r�|dd
t:k(r}|j
j<r|jt>t@�y|j
jBr|jt>tD�y|jt>tF�y|dd
tFk(rdd|j
_d|j
_!|jr|jjd�|jt>tF�y|dd
t@k(rSd|j
_|jr|jjd�|jt>t@�y|dd
tDk(rSd|j
_!|jr|jjd�|jt>tD�y|dd
tHk(r(|jr|jjKd�y|dd
tLk(rSd|j
_'|jr|jjd�|jt>tL�y|dd
tPk(rSd|j
_'|jr|jjd�|jt>tP�y|dd
tRk(r(|jr|jjKd�y|dd
tTk(rSd|j
_+|jr|jjd�|jt>tT�y|dd
tXk(rSd|j
_+|jr|jjd�|jt>tX�y|dd
tZk(r(|jr|jjKd�y|dd
t\k(rSd|j
_/|jr|jjd �|jt>t\�y|dd
t`k(�r�d|j
_/|jr|jjd!�|jt>t`�y|ddtbk(r!|jtdtgdg��y|ddthk(r:|jr|jjd"�|jkd�#�y|ddtlk(r/|jr|jjd$�d|_7y|ddtpk(r/|jr|jjd%�d|_7y|ddtrk(rUtu|dd
�|_;|j�r~|jjd&j|jv��y|ddtxk(rUtu|dd
�|_=|j�r|jjd'j|jz��y|ddt|k(�r�|dd
t~k(r\|j
j��|jr|jjd(�|jt�t~�y|dd
t�k(r\|j
j��|jr|jjd)�|jt�t��y|dd
t�k(rv|j
j��|j
j��|jr|jjd*�|jt�t��y|jr{|jjd+jt�|dd���y|jr7|jjd,jt�|dd���yyyyyy|jr+|jjKd-j|��yy#t$rR}|jr*|jjd
j|��||j
_Yd}~���d}~wwxYw#t$rR}|jr*|jjdj|��||j
_Yd}~��?d}~wwxYw#t$rR}|jr*|jjdj|��||j
_Yd}~�
��d}~wwxYw#t$rR}|jr*|jjdj|��||j
_Yd}~�
�d}~wwxYw).r|rrFzreceived COM_PORT_OPTION: {!r}rEr��z{} baud rate: {}r�r,zfailed to set baud rate: {}Nr�rGz{} data size: {}zfailed to set data size: {}z
{} parity: {}zfailed to set parity: {}z{} stop bits: {}zfailed to set stop bits: {}Fzchanged flow control to NoneTz changed flow control to XON/XOFFzchanged flow control to RTS/CTSz'requested break state - not implementedzchanged BREAK to activezchanged BREAK to inactivez%requested DTR state - not implementedzchanged DTR to activezchanged DTR to inactivez%requested RTS state - not implementedzchanged RTS to activezchanged RTS to inactivezrequest for modem stater��suspend�resumezline state mask: 0x{:02x}zmodem state mask: 0x{:02x}zpurge inz	purge outz
purge bothzundefined PURGE_DATA: {!r}zundefined COM_PORT_OPTION: {!r}zunknown subnegotiation: {!r})Fr�r�r
rlr�r�r�r��unpackrrqr
r�r�r�r��bytesizer�r�r��RFC2217_REVERSE_PARITY_MAPr�rr��stopbits�RFC2217_REVERSE_STOPBIT_MAPr�rr��SET_CONTROL_REQ_FLOW_SETTING�xonxoffr�r�rtsctsrr	�SET_CONTROL_REQ_BREAK_STATErrB�break_conditionrC�SET_CONTROL_REQ_DTRrL�dtrrM�SET_CONTROL_REQ_RTSrG�rtsrH�NOTIFY_LINESTATEr~rr�r�r�r�r��SET_LINESTATE_MASKrr��SET_MODEMSTATE_MASKr�r�r<r�r�r>r��PURGE_BOTH_BUFFERS�list)rer��backupr�r$r�r�r�s        rPriz*PortManager._telnet_process_subnegotiation�s�
���Q�q�>�_�,��{�{����!�!�"B�"I�"I�)�"T�U���1�~��-����-�-��
x�"(�-�-��y��1�~�"F�K�X��1�}�/7����,��{�{����(�(�);�)B�)B�H�5�Z_�ae�al�al�au�au�)v�w��0�0�1D�f�k�k�RW�Y]�Yd�Yd�Ym�Ym�Fn�o��1�Q��<�/����-�-��
x�"(�-�-��y��1�~�"F�K�X��1�}�/7����,��{�{����(�(�);�)B�)B�H�5�Z_�ae�al�al�au�au�)v�w��0�0�1D�f�k�k�RW�Y]�Yd�Yd�Ym�Ym�Fn�o��1�Q��:�-����+�+��
q�#�]�]�5�)�A�a�.�A�!�D�F���{�-G��-O����*��{�{����(�(��)?�)?���UZ�\`�\g�\g�\n�\n�)o�p��0�0�%��K�K��'9�$�+�+�:L�:L�'M�N�P��1�Q��<�/����-�-��
x�%�}�}�U�I�a��N�C�A�F�H��1�}�/J�8�/T����,��{�{����(�(�);�)B�)B�H�5�Z_�ae�al�al�au�au�)v�w��0�0�'��K�K��':�4�;�;�;O�;O�'P�Q�S��1�Q��;�.��Q�q�>�%A�A��{�{�*�*��8�8�9K�Ml�m����+�+��8�8�9K�Ml�m��8�8�9K�Ml�m��q��^�'F�F�*/�D�K�K�'�).�D�K�K�&��{�{����(�(�)G�H��4�4�5G�Ih�i��q��^�'F�F�*.�D�K�K�'��{�{����(�(�)K�L��4�4�5G�Ih�i��q��^�'F�F�)-�D�K�K�&��{�{����(�(�)J�K��4�4�5G�Ih�i��q��^�'B�B��{�{����+�+�,U�V���q��^�';�;�26�D�K�K�/��{�{����(�(�)B�C��4�4�5G�I]�^��q��^�'<�<�27�D�K�K�/��{�{����(�(�)D�E��4�4�5G�I^�_��q��^�':�:��{�{����+�+�,S�T���q��^�'9�9�&*�D�K�K�O��{�{����(�(�)@�A��4�4�5G�I[�\��q��^�':�:�&+�D�K�K�O��{�{����(�(�)B�C��4�4�5G�I\�]��q��^�':�:��{�{����+�+�,S�T���q��^�'9�9�&*�D�K�K�O��{�{����(�(�)@�A��4�4�5G�I[�\��q��^�':�:�&+�D�K�K�O��{�{����(�(�)B�C��4�4�5G�I\�]��1�Q��#3�3��0�0�+��a�S�M�#��1�Q��#4�4��;�;��K�K�$�$�%>�?��&�&�$�&�?��1�Q��#6�6��;�;��K�K�$�$�Y�/�,0��)��1�Q��#5�5��;�;��K�K�$�$�X�.�,1��)��1�Q��#5�5�%(��1�Q��%8��"��;�;��K�K�$�$�%@�%G�%G��HZ�HZ�%[�\��1�Q��#6�6�'*�9�Q�q�>�':��$��;�;��K�K�$�$�%A�%H�%H��I]�I]�%^�_��1�Q��:�-��Q�q�>�%9�9��K�K�2�2�4��{�{����(�(��4��4�4�5F�H\�]��q��^�'<�<��K�K�3�3�5��{�{����(�(��5��4�4�5F�H]�^��q��^�'9�9��K�K�2�2�4��K�K�3�3�5��{�{����(�(��6��4�4�5F�HZ�[��{�{����)�)�*F�*M�*M�d�S\�]^�]_�S`�Na�*b�c��;�;��K�K�%�%�&G�&N�&N�t�T]�^_�^`�Ta�Ob�&c�d��#�)�	�A;�|�{�{����#�#�$B�$I�$I�)�$T�U���e"�2��{�{����)�)�*G�*N�*N�q�*Q�R�+1�D�K�K�(�(��2��"�2��{�{����)�)�*G�*N�*N�q�*Q�R�+1�D�K�K�(�(��2��"�0��{�{����)�)�*D�*K�*K�A�*N�O�)/�D�K�K�&�&��0�� "�2��{�{����)�)�*G�*N�*N�q�*Q�R�+1�D�K�K�(�(��2�sd�'1q�
1r4�-9t�9u0�	r1�Ar,�,r1�4	t�=At
�
t�	u-�Au(�(u-�0	w�9Aw�wrJr�)F)rurvrwrxrgr�rpr�r�r�r�rkrlrirKrhrPr�r��sB��� H�F8�(5�V� 5�H
�"7%�vQ�W�&~Vrhr��__main__zrfc2217://localhost:7000r�z{}
z	write...
shello
z	read: {}
)��
__future__rrr�r�r�r�r�ImportError�urllib.parse�parser��queuer��serial.serialutilrrrrrr	�DEBUG�INFO�WARNING�ERRORrrh�NOP�DM�BRK�IP�AO�AYT�EC�EL�GArgr�r�r�r�r7r8r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r~r��SERVER_FLOWCONTROL_SUSPEND�SERVER_FLOWCONTROL_RESUME�SERVER_SET_LINESTATE_MASK�SERVER_SET_MODEMSTATE_MASKr��RFC2217_ANSWER_MAPr�r	rrr�rBrCr�rLrMr�rGrH�SET_CONTROL_REQ_FLOW_SETTING_IN�"SET_CONTROL_USE_NO_FLOW_CONTROL_IN�!SET_CONTROL_USE_SW_FLOW_CONTOL_IN�!SET_CONTROL_USE_HW_FLOW_CONTOL_IN� SET_CONTROL_USE_DCD_FLOW_CONTROL� SET_CONTROL_USE_DTR_FLOW_CONTROL� SET_CONTROL_USE_DSR_FLOW_CONTROL�LINESTATE_MASK_TIMEOUT�LINESTATE_MASK_SHIFTREG_EMPTY�LINESTATE_MASK_TRANSREG_EMPTY�LINESTATE_MASK_BREAK_DETECT�LINESTATE_MASK_FRAMING_ERROR�LINESTATE_MASK_PARTIY_ERROR�LINESTATE_MASK_OVERRUN_ERROR�LINESTATE_MASK_DATA_READYr\rXrUrQr�r�r�r�r<r>r��PARITY_NONE�
PARITY_ODD�PARITY_EVEN�PARITY_MARK�PARITY_SPACEr�dictr
r��STOPBITS_ONE�STOPBITS_ONE_POINT_FIVE�STOPBITS_TWOrr�rcrfrjrTrUrVrW�objectrYrzr�r�ru�sys�s�stdoutr9rl�flushr3r�rKrhrP�<module>rsb��z'��
�
���$�����)�)��]�]��L�L����
�]�]�	�
�
��
����
������
������������������
����
����
��������
�
�����������������
�
�����������!��"��$��#��#��$�����%��%��!��%��#��-��/��3��1��1��3��!�
�� '��")��")��")��%������������������")��%,�"�$+�!�$+�!�#*� �#*� �#*� ��� "�� "�� �� ���� ��������������������������
����
���q�
����
����
������"�!P�5G�5M�5M�5O�!P�P������
�"�"�A�
������
#�"R�6I�6O�6O�6Q�"R�R��
��
�
���
�	�	����#��CN�6�CN�LDp�6�Dp�NzG�Z�zG�@QV�&�QV�j�z����)�6�2�A��J�J���V�]�]�1�%�&��J�J���\�"��G�G�J���G�G�I��J�J���\�(�(������3�4��G�G�I���S(�$�#�#�$������s"�K�K#�K �K �#	K0�/K0
¿Qué es la limpieza dental de perros? - Clínica veterinaria


Es la eliminación del sarro y la placa adherida a la superficie de los dientes mediante un equipo de ultrasonidos que garantiza la integridad de las piezas dentales a la vez que elimina en profundidad cualquier resto de suciedad.

A continuación se procede al pulido de los dientes mediante una fresa especial que elimina la placa bacteriana y devuelve a los dientes el aspecto sano que deben tener.

Una vez terminado todo el proceso, se mantiene al perro en observación hasta que se despierta de la anestesia, bajo la atenta supervisión de un veterinario.

¿Cada cuánto tiempo tengo que hacerle una limpieza dental a mi perro?

A partir de cierta edad, los perros pueden necesitar una limpieza dental anual o bianual. Depende de cada caso. En líneas generales, puede decirse que los perros de razas pequeñas suelen acumular más sarro y suelen necesitar una atención mayor en cuanto a higiene dental.


Riesgos de una mala higiene


Los riesgos más evidentes de una mala higiene dental en los perros son los siguientes:

  • Cuando la acumulación de sarro no se trata, se puede producir una inflamación y retracción de las encías que puede descalzar el diente y provocar caídas.
  • Mal aliento (halitosis).
  • Sarro perros
  • Puede ir a más
  • Las bacterias de la placa pueden trasladarse a través del torrente circulatorio a órganos vitales como el corazón ocasionando problemas de endocarditis en las válvulas. Las bacterias pueden incluso acantonarse en huesos (La osteomielitis es la infección ósea, tanto cortical como medular) provocando mucho dolor y una artritis séptica).

¿Cómo se forma el sarro?

El sarro es la calcificación de la placa dental. Los restos de alimentos, junto con las bacterias presentes en la boca, van a formar la placa bacteriana o placa dental. Si la placa no se retira, al mezclarse con la saliva y los minerales presentes en ella, reaccionará formando una costra. La placa se calcifica y se forma el sarro.

El sarro, cuando se forma, es de color blanquecino pero a medida que pasa el tiempo se va poniendo amarillo y luego marrón.

Síntomas de una pobre higiene dental
La señal más obvia de una mala salud dental canina es el mal aliento.

Sin embargo, a veces no es tan fácil de detectar
Y hay perros que no se dejan abrir la boca por su dueño. Por ejemplo…

Recientemente nos trajeron a la clínica a un perro que parpadeaba de un ojo y decía su dueño que le picaba un lado de la cara. Tenía molestias y dificultad para comer, lo que había llevado a sus dueños a comprarle comida blanda (que suele ser un poco más cara y llevar más contenido en grasa) durante medio año. Después de una exploración oftalmológica, nos dimos cuenta de que el ojo tenía una úlcera en la córnea probablemente de rascarse . Además, el canto lateral del ojo estaba inflamado. Tenía lo que en humanos llamamos flemón pero como era un perro de pelo largo, no se le notaba a simple vista. Al abrirle la boca nos llamó la atención el ver una muela llena de sarro. Le realizamos una radiografía y encontramos una fístula que llegaba hasta la parte inferior del ojo.

Le tuvimos que extraer la muela. Tras esto, el ojo se curó completamente con unos colirios y una lentilla protectora de úlcera. Afortunadamente, la úlcera no profundizó y no perforó el ojo. Ahora el perro come perfectamente a pesar de haber perdido una muela.

¿Cómo mantener la higiene dental de tu perro?
Hay varias maneras de prevenir problemas derivados de la salud dental de tu perro.

Limpiezas de dientes en casa
Es recomendable limpiar los dientes de tu perro semanal o diariamente si se puede. Existe una gran variedad de productos que se pueden utilizar:

Pastas de dientes.
Cepillos de dientes o dedales para el dedo índice, que hacen más fácil la limpieza.
Colutorios para echar en agua de bebida o directamente sobre el diente en líquido o en spray.

En la Clínica Tus Veterinarios enseñamos a nuestros clientes a tomar el hábito de limpiar los dientes de sus perros desde que son cachorros. Esto responde a nuestro compromiso con la prevención de enfermedades caninas.

Hoy en día tenemos muchos clientes que limpian los dientes todos los días a su mascota, y como resultado, se ahorran el dinero de hacer limpiezas dentales profesionales y consiguen una mejor salud de su perro.


Limpiezas dentales profesionales de perros y gatos

Recomendamos hacer una limpieza dental especializada anualmente. La realizamos con un aparato de ultrasonidos que utiliza agua para quitar el sarro. Después, procedemos a pulir los dientes con un cepillo de alta velocidad y una pasta especial. Hacemos esto para proteger el esmalte.

La frecuencia de limpiezas dentales necesaria varía mucho entre razas. En general, las razas grandes tienen buena calidad de esmalte, por lo que no necesitan hacerlo tan a menudo e incluso pueden pasarse la vida sin requerir una limpieza. Sin embargo, razas pequeñas como el Yorkshire o el Maltés, deben hacérselas todos los años desde cachorros si se quiere conservar sus piezas dentales.

Otro factor fundamental es la calidad del pienso. Algunas marcas han diseñado croquetas que limpian la superficie del diente y de la muela al masticarse.

Ultrasonido para perros

¿Se necesita anestesia para las limpiezas dentales de perros y gatos?

La limpieza dental en perros no es una técnica que pueda practicarse sin anestesia general , aunque hay veces que los propietarios no quieren anestesiar y si tiene poco sarro y el perro es muy bueno se puede intentar…… , pero no se va a poder pulir ni acceder a todas la zona de la boca …. Además los limpiadores dentales van a irrigar agua y hay riesgo de aspiración a vías respiratorias si no se realiza una anestesia correcta con intubación traqueal . En resumen , sin anestesia no se va hacer una correcta limpieza dental.

Tampoco sirve la sedación ya que necesitamos que el animal esté totalmente quieto, y el veterinario tenga un acceso completo a todas sus piezas dentales y encías.

Alimentos para la limpieza dental

Hay que tener cierto cuidado a la hora de comprar determinados alimentos porque no todos son saludables. Algunos tienen demasiado contenido graso, que en exceso puede causar problemas cardiovasculares y obesidad.

Los mejores alimentos para los dientes son aquellos que están elaborados por empresas farmacéuticas y llevan componentes químicos con tratamientos específicos para el diente del perro. Esto implica no solo limpieza a través de la acción mecánica de morder sino también un tratamiento antibacteriano para prevenir el sarro.

Conclusión

Si eres como la mayoría de dueños, por falta de tiempo , es probable que no estés prestando la suficiente atención a la limpieza dental de tu perro. Por eso te animamos a que comiences a limpiar los dientes de tu perro y consideres atender a su higiene bucal con frecuencia.

Estas simples medidas pueden conllevar a que tu perro tenga una vida más larga y mucho más saludable.

Si te resulta imposible introducir un cepillo de dientes a tu perro en la boca, pásate con él por clínica Tus Veterinarios y te explicamos cómo hacerlo.

Necesitas hacer una limpieza dental profesional a tu mascota?
Llámanos al 622575274 o contacta con nosotros

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

¡Hola!