跳转到主要内容

aio asyncio框架的Manhole服务器

项目描述

aio asyncio框架提供的Manhole服务器

构建状态

https://travis-ci.org/phlax/aio.manhole.server.svg?branch=master

安装

需要python >= 3.4

使用以下方法安装

pip install aio.manhole.server

快速开始 - Manhole服务器

将以下内容保存到文件“manhole.conf”中

[server/my_manhole_server]
factory = aio.manhole.server.factory
port = 7373

使用aio run命令运行

aio run -c manhole.conf

现在您应该能够telnet到正在运行的服务器,端口号为7373

aio.manhole.server使用方法

配置

让我们创建一个manhole配置

>>> config = """
... [aio]
... log_level = ERROR
...
... [server/server_name]
... factory = aio.manhole.server.factory
... port = 7373
...
... """
>>> import sys
>>> import io
>>> import aiomanhole
>>> import aio.testing
>>> import aio.app
>>> from aio.app.runner import runner

当我们运行manhole服务器时,它可以通过“server_name”从aio.app.servers访问

>>> @aio.testing.run_forever(sleep=1)
... def run_manhole_server(config):
...     yield from runner(['run'], config_string=config)
...
...     def call_manhole():
...         print(aio.app.servers["server_name"])
...         aio.app.clear()
...
...     return call_manhole
>>> run_manhole_server(config)
<Server sockets=[<socket.socket ...laddr=('0.0.0.0', 7373)...>

让我们尝试调用manhole服务器

>>> import asyncio
>>> import telnetlib3
>>> @aio.testing.run_forever(sleep=1)
... def run_manhole_server(config):
...     yield from runner(['run'], config_string=config)
...
...     class TestTelnetClient(telnetlib3.TelnetClient):
...
...         def data_received(self, data):
...             print(data)
...
...     def call_manhole():
...         loop = asyncio.get_event_loop()
...         transport, protocol = yield from loop.create_connection(
...             TestTelnetClient, "127.0.0.1", 7373)
...         aio.app.clear()
...
...     return call_manhole
>>> run_manhole_server(config)
b'hello...\n>>> '

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分发

aio.manhole.server-0.0.2.tar.gz (3.1 kB 查看散列)

由以下组织支持