404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@18.223.171.83: ~ $
3

M�]W���(@slddlZddlZddlZddlZddlZyddlZWnek
rRddljZYnXyddl	Z	Wnek
r|ddl
Z	YnXddlZddlm
Z
mZmZmZmZejejejejd�ZdZdZdZdZdZd	Zd
ZdZdZd
Z dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4d Z5d!Z6d"Z7d#Z8d$Z9d%Z:d&Z;d'Z<d(Z=d)Z>d*Z?d+Z@d,ZAd-ZBd.ZCe,e8e-e9e.e:e/e;e0e<e1e=e2e>e3e?e4e@e5eAe6eBe7eCiZDdZEdZFdZGdZHdZIdZJdZKdZLdZMdZNd ZOd!ZPd"ZQd/ZRd0ZSd1ZTd2ZUd3ZVd4ZWd5ZXd6ZYd7ZZd8Z[d9Z\d:Z]d;Z^d<Z_d=Z`d6Zad7Zbd8Zcd9Zdd:Zed;Zfd<Zgd=ZhdZidZjdZkejld=ejmd<ejnd>ejod;ejpd?iZqerd@dA�eqjs�D��Ztejud=ejvd>ejwd<iZxerdBdA�exjs�D��ZydZzd=Z{d<Z|dCZ}dDZ~dEZdFZ�GdGdH�dHe��Z�GdIdJ�dJe��Z�GdKdL�dLe
�Z�GdMdN�dNe��Z�e�dOk�rhddl�Z�e�dPdQ�Z�e�j�j�dRj�e���e�j�j�dS�e�j�dT�e�j��e�j�j�dUj�e�j�d?���e�j��dS)V�N)�
SerialBase�SerialException�to_bytes�	iterbytes�portNotOpenError)�debug�info�warning�error��������������������������������s������,�������	�
���e�f�g�h�i�j�k�l�m�n�o�p�
��������@� �������ccs|]\}}||fVqdS)N�)�.0�k�vrFrF�/usr/lib/python3.6/rfc2217.py�	<genexpr>�srKccs|]\}}||fVqdS)NrF)rGrHrIrFrFrJrK�s�	REQUESTED�ACTIVE�INACTIVE�REALLY_INACTIVEc@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
�TelnetOptionz@Manage a single telnet option, keeps track of DO/DONT WILL/WONT.Nc

Cs@||_||_||_||_||_||_||_||_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)
�selfrQrRrSrTrUrVrWZ
initial_staterZrFrFrJ�__init__�s
zTelnetOption.__init__cCsdj|d�S)zString for debug outputsz{o.name}:{o.active}({o.state}))�o)�format)r[rFrFrJ�__repr__szTelnetOption.__repr__cCs&||jkr�|jtkr4t|_d|_|jdk	r�|j�nt|jtkr@nh|jtkr|t|_|jj|j	|j
�d|_|jdk	r�|j�n,|jtkr�|jj|j|j
�nt
dj|���nx||jk�r"|jtkr�t|_d|_nT|jtkr�t|_|jj|j|j
�d|_n*|jtk�rn|jtk�rnt
dj|���dS)zo        A DO/DONT/WILL/WONT was received for this option, update state and
        answer when needed.
        TNzoption in illegal state {!r}F)rVrXrLrMrYrZrNrQ�telnet_send_optionrTrSrOrU�
ValueErrorr^rW)r[�commandrFrFrJ�process_incoming	s<










zTelnetOption.process_incoming)N)�__name__�
__module__�__qualname__�__doc__r\r_rcrFrFrFrJrP�s
rPc@sLeZdZdZddd�Zdd�Zdd�Zd	d
�Zee�Z	ddd
�Z
dd�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.
    NcCs4|dkr|}||_||_||_d|_||_t|_dS)N)rQrRrS�value�
ack_optionrNrX)r[rQrRrSrjrFrFrJr\6szTelnetSubnegotiation.__init__cCsdj|d�S)zString for debug outputs.z{sn.name}:{sn.state})Zsn)r^)r[rFrFrJr_@szTelnetSubnegotiation.__repr__cCsD||_t|_|jj|j|j�|jjr@|jjjdj|j	|j��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)
rirLrXrQ�rfc2217_send_subnegotiationrS�loggerrr^rR)r[rirFrFrJ�setDs
zTelnetSubnegotiation.setcCs$|jtkrtdj|j���|jtkS)z{        Check if answer from server has been received. when server rejects
        the change, raise a ValueError.
        z%remote rejected value for option {!r})rXrOrar^rRrM)r[rFrFrJ�is_readyPs
zTelnetSubnegotiation.is_readyrDcCsFtj�|}x4tj�|kr0tjd�|j�rPqWtdj|j���dS)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.
        g�������?z%timeout while waiting for option {!r}N)�time�sleeprnrr^rR)r[�timeout�timeout_timerFrFrJ�wait[s
zTelnetSubnegotiation.waitcCsN|j|dt|j��kr t|_nt|_|jjrJ|jjjdj|j	||j��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} -> {})
ri�lenrMrXrOrQrlrr^rR)r[�	suboptionrFrFrJ�check_answeris
z!TelnetSubnegotiation.check_answer)N)rD)rdrerfrgr\r_rmrn�propertyrYrsrvrFrFrFrJrh0s

	
rhcseZdZdZdMZ�fdd�Zdd�Zdd�Zdd�Zdd�Z	e
dd��ZdNd d!�Zd"d#�Z
d$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Ze
d.d/��Ze
d0d1��Ze
d2d3��Ze
d4d5��Zd6d7�Zd8d9�Zd:d;�Zd<d=�Zd>d?�Zd@dA�ZdOdCdD�ZdEdF�ZdGdH�ZdIdJ�Z dKdL�Z!�Z"S)P�Serialz<Serial port implementation for RFC 2217 remote serial ports.�2�K�n�����,�X���`	��%�K������csptt|�j||�d|_d|_d|_d|_d|_d|_d|_	d|_
d|_d|_d|_
d|_d|_d|_d|_dS)NrFrD)�superrxr\�_thread�_socket�
_linestate�_modemstate�_modemstate_expires�_remote_suspend_flow�_write_lockrl�_ignore_set_control_answer�_poll_modem_state�_network_timeout�_telnet_options�_rfc2217_port_settings�_rfc2217_options�_read_buffer)r[�args�kwargs)�	__class__rFrJr\}s zSerial.__init__cCsd|_d|_d|_d|_|jdkr*td��|jr8td��y0tj|j	|j
�dd�|_|jjtj
tjd�Wn:tk
r�}zd|_td	j|j
|���WYdd}~XnXtj�|_tj�|_t|d
tttttt�t|dtttttt�g}t|dtttttt�t|d
t ttttt�t|dt ttttt�t|dtttttt�t|dtttttt�g||_!t"|dt#t$�t"|dt%t&�t"|dt't(�t"|dt)t*�d�|_+t"|dt,t-�t"|dt.t/�d�|_0|j0j1|j+�d|_2d|_3d|_4d|_5d|_tj6|j7d�|_8|j8j9d�|j8j:dj|j��|j8j;�y�x,|j!D]"}|j<tk�r|j=|j>|j?��qWt@j@�|j}xTt@j@�|k�r�t@jAd�tBdd�|D��tBd d�|D��k�rPP�qPWtd!j|���|j�r�|jjCd"j|j!��|jD�|jE�s�|jF�|jG�s�|jH�|jI�|jJ�Wn|jK��YnXdS)#zx        Open port with current settings. This may throw a SerialException
        if the port cannot be opened.
        NFrDz.Port must be configured before it can be used.zPort is already open.rE)rqrCzCould not open port {}: {}z	we-BINARYz
we-RFC2217�ECHOzwe-SGAzthey-SGAzthey-BINARYzthey-RFC2217�baudrate�datasize�parity�stopsize)r�r�r�r��purge�control)r�r�rT)�targetz&pySerial RFC 2217 reader thread for {}g�������?css|]}|jVqdS)N)rY)rGr]rFrFrJrK�szSerial.open.<locals>.<genexpr>css|]}|jtkVqdS)N)rXrN)rGr]rFrFrJrK�sz;Remote does not seem to support RFC2217 or BINARY mode {!r}zNegotiated options: {})Lrlr�r�r�Z_portr�is_open�socketZcreate_connection�from_urlZportstrr�Z
setsockoptZIPPROTO_TCPZTCP_NODELAY�	Exceptionr^�Queuer��	threadingZLockr�rP�BINARY�WILL�WONT�DO�DONTrN�COM_PORT_OPTIONrLr��SGAr�rh�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�ZThread�_telnet_read_loopr�Z	setDaemonZsetName�startrXr`rTrSrorp�sumr�_reconfigure_portZ_dsrdtr�_update_dtr_state�_rtscts�_update_rts_state�reset_input_buffer�reset_output_buffer�close)r[�msgZmandadory_optionsrSrrrFrFrJ�open�s~
$



&zSerial.opencCs�|jdkrtd��|jdk	r$td��d|jko8dknsNtdj|j���|jdjt	j
d	|j��|jd
jt	j
d|j��|jdjt	j
dt|j
��|jd
jt	j
dt|j��|jj�}|jr�|jjdj|��tj�|j}xFtj�|k�r&tjd�tdd�|D��t|�kr�Pq�Wtdj|���|j�rP|jjdj|��|j�rj|j�rjtd��n2|j�r~|jt�n|j�r�|jt�n
|jt�dS)z,Set communication parameters on opened port.NzCan only operate on open portsz(write_timeout is currently not supportedrrBr>zinvalid baudrate: {!r}r�s!Ir�s!Br�r�zNegotiating settings: {}g�������?css|]}|jVqdS)N)rY)rGr]rFrFrJrKsz+Serial._reconfigure_port.<locals>.<genexpr>z7Remote does not accept parameter change (RFC2217): {!r}zNegotiated settings: {}z-xonxoff and rtscts together are not supportedl)r�rZ_write_timeout�NotImplementedErrorZ	_baudraterar^r�rm�struct�packZ	_bytesize�RFC2217_PARITY_MAPZ_parity�RFC2217_STOPBIT_MAPZ	_stopbits�valuesrlrror�rpr�rtrr�Z_xonxoff�rfc2217_set_control�SET_CONTROL_USE_HW_FLOW_CONTROL�SET_CONTROL_USE_SW_FLOW_CONTROL�SET_CONTROL_USE_NO_FLOW_CONTROL)r[�itemsrrrFrFrJr��s8




zSerial._reconfigure_portc	Csbd|_|jr6y|jjtj�|jj�WnYnX|jrX|jjd�d|_tj	d�d|_dS)z
Close portF�Ng333333�?)
r�r�Zshutdownr�Z	SHUT_RDWRr�r��joinrorp)r[rFrFrJr�s
zSerial.closecCs.tj|�}|jdkr$tdj|j���y�x�tj|jd�j�D]�\}}|dkr�tj	�tj
d�|_|jjt
|d�|jjd�q:|dkr�d|_q:|d	kr�d|_q:|d
kr�t|d�|_q:tdj|���q:Wd|jko�dkns�td
��Wn2tk
�r }ztdj|���WYdd}~XnX|j|jfS)zu        extract host and port from an URL string, other settings are extracted
        an stored in instance
        Zrfc2217zqexpected a string in the form "rfc2217://<host>:<port>[?option[&option...]]": not starting with rfc2217:// ({!r})T�loggingzpySerial.rfc2217rzenabled loggingZign_set_controlZ
poll_modemrqzunknown option: {!r}izport not in range 0...65535zPexpected a string in the form "rfc2217://<host>:<port>[?option[&option...]]": {}N)�urlparseZurlsplit�schemerr^Zparse_qsZqueryr�r�ZbasicConfigZ	getLoggerrlZsetLevel�
LOGGER_LEVELSrr�r��floatr�raZportZhostname)r[Zurl�partsrSr��erFrFrJr�-s4


zSerial.from_urlcCs|js
t�|jj�S)z9Return the number of bytes currently in the input buffer.)r�rr��qsize)r[rFrFrJ�
in_waitingRszSerial.in_waitingrCcCsl|js
t�t�}y<x6t|�|krH|jdkr2td��||jjd|j�7}qWWnt	j
k
rbYnXt|�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.
        Nz&connection failed (reader thread died)T)r�r�	bytearrayrtr�rr��getZ_timeoutr�ZEmpty�bytes)r[�size�datarFrFrJ�readYs
zSerial.readcCst|js
t�|j�Vy|jjt|�jtt��Wn2t	j
k
r`}ztdj|���WYdd}~XnXWdQRXt
|�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.
        z$connection failed (socket error): {}N)r�rr�r��sendallr�replace�IAC�IAC_DOUBLEDr�r
rr^rt)r[r�r�rFrFrJ�writeks*zSerial.writecCs4|js
t�|jt�x|jj�r.|jjd�qWdS)z9Clear input buffer, discarding all that is in the buffer.FN)r�r�rfc2217_send_purge�PURGE_RECEIVE_BUFFERr�r�r�)r[rFrFrJr�zs

zSerial.reset_input_buffercCs|js
t�|jt�dS)zs        Clear output buffer, aborting the current output and
        discarding all that is in the buffer.
        N)r�rr��PURGE_TRANSMIT_BUFFER)r[rFrFrJr��szSerial.reset_output_buffercCsL|js
t�|jr,|jjdj|jr$dnd��|jr>|jt�n
|jt�dS)z[        Set break: Controls TXD. When active, to transmitting is
        possible.
        zset BREAK to {}rY�inactiveN)	r�rrlrr^Z_break_stater��SET_CONTROL_BREAK_ON�SET_CONTROL_BREAK_OFF)r[rFrFrJ�_update_break_state�szSerial._update_break_statecCsL|js
t�|jr,|jjdj|jr$dnd��|jr>|jt�n
|jt�dS)z*Set terminal status line: Request To Send.z
set RTS to {}rYr�N)	r�rrlrr^Z
_rts_stater��SET_CONTROL_RTS_ON�SET_CONTROL_RTS_OFF)r[rFrFrJr��szSerial._update_rts_statecCsL|js
t�|jr,|jjdj|jr$dnd��|jr>|jt�n
|jt�dS)z.Set terminal status line: Data Terminal Ready.z
set DTR to {}rYr�N)	r�rrlrr^Z
_dtr_stater��SET_CONTROL_DTR_ON�SET_CONTROL_DTR_OFF)r[rFrFrJr��szSerial._update_dtr_statecCs|js
t�t|j�t@�S)z)Read terminal status line: Clear To Send.)r�r�bool�get_modem_state�MODEMSTATE_MASK_CTS)r[rFrFrJ�cts�sz
Serial.ctscCs|js
t�t|j�t@�S)z*Read terminal status line: Data Set Ready.)r�rr�r��MODEMSTATE_MASK_DSR)r[rFrFrJ�dsr�sz
Serial.dsrcCs|js
t�t|j�t@�S)z*Read terminal status line: Ring Indicator.)r�rr�r��MODEMSTATE_MASK_RI)r[rFrFrJ�ri�sz	Serial.ricCs|js
t�t|j�t@�S)z*Read terminal status line: Carrier Detect.)r�rr�r��MODEMSTATE_MASK_CD)r[rFrFrJ�cd�sz	Serial.cdcCs�t}d}�z|�xt|j�r�y|jjd�}WnTtjk
r@wYn>tjk
r|}z |jrj|jjdj	|��PWYdd}~XnX|s�Px�t
|�D]�}|tkr�|tkr�t}n|dk	r�||7}n|j
j|�q�|tk�rd|tk�r|dk	r�|t7}n|j
jt�t}nb|tk�rt�}t}nL|tk�r8|jt|��d}t}n*|ttttfk�rT|}t}n|j|�t}q�|tkr�|j||�t}q�WqWWdd|_|j�r�|jjd�XdS)zRead loop for the socket.Niz!socket error in reader thread: {}zread thread terminated)�M_NORMALr�r�Zrecvr�rqr
rlrr^rr��
M_IAC_SEENr�Zput�SBr��SE�_telnet_process_subnegotiationr�r�r�r�r��M_NEGOTIATE�_telnet_process_command�_telnet_negotiate_optionr�)r[�moderur�r��byte�telnet_commandrFrFrJr��sZ






zSerial._telnet_read_loopcCs|jr|jjdj|��dS)z1Process commands other than DO, DONT, WILL, WONT.zignoring Telnet command: {!r}N)rlr	r^)r[rbrFrFrJrszSerial._telnet_process_commandcCstd}x&|jD]}|j|kr|j|�d}qW|sp|tks@|tkrp|j|tkrPtnt|�|jrp|jj	dj
|��dS)z&Process incoming DO, DONT, WILL, WONT.FTzrejected Telnet option: {!r}N)r�rSrcr�r�r`r�r�rlr	r^)r[rbrS�known�itemrFrFrJrs

zSerial._telnet_negotiate_optioncCs\|dd�tk�r>|dd�tkr\t|�dkr\t|dd��|_|jrZ|jjdj|j��n�|dd�tkr�t|�dkr�t|dd��|_	|jr�|jjdj|j	��t
j
�d|_n�|dd�tkr�d|_
np|dd�tkr�d	|_
nXxr|jj�D].}|j|dd�kr�|jt|dd
���Pq�W|j�rX|jjdj|��n|j�rX|jjdj|��d
S)
z;Process subnegotiation, the data between IAC SB and IAC SE.rrCrBrDzNOTIFY_LINESTATE: {}zNOTIFY_MODEMSTATE: {}g333333�?TFNzignoring COM_PORT_OPTION: {!r}zignoring subnegotiation: {!r})r��SERVER_NOTIFY_LINESTATErt�ordr�rlrr^�SERVER_NOTIFY_MODEMSTATEr�ror��FLOWCONTROL_SUSPENDr��FLOWCONTROL_RESUMEr�r�rjrvr�r	)r[rurrFrFrJr-s,z%Serial._telnet_process_subnegotiationc	Cs"|j�|jj|�WdQRXdS)zGinternal socket write with no data escaping. used to send telnet stuff.N)r�r�r�)r[r�rFrFrJ�_internal_raw_writeMszSerial._internal_raw_writecCs|jtt||g��dS)zSend DO, DONT, WILL, WONT.N)rrr�)r[�actionrSrFrFrJr`RszSerial.telnet_send_option�cCs6|jtt�}|jtttt|gt|�ttg��dS)z%Subnegotiation of RFC2217 parameters.N)	r�r�r�rrrr��listr)r[rSrirFrFrJrkVsz"Serial.rfc2217_send_subnegotiationcCs$|jd}|j|�|j|j�dS)z~        Send purge request to the remote.
        (PURGE_RECEIVE_BUFFER / PURGE_TRANSMIT_BUFFER / PURGE_BOTH_BUFFERS)
        r�N)r�rmrsr�)r[rirrFrFrJr�[s

zSerial.rfc2217_send_purgecCs6|jd}|j|�|jr&tjd�n|j|j�dS)z)transmit change of control line to remoter�g�������?N)r�rmr�rorprsr�)r[rirrFrFrJr�ds


zSerial.rfc2217_set_controlcCsdS)z`        check if server is ready to receive data. block for some time when
        not.
        NrF)r[rFrFrJ�rfc2217_flow_server_readypsz Serial.rfc2217_flow_server_readycCs�|jr||jtj�kr||jr&|jjd�|jt�tj�|j}x<tj�|krhtjd�|jtj�kr@Pq@W|jr||jj	d�|j
dk	r�|jr�|jjd�|j
Std��dS)a        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 (getCTS, getDSR
        etc.)
        zpolling modem stateg�������?zpoll for modem state failedNzusing cached modem statez!remote sends no NOTIFY_MODEMSTATE)r�r�rorlrrk�NOTIFY_MODEMSTATEr�rpr	r�r)r[rrrFrFrJr�xs 


zSerial.get_modem_state)ryrzr{r|r}r~rr�r�r�r�r�r�r�r�r�r�)rC)r)#rdrerfrgZ	BAUDRATESr\r�r�r�r�rwr�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr`rkr�r�rr��
__classcell__rFrF)r�rJrxws>a,%
		C 
	rxc@sfeZdZdZddd�Zdd�Zdd�Zdd
d�Zdd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�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.
    NcCs||_||_||_d|_t|_d|_d|_d|_d|_	d|_
t|dtt
tttt�t|dtt
tttt�t|dtttt
tt�t|dtt
tttt�t|dtttt
tt�t|d	tt
tttt|j�	t|d
tttt
tt|j�	g|_|jr�|jjd�x(|jD]}|jtkr�|j|j|j�q�WdS)NF�rr�zwe-SGAzthey-SGAz	we-BINARYzthey-BINARYz
we-RFC2217zthey-RFC2217z*requesting initial Telnet/RFC 2217 options)�serialrQrl�_client_is_rfc2217rrrur
�modemstate_mask�last_modemstate�
linstate_maskrPr�r�r�r�r�rLr�rNr�r��
_client_okr�rrXr`rTrS)r[Zserial_portrQrlrSrFrFrJr\�s,
zPortManager.__init__cCs(d|_|jr|jjd�|jdd�dS)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)rrlr�check_modem_lines)r[rFrFrJr �szPortManager._client_okcCs|jjtt||g��dS)zSend DO, DONT, WILL, WONT.N)rQr�rr�)r[rrSrFrFrJr`�szPortManager.telnet_send_optionrcCs8|jtt�}|jjtttt|gt|�tt	g��dS)z&Subnegotiation of RFC 2217 parameters.N)
r�r�r�rQr�rrr�rr)r[rSrirFrFrJrk�sz'PortManager.rfc2217_send_subnegotiationFcCs�|jj�ot|jj�otB|jj�o&tB|jj�o4tB}||j	pBdA}|t@rV|t
O}|t@rf|tO}|t@rv|tO}|t@r�|t
O}||j	ks�|r�|jr�||j@s�|r�|jtt||j@g��|jr�|jjdj|��|d@|_	dS)z�        read control lines from serial port and compare the last value sent to remote.
        send updates on changes.
        rzNOTIFY_MODEMSTATE: {}��N)rZgetCTSr�ZgetDSRr�ZgetRIr�ZgetCDr�r�MODEMSTATE_MASK_CTS_CHANGE�MODEMSTATE_MASK_DSR_CHANGE�MODEMSTATE_MASK_RI_CHANGE�MODEMSTATE_MASK_CD_CHANGErrrkrrrlrr^)r[r!Z
modemstateZdeltasrFrFrJr"�s&(zPortManager.check_modem_linesccs2x,t|�D] }|tkr$tVtVq
|Vq
WdS)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)rr�)r[r�r	rFrFrJ�escape
s
zPortManager.escapeccs�xt|�D�]}|jtkrN|tkr,t|_n |jdk	rF|j|7_n|Vq|jtkr�|tkr�|jdk	rz|j|7_n|Vt|_nl|tkr�t�|_t|_nT|tkr�|j	t
|j��d|_t|_n.|ttt
tfkr�||_t|_n|j|�t|_q|jtkr|j|j|�t|_qWdS)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)rrrr�rrurr�rrr�r�r�r�r�r
rrr)r[r�r	rFrFrJ�filters8





zPortManager.filtercCs|jr|jjdj|��dS)z1Process commands other than DO, DONT, WILL, WONT.zignoring Telnet command: {!r}N)rlr	r^)r[rbrFrFrJrYsz#PortManager._telnet_process_commandcCstd}x&|jD]}|j|kr|j|�d}qW|sp|tks@|tkrp|j|tkrPtnt|�|jrp|jj	dj
|��dS)z&Process incoming DO, DONT, WILL, WONT.FTzrejected Telnet option: {!r}N)r�rSrcr�r�r`r�r�rlr	r^)r[rbrSrrrFrFrJr_s

z$PortManager._telnet_negotiate_optioncCs4	|dd�tk�	r|jr*|jjdj|��|dd�tkr�|jj}y*tjd|dd��\}|dkrj||j_WnBt	k
r�}z&|jr�|jj
dj|��||j_WYdd}~Xn(X|jr�|jjd	j|r�d
nd|jj��|jt
tjd|jj���	q0|dd�tk�r�|jj}y,tjd|dd
��\}|dk�r6||j_WnFt	k
�r~}z(|j�rf|jj
dj|��||j_WYdd}~Xn,X|j�r�|jjdj|�r�d
nd|jj��|jttjd|jj���	q0|dd�tk�r�|jj}y2tjd|dd
��d}|dk�rt||j_WnFt	k
�rX}z(|j�r@|jj
dj|��||j_WYdd}~Xn,X|j�r�|jjdj|�rvd
nd|jj��|jttjdt|jj���	q0|dd�tk�r�|jj}y2tjd|dd
��d}|dk�r�t||j_WnFt	k
�r6}z(|j�r|jj
dj|��||j_WYdd}~Xn,X|j�rb|jjdj|�rTd
nd|jj��|jttjdt|jj���	q0|dd�tk�r�|dd
�tk�r�|jj�r�|jtt �n$|jj!�r�|jtt"�n|jtt#��	q|dd
�t#k�r,d|j_d|j_!|j�r|jjd�|jtt#��	q|dd
�t k�rjd|j_|j�rZ|jjd�|jtt ��	q|dd
�t"k�r�d|j_!|j�r�|jjd�|jtt"��	q|dd
�t$k�r�|j�r�|jj%d��	q|dd
�t&k�r|jj'd�|j�r|jjd�|jtt&��	q|dd
�t(k�rV|jj'd�|j�rF|jjd�|jtt(��	q|dd
�t)k�r�|j�r�|jj%d��	q|dd
�t*k�r�|jj+d�|j�r�|jjd�|jtt*�n�|dd
�t,k�r|jj+d�|j�r�|jjd�|jtt,�n�|dd
�t-k�r(|j�r�|jj%d�n~|dd
�t.k�rh|jj/d�|j�rZ|jjd �|jtt.�n>|dd
�t0k�	r|jj/d�|j�r�|jjd!�|jtt0��	q0|dd�t1k�r�|jt2t3dg���	q0|dd�t4k�r|j�r�|jjd"�|j5dd#��	q0|dd�t6k�r8|j�r.|jjd$�d|_7�	q0|dd�t8k�rh|j�r^|jjd%�d|_7�	q0|dd�t9k�r�t:|dd
��|_;|j�	r|jjd&j|j;���	q0|dd�t<k�r�t:|dd
��|_=|j�	r|jjd'j|j=���	q0|dd�t>k�r�|dd
�t?k�r@|jj@�|j�r2|jjd(�|jtAt?�n�|dd
�tBk�r~|jjC�|j�rp|jjd)�|jtAtB�nn|dd
�tDk�r�|jj@�|jjC�|j�r�|jjd*�|jtAtD�n&|j�	r|jj
d+jtE|dd����n&|j�	r0|jj
d,jtE|dd����n|j�	r0|jj%d-j|��dS).z;Process subnegotiation, the data between IAC SB and IAC SE.rrCzreceived COM_PORT_OPTION: {!r}rBs!I�zfailed to set baud rate: {}Nz{} baud rate: {}rmr�s!BrDzfailed to set data size: {}z{} data size: {}zfailed to set parity: {}z
{} parity: {}zfailed to set stop bits: {}z{} 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 state)r!ZsuspendZresumezline 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�rlrr^r�rr�r��unpackrar
rrkr�r�r�Zbytesizer�r�r��RFC2217_REVERSE_PARITY_MAPr�r�r��stopbits�RFC2217_REVERSE_STOPBIT_MAPr�r�r��SET_CONTROL_REQ_FLOW_SETTINGZxonxoffr�r�Zrtsctsr�r��SET_CONTROL_REQ_BREAK_STATEr	r�ZsetBreakr��SET_CONTROL_REQ_DTRr�ZsetDTRr��SET_CONTROL_REQ_RTSr�ZsetRTSr��NOTIFY_LINESTATEr
rrr"rr�r�SET_LINESTATE_MASKrr�SET_MODEMSTATE_MASKrr�r�r�r�r�r��PURGE_BOTH_BUFFERSr)r[ruZbackupr�r�r�r�r-rFrFrJrrsV 
"
"
"







  z*PortManager._telnet_process_subnegotiation)N)r)F)rdrerfrgr\r r`rkr"r(r)rrrrFrFrFrJr�s
#

$;r�__main__zrfc2217://localhost:7000i�z{}
z	write...
shello
z	read: {}
)�r�r�r�r�ror��ImportErrorZurllib.parse�parser�ZqueuerZserial.serialutilrrrrr�DEBUG�INFOZWARNINGZERRORr�rZNOPZDMZBRKZIPZAOZAYTZECZELZGArr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r3rrrr4r5r�r�r�r�r�r�r
rZSERVER_FLOWCONTROL_SUSPENDZSERVER_FLOWCONTROL_RESUMEZSERVER_SET_LINESTATE_MASKZSERVER_SET_MODEMSTATE_MASKr�ZRFC2217_ANSWER_MAPr/r�r�r�r0r�r�r1r�r�r2r�r�ZSET_CONTROL_REQ_FLOW_SETTING_INZ"SET_CONTROL_USE_NO_FLOW_CONTROL_INZ!SET_CONTROL_USE_SW_FLOW_CONTOL_INZ!SET_CONTROL_USE_HW_FLOW_CONTOL_INZ SET_CONTROL_USE_DCD_FLOW_CONTROLZ SET_CONTROL_USE_DTR_FLOW_CONTROLZ SET_CONTROL_USE_DSR_FLOW_CONTROLZLINESTATE_MASK_TIMEOUTZLINESTATE_MASK_SHIFTREG_EMPTYZLINESTATE_MASK_TRANSREG_EMPTYZLINESTATE_MASK_BREAK_DETECTZLINESTATE_MASK_FRAMING_ERRORZLINESTATE_MASK_PARTIY_ERRORZLINESTATE_MASK_OVERRUN_ERRORZLINESTATE_MASK_DATA_READYr�r�r�r�r'r&r%r$r�r�r6ZPARITY_NONEZ
PARITY_ODDZPARITY_EVENZPARITY_MARKZPARITY_SPACEr��dictr�r,ZSTOPBITS_ONEZSTOPBITS_ONE_POINT_FIVEZSTOPBITS_TWOr�r.rrrrLrMrNrO�objectrPrhrxrrd�sys�s�stdoutr�r^�flushr�r�rFrFrFrJ�<module>=s.	


FG,




Filemanager

Name Type Size Permission Actions
__init__.cpython-36.opt-1.pyc File 2 KB 0644
__init__.cpython-36.pyc File 2 KB 0644
aio.cpython-36.opt-1.pyc File 14 KB 0644
aio.cpython-36.pyc File 14.18 KB 0644
rfc2217.cpython-36.opt-1.pyc File 31.88 KB 0644
rfc2217.cpython-36.pyc File 31.88 KB 0644
rs485.cpython-36.opt-1.pyc File 2.72 KB 0644
rs485.cpython-36.pyc File 2.72 KB 0644
serialcli.cpython-36.opt-1.pyc File 6.45 KB 0644
serialcli.cpython-36.pyc File 6.45 KB 0644
serialjava.cpython-36.opt-1.pyc File 7.08 KB 0644
serialjava.cpython-36.pyc File 7.08 KB 0644
serialposix.cpython-36.opt-1.pyc File 18.69 KB 0644
serialposix.cpython-36.pyc File 18.72 KB 0644
serialutil.cpython-36.opt-1.pyc File 16.04 KB 0644
serialutil.cpython-36.pyc File 16.04 KB 0644
serialwin32.cpython-36.opt-1.pyc File 12.11 KB 0644
serialwin32.cpython-36.pyc File 12.11 KB 0644
win32.cpython-36.opt-1.pyc File 6.15 KB 0644
win32.cpython-36.pyc File 6.15 KB 0644