-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
5,460 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Pipfile.lock | ||
settings.json | ||
.venv | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include *.md | ||
recursive-include tests * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[[source]] | ||
name = "pypi" | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
|
||
[dev-packages] | ||
pep8 = "*" | ||
|
||
[packages] | ||
tornado = "*" | ||
mysqlclient = "*" | ||
sqlalchemy = "*" | ||
sqlalchemy-utils = "*" | ||
redis = "==2.10.6" | ||
rsa = "*" | ||
pycryptodome = "*" | ||
pytz = "*" | ||
python-dateutil = "*" | ||
|
||
requests = "*" | ||
raven = "*" | ||
gino = "*" | ||
pika = "*" | ||
|
||
[requires] | ||
python_version = "3.7" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# T-Rest | ||
* T = Tornado | ||
* Rest = Restful | ||
|
||
#### 介绍 | ||
* 基于Tornado结合asyncio的web mvc框架 | ||
* 支持AMQP | ||
* | ||
|
||
#### 软件架构 | ||
软件架构说明 | ||
|
||
``` | ||
``` | ||
|
||
#### 安装教程 | ||
|
||
把下面一行代码放入Pipfile文件 [packages]下面 | ||
> trest = {editable = true,git = "https://gitee.com/leeyi/trest.git"} | ||
或者直接 | ||
> pipenv install -e git+https://gitee.com/leeyi/trest.git#egg=trest | ||
或者 | ||
> pip install git+https://gitee.com/leeyi/trest.git | ||
#### 使用说明 | ||
在根目录下面 pipenv install 之后,添加 server.py 之后 | ||
``` | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
import os | ||
import sys | ||
import resource | ||
resource.setrlimit(resource.RLIMIT_NOFILE, (10240, 9223372036854775807)) | ||
from tornado.options import define | ||
# sys.path.insert(0, '/Users/leeyi/workspace/py3/trest') | ||
ROOT_PATH = os.getcwd() | ||
define('ROOT_PATH', ROOT_PATH) | ||
# 把当前目录添加到 sys.path 开头 | ||
sys.path.insert(0, ROOT_PATH) | ||
from trest.webserver import run | ||
if __name__ == "__main__": | ||
try: | ||
run() | ||
except KeyboardInterrupt: | ||
sys.exit(0) | ||
``` | ||
run | ||
``` | ||
pipenv shell | ||
run server.py | ||
``` | ||
|
||
##### API响应 | ||
在任意的地方使用 raise JsonError | ||
``` | ||
from trest.exception import JsonError | ||
raise JsonError('msg') | ||
raise JsonError('msg', 0) | ||
raise JsonError('msg', 1, []) | ||
raise JsonError('msg', 1, [1,2,3]) | ||
``` | ||
|
||
#### 参与贡献 | ||
|
||
1. Fork 本仓库 | ||
2. 新建 Feat_xxx 分支 | ||
3. 提交代码 | ||
4. 新建 Pull Request | ||
|
||
|
||
#### 码云特技 | ||
|
||
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md | ||
2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com) | ||
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目 | ||
4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目 | ||
5. 码云官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) | ||
6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
""" | ||
>>> python setup.py sdist | ||
>>> python setup.py bdist --format=zip | ||
""" | ||
from setuptools import setup | ||
from setuptools import find_packages | ||
|
||
|
||
setup( | ||
name='trest', | ||
version='1.0.0', | ||
description='基于Tornado结合asyncio的web mvc框架', | ||
author='leeyi', | ||
author_email='[email protected]', | ||
url='https://gitee.com/leeyi/trest', | ||
license='MIT Licence', | ||
|
||
packages=find_packages(), | ||
include_package_data=True, | ||
platforms='any', | ||
install_requires=[ | ||
'tornado>=6.0.0', | ||
'sqlalchemy', | ||
'sqlalchemy-utils', | ||
'redis==2.10.6', | ||
'requests', | ||
'PyJWT', | ||
'pytz', | ||
'rsa', | ||
'pycryptodome', | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .decorator import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
import json | ||
|
||
from .publisher import Publisher | ||
from ..utils import func | ||
from ..settings_manager import settings | ||
|
||
|
||
def push_message(msg, msg_type='transfer_websocket'): | ||
""" | ||
发送消息,消息格式根据需求和前端约定 | ||
""" | ||
option = {} | ||
option['msg_type'] = msg_type | ||
option['exchange'] = 'async_ex.message' | ||
option['routing_key'] = 'async_rtk.message' | ||
option['queue_name'] = 'async_q.message' | ||
option['durable'] = True | ||
option['auto_delete'] = False | ||
return push_to_mq(msg, option) | ||
|
||
def push_sms(param, sms_platform): | ||
""" | ||
发送短信 | ||
""" | ||
param['action'] = 'push_sms' | ||
option = {} | ||
option['msg_type'] = sms_platform | ||
option['exchange'] = 'async_ex.sms' | ||
option['routing_key'] = 'async_rtk.sms' | ||
option['queue_name'] = 'async_q.sms' | ||
option['durable'] = True | ||
option['auto_delete'] = False | ||
return push_to_mq(param, option) | ||
|
||
def push_email(param, email_platform='default'): | ||
""" | ||
发送Email | ||
""" | ||
param['action'] = 'push_email' | ||
option = {} | ||
option['msg_type'] = email_platform | ||
option['exchange'] = 'async_ex.email' | ||
option['routing_key'] = 'async_rtk.email' | ||
option['queue_name'] = 'async_q.email' | ||
option['durable'] = True | ||
option['auto_delete'] = False | ||
return push_to_mq(param, option) | ||
|
||
def push_to_mq(param, option): | ||
# dstr =['%s=%s'%(k.strip(), ','.join([v.decode('utf-8').strip() for v in vl])) for (k, vl) in data.items()] | ||
# param = {k.strip(): ','.join([v.decode('utf-8').strip() for v in vl]) for (k, vl) in data.items()} | ||
msg = {} | ||
msg['msg_type'] = option.get('msg_type', '') | ||
msg['msg_md5'] = func.md5(json.dumps(param)) | ||
msg['msg'] = param | ||
pusher = Publisher(settings.rabbitmq_config) | ||
option['exchange_type'] = option.get('exchange_type', 'topic') | ||
res = pusher.push(msg, option) | ||
# print(res) | ||
return res |
Oops, something went wrong.