Skip to content

Commit eac435b

Browse files
committed
fix lint
1 parent 447b856 commit eac435b

File tree

4 files changed

+33
-36
lines changed

4 files changed

+33
-36
lines changed

app/actions/send_message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from app.actions import BaseAction, ActionChain
66
from app.schemas import ActionParams, ActionContext, Notification
7-
from core.config import settings
7+
from app.core.config import settings
88

99

1010
class SendMessageParams(ActionParams):

app/api/endpoints/discover.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from app.core.security import verify_token
88
from app.schemas import DiscoverSourceEventData
99
from app.schemas.types import ChainEventType, MediaType
10-
from chain.bangumi import BangumiChain
11-
from chain.douban import DoubanChain
12-
from chain.tmdb import TmdbChain
10+
from app.chain.bangumi import BangumiChain
11+
from app.chain.douban import DoubanChain
12+
from app.chain.tmdb import TmdbChain
1313

1414
router = APIRouter()
1515

app/core/cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def get(self, key: str, region: Optional[str] = DEFAULT_CACHE_REGION) -> Any:
196196
return None
197197
return region_cache.get(key)
198198

199-
def delete(self, key: str, region: Optional[str] = DEFAULT_CACHE_REGION) -> None:
199+
def delete(self, key: str, region: Optional[str] = DEFAULT_CACHE_REGION):
200200
"""
201201
删除缓存
202202
@@ -205,7 +205,7 @@ def delete(self, key: str, region: Optional[str] = DEFAULT_CACHE_REGION) -> None
205205
"""
206206
region_cache = self.__get_region_cache(region)
207207
if region_cache is None:
208-
return None
208+
return
209209
with lock:
210210
del region_cache[key]
211211

app/helper/doh.py

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,36 @@
2222
_doh_timeout = 5
2323
_doh_cache: Dict[str, str] = {}
2424

25-
26-
def _patched_getaddrinfo(host, *args, **kwargs):
27-
"""
28-
socket.getaddrinfo的补丁版本。
29-
"""
30-
if host not in settings.DOH_DOMAINS.split(","):
31-
return _orig_getaddrinfo(host, *args, **kwargs)
32-
33-
# 检查主机是否已解析
34-
if host in _doh_cache:
35-
ip = _doh_cache[host]
36-
logger.info("已解析 [%s] 为 [%s] (缓存)", host, ip)
37-
return _orig_getaddrinfo(ip, *args, **kwargs)
38-
39-
# 使用DoH解析主机
40-
futures = []
41-
for resolver in settings.DOH_RESOLVERS.split(","):
42-
futures.append(_executor.submit(_doh_query, resolver, host))
43-
44-
for future in concurrent.futures.as_completed(futures):
45-
ip = future.result()
46-
if ip is not None:
47-
logger.info("已解析 [%s] 为 [%s]", host, ip)
48-
_doh_cache[host] = ip
49-
host = ip
50-
break
51-
52-
return _orig_getaddrinfo(host, *args, **kwargs)
53-
54-
5525
# 对 socket.getaddrinfo 进行补丁
5626
if settings.DOH_ENABLE:
27+
# 保存原始的 socket.getaddrinfo 方法
5728
_orig_getaddrinfo = socket.getaddrinfo
29+
30+
def _patched_getaddrinfo(host, *args, **kwargs):
31+
"""
32+
socket.getaddrinfo的补丁版本。
33+
"""
34+
if host not in settings.DOH_DOMAINS.split(","):
35+
return _orig_getaddrinfo(host, *args, **kwargs)
36+
# 检查主机是否已解析
37+
if host in _doh_cache:
38+
ip = _doh_cache[host]
39+
logger.info("已解析 [%s] 为 [%s] (缓存)", host, ip)
40+
return _orig_getaddrinfo(ip, *args, **kwargs)
41+
# 使用DoH解析主机
42+
futures = []
43+
for resolver in settings.DOH_RESOLVERS.split(","):
44+
futures.append(_executor.submit(_doh_query, resolver, host))
45+
for future in concurrent.futures.as_completed(futures):
46+
ip = future.result()
47+
if ip is not None:
48+
logger.info("已解析 [%s] 为 [%s]", host, ip)
49+
_doh_cache[host] = ip
50+
host = ip
51+
break
52+
return _orig_getaddrinfo(host, *args, **kwargs)
53+
54+
# 替换 socket.getaddrinfo 方法
5855
socket.getaddrinfo = _patched_getaddrinfo
5956

6057

0 commit comments

Comments
 (0)