mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 10:42:34 +01:00
[text] catch general Exceptions
This commit is contained in:
parent
6dac43ad60
commit
5227bb6b1d
@ -73,7 +73,7 @@ def filename_from_url(url):
|
||||
"""Extract the last part of an URL to use as a filename"""
|
||||
try:
|
||||
return url.partition("?")[0].rpartition("/")[2]
|
||||
except (TypeError, AttributeError):
|
||||
except Exception:
|
||||
return ""
|
||||
|
||||
|
||||
@ -122,7 +122,7 @@ def extract(txt, begin, end, pos=0):
|
||||
first = txt.index(begin, pos) + len(begin)
|
||||
last = txt.index(end, first)
|
||||
return txt[first:last], last+len(end)
|
||||
except (ValueError, TypeError, AttributeError):
|
||||
except Exception:
|
||||
return None, pos
|
||||
|
||||
|
||||
@ -131,7 +131,7 @@ def extr(txt, begin, end, default=""):
|
||||
try:
|
||||
first = txt.index(begin) + len(begin)
|
||||
return txt[first:txt.index(end, first)]
|
||||
except (ValueError, TypeError, AttributeError):
|
||||
except Exception:
|
||||
return default
|
||||
|
||||
|
||||
@ -141,7 +141,7 @@ def rextract(txt, begin, end, pos=-1):
|
||||
first = txt.rindex(begin, 0, pos)
|
||||
last = txt.index(end, first + lbeg)
|
||||
return txt[first + lbeg:last], first
|
||||
except (ValueError, TypeError, AttributeError):
|
||||
except Exception:
|
||||
return None, pos
|
||||
|
||||
|
||||
@ -167,7 +167,7 @@ def extract_iter(txt, begin, end, pos=0):
|
||||
last = index(end, first)
|
||||
pos = last + lend
|
||||
yield txt[first:last]
|
||||
except (ValueError, TypeError, AttributeError):
|
||||
except Exception:
|
||||
return
|
||||
|
||||
|
||||
@ -180,7 +180,7 @@ def extract_from(txt, pos=0, default=""):
|
||||
last = index(end, first)
|
||||
pos = last + len(end)
|
||||
return txt[first:last]
|
||||
except (ValueError, TypeError, AttributeError):
|
||||
except Exception:
|
||||
return default
|
||||
return extr
|
||||
|
||||
@ -200,7 +200,7 @@ def parse_bytes(value, default=0, suffixes="bkmgtp"):
|
||||
"""Convert a bytes-amount ("500k", "2.5M", ...) to int"""
|
||||
try:
|
||||
last = value[-1].lower()
|
||||
except (TypeError, LookupError):
|
||||
except Exception:
|
||||
return default
|
||||
|
||||
if last in suffixes:
|
||||
@ -221,7 +221,7 @@ def parse_int(value, default=0):
|
||||
return default
|
||||
try:
|
||||
return int(value)
|
||||
except (ValueError, TypeError):
|
||||
except Exception:
|
||||
return default
|
||||
|
||||
|
||||
@ -231,7 +231,7 @@ def parse_float(value, default=0.0):
|
||||
return default
|
||||
try:
|
||||
return float(value)
|
||||
except (ValueError, TypeError):
|
||||
except Exception:
|
||||
return default
|
||||
|
||||
|
||||
@ -242,7 +242,7 @@ def parse_query(qs):
|
||||
for key, value in urllib.parse.parse_qsl(qs):
|
||||
if key not in result:
|
||||
result[key] = value
|
||||
except AttributeError:
|
||||
except Exception:
|
||||
pass
|
||||
return result
|
||||
|
||||
@ -251,7 +251,7 @@ def parse_timestamp(ts, default=None):
|
||||
"""Create a datetime object from a unix timestamp"""
|
||||
try:
|
||||
return datetime.datetime.utcfromtimestamp(int(ts))
|
||||
except (TypeError, ValueError, OverflowError):
|
||||
except Exception:
|
||||
return default
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user