maybach-request


Namemaybach-request JSON
Version 0.5.0 PyPI version JSON
download
home_pagehttps://gitlab.xiguacity.cn/fee/python/maybach_request
Summary
upload_time2020-09-16 06:50:31
maintainer
docs_urlNone
authorcuvee
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # maybach_request

用户实现 Python 自动批改的库

## 下载

```python
pip install maybach_request
```

## 使用

举一个例子,现在要断言一下代码的正确性:

```python
# main.py
# student_code_starts
name = input('请输入姓名:')
print(name)
# student_code_ends
```

要求:用户输入 `xigua`,控制台能正确打印出来 `xigua` 并且能检查到 `name` 变量为 `xigua`

```python
# test.py
from maybach-request import get_print, send_print, pass_test, no_pass_test

# 获取用户的输入
# 模拟一个用户的输入
send_print('xigua')
# 获取用户的输入
text = get_print()
passed = False
msg = '请打印name变量'
if name == 'xigua':
  for i in text:
    if i.find('xigua'):
      passed = True
      msg = 'success'
      break
else:
  msg = '请声明name变量'

if passed:
  # 通过测试
  pass_test(msg)
else:
  # 测试不通过
  no_pass_test(msg)
```

运行 `python test.py --port 3004 --host 127.0.0.1`,当不传 `--host` 默认使用 `127.0.0.1`

## 依赖

`maybach_request` 依赖服务提供接口获取用户的输入,以及通知服务测试的结果。
[@xigua/maybach-server](https://gitlab.xiguacity.cn/fee/python/maybach-server) 提供了整套服务。

## 动态端口号

`maybach_request` 依赖的服务端口号是动态产生的,因此在执行相应的 `python` 代码的时候,需要通过 `argv`的形式传递给 `python` 进程

```
python xxx.py --port port
```

这样 `maybach_request` 能够拿到相应的端口号,跟对应的进程通信。如果使用了
[@xigua/maybach-vm](https://gitlab.xiguacity.cn/fee/python/maybach-vm)

```js
import { run } from '@xigua/maybach-vm';

run(0, xxx.py, cwd, ['--port', port]).then((res) => {
  console.log(res);
});

run(1, 'print(123)', cwd, ['--port', port], (res) => {
  console.log(res);
});
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.xiguacity.cn/fee/python/maybach_request",
    "name": "maybach-request",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "cuvee",
    "author_email": "cuizaiyong@xigua.club",
    "download_url": "https://files.pythonhosted.org/packages/20/d2/5c78b5f8f0bf1311f7861ada184e36035cd47f2784855073ac338446e225/maybach_request-0.5.0.tar.gz",
    "platform": "",
    "description": "# maybach_request\n\n\u7528\u6237\u5b9e\u73b0 Python \u81ea\u52a8\u6279\u6539\u7684\u5e93\n\n## \u4e0b\u8f7d\n\n```python\npip install maybach_request\n```\n\n## \u4f7f\u7528\n\n\u4e3e\u4e00\u4e2a\u4f8b\u5b50\uff0c\u73b0\u5728\u8981\u65ad\u8a00\u4e00\u4e0b\u4ee3\u7801\u7684\u6b63\u786e\u6027\uff1a\n\n```python\n# main.py\n# student_code_starts\nname = input('\u8bf7\u8f93\u5165\u59d3\u540d\uff1a')\nprint(name)\n# student_code_ends\n```\n\n\u8981\u6c42\uff1a\u7528\u6237\u8f93\u5165 `xigua`\uff0c\u63a7\u5236\u53f0\u80fd\u6b63\u786e\u6253\u5370\u51fa\u6765 `xigua` \u5e76\u4e14\u80fd\u68c0\u67e5\u5230 `name` \u53d8\u91cf\u4e3a `xigua`\n\n```python\n# test.py\nfrom maybach-request import get_print, send_print, pass_test, no_pass_test\n\n# \u83b7\u53d6\u7528\u6237\u7684\u8f93\u5165\n# \u6a21\u62df\u4e00\u4e2a\u7528\u6237\u7684\u8f93\u5165\nsend_print('xigua')\n# \u83b7\u53d6\u7528\u6237\u7684\u8f93\u5165\ntext = get_print()\npassed = False\nmsg = '\u8bf7\u6253\u5370name\u53d8\u91cf'\nif name == 'xigua':\n  for i in text:\n    if i.find('xigua'):\n      passed = True\n      msg = 'success'\n      break\nelse:\n  msg = '\u8bf7\u58f0\u660ename\u53d8\u91cf'\n\nif passed:\n  # \u901a\u8fc7\u6d4b\u8bd5\n  pass_test(msg)\nelse:\n  # \u6d4b\u8bd5\u4e0d\u901a\u8fc7\n  no_pass_test(msg)\n```\n\n\u8fd0\u884c `python test.py --port 3004 --host 127.0.0.1`\uff0c\u5f53\u4e0d\u4f20 `--host` \u9ed8\u8ba4\u4f7f\u7528 `127.0.0.1`\n\n## \u4f9d\u8d56\n\n`maybach_request` \u4f9d\u8d56\u670d\u52a1\u63d0\u4f9b\u63a5\u53e3\u83b7\u53d6\u7528\u6237\u7684\u8f93\u5165\uff0c\u4ee5\u53ca\u901a\u77e5\u670d\u52a1\u6d4b\u8bd5\u7684\u7ed3\u679c\u3002\n[@xigua/maybach-server](https://gitlab.xiguacity.cn/fee/python/maybach-server) \u63d0\u4f9b\u4e86\u6574\u5957\u670d\u52a1\u3002\n\n## \u52a8\u6001\u7aef\u53e3\u53f7\n\n`maybach_request` \u4f9d\u8d56\u7684\u670d\u52a1\u7aef\u53e3\u53f7\u662f\u52a8\u6001\u4ea7\u751f\u7684\uff0c\u56e0\u6b64\u5728\u6267\u884c\u76f8\u5e94\u7684 `python` \u4ee3\u7801\u7684\u65f6\u5019\uff0c\u9700\u8981\u901a\u8fc7 `argv`\u7684\u5f62\u5f0f\u4f20\u9012\u7ed9 `python` \u8fdb\u7a0b\n\n```\npython xxx.py --port port\n```\n\n\u8fd9\u6837 `maybach_request` \u80fd\u591f\u62ff\u5230\u76f8\u5e94\u7684\u7aef\u53e3\u53f7\uff0c\u8ddf\u5bf9\u5e94\u7684\u8fdb\u7a0b\u901a\u4fe1\u3002\u5982\u679c\u4f7f\u7528\u4e86\n[@xigua/maybach-vm](https://gitlab.xiguacity.cn/fee/python/maybach-vm)\n\n```js\nimport { run } from '@xigua/maybach-vm';\n\nrun(0, xxx.py, cwd, ['--port', port]).then((res) => {\n  console.log(res);\n});\n\nrun(1, 'print(123)', cwd, ['--port', port], (res) => {\n  console.log(res);\n});\n```\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "",
    "version": "0.5.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "c7b4e3a7a170b45d27ccca91bd6fa51f",
                "sha256": "ffd247fae5edc24dda781feff39cbf9a8fdbe89e91856d79ec363768f92998ce"
            },
            "downloads": -1,
            "filename": "maybach_request-0.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c7b4e3a7a170b45d27ccca91bd6fa51f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 2765,
            "upload_time": "2020-09-16T06:50:27",
            "upload_time_iso_8601": "2020-09-16T06:50:27.699556Z",
            "url": "https://files.pythonhosted.org/packages/2c/23/556ac8af2c30b5baf42e14576b04e4b50a9513f1d29f2376bfcad7fda66b/maybach_request-0.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "0e1fa5024def2ab0eb65f10e1cdbea0a",
                "sha256": "a1a703bf40f70973fe02de4abcb2bde8acc275f939627707db29dc18cdb25551"
            },
            "downloads": -1,
            "filename": "maybach_request-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0e1fa5024def2ab0eb65f10e1cdbea0a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 2797,
            "upload_time": "2020-09-16T06:50:31",
            "upload_time_iso_8601": "2020-09-16T06:50:31.342787Z",
            "url": "https://files.pythonhosted.org/packages/20/d2/5c78b5f8f0bf1311f7861ada184e36035cd47f2784855073ac338446e225/maybach_request-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-09-16 06:50:31",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "maybach-request"
}
        
Elapsed time: 0.14422s