Skip to content

Commit 85f0f57

Browse files
committed
Backport to Python 3.7
1 parent c53c2e4 commit 85f0f57

43 files changed

Lines changed: 212 additions & 111 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

devscripts/install_deps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def main():
4848

4949
def yield_deps(group):
5050
for dep in group:
51-
if mobj := recursive_pattern.fullmatch(dep):
51+
mobj = recursive_pattern.fullmatch(dep)
52+
if mobj:
5253
yield from optional_groups.get(mobj.group('group_name'), [])
5354
else:
5455
yield dep

devscripts/make_changelog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CommitGroup(enum.Enum):
3535
MISC = 'Misc.'
3636

3737
@classmethod
38-
@lru_cache
38+
@lru_cache()
3939
def subgroup_lookup(cls):
4040
return {
4141
name: group
@@ -56,7 +56,7 @@ def subgroup_lookup(cls):
5656
}
5757

5858
@classmethod
59-
@lru_cache
59+
@lru_cache()
6060
def group_lookup(cls):
6161
result = {
6262
'fd': cls.DOWNLOADER,

devscripts/tomlparse.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,22 @@ def get_target(root: dict, paths: list[str], is_list=False):
6464
def parse_enclosed(data: str, index: int, end: str, ws_re: re.Pattern):
6565
index += 1
6666

67-
if match := ws_re.match(data, index):
67+
match = ws_re.match(data, index)
68+
if match:
6869
index = match.end()
6970

7071
while data[index] != end:
7172
index = yield True, index
7273

73-
if match := ws_re.match(data, index):
74+
match = ws_re.match(data, index)
75+
if match:
7476
index = match.end()
7577

7678
if data[index] == ',':
7779
index += 1
7880

79-
if match := ws_re.match(data, index):
81+
match = ws_re.match(data, index)
82+
if match:
8083
index = match.end()
8184

8285
assert data[index] == end
@@ -106,7 +109,8 @@ def parse_value(data: str, index: int):
106109

107110
return index, result
108111

109-
if match := STRING_RE.match(data, index):
112+
match = STRING_RE.match(data, index)
113+
if match:
110114
return match.end(), json.loads(match[0]) if match[0][0] == '"' else match[0][1:-1]
111115

112116
match = LEFTOVER_VALUE_RE.match(data, index)

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ maintainers = [
1212
]
1313
description = "A feature-rich command-line audio/video downloader"
1414
readme = "README.md"
15-
requires-python = ">=3.8"
15+
requires-python = ">=3.7"
1616
keywords = [
1717
"youtube-dl",
1818
"video-downloader",
@@ -28,6 +28,7 @@ classifiers = [
2828
"Environment :: Console",
2929
"Programming Language :: Python",
3030
"Programming Language :: Python :: 3 :: Only",
31+
"Programming Language :: Python :: 3.7",
3132
"Programming Language :: Python :: 3.8",
3233
"Programming Language :: Python :: 3.9",
3334
"Programming Language :: Python :: 3.10",
@@ -48,7 +49,7 @@ dependencies = [
4849
"pycryptodomex",
4950
"requests>=2.31.0,<3",
5051
"urllib3>=1.26.17,<3",
51-
"websockets>=12.0",
52+
"websockets>=11.0.0",
5253
]
5354

5455
[project.optional-dependencies]

setup.cfg

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,23 @@ remove-unused-variables = true
1616

1717
[tox:tox]
1818
skipsdist = true
19-
envlist = py{38,39,310,311,312},pypy{38,39,310}
19+
envlist = py{37,38,39,310,311,312},pypy{37,38,39,310}
2020
skip_missing_interpreters = true
2121

2222
[testenv] # tox
2323
deps =
2424
pytest
25+
requests
26+
curl-cffi
27+
websockets
2528
commands = pytest {posargs:"-m not download"}
2629
passenv = HOME # For test_compat_expanduser
2730
setenv =
2831
# PYTHONWARNINGS = error # Catches PIP's warnings too
2932

3033

3134
[isort]
32-
py_version = 38
35+
py_version = 37
3336
multi_line_output = VERTICAL_HANGING_INDENT
3437
line_length = 80
3538
reverse_relative = true

test/test_traversal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def test_traversal_morsel(self):
402402
'secure': 'f',
403403
'httponly': 'g',
404404
'version': 'h',
405-
'samesite': 'i',
405+
# 'samesite': 'i',
406406
}
407407
morsel = http.cookies.Morsel()
408408
morsel.set('item_key', 'item_value', 'coded_value')

yt_dlp/YoutubeDL.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,8 @@ def check_deprecated(param, option, suggestion):
718718
for msg in self.params.get('_deprecation_warnings', []):
719719
self.deprecated_feature(msg)
720720

721-
if impersonate_target := self.params.get('impersonate'):
721+
impersonate_target = self.params.get('impersonate')
722+
if impersonate_target:
722723
if not self._impersonate_target_available(impersonate_target):
723724
raise YoutubeDLError(
724725
f'Impersonate target "{impersonate_target}" is not available. '
@@ -2680,10 +2681,14 @@ def _fill_common_fields(self, info_dict, final=True):
26802681
if new_key in info_dict and old_key in info_dict:
26812682
if '_version' not in info_dict: # HACK: Do not warn when using --load-info-json
26822683
self.deprecation_warning(f'Do not return {old_key!r} when {new_key!r} is present')
2683-
elif old_value := info_dict.get(old_key):
2684-
info_dict[new_key] = old_value.split(', ')
2685-
elif new_value := info_dict.get(new_key):
2686-
info_dict[old_key] = ', '.join(v.replace(',', '\N{FULLWIDTH COMMA}') for v in new_value)
2684+
else:
2685+
old_value = info_dict.get(old_key)
2686+
if old_value:
2687+
info_dict[new_key] = old_value.split(', ')
2688+
else:
2689+
new_value = info_dict.get(new_key)
2690+
if new_value:
2691+
info_dict[old_key] = ', '.join(v.replace(',', '\N{FULLWIDTH COMMA}') for v in new_value)
26872692

26882693
def _raise_pending_errors(self, info):
26892694
err = info.pop('__pending_error', None)

yt_dlp/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import sys
22

3-
if sys.version_info < (3, 8):
3+
if sys.version_info < (3, 7):
44
raise ImportError(
5-
f'You are using an unsupported version of Python. Only Python versions 3.8 and above are supported by yt-dlp') # noqa: F541
5+
f'You are using an unsupported version of Python. Only Python versions 3.7 and above are supported by yt-dlp') # noqa: F541
66

77
__license__ = 'The Unlicense'
88

yt_dlp/compat/functools.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,17 @@
1010
cache # >= 3.9
1111
except NameError:
1212
cache = lru_cache(maxsize=None)
13+
14+
try:
15+
cached_property # >= 3.8
16+
except NameError:
17+
class cached_property:
18+
def __init__(self, func):
19+
update_wrapper(self, func)
20+
self.func = func
21+
22+
def __get__(self, instance, _):
23+
if instance is None:
24+
return self
25+
setattr(instance, self.func.__name__, self.func(instance))
26+
return getattr(instance, self.func.__name__)

yt_dlp/compat/shlex.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# flake8: noqa: F405
2+
from shlex import * # noqa: F403
3+
4+
from .compat_utils import passthrough_module
5+
6+
passthrough_module(__name__, 'shlex')
7+
del passthrough_module
8+
9+
10+
try:
11+
join
12+
except NameError:
13+
def join(split_command):
14+
"""Return a shell-escaped string from *split_command*."""
15+
return ' '.join(quote(arg) for arg in split_command)

0 commit comments

Comments
 (0)