Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python3....
File: telnetlib.py
[500] Fix | Delete
"""
[501] Fix | Delete
if not self.rawq:
[502] Fix | Delete
self.fill_rawq()
[503] Fix | Delete
if self.eof:
[504] Fix | Delete
raise EOFError
[505] Fix | Delete
c = self.rawq[self.irawq:self.irawq+1]
[506] Fix | Delete
self.irawq = self.irawq + 1
[507] Fix | Delete
if self.irawq >= len(self.rawq):
[508] Fix | Delete
self.rawq = b''
[509] Fix | Delete
self.irawq = 0
[510] Fix | Delete
return c
[511] Fix | Delete
[512] Fix | Delete
def fill_rawq(self):
[513] Fix | Delete
"""Fill raw queue from exactly one recv() system call.
[514] Fix | Delete
[515] Fix | Delete
Block if no data is immediately available. Set self.eof when
[516] Fix | Delete
connection is closed.
[517] Fix | Delete
[518] Fix | Delete
"""
[519] Fix | Delete
if self.irawq >= len(self.rawq):
[520] Fix | Delete
self.rawq = b''
[521] Fix | Delete
self.irawq = 0
[522] Fix | Delete
# The buffer size should be fairly small so as to avoid quadratic
[523] Fix | Delete
# behavior in process_rawq() above
[524] Fix | Delete
buf = self.sock.recv(50)
[525] Fix | Delete
self.msg("recv %r", buf)
[526] Fix | Delete
self.eof = (not buf)
[527] Fix | Delete
self.rawq = self.rawq + buf
[528] Fix | Delete
[529] Fix | Delete
def sock_avail(self):
[530] Fix | Delete
"""Test whether data is available on the socket."""
[531] Fix | Delete
with _TelnetSelector() as selector:
[532] Fix | Delete
selector.register(self, selectors.EVENT_READ)
[533] Fix | Delete
return bool(selector.select(0))
[534] Fix | Delete
[535] Fix | Delete
def interact(self):
[536] Fix | Delete
"""Interaction function, emulates a very dumb telnet client."""
[537] Fix | Delete
if sys.platform == "win32":
[538] Fix | Delete
self.mt_interact()
[539] Fix | Delete
return
[540] Fix | Delete
with _TelnetSelector() as selector:
[541] Fix | Delete
selector.register(self, selectors.EVENT_READ)
[542] Fix | Delete
selector.register(sys.stdin, selectors.EVENT_READ)
[543] Fix | Delete
[544] Fix | Delete
while True:
[545] Fix | Delete
for key, events in selector.select():
[546] Fix | Delete
if key.fileobj is self:
[547] Fix | Delete
try:
[548] Fix | Delete
text = self.read_eager()
[549] Fix | Delete
except EOFError:
[550] Fix | Delete
print('*** Connection closed by remote host ***')
[551] Fix | Delete
return
[552] Fix | Delete
if text:
[553] Fix | Delete
sys.stdout.write(text.decode('ascii'))
[554] Fix | Delete
sys.stdout.flush()
[555] Fix | Delete
elif key.fileobj is sys.stdin:
[556] Fix | Delete
line = sys.stdin.readline().encode('ascii')
[557] Fix | Delete
if not line:
[558] Fix | Delete
return
[559] Fix | Delete
self.write(line)
[560] Fix | Delete
[561] Fix | Delete
def mt_interact(self):
[562] Fix | Delete
"""Multithreaded version of interact()."""
[563] Fix | Delete
import _thread
[564] Fix | Delete
_thread.start_new_thread(self.listener, ())
[565] Fix | Delete
while 1:
[566] Fix | Delete
line = sys.stdin.readline()
[567] Fix | Delete
if not line:
[568] Fix | Delete
break
[569] Fix | Delete
self.write(line.encode('ascii'))
[570] Fix | Delete
[571] Fix | Delete
def listener(self):
[572] Fix | Delete
"""Helper for mt_interact() -- this executes in the other thread."""
[573] Fix | Delete
while 1:
[574] Fix | Delete
try:
[575] Fix | Delete
data = self.read_eager()
[576] Fix | Delete
except EOFError:
[577] Fix | Delete
print('*** Connection closed by remote host ***')
[578] Fix | Delete
return
[579] Fix | Delete
if data:
[580] Fix | Delete
sys.stdout.write(data.decode('ascii'))
[581] Fix | Delete
else:
[582] Fix | Delete
sys.stdout.flush()
[583] Fix | Delete
[584] Fix | Delete
def expect(self, list, timeout=None):
[585] Fix | Delete
"""Read until one from a list of a regular expressions matches.
[586] Fix | Delete
[587] Fix | Delete
The first argument is a list of regular expressions, either
[588] Fix | Delete
compiled (re.Pattern instances) or uncompiled (strings).
[589] Fix | Delete
The optional second argument is a timeout, in seconds; default
[590] Fix | Delete
is no timeout.
[591] Fix | Delete
[592] Fix | Delete
Return a tuple of three items: the index in the list of the
[593] Fix | Delete
first regular expression that matches; the re.Match object
[594] Fix | Delete
returned; and the text read up till and including the match.
[595] Fix | Delete
[596] Fix | Delete
If EOF is read and no text was read, raise EOFError.
[597] Fix | Delete
Otherwise, when nothing matches, return (-1, None, text) where
[598] Fix | Delete
text is the text received so far (may be the empty string if a
[599] Fix | Delete
timeout happened).
[600] Fix | Delete
[601] Fix | Delete
If a regular expression ends with a greedy match (e.g. '.*')
[602] Fix | Delete
or if more than one expression can match the same input, the
[603] Fix | Delete
results are undeterministic, and may depend on the I/O timing.
[604] Fix | Delete
[605] Fix | Delete
"""
[606] Fix | Delete
re = None
[607] Fix | Delete
list = list[:]
[608] Fix | Delete
indices = range(len(list))
[609] Fix | Delete
for i in indices:
[610] Fix | Delete
if not hasattr(list[i], "search"):
[611] Fix | Delete
if not re: import re
[612] Fix | Delete
list[i] = re.compile(list[i])
[613] Fix | Delete
if timeout is not None:
[614] Fix | Delete
deadline = _time() + timeout
[615] Fix | Delete
with _TelnetSelector() as selector:
[616] Fix | Delete
selector.register(self, selectors.EVENT_READ)
[617] Fix | Delete
while not self.eof:
[618] Fix | Delete
self.process_rawq()
[619] Fix | Delete
for i in indices:
[620] Fix | Delete
m = list[i].search(self.cookedq)
[621] Fix | Delete
if m:
[622] Fix | Delete
e = m.end()
[623] Fix | Delete
text = self.cookedq[:e]
[624] Fix | Delete
self.cookedq = self.cookedq[e:]
[625] Fix | Delete
return (i, m, text)
[626] Fix | Delete
if timeout is not None:
[627] Fix | Delete
ready = selector.select(timeout)
[628] Fix | Delete
timeout = deadline - _time()
[629] Fix | Delete
if not ready:
[630] Fix | Delete
if timeout < 0:
[631] Fix | Delete
break
[632] Fix | Delete
else:
[633] Fix | Delete
continue
[634] Fix | Delete
self.fill_rawq()
[635] Fix | Delete
text = self.read_very_lazy()
[636] Fix | Delete
if not text and self.eof:
[637] Fix | Delete
raise EOFError
[638] Fix | Delete
return (-1, None, text)
[639] Fix | Delete
[640] Fix | Delete
def __enter__(self):
[641] Fix | Delete
return self
[642] Fix | Delete
[643] Fix | Delete
def __exit__(self, type, value, traceback):
[644] Fix | Delete
self.close()
[645] Fix | Delete
[646] Fix | Delete
[647] Fix | Delete
def test():
[648] Fix | Delete
"""Test program for telnetlib.
[649] Fix | Delete
[650] Fix | Delete
Usage: python telnetlib.py [-d] ... [host [port]]
[651] Fix | Delete
[652] Fix | Delete
Default host is localhost; default port is 23.
[653] Fix | Delete
[654] Fix | Delete
"""
[655] Fix | Delete
debuglevel = 0
[656] Fix | Delete
while sys.argv[1:] and sys.argv[1] == '-d':
[657] Fix | Delete
debuglevel = debuglevel+1
[658] Fix | Delete
del sys.argv[1]
[659] Fix | Delete
host = 'localhost'
[660] Fix | Delete
if sys.argv[1:]:
[661] Fix | Delete
host = sys.argv[1]
[662] Fix | Delete
port = 0
[663] Fix | Delete
if sys.argv[2:]:
[664] Fix | Delete
portstr = sys.argv[2]
[665] Fix | Delete
try:
[666] Fix | Delete
port = int(portstr)
[667] Fix | Delete
except ValueError:
[668] Fix | Delete
port = socket.getservbyname(portstr, 'tcp')
[669] Fix | Delete
with Telnet() as tn:
[670] Fix | Delete
tn.set_debuglevel(debuglevel)
[671] Fix | Delete
tn.open(host, port, timeout=0.5)
[672] Fix | Delete
tn.interact()
[673] Fix | Delete
[674] Fix | Delete
if __name__ == '__main__':
[675] Fix | Delete
test()
[676] Fix | Delete
[677] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function