Skip to content

Commit

Permalink
refine code style
Browse files Browse the repository at this point in the history
  • Loading branch information
wang0618 committed May 23, 2022
1 parent e6b2b1c commit c816363
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 37 deletions.
5 changes: 2 additions & 3 deletions demos/gomoku_game.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import time

import pywebio
from pywebio import session, start_server
from pywebio.output import *
from pywebio import session

goboard_size = 15
# -1 -> none, 0 -> black, 1 -> white
Expand Down Expand Up @@ -92,4 +91,4 @@ def show_goboard():


if __name__ == '__main__':
pywebio.start_server(main, debug=True, port=8080)
start_server(main, debug=True, port=8080)
2 changes: 1 addition & 1 deletion pywebio/io_ctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class OutputList(UserList):
def __del__(self):
"""返回值没有被变量接收时的操作:顺序输出其持有的内容"""
for o in self.data:
o.__del__()
o.__del__() # lgtm [py/explicit-call-to-delete]


def safely_destruct_output_when_exp(content_param):
Expand Down
14 changes: 7 additions & 7 deletions pywebio/platform/aiohttp.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import os
import asyncio
import fnmatch
import json
import logging
import os
from functools import partial
from os import path, listdir
from urllib.parse import urlparse

from aiohttp import web

from .page import make_applications, render_page
from .remote_access import start_remote_access_service
from .tornado import open_webbrowser_on_server_started
from .page import make_applications, render_page
from .utils import cdn_validation, deserialize_binary_event, print_listen_address
from ..session import CoroutineBasedSession, ThreadBasedSession, register_session_implement_for_target, Session
from ..session.base import get_session_info_from_headers
Expand Down Expand Up @@ -47,6 +46,7 @@ def _webio_handler(applications, cdn, websocket_settings, check_origin_func=_is_
:param callable check_origin_func: check_origin_func(origin, host) -> bool
:return: aiohttp Request Handler
"""

async def wshandle(request: web.Request):
ioloop = asyncio.get_event_loop()

Expand Down Expand Up @@ -157,11 +157,11 @@ def static_routes(prefix='/'):
"""

async def index(request):
return web.FileResponse(path.join(STATIC_PATH, 'index.html'))
return web.FileResponse(os.path.join(STATIC_PATH, 'index.html'))

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

Expand Down
3 changes: 2 additions & 1 deletion pywebio/platform/bokeh.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def show_app(app, state, notebook_url, port=0, **kw):
from bokeh.embed import server_document
script = server_document(url, resources=None)

script = re.sub(r'<script(.*?)>([\s\S]*?)</script>', r"""
script = re.sub(r'<script(.*?)>([\s\S]*?)</script>', # lgtm [py/bad-tag-filter]
r"""
<script \g<1>>
requirejs(['bokeh', 'bokeh-widgets', 'bokeh-tables'], function(Bokeh) {
\g<2>
Expand Down
32 changes: 16 additions & 16 deletions pywebio/platform/path_deploy.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import ast
import os.path
from functools import partial
from contextlib import contextmanager
import ast
from functools import partial

import tornado
from tornado import template
from tornado.web import HTTPError, Finish
from tornado.web import StaticFileHandler
import tornado.template
import tornado.web
import tornado.ioloop

from . import page
from .httpbased import HttpHandler
from .page import make_applications
from .tornado import webio_handler, set_ioloop
from .tornado_http import TornadoHttpContext
from .utils import cdn_validation, print_listen_address
from .page import make_applications
from ..session import register_session_implement, CoroutineBasedSession, ThreadBasedSession, Session
from ..utils import get_free_port, STATIC_PATH, parse_file_size

Expand Down Expand Up @@ -103,7 +102,7 @@ def add_to_path(p):
return module


_app_list_tpl = template.Template("""
_app_list_tpl = tornado.template.Template("""
<!DOCTYPE html>
<html lang="">
<head>
Expand Down Expand Up @@ -145,7 +144,7 @@ def default_index_page(path, base):
dirs.append([(f + '/'), ''])

items = dirs + files
max_name_width = max([len(n) for n, _ in items]+[0])
max_name_width = max([len(n) for n, _ in items] + [0])
return _app_list_tpl.generate(files=items, title=title, max_name_width=max_name_width)


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

handlers = []
if static_dir is not None:
handlers.append((r"/static/(.*)", StaticFileHandler, {"path": static_dir}))
handlers.append((LOCAL_STATIC_URL+r"/(.*)", StaticFileHandler, {"path": STATIC_PATH}))
handlers.append((r"/static/(.*)", tornado.web.StaticFileHandler, {"path": static_dir}))
handlers.append((LOCAL_STATIC_URL + r"/(.*)", tornado.web.StaticFileHandler, {"path": STATIC_PATH}))
handlers.append((r"/.*", RequestHandler))

print_listen_address(host, port)
Expand Down Expand Up @@ -250,7 +249,8 @@ def path_deploy(base, port=0, host='',
# use `websocket_ping_interval` to keep the connection alive
tornado_app_settings.setdefault('websocket_ping_interval', 30)
tornado_app_settings.setdefault('websocket_max_message_size', max_payload_size) # Backward compatible
tornado_app_settings['websocket_max_message_size'] = parse_file_size(tornado_app_settings['websocket_max_message_size'])
tornado_app_settings['websocket_max_message_size'] = parse_file_size(
tornado_app_settings['websocket_max_message_size'])
gen = _path_deploy(base, port=port, host=host,
static_dir=static_dir, debug=debug,
max_payload_size=max_payload_size,
Expand All @@ -277,9 +277,9 @@ def get_app(self):
reload = self.get_query_argument('reload', None) is not None
type, res = get_app_from_path(self.request.path, abs_base, index=index_func, reload=reload)
if type == 'error':
raise HTTPError(status_code=res)
raise tornado.web.HTTPError(status_code=res)
elif type == 'html':
raise Finish(res)
raise tornado.web.Finish(res)

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

type, res = get_app_from_path(context.get_path(), abs_base, index=index_func, reload=reload)
if type == 'error':
raise HTTPError(status_code=res)
raise tornado.web.HTTPError(status_code=res)
elif type == 'html':
raise Finish(res)
raise tornado.web.Finish(res)

app_name = context.request_url_parameter('app', 'index')
return res.get(app_name) or res['index']
Expand Down
3 changes: 2 additions & 1 deletion pywebio/platform/remote_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def start_remote_access_service_(**kwargs):

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

server = os.environ.get('PYWEBIO_REMOTE_ACCESS', 'app.pywebio.online:1022')
if ':' not in server:
Expand Down
1 change: 0 additions & 1 deletion pywebio/session/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import os
import sys
import traceback
from collections import defaultdict
Expand Down
6 changes: 1 addition & 5 deletions test/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
import signal
import subprocess
import sys
import threading
from functools import partial
from urllib.parse import urlparse

from selenium import webdriver

from pywebio import STATIC_PATH
from pywebio.utils import wait_host_port
from selenium import webdriver

default_chrome_options = webdriver.ChromeOptions()
default_chrome_options.add_argument('--no-sandbox')
Expand Down
3 changes: 1 addition & 2 deletions webiojs/src/models/input/textarea.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {InputItem} from "./base";
import {deep_copy, make_set} from "../../utils"
import {config as appConfig} from "../../state";
import {t} from "../../i18n";


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

0 comments on commit c816363

Please sign in to comment.