当前位置: 首页>>代码示例>>Python>>正文


Python asyncore.dispatcher方法代码示例

本文整理汇总了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) 
开发者ID:glmcdona,项目名称:meddle,代码行数:21,代码来源:smtpd.py

示例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) 
开发者ID:glmcdona,项目名称:meddle,代码行数:18,代码来源:asynchat.py

示例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 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:24,代码来源:channel.py

示例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 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_ftplib.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_asyncore.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:test_asyncore.py

示例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)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_asyncore.py

示例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() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_asyncore.py

示例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() 
开发者ID:ItsDeidara,项目名称:CommunityController,代码行数:25,代码来源:main.py

示例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 
开发者ID:sdn-ixp,项目名称:iSDX,代码行数:7,代码来源:logServer.py

示例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 = "" 
开发者ID:LightTable,项目名称:Python,代码行数:8,代码来源:ltmain.py

示例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) 
开发者ID:cylance,项目名称:MarkovObfuscate,代码行数:13,代码来源:mtunnel.py

示例13: close

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import dispatcher [as 别名]
def close(self):
        asyncore.dispatcher.close(self)


    # Node management 
开发者ID:ricmoo,项目名称:pycoind,代码行数:7,代码来源:basenode.py


注:本文中的asyncore.dispatcher方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。