Skip to content

Commit c816363

Browse files
committed
refine code style
1 parent e6b2b1c commit c816363

File tree

9 files changed

+32
-37
lines changed

9 files changed

+32
-37
lines changed

demos/gomoku_game.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import time
22

3-
import pywebio
3+
from pywebio import session, start_server
44
from pywebio.output import *
5-
from pywebio import session
65

76
goboard_size = 15
87
# -1 -> none, 0 -> black, 1 -> white
@@ -92,4 +91,4 @@ def show_goboard():
9291

9392

9493
if __name__ == '__main__':
95-
pywebio.start_server(main, debug=True, port=8080)
94+
start_server(main, debug=True, port=8080)

pywebio/io_ctrl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class OutputList(UserList):
179179
def __del__(self):
180180
"""返回值没有被变量接收时的操作:顺序输出其持有的内容"""
181181
for o in self.data:
182-
o.__del__()
182+
o.__del__() # lgtm [py/explicit-call-to-delete]
183183

184184

185185
def safely_destruct_output_when_exp(content_param):

pywebio/platform/aiohttp.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import os
21
import asyncio
32
import fnmatch
43
import json
54
import logging
5+
import os
66
from functools import partial
7-
from os import path, listdir
87
from urllib.parse import urlparse
98

109
from aiohttp import web
1110

11+
from .page import make_applications, render_page
1212
from .remote_access import start_remote_access_service
1313
from .tornado import open_webbrowser_on_server_started
14-
from .page import make_applications, render_page
1514
from .utils import cdn_validation, deserialize_binary_event, print_listen_address
1615
from ..session import CoroutineBasedSession, ThreadBasedSession, register_session_implement_for_target, Session
1716
from ..session.base import get_session_info_from_headers
@@ -47,6 +46,7 @@ def _webio_handler(applications, cdn, websocket_settings, check_origin_func=_is_
4746
:param callable check_origin_func: check_origin_func(origin, host) -> bool
4847
:return: aiohttp Request Handler
4948
"""
49+
5050
async def wshandle(request: web.Request):
5151
ioloop = asyncio.get_event_loop()
5252

@@ -157,11 +157,11 @@ def static_routes(prefix='/'):
157157
"""
158158

159159
async def index(request):
160-
return web.FileResponse(path.join(STATIC_PATH, 'index.html'))
160+
return web.FileResponse(os.path.join(STATIC_PATH, 'index.html'))
161161

162-
files = [path.join(STATIC_PATH, d) for d in listdir(STATIC_PATH)]
163-
dirs = filter(path.isdir, files)
164-
routes = [web.static(prefix + path.basename(d), d) for d in dirs]
162+
files = [os.path.join(STATIC_PATH, d) for d in os.listdir(STATIC_PATH)]
163+
dirs = filter(os.path.isdir, files)
164+
routes = [web.static(prefix + os.path.basename(d), d) for d in dirs]
165165
routes.append(web.get(prefix, index))
166166
return routes
167167

pywebio/platform/bokeh.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ def show_app(app, state, notebook_url, port=0, **kw):
143143
from bokeh.embed import server_document
144144
script = server_document(url, resources=None)
145145

146-
script = re.sub(r'<script(.*?)>([\s\S]*?)</script>', r"""
146+
script = re.sub(r'<script(.*?)>([\s\S]*?)</script>', # lgtm [py/bad-tag-filter]
147+
r"""
147148
<script \g<1>>
148149
requirejs(['bokeh', 'bokeh-widgets', 'bokeh-tables'], function(Bokeh) {
149150
\g<2>

pywebio/platform/path_deploy.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1+
import ast
12
import os.path
2-
from functools import partial
33
from contextlib import contextmanager
4-
import ast
4+
from functools import partial
55

6-
import tornado
7-
from tornado import template
8-
from tornado.web import HTTPError, Finish
9-
from tornado.web import StaticFileHandler
6+
import tornado.template
7+
import tornado.web
8+
import tornado.ioloop
109

1110
from . import page
1211
from .httpbased import HttpHandler
12+
from .page import make_applications
1313
from .tornado import webio_handler, set_ioloop
1414
from .tornado_http import TornadoHttpContext
1515
from .utils import cdn_validation, print_listen_address
16-
from .page import make_applications
1716
from ..session import register_session_implement, CoroutineBasedSession, ThreadBasedSession, Session
1817
from ..utils import get_free_port, STATIC_PATH, parse_file_size
1918

@@ -103,7 +102,7 @@ def add_to_path(p):
103102
return module
104103

105104

106-
_app_list_tpl = template.Template("""
105+
_app_list_tpl = tornado.template.Template("""
107106
<!DOCTYPE html>
108107
<html lang="">
109108
<head>
@@ -145,7 +144,7 @@ def default_index_page(path, base):
145144
dirs.append([(f + '/'), ''])
146145

147146
items = dirs + files
148-
max_name_width = max([len(n) for n, _ in items]+[0])
147+
max_name_width = max([len(n) for n, _ in items] + [0])
149148
return _app_list_tpl.generate(files=items, title=title, max_name_width=max_name_width)
150149

151150

@@ -204,8 +203,8 @@ def _path_deploy(base, port=0, host='', static_dir=None, max_payload_size=2 ** 2
204203

205204
handlers = []
206205
if static_dir is not None:
207-
handlers.append((r"/static/(.*)", StaticFileHandler, {"path": static_dir}))
208-
handlers.append((LOCAL_STATIC_URL+r"/(.*)", StaticFileHandler, {"path": STATIC_PATH}))
206+
handlers.append((r"/static/(.*)", tornado.web.StaticFileHandler, {"path": static_dir}))
207+
handlers.append((LOCAL_STATIC_URL + r"/(.*)", tornado.web.StaticFileHandler, {"path": STATIC_PATH}))
209208
handlers.append((r"/.*", RequestHandler))
210209

211210
print_listen_address(host, port)
@@ -250,7 +249,8 @@ def path_deploy(base, port=0, host='',
250249
# use `websocket_ping_interval` to keep the connection alive
251250
tornado_app_settings.setdefault('websocket_ping_interval', 30)
252251
tornado_app_settings.setdefault('websocket_max_message_size', max_payload_size) # Backward compatible
253-
tornado_app_settings['websocket_max_message_size'] = parse_file_size(tornado_app_settings['websocket_max_message_size'])
252+
tornado_app_settings['websocket_max_message_size'] = parse_file_size(
253+
tornado_app_settings['websocket_max_message_size'])
254254
gen = _path_deploy(base, port=port, host=host,
255255
static_dir=static_dir, debug=debug,
256256
max_payload_size=max_payload_size,
@@ -277,9 +277,9 @@ def get_app(self):
277277
reload = self.get_query_argument('reload', None) is not None
278278
type, res = get_app_from_path(self.request.path, abs_base, index=index_func, reload=reload)
279279
if type == 'error':
280-
raise HTTPError(status_code=res)
280+
raise tornado.web.HTTPError(status_code=res)
281281
elif type == 'html':
282-
raise Finish(res)
282+
raise tornado.web.Finish(res)
283283

284284
app_name = self.get_query_argument('app', 'index')
285285
app = res.get(app_name) or res['index']
@@ -326,9 +326,9 @@ def get_app(context: TornadoHttpContext):
326326

327327
type, res = get_app_from_path(context.get_path(), abs_base, index=index_func, reload=reload)
328328
if type == 'error':
329-
raise HTTPError(status_code=res)
329+
raise tornado.web.HTTPError(status_code=res)
330330
elif type == 'html':
331-
raise Finish(res)
331+
raise tornado.web.Finish(res)
332332

333333
app_name = context.request_url_parameter('app', 'index')
334334
return res.get(app_name) or res['index']

pywebio/platform/remote_access.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ def start_remote_access_service_(**kwargs):
111111

112112
def start_remote_access_service(**kwargs):
113113
if not shutil.which("ssh"):
114-
return logging.error("No ssh client found, remote access service can't start.")
114+
logging.error("No ssh client found, remote access service can't start.")
115+
return
115116

116117
server = os.environ.get('PYWEBIO_REMOTE_ACCESS', 'app.pywebio.online:1022')
117118
if ':' not in server:

pywebio/session/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
import os
32
import sys
43
import traceback
54
from collections import defaultdict

test/util.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22
import signal
33
import subprocess
44
import sys
5-
import threading
6-
from functools import partial
75
from urllib.parse import urlparse
86

9-
from selenium import webdriver
10-
11-
from pywebio import STATIC_PATH
127
from pywebio.utils import wait_host_port
8+
from selenium import webdriver
139

1410
default_chrome_options = webdriver.ChromeOptions()
1511
default_chrome_options.add_argument('--no-sandbox')

webiojs/src/models/input/textarea.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {InputItem} from "./base";
22
import {deep_copy, make_set} from "../../utils"
33
import {config as appConfig} from "../../state";
4-
import {t} from "../../i18n";
54

65

76
const textarea_input_tpl = `
@@ -60,7 +59,7 @@ export class Textarea extends InputItem {
6059
// 将额外的html参数加到input标签上
6160
let ignore_keys = make_set(['value', 'type', 'label', 'invalid_feedback', 'valid_feedback',
6261
'help_text', 'rows', 'code', 'onchange']);
63-
if (spec.code && spec.required){
62+
if (spec.code && spec.required) {
6463
ignore_keys['required'] = '';
6564
}
6665
for (let key in this.spec) {

0 commit comments

Comments
 (0)