Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../proc/self/root/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
self.sock = socket.create_connection((host, port), timeout)
[233] Fix | Delete
[234] Fix | Delete
def __del__(self):
[235] Fix | Delete
"""Destructor -- close the connection."""
[236] Fix | Delete
self.close()
[237] Fix | Delete
[238] Fix | Delete
def msg(self, msg, *args):
[239] Fix | Delete
"""Print a debug message, when the debug level is > 0.
[240] Fix | Delete
[241] Fix | Delete
If extra arguments are present, they are substituted in the
[242] Fix | Delete
message using the standard string formatting operator.
[243] Fix | Delete
[244] Fix | Delete
"""
[245] Fix | Delete
if self.debuglevel > 0:
[246] Fix | Delete
print('Telnet(%s,%s):' % (self.host, self.port), end=' ')
[247] Fix | Delete
if args:
[248] Fix | Delete
print(msg % args)
[249] Fix | Delete
else:
[250] Fix | Delete
print(msg)
[251] Fix | Delete
[252] Fix | Delete
def set_debuglevel(self, debuglevel):
[253] Fix | Delete
"""Set the debug level.
[254] Fix | Delete
[255] Fix | Delete
The higher it is, the more debug output you get (on sys.stdout).
[256] Fix | Delete
[257] Fix | Delete
"""
[258] Fix | Delete
self.debuglevel = debuglevel
[259] Fix | Delete
[260] Fix | Delete
def close(self):
[261] Fix | Delete
"""Close the connection."""
[262] Fix | Delete
sock = self.sock
[263] Fix | Delete
self.sock = None
[264] Fix | Delete
self.eof = True
[265] Fix | Delete
self.iacseq = b''
[266] Fix | Delete
self.sb = 0
[267] Fix | Delete
if sock:
[268] Fix | Delete
sock.close()
[269] Fix | Delete
[270] Fix | Delete
def get_socket(self):
[271] Fix | Delete
"""Return the socket object used internally."""
[272] Fix | Delete
return self.sock
[273] Fix | Delete
[274] Fix | Delete
def fileno(self):
[275] Fix | Delete
"""Return the fileno() of the socket object used internally."""
[276] Fix | Delete
return self.sock.fileno()
[277] Fix | Delete
[278] Fix | Delete
def write(self, buffer):
[279] Fix | Delete
"""Write a string to the socket, doubling any IAC characters.
[280] Fix | Delete
[281] Fix | Delete
Can block if the connection is blocked. May raise
[282] Fix | Delete
OSError if the connection is closed.
[283] Fix | Delete
[284] Fix | Delete
"""
[285] Fix | Delete
if IAC in buffer:
[286] Fix | Delete
buffer = buffer.replace(IAC, IAC+IAC)
[287] Fix | Delete
self.msg("send %r", buffer)
[288] Fix | Delete
self.sock.sendall(buffer)
[289] Fix | Delete
[290] Fix | Delete
def read_until(self, match, timeout=None):
[291] Fix | Delete
"""Read until a given string is encountered or until timeout.
[292] Fix | Delete
[293] Fix | Delete
When no match is found, return whatever is available instead,
[294] Fix | Delete
possibly the empty string. Raise EOFError if the connection
[295] Fix | Delete
is closed and no cooked data is available.
[296] Fix | Delete
[297] Fix | Delete
"""
[298] Fix | Delete
n = len(match)
[299] Fix | Delete
self.process_rawq()
[300] Fix | Delete
i = self.cookedq.find(match)
[301] Fix | Delete
if i >= 0:
[302] Fix | Delete
i = i+n
[303] Fix | Delete
buf = self.cookedq[:i]
[304] Fix | Delete
self.cookedq = self.cookedq[i:]
[305] Fix | Delete
return buf
[306] Fix | Delete
if timeout is not None:
[307] Fix | Delete
deadline = _time() + timeout
[308] Fix | Delete
with _TelnetSelector() as selector:
[309] Fix | Delete
selector.register(self, selectors.EVENT_READ)
[310] Fix | Delete
while not self.eof:
[311] Fix | Delete
if selector.select(timeout):
[312] Fix | Delete
i = max(0, len(self.cookedq)-n)
[313] Fix | Delete
self.fill_rawq()
[314] Fix | Delete
self.process_rawq()
[315] Fix | Delete
i = self.cookedq.find(match, i)
[316] Fix | Delete
if i >= 0:
[317] Fix | Delete
i = i+n
[318] Fix | Delete
buf = self.cookedq[:i]
[319] Fix | Delete
self.cookedq = self.cookedq[i:]
[320] Fix | Delete
return buf
[321] Fix | Delete
if timeout is not None:
[322] Fix | Delete
timeout = deadline - _time()
[323] Fix | Delete
if timeout < 0:
[324] Fix | Delete
break
[325] Fix | Delete
return self.read_very_lazy()
[326] Fix | Delete
[327] Fix | Delete
def read_all(self):
[328] Fix | Delete
"""Read all data until EOF; block until connection closed."""
[329] Fix | Delete
self.process_rawq()
[330] Fix | Delete
while not self.eof:
[331] Fix | Delete
self.fill_rawq()
[332] Fix | Delete
self.process_rawq()
[333] Fix | Delete
buf = self.cookedq
[334] Fix | Delete
self.cookedq = b''
[335] Fix | Delete
return buf
[336] Fix | Delete
[337] Fix | Delete
def read_some(self):
[338] Fix | Delete
"""Read at least one byte of cooked data unless EOF is hit.
[339] Fix | Delete
[340] Fix | Delete
Return b'' if EOF is hit. Block if no data is immediately
[341] Fix | Delete
available.
[342] Fix | Delete
[343] Fix | Delete
"""
[344] Fix | Delete
self.process_rawq()
[345] Fix | Delete
while not self.cookedq and not self.eof:
[346] Fix | Delete
self.fill_rawq()
[347] Fix | Delete
self.process_rawq()
[348] Fix | Delete
buf = self.cookedq
[349] Fix | Delete
self.cookedq = b''
[350] Fix | Delete
return buf
[351] Fix | Delete
[352] Fix | Delete
def read_very_eager(self):
[353] Fix | Delete
"""Read everything that's possible without blocking in I/O (eager).
[354] Fix | Delete
[355] Fix | Delete
Raise EOFError if connection closed and no cooked data
[356] Fix | Delete
available. Return b'' if no cooked data available otherwise.
[357] Fix | Delete
Don't block unless in the midst of an IAC sequence.
[358] Fix | Delete
[359] Fix | Delete
"""
[360] Fix | Delete
self.process_rawq()
[361] Fix | Delete
while not self.eof and self.sock_avail():
[362] Fix | Delete
self.fill_rawq()
[363] Fix | Delete
self.process_rawq()
[364] Fix | Delete
return self.read_very_lazy()
[365] Fix | Delete
[366] Fix | Delete
def read_eager(self):
[367] Fix | Delete
"""Read readily available data.
[368] Fix | Delete
[369] Fix | Delete
Raise EOFError if connection closed and no cooked data
[370] Fix | Delete
available. Return b'' if no cooked data available otherwise.
[371] Fix | Delete
Don't block unless in the midst of an IAC sequence.
[372] Fix | Delete
[373] Fix | Delete
"""
[374] Fix | Delete
self.process_rawq()
[375] Fix | Delete
while not self.cookedq and not self.eof and self.sock_avail():
[376] Fix | Delete
self.fill_rawq()
[377] Fix | Delete
self.process_rawq()
[378] Fix | Delete
return self.read_very_lazy()
[379] Fix | Delete
[380] Fix | Delete
def read_lazy(self):
[381] Fix | Delete
"""Process and return data that's already in the queues (lazy).
[382] Fix | Delete
[383] Fix | Delete
Raise EOFError if connection closed and no data available.
[384] Fix | Delete
Return b'' if no cooked data available otherwise. Don't block
[385] Fix | Delete
unless in the midst of an IAC sequence.
[386] Fix | Delete
[387] Fix | Delete
"""
[388] Fix | Delete
self.process_rawq()
[389] Fix | Delete
return self.read_very_lazy()
[390] Fix | Delete
[391] Fix | Delete
def read_very_lazy(self):
[392] Fix | Delete
"""Return any data available in the cooked queue (very lazy).
[393] Fix | Delete
[394] Fix | Delete
Raise EOFError if connection closed and no data available.
[395] Fix | Delete
Return b'' if no cooked data available otherwise. Don't block.
[396] Fix | Delete
[397] Fix | Delete
"""
[398] Fix | Delete
buf = self.cookedq
[399] Fix | Delete
self.cookedq = b''
[400] Fix | Delete
if not buf and self.eof and not self.rawq:
[401] Fix | Delete
raise EOFError('telnet connection closed')
[402] Fix | Delete
return buf
[403] Fix | Delete
[404] Fix | Delete
def read_sb_data(self):
[405] Fix | Delete
"""Return any data available in the SB ... SE queue.
[406] Fix | Delete
[407] Fix | Delete
Return b'' if no SB ... SE available. Should only be called
[408] Fix | Delete
after seeing a SB or SE command. When a new SB command is
[409] Fix | Delete
found, old unread SB data will be discarded. Don't block.
[410] Fix | Delete
[411] Fix | Delete
"""
[412] Fix | Delete
buf = self.sbdataq
[413] Fix | Delete
self.sbdataq = b''
[414] Fix | Delete
return buf
[415] Fix | Delete
[416] Fix | Delete
def set_option_negotiation_callback(self, callback):
[417] Fix | Delete
"""Provide a callback function called after each receipt of a telnet option."""
[418] Fix | Delete
self.option_callback = callback
[419] Fix | Delete
[420] Fix | Delete
def process_rawq(self):
[421] Fix | Delete
"""Transfer from raw queue to cooked queue.
[422] Fix | Delete
[423] Fix | Delete
Set self.eof when connection is closed. Don't block unless in
[424] Fix | Delete
the midst of an IAC sequence.
[425] Fix | Delete
[426] Fix | Delete
"""
[427] Fix | Delete
buf = [b'', b'']
[428] Fix | Delete
try:
[429] Fix | Delete
while self.rawq:
[430] Fix | Delete
c = self.rawq_getchar()
[431] Fix | Delete
if not self.iacseq:
[432] Fix | Delete
if c == theNULL:
[433] Fix | Delete
continue
[434] Fix | Delete
if c == b"\021":
[435] Fix | Delete
continue
[436] Fix | Delete
if c != IAC:
[437] Fix | Delete
buf[self.sb] = buf[self.sb] + c
[438] Fix | Delete
continue
[439] Fix | Delete
else:
[440] Fix | Delete
self.iacseq += c
[441] Fix | Delete
elif len(self.iacseq) == 1:
[442] Fix | Delete
# 'IAC: IAC CMD [OPTION only for WILL/WONT/DO/DONT]'
[443] Fix | Delete
if c in (DO, DONT, WILL, WONT):
[444] Fix | Delete
self.iacseq += c
[445] Fix | Delete
continue
[446] Fix | Delete
[447] Fix | Delete
self.iacseq = b''
[448] Fix | Delete
if c == IAC:
[449] Fix | Delete
buf[self.sb] = buf[self.sb] + c
[450] Fix | Delete
else:
[451] Fix | Delete
if c == SB: # SB ... SE start.
[452] Fix | Delete
self.sb = 1
[453] Fix | Delete
self.sbdataq = b''
[454] Fix | Delete
elif c == SE:
[455] Fix | Delete
self.sb = 0
[456] Fix | Delete
self.sbdataq = self.sbdataq + buf[1]
[457] Fix | Delete
buf[1] = b''
[458] Fix | Delete
if self.option_callback:
[459] Fix | Delete
# Callback is supposed to look into
[460] Fix | Delete
# the sbdataq
[461] Fix | Delete
self.option_callback(self.sock, c, NOOPT)
[462] Fix | Delete
else:
[463] Fix | Delete
# We can't offer automatic processing of
[464] Fix | Delete
# suboptions. Alas, we should not get any
[465] Fix | Delete
# unless we did a WILL/DO before.
[466] Fix | Delete
self.msg('IAC %d not recognized' % ord(c))
[467] Fix | Delete
elif len(self.iacseq) == 2:
[468] Fix | Delete
cmd = self.iacseq[1:2]
[469] Fix | Delete
self.iacseq = b''
[470] Fix | Delete
opt = c
[471] Fix | Delete
if cmd in (DO, DONT):
[472] Fix | Delete
self.msg('IAC %s %d',
[473] Fix | Delete
cmd == DO and 'DO' or 'DONT', ord(opt))
[474] Fix | Delete
if self.option_callback:
[475] Fix | Delete
self.option_callback(self.sock, cmd, opt)
[476] Fix | Delete
else:
[477] Fix | Delete
self.sock.sendall(IAC + WONT + opt)
[478] Fix | Delete
elif cmd in (WILL, WONT):
[479] Fix | Delete
self.msg('IAC %s %d',
[480] Fix | Delete
cmd == WILL and 'WILL' or 'WONT', ord(opt))
[481] Fix | Delete
if self.option_callback:
[482] Fix | Delete
self.option_callback(self.sock, cmd, opt)
[483] Fix | Delete
else:
[484] Fix | Delete
self.sock.sendall(IAC + DONT + opt)
[485] Fix | Delete
except EOFError: # raised by self.rawq_getchar()
[486] Fix | Delete
self.iacseq = b'' # Reset on EOF
[487] Fix | Delete
self.sb = 0
[488] Fix | Delete
pass
[489] Fix | Delete
self.cookedq = self.cookedq + buf[0]
[490] Fix | Delete
self.sbdataq = self.sbdataq + buf[1]
[491] Fix | Delete
[492] Fix | Delete
def rawq_getchar(self):
[493] Fix | Delete
"""Get next char from raw queue.
[494] Fix | Delete
[495] Fix | Delete
Block if no data is immediately available. Raise EOFError
[496] Fix | Delete
when connection is closed.
[497] Fix | Delete
[498] Fix | Delete
"""
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function