當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。