Skip to content

Commit 53a25e1

Browse files
committed
[2020-07-19] 添加wood预设逻辑模块,同时增加freedom预设接口
1 parent d965c68 commit 53a25e1

File tree

24 files changed

+533
-65
lines changed

24 files changed

+533
-65
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
end_of_line = crlf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[*.{py, js, jsx, ts, tsx}]
13+
indent_style = space
14+
indent_size = 4

docs/ancient.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
ancient/module
1212
ancient/rig
1313
ancient/view
14-
ancient/boot
14+
ancient/wood
15+
ancient/boot

docs/ancient/rig.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ register
3333
:undoc-members:
3434
:show-inheritance:
3535

36+
template
37+
---------------------------
38+
39+
.. automodule:: ancient.rig.template
40+
:members:
41+
:undoc-members:
42+
:show-inheritance:
43+
3644
utils
3745
---------------------------
3846

docs/ancient/view.rst

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
``ancient.view`` --- 视图模块
22
======================================
33

4-
backstage
4+
example
55
-----------------------------
66

7-
.. automodule:: ancient.view.backstage
8-
:members:
9-
:undoc-members:
10-
:show-inheritance:
11-
12-
reception
13-
-----------------------------
14-
15-
.. automodule:: ancient.view.reception
7+
.. automodule:: ancient.view.example
168
:members:
179
:undoc-members:
1810
:show-inheritance:

docs/ancient/wood.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
``ancient.wood`` --- 预设视图模块
2+
======================================
3+
4+
freedom
5+
-----------------------------
6+
7+
.. automodule:: ancient.wood.freedom
8+
:members:
9+
:undoc-members:
10+
:show-inheritance:
11+
12+
upload
13+
-----------------------------
14+
15+
.. automodule:: ancient.wood.upload
16+
:members:
17+
:undoc-members:
18+
:show-inheritance:

madtornado/ancient/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def import_view():
2828
for i in os.listdir("ancient/view"):
2929
if i.endswith(".py") and i not in exclude_file:
3030
__import__("ancient.view.{}".format(i[:-3]))
31+
for i in os.listdir("ancient/wood"):
32+
if i.endswith(".py") and i not in exclude_file:
33+
__import__("ancient.wood.{}".format(i[:-3]))
3134

3235

3336
import_view()

madtornado/ancient/boot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def boot():
2323
:return: None
2424
2525
"""
26+
2627
print("Boot hook is started")
2728

2829
# 自启动浏览器,需要该功能请取消注释

madtornado/ancient/handlers/dealHandler.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from tornado.web import StaticFileHandler
55

66
"""
7-
改模块下包含一些基类,可以通过配置文件控制这些基类的反应行为
7+
该模块下包含一些基类,可以通过配置文件控制这些基类的反应行为
88
"""
99

1010

@@ -15,31 +15,31 @@ class StaticHandler(StaticFileHandler, Base):
1515
1616
"""
1717

18-
def initialize(self, path: str, default_filename: str = None, prefix: str = None) -> None:
18+
def initialize(self, path: str, default_filename: str = None, prefix: str = None, spa_page: str = None) -> None:
1919
super(StaticHandler, self).initialize(path, default_filename)
2020
self.prefix = prefix
2121
self.absolute_path = path # 缺少这个属性web.py会报错,问题不大
22+
self.spa_page = spa_page
2223

2324
# @override
2425
async def get(self, path, include_body=True):
2526
"""
2627
2728
默认等于StaticFileHandler.get()行为,通过写该方法,对文件进行控制,可以直接在这里编写代码
2829
29-
结合单页面应用使用,请改写成以下内容,可以替换index.html为自己的单页面::
30-
30+
"""
31+
if self.spa_page:
3132
if not self.prefix:
3233
try:
3334
await super(StaticHandler, self).get(path, include_body)
3435
return
3536
except Exception as e:
36-
await super(StaticHandler, self).get("index.html", include_body)
37+
await super(StaticHandler, self).get(self.spa_page, include_body)
3738
return
3839
else:
3940
await super(StaticHandler, self).get(path, include_body)
40-
41-
"""
42-
await super(StaticHandler, self).get(path, include_body)
41+
else:
42+
await super(StaticHandler, self).get(path, include_body)
4343

4444

4545
class ProxyHandler(Base):
@@ -233,15 +233,15 @@ async def proxy(self):
233233
class PongHandler(Base):
234234
"""
235235
236-
有时可能需要测试服务器的服务是否启动,请访问/init,来进行确定
236+
有时可能需要测试服务器的服务是否启动,请访问/pong,来进行确定
237237
238238
"""
239239

240240
# @override
241241
async def get(self):
242242
"""
243243
244-
有时可能需要测试服务器的服务是否启动,请访问/init,来进行确定
244+
有时可能需要测试服务器的服务是否启动,请访问/pong,来进行确定
245245
246246
"""
247247
self.throw(200, log_message="connected")
@@ -250,7 +250,7 @@ async def get(self):
250250
async def post(self):
251251
"""
252252
253-
有时可能需要测试服务器的服务是否启动,请访问/init,来进行确定
253+
有时可能需要测试服务器的服务是否启动,请访问/pong,来进行确定
254254
255255
"""
256256
await self.get()

madtornado/ancient/module/syncFile.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,19 @@ def read(self, path: str, auto_close: bool = True) -> Iterable:
159159
self.read_fp = None
160160
return
161161

162-
def is_exist(self, file_name: str) -> bool:
162+
@staticmethod
163+
def is_exist(path: str) -> bool:
164+
"""
165+
166+
判断文件是否存在
167+
168+
:param path: 路径
169+
:return: 布尔值,是否存在
170+
171+
"""
172+
return os.path.exists(path)
173+
174+
def is_safe_exist(self, file_name: str) -> bool:
163175
"""
164176
165177
判断文件是否存在,需要[捕获异常]处理

madtornado/ancient/rig/register.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def get_pe8(content: str):
222222
content = content.replace(i, "_" + i.lower())
223223
return content.strip("_")
224224

225-
def route(self, prefix: str = "", url: str = None, urls: list = None, end=False):
225+
def route(self, url: str = None, prefix: str = "", urls: list = None, end=False):
226226
"""
227227
228228
``装饰器`` 添加该装饰器的请求实例,路由路径会被自动注册到路由表中
@@ -236,8 +236,8 @@ def route(self, prefix: str = "", url: str = None, urls: list = None, end=False)
236236
如果你在配置文件中配置了url_prefix = [] 这是一个列表,会生成一组带前缀的静态文件路由匹配项
237237
而我们的end=True的路由会放到这些带前缀的静态文件管理路由后面
238238
239-
:param prefix: 如果提供该内容将在路由中添加一个前缀,这个前缀是在统一路由前缀后面的
240239
:param url: 路由路径,不填写默认会根据类名生成路径
240+
:param prefix: 如果提供该内容将在路由中添加一个前缀,这个前缀是在统一路由前缀后面的
241241
:param urls: 如果设置该参数,传入一个列表对象,url将不起效果,同时为该类增加多个可匹配的路由
242242
:param end: 声明该路由是否注册到默认路由后面,系统默认路由参考server.py中的default_route
243243
:return: None

0 commit comments

Comments
 (0)