mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-07-02 19:38:32 +00:00
Merge a2fca0bcf6
into 73bf102116
This commit is contained in:
commit
d97bcc1431
@ -604,6 +604,7 @@ def test_str_to_int(self):
|
||||
self.assertEqual(str_to_int(523), 523)
|
||||
self.assertEqual(str_to_int('noninteger'), None)
|
||||
self.assertEqual(str_to_int([]), None)
|
||||
self.assertEqual(str_to_int('123.456', dot_decimal=True), 123)
|
||||
|
||||
def test_url_basename(self):
|
||||
self.assertEqual(url_basename('http://foo.de/'), '')
|
||||
|
@ -2010,13 +2010,18 @@ def str_or_none(v, default=None):
|
||||
return default if v is None else str(v)
|
||||
|
||||
|
||||
def str_to_int(int_str):
|
||||
def str_to_int(int_str, *, dot_decimal=False):
|
||||
""" A more relaxed version of int_or_none """
|
||||
if isinstance(int_str, int):
|
||||
return int_str
|
||||
elif isinstance(int_str, str):
|
||||
int_str = re.sub(r'[,\.\+]', '', int_str)
|
||||
return int_or_none(int_str)
|
||||
if not isinstance(int_str, str):
|
||||
return None
|
||||
int_str = re.sub(r'[,+]', '', int_str)
|
||||
|
||||
if dot_decimal:
|
||||
f = float_or_none(int_str)
|
||||
return int(f) if f is not None else None
|
||||
return int_or_none(int_str.replace('.', ''))
|
||||
|
||||
|
||||
@partial_application
|
||||
|
Loading…
Reference in New Issue
Block a user