�
p�1c�� � �� � d dl mZ d dlZd dlZd dlZd dlZd dlZ d dlZn# e$ r d dl m
Z Y nw xY w d dlZn# e$ r d dlZY nw xY wd dl
Z
d dlmZmZmZmZmZmZ ej ej ej ej d�ZdZdZdZdZd Zd
ZdZ dZ!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:eFiZGdZHdZIdZJdZKdZLdZMdZNdZOdZPd ZQd!ZRd"ZSd#ZTd0ZUd1ZVd2ZWd3ZXd4ZYd5ZZd6Z[d7Z\d8Z]d9Z^d:Z_d;Z`d<Zad=Zbd>Zcd7Zdd8Zed9Zfd:Zgd;Zhd<Zid=Zjd>ZkdZldZmdZne
jo d>e
jp d=e
jq d?e
jr d<e
js d@iZt eudA� et�v � � D � � � � Zwe
jx d>e
jy d?e
jz d=iZ{ eudB� e{�v � � D � � � � Z|d Z}d>Z~d=ZdCZ�dDZ�dEZ�dFZ� G dG� dHe�� � Z� G dI� dJe�� � Z� G dK� dLe� � Z� G dM� dNe�� � Z�e�dOk r�d dl�Z� e�dPdQ� � Z�e�j� �� dR�� e�� � � � e�j� �� dS� � e��� dT� � e��� � � e�j� �� dU�� e��� d@� � � � � � e��� � � dS dS )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 � | ]\ }}||fV � �d S �N� ��.0�k�vs �0/usr/lib/python3/dist-packages/serial/rfc2217.py� <genexpr>rQ � s* � � � �!P�!P�T�Q��1�a�&�!P�!P�!P�!P�!P�!P� c # �$ K � | ]\ }}||fV � �d S rJ rK rL s rP rQ rQ � s* � � � �"R�"R�d�a��A�q�6�"R�"R�"R�"R�"R�"RrR � REQUESTED�ACTIVE�INACTIVE�REALLY_INACTIVEc �( � e Zd ZdZ dd�Zd� Zd� ZdS )�TelnetOptionz@Manage a single telnet option, keeps track of DO/DONT WILL/WONT.Nc
� � || _ || _ || _ || _ || _ || _ || _ || _ d| _ | | _ dS )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_staterd s
rP �__init__zTelnetOption.__init__� sQ � � %����� ���� ��
����������"��
����#6�� � � rR c �. � d� | �� � S )zString for debug outputsz{o.name}:{o.active}({o.state}))�o��format�re s rP �__repr__zTelnetOption.__repr__ s � �/�6�6��6�>�>�>rR c � � || j k �r| j t u r2t | _ d| _ | j �| � � � dS dS | j t u rdS | j t u rWt | _ | j � | j | j
� � d| _ | j �| � � � dS dS | j t u r'| j � | j | j
� � dS t d� | � � � � �|| j k r�| j t u rt | _ d| _ dS | j t u r:t | _ | j � | j | j
� � d| _ dS | j t u rdS | j t u rdS t d� | � � � � �dS )zo A DO/DONT/WILL/WONT was received for this option, update state and
answer when needed.
TNzoption in illegal state {!r}F)r` rb rT rU rc rd rV r[ �telnet_send_optionr^ r] rW r_ �
ValueErrorrk ra �re �commands rP �process_incomingzTelnetOption.process_incoming s� � �
�d�l�"�"��z�Y�&�&�#��
�"����+�7��,�,�.�.�.�.�.� 8�7���v�%�%�����x�'�'�#��
���2�2�4�=�$�+�N�N�N�"����+�7��,�,�.�.�.�.�.� 8�7����.�.���2�2�4�<���M�M�M�M�M� �!?�!F�!F�t�!L�!L�M�M�M�
���
#�
#��z�Y�&�&�%��
�#�������v�%�%�%��
���2�2�4�<���M�M�M�#�������x�'�'������.�.��� �!?�!F�!F�t�!L�!L�M�M�M� $�
#rR rJ )�__name__�
__module__�__qualname__�__doc__rg rm rs rK rR rP rY rY � sW � � � � � �J�J� =A�7� 7� 7� 7�0?� ?� ?�$N� $N� $N� $N� $NrR rY c �P � e Zd ZdZd
d�Zd� Zd� Zd� Z ee� � Z dd�Z
d � ZdS )�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 �l � |�|}|| _ || _ || _ d | _ || _ t
| _ d S rJ )r[ r\ r] �value�
ack_optionrV rb )re r[ r\ r] r| s rP rg zTelnetSubnegotiation.__init__9 s; � ����J�$����� ������
�$�����
�
�
rR c �. � d� | �� � S )zString for debug outputs.z{sn.name}:{sn.state})�snrj rl s rP rm zTelnetSubnegotiation.__repr__C s � �%�,�,��,�5�5�5rR c � � || _ t | _ | j � | j | j � � | j j r?| j j � d� | j | j � � � � dS dS )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{ rT rb r[ �rfc2217_send_subnegotiationr] �loggerr
rk r\ )re r{ s rP �setzTelnetSubnegotiation.setG s~ � � ��
���
���3�3�D�K���L�L�L��?�!� c��O�"�(�(�)C�)J�)J�4�9�VZ�V`�)a�)a�b�b�b�b�b� c� crR c � � | j t k r't d� | j � � � � �| j t
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})rb rW rp rk r\ rU rl s rP �is_readyzTelnetSubnegotiation.is_readyS s= � �
�:��(�(��D�K�K�D�I�V�V�W�W�W��z�V�#�#rR rG c � � t |� � }|� � � s>t j d� � | � � � rdS |� � � �>t d� | 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� r rk r\ )re �timeout�
timeout_timers rP �waitzTelnetSubnegotiation.wait^ s� � � ��(�(�
��'�'�)�)� ]��J�t�����}�}���
��� �'�'�)�)� ]�
"�"I�"P�"P�QU�QZ�"[�"[�\�\�\rR c � � | j |dt | j � � � k r
t | _ nt | _ | j j r@| j j � d� | j || j � � � � dS dS )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{ �lenrU rb rW r[ r� r
rk r\ )re � suboptions rP �check_answerz!TelnetSubnegotiation.check_answerl s� � �
�:��#3�C��
�O�O�#3�4�4�4��D�J�J� )�D�J��?�!� p��O�"�(�(�)E�)L�)L�T�Y�Xa�cg�cm�)n�)n�o�o�o�o�o� p� prR rJ )rG )rt ru rv rw rg rm r� r� �propertyrc r� r� rK rR rP ry ry 3 s� � � � � � �� �
� � � �6� 6� 6�
c�
c�
c�$� $� $� �X�h�
�
�F�]� ]� ]� ]�p� p� p� p� prR ry c �R � � e Zd ZdZdZ� fd�Zd� Zd� Zd� Zd� Z e
d� � � Zd#d
�Zd� Z
d� Zd
� Zd� Zd� Zd� Ze
d� � � Ze
d� � � Ze
d� � � Ze
d� � � Ze
d� � � Zej d� � � 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, iX i� i i` i� i�% i K i � i � � � c �4 �� d | _ d | _ d| _ d | _ t d� � | _ d| _ d | _ d | _ d| _ d| _
d| _ d | _ d | _
d | _ d | _ t! t" |