python 如何让read_until读取的内容显示出来

转自:http://www.xyrland.com/?p=2827

操作步骤

方法:修改telnetlib.py,达到read_until读取的内容显示出来
1.cmd下执行python,然后import telnetlib,telnetlib.__file__就知道源码位置。

Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import telnetlib
>>> telnetlib.__file__
'C:\\Python27\\lib\\telnetlib.pyc'
>>> import select
>>> hasattr(select ,"poll")
False
>>>


2.用geany打开telnetlib.py,进行改动编辑
3.修改如下

def _read_until_with_select(self, match, timeout=None):
"""Read until a given string is encountered or until timeout.

The timeout is implemented using select.select().
"""
n = len(match)
self.process_rawq()
print self.cookedq#增加这一句
i = self.cookedq.find(match)
if i >= 0:



while not self.eof and select.select(*s_args) == s_reply:
i = max(0, len(self.cookedq)-n)
self.fill_rawq()
self.process_rawq()
print self.cookedq#增加这一句
i = self.cookedq.find(match, i)
if i >= 0:



def read_very_lazy(self):
"""Return any data available in the cooked queue (very lazy).

Raise EOFError if connection closed and no data available.
Return '' if no cooked data available otherwise. Don't block.

"""
buf = self.cookedq
print buf#增加这一句
self.cookedq = ''
if not buf and self.eof and not self.rawq:
raise EOFError, 'telnet connection closed'
return buf

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值