From 57c9dc6cc56eceb9c8a0f79f0ee4a92f43a7125f Mon Sep 17 00:00:00 2001 From: clericpy Date: Mon, 23 May 2022 23:22:21 +0800 Subject: [PATCH] support --allow_new_request to use requests / aiohttp / tPool / Requests in UDFParser --- requirements.txt | 2 +- watchdogs/__init__.py | 2 +- watchdogs/main.py | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 6d548a3..4d52a92 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,5 +13,5 @@ pyyaml>=5.3 selectolax toml torequests>=5.0.4 -uniparser>=3.0.1 +uniparser>=3.0.2 uvicorn diff --git a/watchdogs/__init__.py b/watchdogs/__init__.py index 3faba98..e761584 100644 --- a/watchdogs/__init__.py +++ b/watchdogs/__init__.py @@ -3,6 +3,6 @@ from .config import Config from .main import init_app -__version__ = '1.9.4' +__version__ = '1.9.5' __all__ = ['Config', 'init_app'] logging.getLogger('watchdogs').addHandler(logging.NullHandler()) diff --git a/watchdogs/main.py b/watchdogs/main.py index a0ac972..759738a 100644 --- a/watchdogs/main.py +++ b/watchdogs/main.py @@ -30,12 +30,25 @@ def init_app(db_url=None, md5_salt=None, config_dir=None, use_default_cdn=False, + allow_new_request=False, **uvicorn_kwargs): if config_dir: Config.CONFIG_DIR = ensure_dir(config_dir) if uninstall: clear_dir(Config.CONFIG_DIR) sys.exit('Config dir cleared.') + if allow_new_request: + # will allow use requests / aiohttp / tPool / Requests in UDFParser + import aiohttp + import requests + from torequests.dummy import Requests + from torequests.main import tPool + from uniparser.parsers import UDFParser + + UDFParser._GLOBALS_ARGS.update(aiohttp=aiohttp, + requests=requests, + Requests=Requests, + tPool=tPool) # backward compatibility for ignore_stdout_log & ignore_file_log Config.mute_std_log = get_valid_value( [uvicorn_kwargs.pop('ignore_stdout_log', NotSet), mute_std_log], @@ -63,6 +76,7 @@ def start_app(db_url=None, md5_salt=None, config_dir=None, use_default_cdn=False, + allow_new_request=False, **uvicorn_kwargs): app = init_app(db_url=db_url, password=password, @@ -72,6 +86,7 @@ def start_app(db_url=None, md5_salt=md5_salt, config_dir=config_dir, use_default_cdn=use_default_cdn, + allow_new_request=allow_new_request, **uvicorn_kwargs) from fastapi.middleware.gzip import GZipMiddleware app.add_middleware(GZipMiddleware, minimum_size=1000)