本文整理汇总了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)
示例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
示例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
示例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()
示例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())
示例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()
示例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()
示例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)
示例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)
示例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)
示例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()
示例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)
示例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)
示例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')
示例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)