diff options
author | dirkf <fieldhouse@gmx.net> | 2024-03-04 20:52:58 +0000 |
---|---|---|
committer | dirkf <fieldhouse@gmx.net> | 2024-03-08 13:03:42 +0000 |
commit | acc383b9e3c2d454121c22570c901dd2c689dc26 (patch) | |
tree | 3849199371f9767211b2d83df600569795060eb2 /youtube_dl | |
parent | f0812d784836d18fd25ea32f9b5a0c9c6e92425b (diff) |
[utils] Let int_or_none() accept a base, like int()
Diffstat (limited to 'youtube_dl')
-rw-r--r-- | youtube_dl/utils.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index c249e7168..03c73dff3 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -3852,14 +3852,15 @@ class PUTRequest(compat_urllib_request.Request): return 'PUT' -def int_or_none(v, scale=1, default=None, get_attr=None, invscale=1): +def int_or_none(v, scale=1, default=None, get_attr=None, invscale=1, base=None): if get_attr: if v is not None: v = getattr(v, get_attr, None) if v in (None, ''): return default try: - return int(v) * invscale // scale + # like int, raise if base is specified and v is not a string + return (int(v) if base is None else int(v, base=base)) * invscale // scale except (ValueError, TypeError, OverflowError): return default |