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


Python asyncio.open_unix_connection方法代码示例

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


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

示例1: _setUp

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import open_unix_connection [as 别名]
def _setUp(self):
        self.r, self.w = yield from asyncio.open_unix_connection(self.path)
        config = H2Configuration(header_encoding='utf-8')
        self.conn = H2Connection(config=config)
        self.conn.initiate_connection()
        self.w.write(self.conn.data_to_send())
        events = yield from self._expect_events(3)
        self.assertIsInstance(events[0], RemoteSettingsChanged)
        self.assertIsInstance(events[1], RemoteSettingsChanged)
        self.assertIsInstance(events[2], SettingsAcknowledged)

        self.assertIsInstance((yield from self.server.events.get()),
                              RemoteSettingsChanged)
        self.assertIsInstance((yield from self.server.events.get()),
                              SettingsAcknowledged)
        self.assertIsInstance((yield from self.server.events.get()),
                              SettingsAcknowledged) 
开发者ID:decentfox,项目名称:aioh2,代码行数:19,代码来源:__init__.py

示例2: handshake

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import open_unix_connection [as 别名]
def handshake(self):
        if sys.platform == 'linux' or sys.platform == 'darwin':
            self.sock_reader, self.sock_writer = await asyncio.open_unix_connection(self.ipc_path, loop=self.loop)
        elif sys.platform == 'win32' or sys.platform == 'win64':
            self.sock_reader = asyncio.StreamReader(loop=self.loop)
            reader_protocol = asyncio.StreamReaderProtocol(
                self.sock_reader, loop=self.loop)
            try:
                self.sock_writer, _ = await self.loop.create_pipe_connection(lambda: reader_protocol, self.ipc_path)
            except FileNotFoundError:
                raise InvalidPipe
        self.send_data(0, {'v': 1, 'client_id': self.client_id})
        data = await self.sock_reader.read(1024)
        code, length = struct.unpack('<ii', data[:8])
        if self._events_on:
            self.sock_reader.feed_data = self.on_event 
开发者ID:qwertyquerty,项目名称:pypresence,代码行数:18,代码来源:baseclient.py

示例3: send

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import open_unix_connection [as 别名]
def send(hub, worker, payload):
    '''
    Send the given payload to the given worker, yield iterations based on the
    returns from the remote.
    '''
    mp = msgpack.dumps(payload, use_bin_type=True)
    mp += hub.proc.DELIM
    reader, writer = await asyncio.open_unix_connection(path=worker['path'])
    writer.write(mp)
    await writer.drain()
    final_ret = True
    while True:
        ret = await reader.readuntil(hub.proc.DELIM)
        p_ret = ret[:-len(hub.proc.DELIM)]
        i_flag = p_ret[-1:]
        ret = msgpack.loads(p_ret[:-1], raw=False)
        if i_flag == hub.proc.D_FLAG:
            # break for the end of the sequence
            break
        yield ret
        final_ret = False
    if final_ret:
        yield ret 
开发者ID:saltstack,项目名称:pop,代码行数:25,代码来源:run.py

示例4: test_unix_responder

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import open_unix_connection [as 别名]
def test_unix_responder(unix_responder, params):
    (request, response), bufsize = params
    resp, path = unix_responder
    stream_reader = netstring.StreamReader()
    string_reader = stream_reader.next_string()
    assert os.stat(path).st_mode & 0o777 == 0o666
    reader, writer = await asyncio.open_unix_connection(path)
    try:
        writer.write(netstring.encode(request))
        res = b''
        while True:
            try:
                part = string_reader.read()
            except netstring.WantRead:
                data = await reader.read(bufsize)
                assert data
                stream_reader.feed(data)
            else:
                if not part:
                    break
                res += part
        assert res == response
    finally:
        writer.close() 
开发者ID:Snawoot,项目名称:postfix-mta-sts-resolver,代码行数:26,代码来源:test_responder.py

示例5: get_ipc_response

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import open_unix_connection [as 别名]
def get_ipc_response(
        jsonrpc_ipc_pipe_path,
        request_msg,
        event_loop,
        event_bus):

    # Give event subsriptions a moment to propagate.
    await asyncio.sleep(0.01)

    assert wait_for(jsonrpc_ipc_pipe_path), "IPC server did not successfully start with IPC file"

    reader, writer = await asyncio.open_unix_connection(str(jsonrpc_ipc_pipe_path))

    writer.write(request_msg)
    await writer.drain()
    result_bytes = b''
    while not can_decode_json(result_bytes):
        result_bytes += await asyncio.tasks.wait_for(reader.readuntil(b'}'), 0.25)

    writer.close()
    return json.loads(result_bytes.decode()) 
开发者ID:ethereum,项目名称:trinity,代码行数:23,代码来源:test_rpc_during_beam_sync.py

示例6: test_uds_server

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import open_unix_connection [as 别名]
def test_uds_server(event_loop, tmpdir):
    path = str(tmpdir / "test.uds")
    server = await start_console_server(path=path, banner="test")

    stream = io.StringIO()
    print_server(server, "test console", file=stream)
    expected = "The test console is being served on {}\n"
    assert stream.getvalue() == expected.format(path)

    address = server.sockets[0].getsockname()
    reader, writer = await asyncio.open_unix_connection(address)
    assert (await reader.readline()) == b"test\n"
    writer.write(b"1+1\n")
    assert (await reader.readline()) == b">>> 2\n"
    writer.write_eof()
    assert (await reader.readline()) == b">>> \n"
    writer.close()
    if compat.PY37:
        await writer.wait_closed()
    server.close()
    await server.wait_closed() 
开发者ID:vxgmichel,项目名称:aioconsole,代码行数:23,代码来源:test_server.py

示例7: qubesd_client

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import open_unix_connection [as 别名]
def qubesd_client(socket, payload, *args):
    '''
    Connect to qubesd, send request and passthrough response to stdout

    :param socket: path to qubesd socket
    :param payload: payload of the request
    :param args: request to qubesd
    :return:
    '''
    try:
        reader, writer = yield from asyncio.open_unix_connection(socket)
    except asyncio.CancelledError:
        return 1

    for arg in args:
        writer.write(arg.encode('ascii'))
        writer.write(b'\0')
    writer.write(payload)
    writer.write_eof()

    try:
        header_data = yield from reader.read(1)
        returncode = int(header_data)
        sys.stdout.buffer.write(header_data)  # pylint: disable=no-member
        while not reader.at_eof():
            data = yield from reader.read(4096)
            sys.stdout.buffer.write(data)  # pylint: disable=no-member
            sys.stdout.flush()
        return returncode
    except asyncio.CancelledError:
        return 1
    finally:
        writer.close() 
开发者ID:QubesOS,项目名称:qubes-core-admin,代码行数:35,代码来源:qubesd_query.py

示例8: test_open_unix_connection

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import open_unix_connection [as 别名]
def test_open_unix_connection(self):
        with test_utils.run_test_unix_server() as httpd:
            conn_fut = asyncio.open_unix_connection(httpd.address,
                                                    loop=self.loop)
            self._basetest_open_connection(conn_fut) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_streams.py

示例9: test_open_unix_connection_no_loop_ssl

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import open_unix_connection [as 别名]
def test_open_unix_connection_no_loop_ssl(self):
        with test_utils.run_test_unix_server(use_ssl=True) as httpd:
            conn_fut = asyncio.open_unix_connection(
                httpd.address,
                ssl=test_utils.dummy_ssl_context(),
                server_hostname='',
                loop=self.loop)

            self._basetest_open_connection_no_loop_ssl(conn_fut) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_streams.py

示例10: test_open_unix_connection_error

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import open_unix_connection [as 别名]
def test_open_unix_connection_error(self):
        with test_utils.run_test_unix_server() as httpd:
            conn_fut = asyncio.open_unix_connection(httpd.address,
                                                    loop=self.loop)
            self._basetest_open_connection_error(conn_fut) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_streams.py

示例11: _connect

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import open_unix_connection [as 别名]
def _connect(self):
        reader, writer = await exec_with_timeout(
            asyncio.open_unix_connection(path=self.path,
                                         ssl=self.ssl_context,
                                         loop=self.loop),
            self._connect_timeout,
            loop=self.loop
        )
        self._reader = reader
        self._writer = writer
        await self.on_connect() 
开发者ID:NoneGG,项目名称:aredis,代码行数:13,代码来源:connection.py

示例12: proxy_for_unix_connection

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import open_unix_connection [as 别名]
def proxy_for_unix_connection(path):
    reader, writer = await asyncio.open_unix_connection(path)
    return request_response_proxy(reader, writer, ledger_sim.REMOTE_SIGNATURES) 
开发者ID:Chia-Network,项目名称:wallets,代码行数:5,代码来源:test_CP_tranasactions.py

示例13: proxy_for_unix_connection

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import open_unix_connection [as 别名]
def proxy_for_unix_connection(path):
    reader, writer = await asyncio.open_unix_connection(str(path))
    return request_response_proxy(reader, writer, ledger_sim.REMOTE_SIGNATURES) 
开发者ID:Chia-Network,项目名称:wallets,代码行数:5,代码来源:test_puzzles.py

示例14: ret

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import open_unix_connection [as 别名]
def ret(hub, payload):
    '''
    Send a return payload to the spawning process. This return will be tagged
    with the index of the process that returned it
    '''
    payload = {'ind': hub.proc.IND, 'payload': payload}
    mp = msgpack.dumps(payload, use_bin_type=True)
    mp += hub.proc.DELIM
    reader, writer = await asyncio.open_unix_connection(path=hub.proc.RET_SOCK_PATH)
    writer.write(mp)
    await writer.drain()
    ret = await reader.readuntil(hub.proc.DELIM)
    ret = ret[:-len(hub.proc.DELIM)]
    writer.close()
    return msgpack.loads(ret, encoding='utf8') 
开发者ID:saltstack,项目名称:pop,代码行数:17,代码来源:worker.py

示例15: server_run

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import open_unix_connection [as 别名]
def server_run(self, handler):
        errwait = 0
        while not self.closed:
            if self.uri.unix:
                wait = asyncio.open_unix_connection(path=self.uri.bind)
            else:
                wait = asyncio.open_connection(host=self.uri.host_name, port=self.uri.port, local_addr=(self.uri.lbind, 0) if self.uri.lbind else None)
            try:
                reader, writer = await asyncio.wait_for(wait, timeout=SOCKET_TIMEOUT)
                writer.write(self.uri.auth)
                self.writer = writer
                try:
                    data = await reader.read_n(1)
                except asyncio.TimeoutError:
                    data = None
                if data and data[0] != 0:
                    reader._buffer[0:0] = data
                    asyncio.ensure_future(handler(reader, writer))
                else:
                    writer.close()
                errwait = 0
            except Exception as ex:
                try:
                    writer.close()
                except Exception:
                    pass
                if not self.closed:
                    await asyncio.sleep(errwait)
                    errwait = min(errwait*1.3 + 0.1, 30) 
开发者ID:qwj,项目名称:python-proxy,代码行数:31,代码来源:server.py


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