本文整理汇总了Python中asynchat.async_chat方法的典型用法代码示例。如果您正苦于以下问题:Python asynchat.async_chat方法的具体用法?Python asynchat.async_chat怎么用?Python asynchat.async_chat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asynchat
的用法示例。
在下文中一共展示了asynchat.async_chat方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import asynchat [as 别名]
# 或者: from asynchat import async_chat [as 别名]
def __init__(self, server, conn, addr):
asynchat.async_chat.__init__(self, conn)
self.__server = server
self.__conn = conn
self.__addr = addr
self.__line = []
self.__state = self.COMMAND
self.__greeting = 0
self.__mailfrom = None
self.__rcpttos = []
self.__data = ''
self.__fqdn = socket.getfqdn()
try:
self.__peer = conn.getpeername()
except socket.error, err:
# a race condition may occur if the other end is closing
# before we can get the peername
self.close()
if err[0] != errno.ENOTCONN:
raise
return
示例2: test_blockingioerror
# 需要导入模块: import asynchat [as 别名]
# 或者: from asynchat import async_chat [as 别名]
def test_blockingioerror(self):
# Issue #16133: handle_read() must ignore blocking I/O errors like
# EAGAIN
class fake_socket:
def fileno(self):
return 0
def recv(self, size):
raise socket.error(errno.EAGAIN, "EAGAIN")
class MyChat(asynchat.async_chat):
def handle_error(self):
raise Exception("error")
sock = fake_socket()
dispatcher = MyChat()
dispatcher.set_socket(sock)
self.addCleanup(dispatcher.del_channel)
# must not call handle_error()
dispatcher.handle_read()
示例3: initiate_send
# 需要导入模块: import asynchat [as 别名]
# 或者: from asynchat import async_chat [as 别名]
def initiate_send(self):
asynchat.async_chat.initiate_send(self)
if not self._closed:
# if there's still data to send we want to be ready
# for writing, else we're only intereseted in reading
if not self.producer_fifo:
wanted = self.ioloop.READ
else:
# In FTPHandler, we also want to listen for user input
# hence the READ. DTPHandler has its own initiate_send()
# which will either READ or WRITE.
wanted = self.ioloop.READ | self.ioloop.WRITE
if self._wanted_io_events != wanted:
self.ioloop.modify(self._fileno, wanted)
self._wanted_io_events = wanted
else:
debug("call: initiate_send(); called with no connection",
inst=self)
示例4: __init__
# 需要导入模块: import asynchat [as 别名]
# 或者: from asynchat import async_chat [as 别名]
def __init__(self, terminator, server_port):
asynchat.async_chat.__init__(self)
self.contents = []
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((HOST, server_port))
self.set_terminator(terminator)
self.buffer = b""
def handle_connect(self):
pass
if sys.platform == 'darwin':
# select.poll returns a select.POLLHUP at the end of the tests
# on darwin, so just ignore it
def handle_expt(self):
pass
示例5: line_terminator_check
# 需要导入模块: import asynchat [as 别名]
# 或者: from asynchat import async_chat [as 别名]
def line_terminator_check(self, term, server_chunk):
event = threading.Event()
s = echo_server(event)
s.chunk_size = server_chunk
s.start()
event.wait()
event.clear()
time.sleep(0.01) # Give server time to start accepting.
c = echo_client(term, s.port)
c.push(b"hello ")
c.push(b"world" + term)
c.push(b"I'm not dead yet!" + term)
c.push(SERVER_QUIT)
asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
s.join(timeout=TIMEOUT)
if s.is_alive():
self.fail("join() timed out")
self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"])
# the line terminator tests below check receiving variously-sized
# chunks back from the server in order to exercise all branches of
# async_chat.handle_read
示例6: push
# 需要导入模块: import asynchat [as 别名]
# 或者: from asynchat import async_chat [as 别名]
def push(self, msg):
asynchat.async_chat.push(self, msg + '\r\n')
# Implementation of base class abstract method
示例7: __init__
# 需要导入模块: import asynchat [as 别名]
# 或者: from asynchat import async_chat [as 别名]
def __init__(self, conn, baseclass):
asynchat.async_chat.__init__(self, conn)
self.baseclass = baseclass
self.baseclass.last_received_data = ''
示例8: push
# 需要导入模块: import asynchat [as 别名]
# 或者: from asynchat import async_chat [as 别名]
def push(self, data):
asynchat.async_chat.push(self, data + '\r\n')
示例9: cmd_list
# 需要导入模块: import asynchat [as 别名]
# 或者: from asynchat import async_chat [as 别名]
def cmd_list(self, arg):
if arg:
self.push('+OK %s %s' %(arg, arg))
else:
self.push('+OK')
asynchat.async_chat.push(self, LIST_RESP)
示例10: cmd_retr
# 需要导入模块: import asynchat [as 别名]
# 或者: from asynchat import async_chat [as 别名]
def cmd_retr(self, arg):
self.push('+OK %s bytes' %len(RETR_RESP))
asynchat.async_chat.push(self, RETR_RESP)
示例11: __init__
# 需要导入模块: import asynchat [as 别名]
# 或者: from asynchat import async_chat [as 别名]
def __init__(self, conn):
asynchat.async_chat.__init__(self, conn)
self.socket = ssl.wrap_socket(self.socket, certfile=CERTFILE,
server_side=True,
do_handshake_on_connect=False)
# Must try handshake before calling push()
self._ssl_accepting = True
self._do_ssl_handshake()
self.set_terminator("\r\n")
self.in_buffer = []
self.push('+OK dummy pop3 server ready.')
示例12: __init__
# 需要导入模块: import asynchat [as 别名]
# 或者: from asynchat import async_chat [as 别名]
def __init__(self, terminator, server_port):
asynchat.async_chat.__init__(self)
self.contents = []
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((HOST, server_port))
self.set_terminator(terminator)
self.buffer = ''
示例13: test_numeric_terminator1
# 需要导入模块: import asynchat [as 别名]
# 或者: from asynchat import async_chat [as 别名]
def test_numeric_terminator1(self):
# check that ints & longs both work (since type is
# explicitly checked in async_chat.handle_read)
self.numeric_terminator_check(1)
self.numeric_terminator_check(1L)