mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2025-12-08 15:12:43 +01:00
[utils] Apply partial_application decorator to existing functions
Thx: yt-dlp/yt-dlp#10653 (etc)
This commit is contained in:
@@ -1730,13 +1730,13 @@ Line 1
|
|||||||
callable(test_fn(kwarg=10)),
|
callable(test_fn(kwarg=10)),
|
||||||
'missing positional parameter should apply partially')
|
'missing positional parameter should apply partially')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
test_fn(10, kwarg=0.1), '10, kwarg=0.1',
|
test_fn(10, kwarg=42), '10, kwarg=42',
|
||||||
'positionally passed argument should call function')
|
'positionally passed argument should call function')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
test_fn(x=10), '10, kwarg=None',
|
test_fn(x=10), '10, kwarg=None',
|
||||||
'keyword passed positional should call function')
|
'keyword passed positional should call function')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
test_fn(kwarg=0.1)(10), '10, kwarg=0.1',
|
test_fn(kwarg=42)(10), '10, kwarg=42',
|
||||||
'call after partial application should call the function')
|
'call after partial application should call the function')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3187,6 +3187,7 @@ def extract_timezone(date_str):
|
|||||||
return timezone, date_str
|
return timezone, date_str
|
||||||
|
|
||||||
|
|
||||||
|
@partial_application
|
||||||
def parse_iso8601(date_str, delimiter='T', timezone=None):
|
def parse_iso8601(date_str, delimiter='T', timezone=None):
|
||||||
""" Return a UNIX timestamp from the given date """
|
""" Return a UNIX timestamp from the given date """
|
||||||
|
|
||||||
@@ -3264,6 +3265,7 @@ def unified_timestamp(date_str, day_first=True):
|
|||||||
return calendar.timegm(timetuple) + pm_delta * 3600 - compat_datetime_timedelta_total_seconds(timezone)
|
return calendar.timegm(timetuple) + pm_delta * 3600 - compat_datetime_timedelta_total_seconds(timezone)
|
||||||
|
|
||||||
|
|
||||||
|
@partial_application
|
||||||
def determine_ext(url, default_ext='unknown_video'):
|
def determine_ext(url, default_ext='unknown_video'):
|
||||||
if url is None or '.' not in url:
|
if url is None or '.' not in url:
|
||||||
return default_ext
|
return default_ext
|
||||||
@@ -3842,6 +3844,7 @@ def base_url(url):
|
|||||||
return re.match(r'https?://[^?#&]+/', url).group()
|
return re.match(r'https?://[^?#&]+/', url).group()
|
||||||
|
|
||||||
|
|
||||||
|
@partial_application
|
||||||
def urljoin(base, path):
|
def urljoin(base, path):
|
||||||
path = _decode_compat_str(path, encoding='utf-8', or_none=True)
|
path = _decode_compat_str(path, encoding='utf-8', or_none=True)
|
||||||
if not path:
|
if not path:
|
||||||
@@ -3866,6 +3869,7 @@ class PUTRequest(compat_urllib_request.Request):
|
|||||||
return 'PUT'
|
return 'PUT'
|
||||||
|
|
||||||
|
|
||||||
|
@partial_application
|
||||||
def int_or_none(v, scale=1, default=None, get_attr=None, invscale=1, base=None):
|
def int_or_none(v, scale=1, default=None, get_attr=None, invscale=1, base=None):
|
||||||
if get_attr:
|
if get_attr:
|
||||||
if v is not None:
|
if v is not None:
|
||||||
@@ -3892,6 +3896,7 @@ def str_to_int(int_str):
|
|||||||
return int_or_none(int_str)
|
return int_or_none(int_str)
|
||||||
|
|
||||||
|
|
||||||
|
@partial_application
|
||||||
def float_or_none(v, scale=1, invscale=1, default=None):
|
def float_or_none(v, scale=1, invscale=1, default=None):
|
||||||
if v is None:
|
if v is None:
|
||||||
return default
|
return default
|
||||||
@@ -4286,6 +4291,7 @@ def urlencode_postdata(*args, **kargs):
|
|||||||
return compat_urllib_parse_urlencode(*args, **kargs).encode('ascii')
|
return compat_urllib_parse_urlencode(*args, **kargs).encode('ascii')
|
||||||
|
|
||||||
|
|
||||||
|
@partial_application
|
||||||
def update_url(url, **kwargs):
|
def update_url(url, **kwargs):
|
||||||
"""Replace URL components specified by kwargs
|
"""Replace URL components specified by kwargs
|
||||||
url: compat_str or parsed URL tuple
|
url: compat_str or parsed URL tuple
|
||||||
@@ -4307,6 +4313,7 @@ def update_url(url, **kwargs):
|
|||||||
return compat_urllib_parse.urlunparse(url._replace(**kwargs))
|
return compat_urllib_parse.urlunparse(url._replace(**kwargs))
|
||||||
|
|
||||||
|
|
||||||
|
@partial_application
|
||||||
def update_url_query(url, query):
|
def update_url_query(url, query):
|
||||||
return update_url(url, query_update=query)
|
return update_url(url, query_update=query)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user