Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
XianxinMao
Yt Dlp
提交
9196cbfe
Y
Yt Dlp
项目概览
XianxinMao
/
Yt Dlp
12 个月 前同步成功
通知
27
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
Yt Dlp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
9196cbfe
编写于
4月 24, 2022
作者:
P
pukkandan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[compat] Ensure submodules are correctly wrapped
上级
9cd08050
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
73 addition
and
22 deletion
+73
-22
test/test_compat.py
test/test_compat.py
+7
-0
yt_dlp/compat/__init__.py
yt_dlp/compat/__init__.py
+8
-22
yt_dlp/compat/asyncio/__init__.py
yt_dlp/compat/asyncio/__init__.py
+4
-0
yt_dlp/compat/asyncio/tasks.py
yt_dlp/compat/asyncio/tasks.py
+5
-0
yt_dlp/compat/compat_utils.py
yt_dlp/compat/compat_utils.py
+44
-0
yt_dlp/compat/re.py
yt_dlp/compat/re.py
+5
-0
未找到文件。
test/test_compat.py
浏览文件 @
9196cbfe
...
...
@@ -7,6 +7,7 @@
sys
.
path
.
insert
(
0
,
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))))
from
yt_dlp
import
compat
from
yt_dlp.compat
import
(
compat_etree_fromstring
,
compat_expanduser
,
...
...
@@ -21,6 +22,12 @@
class
TestCompat
(
unittest
.
TestCase
):
def
test_compat_passthrough
(
self
):
with
self
.
assertWarns
(
DeprecationWarning
):
compat
.
compat_basestring
compat
.
asyncio
.
events
# Must not raise error
def
test_compat_getenv
(
self
):
test_str
=
'тест'
compat_setenv
(
'yt_dlp_COMPAT_GETENV'
,
test_str
)
...
...
yt_dlp/compat/__init__.py
浏览文件 @
9196cbfe
...
...
@@ -2,11 +2,18 @@
import
os
import
subprocess
import
sys
import
type
s
import
warning
s
import
xml.etree.ElementTree
as
etree
from
.
import
re
from
._deprecated
import
*
# noqa: F401, F403
from
.compat_utils
import
passthrough_module
# XXX: Implement this the same way as other DeprecationWarnings without circular import
passthrough_module
(
__name__
,
'._legacy'
,
callback
=
lambda
attr
:
warnings
.
warn
(
DeprecationWarning
(
f
'
{
__name__
}
.
{
attr
}
is deprecated'
),
stacklevel
=
2
))
del
passthrough_module
# HTMLParseError has been deprecated in Python 3.3 and removed in
...
...
@@ -85,24 +92,3 @@ def windows_enable_vt_mode(): # TODO: Do this the proper way https://bugs.pytho
with
contextlib
.
suppress
(
Exception
):
subprocess
.
Popen
(
''
,
shell
=
True
,
startupinfo
=
startupinfo
).
wait
()
WINDOWS_VT_MODE
=
True
class
_PassthroughLegacy
(
types
.
ModuleType
):
def
__getattr__
(
self
,
attr
):
import
importlib
with
contextlib
.
suppress
(
ImportError
):
return
importlib
.
import_module
(
f
'.
{
attr
}
'
,
__name__
)
legacy
=
importlib
.
import_module
(
'._legacy'
,
__name__
)
if
not
hasattr
(
legacy
,
attr
):
raise
AttributeError
(
f
'module
{
__name__
}
has no attribute
{
attr
}
'
)
# XXX: Implement this the same way as other DeprecationWarnings without circular import
import
warnings
warnings
.
warn
(
DeprecationWarning
(
f
'
{
__name__
}
.
{
attr
}
is deprecated'
),
stacklevel
=
2
)
return
getattr
(
legacy
,
attr
)
# Python 3.6 does not have module level __getattr__
# https://peps.python.org/pep-0562/
sys
.
modules
[
__name__
].
__class__
=
_PassthroughLegacy
yt_dlp/compat/asyncio/__init__.py
浏览文件 @
9196cbfe
...
...
@@ -3,6 +3,10 @@
from
asyncio
import
*
# noqa: F403
from
.
import
tasks
# noqa: F401
from
..compat_utils
import
passthrough_module
passthrough_module
(
__name__
,
'asyncio'
)
del
passthrough_module
try
:
run
# >= 3.7
...
...
yt_dlp/compat/asyncio/tasks.py
浏览文件 @
9196cbfe
...
...
@@ -2,6 +2,11 @@
from
asyncio.tasks
import
*
# noqa: F403
from
..compat_utils
import
passthrough_module
passthrough_module
(
__name__
,
'asyncio.tasks'
)
del
passthrough_module
try
:
# >= 3.7
all_tasks
except
NameError
:
...
...
yt_dlp/compat/compat_utils.py
0 → 100644
浏览文件 @
9196cbfe
import
contextlib
import
importlib
import
sys
import
types
def
_is_package
(
module
):
try
:
module
.
__getattribute__
(
'__path__'
)
except
AttributeError
:
return
False
return
True
_NO_ATTRIBUTE
=
object
()
def
passthrough_module
(
parent
,
child
,
*
,
callback
=
lambda
_
:
None
):
parent_module
=
importlib
.
import_module
(
parent
)
child_module
=
importlib
.
import_module
(
child
,
parent
)
class
PassthroughModule
(
types
.
ModuleType
):
def
__getattr__
(
self
,
attr
):
if
_is_package
(
parent_module
):
with
contextlib
.
suppress
(
ImportError
):
return
importlib
.
import_module
(
f
'.
{
attr
}
'
,
parent
)
ret
=
_NO_ATTRIBUTE
with
contextlib
.
suppress
(
AttributeError
):
ret
=
getattr
(
child_module
,
attr
)
if
_is_package
(
child_module
):
with
contextlib
.
suppress
(
ImportError
):
ret
=
importlib
.
import_module
(
f
'.
{
attr
}
'
,
child
)
if
ret
is
_NO_ATTRIBUTE
:
raise
AttributeError
(
f
'module
{
parent
}
has no attribute
{
attr
}
'
)
callback
(
attr
)
return
ret
# Python 3.6 does not have module level __getattr__
# https://peps.python.org/pep-0562/
sys
.
modules
[
parent
].
__class__
=
PassthroughModule
yt_dlp/compat/re.py
浏览文件 @
9196cbfe
...
...
@@ -2,6 +2,11 @@
from
re
import
*
# F403
from
.compat_utils
import
passthrough_module
passthrough_module
(
__name__
,
're'
)
del
passthrough_module
try
:
Pattern
# >= 3.7
except
NameError
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录