30 lines
886 B
Python
30 lines
886 B
Python
"""Telethon Connection 模式(与 Telegram Desktop 使用的传输类似可选用 obfuscated)。"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from typing import Type
|
||
|
||
from telethon.network.connection import (
|
||
Connection,
|
||
ConnectionTcpAbridged,
|
||
ConnectionTcpFull,
|
||
ConnectionTcpIntermediate,
|
||
ConnectionTcpObfuscated,
|
||
)
|
||
|
||
|
||
def resolve_connection_class(mode: str) -> Type[Connection]:
|
||
m = (mode or "").strip().lower().replace("-", "_")
|
||
if not m or m == "tcp_full":
|
||
return ConnectionTcpFull
|
||
if m == "tcp_obfuscated":
|
||
return ConnectionTcpObfuscated
|
||
if m == "tcp_intermediate":
|
||
return ConnectionTcpIntermediate
|
||
if m == "tcp_abridged":
|
||
return ConnectionTcpAbridged
|
||
raise ValueError(
|
||
f"不支持的 TELEGRAM_CONNECTION={mode!r},可用: "
|
||
"tcp_full, tcp_obfuscated, tcp_intermediate, tcp_abridged"
|
||
)
|