Skip to content

Commit

Permalink
添加restful风格的装饰器
Browse files Browse the repository at this point in the history
  • Loading branch information
leeyisoft committed Jul 14, 2019
1 parent 1f16b0d commit 7705ff7
Show file tree
Hide file tree
Showing 51 changed files with 5,460 additions and 47 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Pipfile.lock
settings.json
.venv
.vscode
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include *.md
recursive-include tests *
26 changes: 26 additions & 0 deletions Pipfile
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"
69 changes: 61 additions & 8 deletions README.en.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,75 @@
# pyadmin
# T-Rest
* T = Tornado
* Rest = Restful

#### Description
{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
Web MVC framework based on Tornado combined with asyncio

#### Software Architecture
Software architecture description

#### Installation

1. xxxx
2. xxxx
3. xxxx
Put the following line of code into the Pipfile file [packages]
> trest = {editable = true,git = "https://gitee.com/leeyi/trest.git"}
or
> pipenv install -e git+https://gitee.com/leeyi/trest.git#egg=trest
or
> pip install git+https://gitee.com/leeyi/trest.git
#### Instructions
After pipenv install under the root directory, add 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
```

##### The API response
Use the raise JsonError wherever
```
from trest.exception import JsonError
raise JsonError('msg')
raise JsonError('msg', 0)
raise JsonError('msg', 1, [])
raise JsonError('msg', 1, [1,2,3])
```

1. xxxx
2. xxxx
3. xxxx
#### Test
```
pipenv install --skip-lock
```

#### Contribution

Expand Down
39 changes: 0 additions & 39 deletions README.md

This file was deleted.

90 changes: 90 additions & 0 deletions README_zh.md
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/)
34 changes: 34 additions & 0 deletions setup.py
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',
],
)
1 change: 1 addition & 0 deletions trest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .decorator import *
62 changes: 62 additions & 0 deletions trest/amqp/__init__.py
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
Loading

0 comments on commit 7705ff7

Please sign in to comment.