本文整理汇总了Python中asyncore.dispatcher方法的典型用法代码示例。如果您正苦于以下问题:Python asyncore.dispatcher方法的具体用法?Python asyncore.dispatcher怎么用?Python asyncore.dispatcher使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asyncore
的用法示例。
在下文中一共展示了asyncore.dispatcher方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import dispatcher [as 别名]
def __init__(self, localaddr, remoteaddr):
self._localaddr = localaddr
self._remoteaddr = remoteaddr
asyncore.dispatcher.__init__(self)
try:
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
# try to re-use a server port if possible
self.set_reuse_addr()
self.bind(localaddr)
self.listen(5)
except:
# cleanup asyncore.socket_map before raising
self.close()
raise
else:
print >> DEBUGSTREAM, \
'%s started at %s\n\tLocal addr: %s\n\tRemote addr:%s' % (
self.__class__.__name__, time.ctime(time.time()),
localaddr, remoteaddr)
示例2: __init__
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import dispatcher [as 别名]
def __init__ (self, sock=None, map=None):
# for string terminator matching
self.ac_in_buffer = ''
# we use a list here rather than cStringIO for a few reasons...
# del lst[:] is faster than sio.truncate(0)
# lst = [] is faster than sio.truncate(0)
# cStringIO will be gaining unicode support in py3k, which
# will negatively affect the performance of bytes compared to
# a ''.join() equivalent
self.incoming = []
# we toss the use of the "simple producer" and replace it with
# a pure deque, which the original fifo was a wrapping of
self.producer_fifo = deque()
asyncore.dispatcher.__init__ (self, sock, map)
示例3: __init__
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import dispatcher [as 别名]
def __init__(
self,
server,
sock,
addr,
adj,
map=None,
):
self.server = server
self.adj = adj
self.outbufs = [OverflowableBuffer(adj.outbuf_overflow)]
self.creation_time = self.last_activity = time.time()
# task_lock used to push/pop requests
self.task_lock = thread.allocate_lock()
# outbuf_lock used to access any outbuf
self.outbuf_lock = thread.allocate_lock()
asyncore.dispatcher.__init__(self, sock, map=map)
# Don't let asyncore.dispatcher throttle self.addr on us.
self.addr = addr
示例4: __init__
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import dispatcher [as 别名]
def __init__(self, address, af=socket.AF_INET):
threading.Thread.__init__(self)
asyncore.dispatcher.__init__(self)
self.create_socket(af, socket.SOCK_STREAM)
try:
self.bind(address)
self.listen(5)
self.active = False
self.active_lock = threading.Lock()
self.host, self.port = self.socket.getsockname()[:2]
self.handler_instance = None
except:
# unregister the server on bind() error,
# needed by TestIPv6Environment.setUpClass()
self.del_channel()
raise
示例5: test_log_info
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import dispatcher [as 别名]
def test_log_info(self):
d = asyncore.dispatcher()
# capture output of dispatcher.log_info() (to stdout via print)
fp = StringIO()
stdout = sys.stdout
l1 = "Have you got anything without spam?"
l2 = "Why can't she have egg bacon spam and sausage?"
l3 = "THAT'S got spam in it!"
try:
sys.stdout = fp
d.log_info(l1, 'EGGS')
d.log_info(l2)
d.log_info(l3, 'SPAM')
finally:
sys.stdout = stdout
lines = fp.getvalue().splitlines()
expected = ['EGGS: %s' % l1, 'info: %s' % l2, 'SPAM: %s' % l3]
self.assertEqual(lines, expected)
示例6: test_unhandled
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import dispatcher [as 别名]
def test_unhandled(self):
d = asyncore.dispatcher()
d.ignore_log_types = ()
# capture output of dispatcher.log_info() (to stdout via print)
fp = StringIO()
stdout = sys.stdout
try:
sys.stdout = fp
d.handle_expt()
d.handle_read()
d.handle_write()
d.handle_connect()
d.handle_accept()
finally:
sys.stdout = stdout
lines = fp.getvalue().splitlines()
expected = ['warning: unhandled incoming priority event',
'warning: unhandled read event',
'warning: unhandled write event',
'warning: unhandled connect event',
'warning: unhandled accept event']
self.assertEqual(lines, expected)
示例7: test_issue_8594
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import dispatcher [as 别名]
def test_issue_8594(self):
# XXX - this test is supposed to be removed in next major Python
# version
d = asyncore.dispatcher(socket.socket())
# make sure the error message no longer refers to the socket
# object but the dispatcher instance instead
self.assertRaisesRegexp(AttributeError, 'dispatcher instance',
getattr, d, 'foo')
# cheap inheritance with the underlying socket is supposed
# to still work but a DeprecationWarning is expected
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
family = d.family
self.assertEqual(family, socket.AF_INET)
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[0].category, DeprecationWarning))
示例8: test_set_reuse_addr
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import dispatcher [as 别名]
def test_set_reuse_addr(self):
sock = socket.socket()
try:
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
except socket.error:
unittest.skip("SO_REUSEADDR not supported on this platform")
else:
# if SO_REUSEADDR succeeded for sock we expect asyncore
# to do the same
s = asyncore.dispatcher(socket.socket())
self.assertFalse(s.socket.getsockopt(socket.SOL_SOCKET,
socket.SO_REUSEADDR))
s.create_socket(socket.AF_INET, socket.SOCK_STREAM)
s.set_reuse_addr()
self.assertTrue(s.socket.getsockopt(socket.SOL_SOCKET,
socket.SO_REUSEADDR))
finally:
sock.close()
示例9: __init__
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import dispatcher [as 别名]
def __init__(self, username: str, password: str, channel: str) -> None:
assert username is not None, "No username specified!"
assert password is not None, "No password specified!"
assert channel is not None, "No channel specified!"
self.username = username
self.password = password
self.channel = channel
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((TWITCH_HOST, TWITCH_PORT))
self.buffer = bytes("PASS %s\r\nNICK %s\r\n" % (password, username), "utf8")
prevent_timeout()
global DEMOCRACY_IS_IN_PAUSE
global ANARCHY_MODE
global DEMOCRACY_PAUSE_BUTTON
global DEMOCRACY_PAUSE_ENABLED
if DEMOCRACY_PAUSE_ENABLED and not DEMOCRACY_IS_IN_PAUSE and not ANARCHY_MODE:
controller.push_button(DEMOCRACY_PAUSE_BUTTON)
sleep(0.6)
write_votes()
示例10: __init__
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import dispatcher [as 别名]
def __init__(self, sock):
asyncore.dispatcher.__init__(self, sock)
self.data = ''
self.rlen = 0
self.dlen = 4
示例11: __init__
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import dispatcher [as 别名]
def __init__(self, host, port):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect( (host, port) )
self.buffer = ""
self.cur = ""
示例12: __init__
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import dispatcher [as 别名]
def __init__(self, markov, localHost, localPort, mtunnelHost, mtunnelPort):
"""Creates the socket, binds to clientPort"""
asyncore.dispatcher.__init__(self)
self.markov = markov
self.clientPort = localPort
self.host = localHost
self.mtunnel_host = mtunnelHost
self.mtunnel_port = mtunnelPort
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.bind((self.host, self.clientPort))
self.listen(5)
示例13: close
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import dispatcher [as 别名]
def close(self):
asyncore.dispatcher.close(self)
# Node management