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


Python asyncio.DatagramProtocol方法代码示例

本文整理汇总了Python中asyncio.DatagramProtocol方法的典型用法代码示例。如果您正苦于以下问题:Python asyncio.DatagramProtocol方法的具体用法?Python asyncio.DatagramProtocol怎么用?Python asyncio.DatagramProtocol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在asyncio的用法示例。


在下文中一共展示了asyncio.DatagramProtocol方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_empty

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DatagramProtocol [as 别名]
def test_empty(self):
        f = mock.Mock()
        p = asyncio.Protocol()
        self.assertIsNone(p.connection_made(f))
        self.assertIsNone(p.connection_lost(f))
        self.assertIsNone(p.data_received(f))
        self.assertIsNone(p.eof_received())

        dp = asyncio.DatagramProtocol()
        self.assertIsNone(dp.connection_made(f))
        self.assertIsNone(dp.connection_lost(f))
        self.assertIsNone(dp.error_received(f))
        self.assertIsNone(dp.datagram_received(f, f))

        sp = asyncio.SubprocessProtocol()
        self.assertIsNone(sp.connection_made(f))
        self.assertIsNone(sp.connection_lost(f))
        self.assertIsNone(sp.pipe_data_received(1, f))
        self.assertIsNone(sp.pipe_connection_lost(1, f))
        self.assertIsNone(sp.process_exited()) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:22,代码来源:test_events.py

示例2: create_socket

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DatagramProtocol [as 别名]
def create_socket(self) -> None:
        """Use the loop.create_datagram_endpoint method to create a socket."""
        self._transport, _ = await self._loop.create_datagram_endpoint(
            asyncio.DatagramProtocol,
            family=socket.AF_INET,
            remote_addr=self._addr
        ) 
开发者ID:python-discord,项目名称:bot,代码行数:9,代码来源:async_stats.py

示例3: setUp

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DatagramProtocol [as 别名]
def setUp(self):
        self.loop = self.new_test_loop()
        self.protocol = test_utils.make_test_protocol(asyncio.DatagramProtocol)
        self.sock = mock.Mock(spec_set=socket.socket)
        self.sock.fileno.return_value = 7 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_selector_events.py

示例4: test_create_datagram_endpoint_connect_err

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DatagramProtocol [as 别名]
def test_create_datagram_endpoint_connect_err(self):
        self.loop.sock_connect = mock.Mock()
        self.loop.sock_connect.side_effect = OSError

        coro = self.loop.create_datagram_endpoint(
            asyncio.DatagramProtocol, remote_addr=('127.0.0.1', 0))
        self.assertRaises(
            OSError, self.loop.run_until_complete, coro) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_base_events.py

示例5: test_create_datagram_endpoint_socket_err

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DatagramProtocol [as 别名]
def test_create_datagram_endpoint_socket_err(self, m_socket):
        m_socket.getaddrinfo = socket.getaddrinfo
        m_socket.socket.side_effect = OSError

        coro = self.loop.create_datagram_endpoint(
            asyncio.DatagramProtocol, family=socket.AF_INET)
        self.assertRaises(
            OSError, self.loop.run_until_complete, coro)

        coro = self.loop.create_datagram_endpoint(
            asyncio.DatagramProtocol, local_addr=('127.0.0.1', 0))
        self.assertRaises(
            OSError, self.loop.run_until_complete, coro) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:15,代码来源:test_base_events.py

示例6: test_create_datagram_endpoint_no_matching_family

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DatagramProtocol [as 别名]
def test_create_datagram_endpoint_no_matching_family(self):
        coro = self.loop.create_datagram_endpoint(
            asyncio.DatagramProtocol,
            remote_addr=('127.0.0.1', 0), local_addr=('::1', 0))
        self.assertRaises(
            ValueError, self.loop.run_until_complete, coro) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_base_events.py

示例7: test_create_datagram_endpoint_noaddr_nofamily

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DatagramProtocol [as 别名]
def test_create_datagram_endpoint_noaddr_nofamily(self):
        coro = self.loop.create_datagram_endpoint(
            asyncio.DatagramProtocol)
        self.assertRaises(ValueError, self.loop.run_until_complete, coro) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_base_events.py

示例8: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DatagramProtocol [as 别名]
def __init__(self):
        asyncio.DatagramProtocol.__init__(self)
        OscProtocol.__init__(self)
        self.loop = None

    ### PRIVATE METHODS ### 
开发者ID:josiah-wolf-oberholtzer,项目名称:supriya,代码行数:8,代码来源:protocols.py

示例9: open_udp_connection

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DatagramProtocol [as 别名]
def open_udp_connection(self, host, port, data, addr, reply):
        class Protocol(asyncio.DatagramProtocol):
            def __init__(prot, data):
                self.udpmap[addr] = prot
                prot.databuf = [data]
                prot.transport = None
                prot.update = 0
            def connection_made(prot, transport):
                prot.transport = transport
                for data in prot.databuf:
                    transport.sendto(data)
                prot.databuf.clear()
                prot.update = time.perf_counter()
            def new_data_arrived(prot, data):
                if prot.transport:
                    prot.transport.sendto(data)
                else:
                    prot.databuf.append(data)
                prot.update = time.perf_counter()
            def datagram_received(prot, data, addr):
                data = self.cipher.datagram.decrypt(data) if self.cipher else data
                data = self.rproto.udp_client(data) if not self.direct else data
                reply(data)
                prot.update = time.perf_counter()
            def connection_lost(prot, exc):
                self.udpmap.pop(addr, None)
        if addr in self.udpmap:
            self.udpmap[addr].new_data_arrived(data)
        else:
            if self.direct and host == 'tunnel':
                raise Exception('Unknown tunnel endpoint')
            self.connection_change(1)
            if len(self.udpmap) > UDP_LIMIT:
                min_addr = min(self.udpmap, key=lambda x: self.udpmap[x].update)
                prot = self.udpmap.pop(min_addr)
                if prot.transport:
                    prot.transport.close()
            prot = Protocol(data)
            remote_addr = (host, port) if self.direct else (self.host_name, self.port)
            await asyncio.get_event_loop().create_datagram_endpoint(lambda: prot, remote_addr=remote_addr) 
开发者ID:qwj,项目名称:python-proxy,代码行数:42,代码来源:server.py

示例10: start_udp_server

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DatagramProtocol [as 别名]
def start_udp_server(self, args):
        class Protocol(asyncio.DatagramProtocol):
            def connection_made(prot, transport):
                prot.transport = transport
            def datagram_received(prot, data, addr):
                asyncio.ensure_future(datagram_handler(prot.transport, data, addr, **vars(self), **args))
        return asyncio.get_event_loop().create_datagram_endpoint(Protocol, local_addr=(self.host_name, self.port)) 
开发者ID:qwj,项目名称:python-proxy,代码行数:9,代码来源:server.py

示例11: setUp

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DatagramProtocol [as 别名]
def setUp(self):
        super().setUp()
        self.loop = self.new_test_loop()
        self.protocol = test_utils.make_test_protocol(asyncio.DatagramProtocol)
        self.sock = mock.Mock(spec_set=socket.socket)
        self.sock.fileno.return_value = 7 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:8,代码来源:test_selector_events.py


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