Skip to content

Commit

Permalink
support --allow_new_request to use requests / aiohttp / tPool / Reque…
Browse files Browse the repository at this point in the history
…sts in UDFParser
  • Loading branch information
ClericPy committed May 23, 2022
1 parent 1f8fd2f commit 57c9dc6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ pyyaml>=5.3
selectolax
toml
torequests>=5.0.4
uniparser>=3.0.1
uniparser>=3.0.2
uvicorn
2 changes: 1 addition & 1 deletion watchdogs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
15 changes: 15 additions & 0 deletions watchdogs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 57c9dc6

Please sign in to comment.