Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../usr/lib64/python3....
File: telnetlib.py
r"""TELNET client class.
[0] Fix | Delete
[1] Fix | Delete
Based on RFC 854: TELNET Protocol Specification, by J. Postel and
[2] Fix | Delete
J. Reynolds
[3] Fix | Delete
[4] Fix | Delete
Example:
[5] Fix | Delete
[6] Fix | Delete
>>> from telnetlib import Telnet
[7] Fix | Delete
>>> tn = Telnet('www.python.org', 79) # connect to finger port
[8] Fix | Delete
>>> tn.write(b'guido\r\n')
[9] Fix | Delete
>>> print(tn.read_all())
[10] Fix | Delete
Login Name TTY Idle When Where
[11] Fix | Delete
guido Guido van Rossum pts/2 <Dec 2 11:10> snag.cnri.reston..
[12] Fix | Delete
[13] Fix | Delete
>>>
[14] Fix | Delete
[15] Fix | Delete
Note that read_all() won't read until eof -- it just reads some data
[16] Fix | Delete
-- but it guarantees to read at least one byte unless EOF is hit.
[17] Fix | Delete
[18] Fix | Delete
It is possible to pass a Telnet object to a selector in order to wait until
[19] Fix | Delete
more data is available. Note that in this case, read_eager() may return b''
[20] Fix | Delete
even if there was data on the socket, because the protocol negotiation may have
[21] Fix | Delete
eaten the data. This is why EOFError is needed in some cases to distinguish
[22] Fix | Delete
between "no data" and "connection closed" (since the socket also appears ready
[23] Fix | Delete
for reading when it is closed).
[24] Fix | Delete
[25] Fix | Delete
To do:
[26] Fix | Delete
- option negotiation
[27] Fix | Delete
- timeout should be intrinsic to the connection object instead of an
[28] Fix | Delete
option on one of the read calls only
[29] Fix | Delete
[30] Fix | Delete
"""
[31] Fix | Delete
[32] Fix | Delete
[33] Fix | Delete
# Imported modules
[34] Fix | Delete
import sys
[35] Fix | Delete
import socket
[36] Fix | Delete
import selectors
[37] Fix | Delete
from time import monotonic as _time
[38] Fix | Delete
[39] Fix | Delete
__all__ = ["Telnet"]
[40] Fix | Delete
[41] Fix | Delete
# Tunable parameters
[42] Fix | Delete
DEBUGLEVEL = 0
[43] Fix | Delete
[44] Fix | Delete
# Telnet protocol defaults
[45] Fix | Delete
TELNET_PORT = 23
[46] Fix | Delete
[47] Fix | Delete
# Telnet protocol characters (don't change)
[48] Fix | Delete
IAC = bytes([255]) # "Interpret As Command"
[49] Fix | Delete
DONT = bytes([254])
[50] Fix | Delete
DO = bytes([253])
[51] Fix | Delete
WONT = bytes([252])
[52] Fix | Delete
WILL = bytes([251])
[53] Fix | Delete
theNULL = bytes([0])
[54] Fix | Delete
[55] Fix | Delete
SE = bytes([240]) # Subnegotiation End
[56] Fix | Delete
NOP = bytes([241]) # No Operation
[57] Fix | Delete
DM = bytes([242]) # Data Mark
[58] Fix | Delete
BRK = bytes([243]) # Break
[59] Fix | Delete
IP = bytes([244]) # Interrupt process
[60] Fix | Delete
AO = bytes([245]) # Abort output
[61] Fix | Delete
AYT = bytes([246]) # Are You There
[62] Fix | Delete
EC = bytes([247]) # Erase Character
[63] Fix | Delete
EL = bytes([248]) # Erase Line
[64] Fix | Delete
GA = bytes([249]) # Go Ahead
[65] Fix | Delete
SB = bytes([250]) # Subnegotiation Begin
[66] Fix | Delete
[67] Fix | Delete
[68] Fix | Delete
# Telnet protocol options code (don't change)
[69] Fix | Delete
# These ones all come from arpa/telnet.h
[70] Fix | Delete
BINARY = bytes([0]) # 8-bit data path
[71] Fix | Delete
ECHO = bytes([1]) # echo
[72] Fix | Delete
RCP = bytes([2]) # prepare to reconnect
[73] Fix | Delete
SGA = bytes([3]) # suppress go ahead
[74] Fix | Delete
NAMS = bytes([4]) # approximate message size
[75] Fix | Delete
STATUS = bytes([5]) # give status
[76] Fix | Delete
TM = bytes([6]) # timing mark
[77] Fix | Delete
RCTE = bytes([7]) # remote controlled transmission and echo
[78] Fix | Delete
NAOL = bytes([8]) # negotiate about output line width
[79] Fix | Delete
NAOP = bytes([9]) # negotiate about output page size
[80] Fix | Delete
NAOCRD = bytes([10]) # negotiate about CR disposition
[81] Fix | Delete
NAOHTS = bytes([11]) # negotiate about horizontal tabstops
[82] Fix | Delete
NAOHTD = bytes([12]) # negotiate about horizontal tab disposition
[83] Fix | Delete
NAOFFD = bytes([13]) # negotiate about formfeed disposition
[84] Fix | Delete
NAOVTS = bytes([14]) # negotiate about vertical tab stops
[85] Fix | Delete
NAOVTD = bytes([15]) # negotiate about vertical tab disposition
[86] Fix | Delete
NAOLFD = bytes([16]) # negotiate about output LF disposition
[87] Fix | Delete
XASCII = bytes([17]) # extended ascii character set
[88] Fix | Delete
LOGOUT = bytes([18]) # force logout
[89] Fix | Delete
BM = bytes([19]) # byte macro
[90] Fix | Delete
DET = bytes([20]) # data entry terminal
[91] Fix | Delete
SUPDUP = bytes([21]) # supdup protocol
[92] Fix | Delete
SUPDUPOUTPUT = bytes([22]) # supdup output
[93] Fix | Delete
SNDLOC = bytes([23]) # send location
[94] Fix | Delete
TTYPE = bytes([24]) # terminal type
[95] Fix | Delete
EOR = bytes([25]) # end or record
[96] Fix | Delete
TUID = bytes([26]) # TACACS user identification
[97] Fix | Delete
OUTMRK = bytes([27]) # output marking
[98] Fix | Delete
TTYLOC = bytes([28]) # terminal location number
[99] Fix | Delete
VT3270REGIME = bytes([29]) # 3270 regime
[100] Fix | Delete
X3PAD = bytes([30]) # X.3 PAD
[101] Fix | Delete
NAWS = bytes([31]) # window size
[102] Fix | Delete
TSPEED = bytes([32]) # terminal speed
[103] Fix | Delete
LFLOW = bytes([33]) # remote flow control
[104] Fix | Delete
LINEMODE = bytes([34]) # Linemode option
[105] Fix | Delete
XDISPLOC = bytes([35]) # X Display Location
[106] Fix | Delete
OLD_ENVIRON = bytes([36]) # Old - Environment variables
[107] Fix | Delete
AUTHENTICATION = bytes([37]) # Authenticate
[108] Fix | Delete
ENCRYPT = bytes([38]) # Encryption option
[109] Fix | Delete
NEW_ENVIRON = bytes([39]) # New - Environment variables
[110] Fix | Delete
# the following ones come from
[111] Fix | Delete
# http://www.iana.org/assignments/telnet-options
[112] Fix | Delete
# Unfortunately, that document does not assign identifiers
[113] Fix | Delete
# to all of them, so we are making them up
[114] Fix | Delete
TN3270E = bytes([40]) # TN3270E
[115] Fix | Delete
XAUTH = bytes([41]) # XAUTH
[116] Fix | Delete
CHARSET = bytes([42]) # CHARSET
[117] Fix | Delete
RSP = bytes([43]) # Telnet Remote Serial Port
[118] Fix | Delete
COM_PORT_OPTION = bytes([44]) # Com Port Control Option
[119] Fix | Delete
SUPPRESS_LOCAL_ECHO = bytes([45]) # Telnet Suppress Local Echo
[120] Fix | Delete
TLS = bytes([46]) # Telnet Start TLS
[121] Fix | Delete
KERMIT = bytes([47]) # KERMIT
[122] Fix | Delete
SEND_URL = bytes([48]) # SEND-URL
[123] Fix | Delete
FORWARD_X = bytes([49]) # FORWARD_X
[124] Fix | Delete
PRAGMA_LOGON = bytes([138]) # TELOPT PRAGMA LOGON
[125] Fix | Delete
SSPI_LOGON = bytes([139]) # TELOPT SSPI LOGON
[126] Fix | Delete
PRAGMA_HEARTBEAT = bytes([140]) # TELOPT PRAGMA HEARTBEAT
[127] Fix | Delete
EXOPL = bytes([255]) # Extended-Options-List
[128] Fix | Delete
NOOPT = bytes([0])
[129] Fix | Delete
[130] Fix | Delete
[131] Fix | Delete
# poll/select have the advantage of not requiring any extra file descriptor,
[132] Fix | Delete
# contrarily to epoll/kqueue (also, they require a single syscall).
[133] Fix | Delete
if hasattr(selectors, 'PollSelector'):
[134] Fix | Delete
_TelnetSelector = selectors.PollSelector
[135] Fix | Delete
else:
[136] Fix | Delete
_TelnetSelector = selectors.SelectSelector
[137] Fix | Delete
[138] Fix | Delete
[139] Fix | Delete
class Telnet:
[140] Fix | Delete
[141] Fix | Delete
"""Telnet interface class.
[142] Fix | Delete
[143] Fix | Delete
An instance of this class represents a connection to a telnet
[144] Fix | Delete
server. The instance is initially not connected; the open()
[145] Fix | Delete
method must be used to establish a connection. Alternatively, the
[146] Fix | Delete
host name and optional port number can be passed to the
[147] Fix | Delete
constructor, too.
[148] Fix | Delete
[149] Fix | Delete
Don't try to reopen an already connected instance.
[150] Fix | Delete
[151] Fix | Delete
This class has many read_*() methods. Note that some of them
[152] Fix | Delete
raise EOFError when the end of the connection is read, because
[153] Fix | Delete
they can return an empty string for other reasons. See the
[154] Fix | Delete
individual doc strings.
[155] Fix | Delete
[156] Fix | Delete
read_until(expected, [timeout])
[157] Fix | Delete
Read until the expected string has been seen, or a timeout is
[158] Fix | Delete
hit (default is no timeout); may block.
[159] Fix | Delete
[160] Fix | Delete
read_all()
[161] Fix | Delete
Read all data until EOF; may block.
[162] Fix | Delete
[163] Fix | Delete
read_some()
[164] Fix | Delete
Read at least one byte or EOF; may block.
[165] Fix | Delete
[166] Fix | Delete
read_very_eager()
[167] Fix | Delete
Read all data available already queued or on the socket,
[168] Fix | Delete
without blocking.
[169] Fix | Delete
[170] Fix | Delete
read_eager()
[171] Fix | Delete
Read either data already queued or some data available on the
[172] Fix | Delete
socket, without blocking.
[173] Fix | Delete
[174] Fix | Delete
read_lazy()
[175] Fix | Delete
Read all data in the raw queue (processing it first), without
[176] Fix | Delete
doing any socket I/O.
[177] Fix | Delete
[178] Fix | Delete
read_very_lazy()
[179] Fix | Delete
Reads all data in the cooked queue, without doing any socket
[180] Fix | Delete
I/O.
[181] Fix | Delete
[182] Fix | Delete
read_sb_data()
[183] Fix | Delete
Reads available data between SB ... SE sequence. Don't block.
[184] Fix | Delete
[185] Fix | Delete
set_option_negotiation_callback(callback)
[186] Fix | Delete
Each time a telnet option is read on the input flow, this callback
[187] Fix | Delete
(if set) is called with the following parameters :
[188] Fix | Delete
callback(telnet socket, command, option)
[189] Fix | Delete
option will be chr(0) when there is no option.
[190] Fix | Delete
No other action is done afterwards by telnetlib.
[191] Fix | Delete
[192] Fix | Delete
"""
[193] Fix | Delete
[194] Fix | Delete
def __init__(self, host=None, port=0,
[195] Fix | Delete
timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
[196] Fix | Delete
"""Constructor.
[197] Fix | Delete
[198] Fix | Delete
When called without arguments, create an unconnected instance.
[199] Fix | Delete
With a hostname argument, it connects the instance; port number
[200] Fix | Delete
and timeout are optional.
[201] Fix | Delete
"""
[202] Fix | Delete
self.debuglevel = DEBUGLEVEL
[203] Fix | Delete
self.host = host
[204] Fix | Delete
self.port = port
[205] Fix | Delete
self.timeout = timeout
[206] Fix | Delete
self.sock = None
[207] Fix | Delete
self.rawq = b''
[208] Fix | Delete
self.irawq = 0
[209] Fix | Delete
self.cookedq = b''
[210] Fix | Delete
self.eof = 0
[211] Fix | Delete
self.iacseq = b'' # Buffer for IAC sequence.
[212] Fix | Delete
self.sb = 0 # flag for SB and SE sequence.
[213] Fix | Delete
self.sbdataq = b''
[214] Fix | Delete
self.option_callback = None
[215] Fix | Delete
if host is not None:
[216] Fix | Delete
self.open(host, port, timeout)
[217] Fix | Delete
[218] Fix | Delete
def open(self, host, port=0, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
[219] Fix | Delete
"""Connect to a host.
[220] Fix | Delete
[221] Fix | Delete
The optional second argument is the port number, which
[222] Fix | Delete
defaults to the standard telnet port (23).
[223] Fix | Delete
[224] Fix | Delete
Don't try to reopen an already connected instance.
[225] Fix | Delete
"""
[226] Fix | Delete
self.eof = 0
[227] Fix | Delete
if not port:
[228] Fix | Delete
port = TELNET_PORT
[229] Fix | Delete
self.host = host
[230] Fix | Delete
self.port = port
[231] Fix | Delete
self.timeout = timeout
[232] Fix | Delete
sys.audit("telnetlib.Telnet.open", self, host, port)
[233] Fix | Delete
self.sock = socket.create_connection((host, port), timeout)
[234] Fix | Delete
[235] Fix | Delete
def __del__(self):
[236] Fix | Delete
"""Destructor -- close the connection."""
[237] Fix | Delete
self.close()
[238] Fix | Delete
[239] Fix | Delete
def msg(self, msg, *args):
[240] Fix | Delete
"""Print a debug message, when the debug level is > 0.
[241] Fix | Delete
[242] Fix | Delete
If extra arguments are present, they are substituted in the
[243] Fix | Delete
message using the standard string formatting operator.
[244] Fix | Delete
[245] Fix | Delete
"""
[246] Fix | Delete
if self.debuglevel > 0:
[247] Fix | Delete
print('Telnet(%s,%s):' % (self.host, self.port), end=' ')
[248] Fix | Delete
if args:
[249] Fix | Delete
print(msg % args)
[250] Fix | Delete
else:
[251] Fix | Delete
print(msg)
[252] Fix | Delete
[253] Fix | Delete
def set_debuglevel(self, debuglevel):
[254] Fix | Delete
"""Set the debug level.
[255] Fix | Delete
[256] Fix | Delete
The higher it is, the more debug output you get (on sys.stdout).
[257] Fix | Delete
[258] Fix | Delete
"""
[259] Fix | Delete
self.debuglevel = debuglevel
[260] Fix | Delete
[261] Fix | Delete
def close(self):
[262] Fix | Delete
"""Close the connection."""
[263] Fix | Delete
sock = self.sock
[264] Fix | Delete
self.sock = None
[265] Fix | Delete
self.eof = True
[266] Fix | Delete
self.iacseq = b''
[267] Fix | Delete
self.sb = 0
[268] Fix | Delete
if sock:
[269] Fix | Delete
sock.close()
[270] Fix | Delete
[271] Fix | Delete
def get_socket(self):
[272] Fix | Delete
"""Return the socket object used internally."""
[273] Fix | Delete
return self.sock
[274] Fix | Delete
[275] Fix | Delete
def fileno(self):
[276] Fix | Delete
"""Return the fileno() of the socket object used internally."""
[277] Fix | Delete
return self.sock.fileno()
[278] Fix | Delete
[279] Fix | Delete
def write(self, buffer):
[280] Fix | Delete
"""Write a string to the socket, doubling any IAC characters.
[281] Fix | Delete
[282] Fix | Delete
Can block if the connection is blocked. May raise
[283] Fix | Delete
OSError if the connection is closed.
[284] Fix | Delete
[285] Fix | Delete
"""
[286] Fix | Delete
if IAC in buffer:
[287] Fix | Delete
buffer = buffer.replace(IAC, IAC+IAC)
[288] Fix | Delete
sys.audit("telnetlib.Telnet.write", self, buffer)
[289] Fix | Delete
self.msg("send %r", buffer)
[290] Fix | Delete
self.sock.sendall(buffer)
[291] Fix | Delete
[292] Fix | Delete
def read_until(self, match, timeout=None):
[293] Fix | Delete
"""Read until a given string is encountered or until timeout.
[294] Fix | Delete
[295] Fix | Delete
When no match is found, return whatever is available instead,
[296] Fix | Delete
possibly the empty string. Raise EOFError if the connection
[297] Fix | Delete
is closed and no cooked data is available.
[298] Fix | Delete
[299] Fix | Delete
"""
[300] Fix | Delete
n = len(match)
[301] Fix | Delete
self.process_rawq()
[302] Fix | Delete
i = self.cookedq.find(match)
[303] Fix | Delete
if i >= 0:
[304] Fix | Delete
i = i+n
[305] Fix | Delete
buf = self.cookedq[:i]
[306] Fix | Delete
self.cookedq = self.cookedq[i:]
[307] Fix | Delete
return buf
[308] Fix | Delete
if timeout is not None:
[309] Fix | Delete
deadline = _time() + timeout
[310] Fix | Delete
with _TelnetSelector() as selector:
[311] Fix | Delete
selector.register(self, selectors.EVENT_READ)
[312] Fix | Delete
while not self.eof:
[313] Fix | Delete
if selector.select(timeout):
[314] Fix | Delete
i = max(0, len(self.cookedq)-n)
[315] Fix | Delete
self.fill_rawq()
[316] Fix | Delete
self.process_rawq()
[317] Fix | Delete
i = self.cookedq.find(match, i)
[318] Fix | Delete
if i >= 0:
[319] Fix | Delete
i = i+n
[320] Fix | Delete
buf = self.cookedq[:i]
[321] Fix | Delete
self.cookedq = self.cookedq[i:]
[322] Fix | Delete
return buf
[323] Fix | Delete
if timeout is not None:
[324] Fix | Delete
timeout = deadline - _time()
[325] Fix | Delete
if timeout < 0:
[326] Fix | Delete
break
[327] Fix | Delete
return self.read_very_lazy()
[328] Fix | Delete
[329] Fix | Delete
def read_all(self):
[330] Fix | Delete
"""Read all data until EOF; block until connection closed."""
[331] Fix | Delete
self.process_rawq()
[332] Fix | Delete
while not self.eof:
[333] Fix | Delete
self.fill_rawq()
[334] Fix | Delete
self.process_rawq()
[335] Fix | Delete
buf = self.cookedq
[336] Fix | Delete
self.cookedq = b''
[337] Fix | Delete
return buf
[338] Fix | Delete
[339] Fix | Delete
def read_some(self):
[340] Fix | Delete
"""Read at least one byte of cooked data unless EOF is hit.
[341] Fix | Delete
[342] Fix | Delete
Return b'' if EOF is hit. Block if no data is immediately
[343] Fix | Delete
available.
[344] Fix | Delete
[345] Fix | Delete
"""
[346] Fix | Delete
self.process_rawq()
[347] Fix | Delete
while not self.cookedq and not self.eof:
[348] Fix | Delete
self.fill_rawq()
[349] Fix | Delete
self.process_rawq()
[350] Fix | Delete
buf = self.cookedq
[351] Fix | Delete
self.cookedq = b''
[352] Fix | Delete
return buf
[353] Fix | Delete
[354] Fix | Delete
def read_very_eager(self):
[355] Fix | Delete
"""Read everything that's possible without blocking in I/O (eager).
[356] Fix | Delete
[357] Fix | Delete
Raise EOFError if connection closed and no cooked data
[358] Fix | Delete
available. Return b'' if no cooked data available otherwise.
[359] Fix | Delete
Don't block unless in the midst of an IAC sequence.
[360] Fix | Delete
[361] Fix | Delete
"""
[362] Fix | Delete
self.process_rawq()
[363] Fix | Delete
while not self.eof and self.sock_avail():
[364] Fix | Delete
self.fill_rawq()
[365] Fix | Delete
self.process_rawq()
[366] Fix | Delete
return self.read_very_lazy()
[367] Fix | Delete
[368] Fix | Delete
def read_eager(self):
[369] Fix | Delete
"""Read readily available data.
[370] Fix | Delete
[371] Fix | Delete
Raise EOFError if connection closed and no cooked data
[372] Fix | Delete
available. Return b'' if no cooked data available otherwise.
[373] Fix | Delete
Don't block unless in the midst of an IAC sequence.
[374] Fix | Delete
[375] Fix | Delete
"""
[376] Fix | Delete
self.process_rawq()
[377] Fix | Delete
while not self.cookedq and not self.eof and self.sock_avail():
[378] Fix | Delete
self.fill_rawq()
[379] Fix | Delete
self.process_rawq()
[380] Fix | Delete
return self.read_very_lazy()
[381] Fix | Delete
[382] Fix | Delete
def read_lazy(self):
[383] Fix | Delete
"""Process and return data that's already in the queues (lazy).
[384] Fix | Delete
[385] Fix | Delete
Raise EOFError if connection closed and no data available.
[386] Fix | Delete
Return b'' if no cooked data available otherwise. Don't block
[387] Fix | Delete
unless in the midst of an IAC sequence.
[388] Fix | Delete
[389] Fix | Delete
"""
[390] Fix | Delete
self.process_rawq()
[391] Fix | Delete
return self.read_very_lazy()
[392] Fix | Delete
[393] Fix | Delete
def read_very_lazy(self):
[394] Fix | Delete
"""Return any data available in the cooked queue (very lazy).
[395] Fix | Delete
[396] Fix | Delete
Raise EOFError if connection closed and no data available.
[397] Fix | Delete
Return b'' if no cooked data available otherwise. Don't block.
[398] Fix | Delete
[399] Fix | Delete
"""
[400] Fix | Delete
buf = self.cookedq
[401] Fix | Delete
self.cookedq = b''
[402] Fix | Delete
if not buf and self.eof and not self.rawq:
[403] Fix | Delete
raise EOFError('telnet connection closed')
[404] Fix | Delete
return buf
[405] Fix | Delete
[406] Fix | Delete
def read_sb_data(self):
[407] Fix | Delete
"""Return any data available in the SB ... SE queue.
[408] Fix | Delete
[409] Fix | Delete
Return b'' if no SB ... SE available. Should only be called
[410] Fix | Delete
after seeing a SB or SE command. When a new SB command is
[411] Fix | Delete
found, old unread SB data will be discarded. Don't block.
[412] Fix | Delete
[413] Fix | Delete
"""
[414] Fix | Delete
buf = self.sbdataq
[415] Fix | Delete
self.sbdataq = b''
[416] Fix | Delete
return buf
[417] Fix | Delete
[418] Fix | Delete
def set_option_negotiation_callback(self, callback):
[419] Fix | Delete
"""Provide a callback function called after each receipt of a telnet option."""
[420] Fix | Delete
self.option_callback = callback
[421] Fix | Delete
[422] Fix | Delete
def process_rawq(self):
[423] Fix | Delete
"""Transfer from raw queue to cooked queue.
[424] Fix | Delete
[425] Fix | Delete
Set self.eof when connection is closed. Don't block unless in
[426] Fix | Delete
the midst of an IAC sequence.
[427] Fix | Delete
[428] Fix | Delete
"""
[429] Fix | Delete
buf = [b'', b'']
[430] Fix | Delete
try:
[431] Fix | Delete
while self.rawq:
[432] Fix | Delete
c = self.rawq_getchar()
[433] Fix | Delete
if not self.iacseq:
[434] Fix | Delete
if c == theNULL:
[435] Fix | Delete
continue
[436] Fix | Delete
if c == b"\021":
[437] Fix | Delete
continue
[438] Fix | Delete
if c != IAC:
[439] Fix | Delete
buf[self.sb] = buf[self.sb] + c
[440] Fix | Delete
continue
[441] Fix | Delete
else:
[442] Fix | Delete
self.iacseq += c
[443] Fix | Delete
elif len(self.iacseq) == 1:
[444] Fix | Delete
# 'IAC: IAC CMD [OPTION only for WILL/WONT/DO/DONT]'
[445] Fix | Delete
if c in (DO, DONT, WILL, WONT):
[446] Fix | Delete
self.iacseq += c
[447] Fix | Delete
continue
[448] Fix | Delete
[449] Fix | Delete
self.iacseq = b''
[450] Fix | Delete
if c == IAC:
[451] Fix | Delete
buf[self.sb] = buf[self.sb] + c
[452] Fix | Delete
else:
[453] Fix | Delete
if c == SB: # SB ... SE start.
[454] Fix | Delete
self.sb = 1
[455] Fix | Delete
self.sbdataq = b''
[456] Fix | Delete
elif c == SE:
[457] Fix | Delete
self.sb = 0
[458] Fix | Delete
self.sbdataq = self.sbdataq + buf[1]
[459] Fix | Delete
buf[1] = b''
[460] Fix | Delete
if self.option_callback:
[461] Fix | Delete
# Callback is supposed to look into
[462] Fix | Delete
# the sbdataq
[463] Fix | Delete
self.option_callback(self.sock, c, NOOPT)
[464] Fix | Delete
else:
[465] Fix | Delete
# We can't offer automatic processing of
[466] Fix | Delete
# suboptions. Alas, we should not get any
[467] Fix | Delete
# unless we did a WILL/DO before.
[468] Fix | Delete
self.msg('IAC %d not recognized' % ord(c))
[469] Fix | Delete
elif len(self.iacseq) == 2:
[470] Fix | Delete
cmd = self.iacseq[1:2]
[471] Fix | Delete
self.iacseq = b''
[472] Fix | Delete
opt = c
[473] Fix | Delete
if cmd in (DO, DONT):
[474] Fix | Delete
self.msg('IAC %s %d',
[475] Fix | Delete
cmd == DO and 'DO' or 'DONT', ord(opt))
[476] Fix | Delete
if self.option_callback:
[477] Fix | Delete
self.option_callback(self.sock, cmd, opt)
[478] Fix | Delete
else:
[479] Fix | Delete
self.sock.sendall(IAC + WONT + opt)
[480] Fix | Delete
elif cmd in (WILL, WONT):
[481] Fix | Delete
self.msg('IAC %s %d',
[482] Fix | Delete
cmd == WILL and 'WILL' or 'WONT', ord(opt))
[483] Fix | Delete
if self.option_callback:
[484] Fix | Delete
self.option_callback(self.sock, cmd, opt)
[485] Fix | Delete
else:
[486] Fix | Delete
self.sock.sendall(IAC + DONT + opt)
[487] Fix | Delete
except EOFError: # raised by self.rawq_getchar()
[488] Fix | Delete
self.iacseq = b'' # Reset on EOF
[489] Fix | Delete
self.sb = 0
[490] Fix | Delete
pass
[491] Fix | Delete
self.cookedq = self.cookedq + buf[0]
[492] Fix | Delete
self.sbdataq = self.sbdataq + buf[1]
[493] Fix | Delete
[494] Fix | Delete
def rawq_getchar(self):
[495] Fix | Delete
"""Get next char from raw queue.
[496] Fix | Delete
[497] Fix | Delete
Block if no data is immediately available. Raise EOFError
[498] Fix | Delete
when connection is closed.
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function