aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/util.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2019-11-10 22:14:10 -0500
committerLibravatarUnit 193 <unit193@ubuntu.com>2019-11-10 22:14:10 -0500
commit0c73e982fa596da07f23b377621ab894a9e64884 (patch)
tree96f6a40a5656c15a2ec7217a8a1efcff5827bcbb /gallery_dl/util.py
parent40f5fe6edef268632d3bc484e85e5b37bad67bff (diff)
New upstream version 1.11.1upstream/1.11.1
Diffstat (limited to 'gallery_dl/util.py')
-rw-r--r--gallery_dl/util.py32
1 files changed, 16 insertions, 16 deletions
diff --git a/gallery_dl/util.py b/gallery_dl/util.py
index d87184d..fb51edf 100644
--- a/gallery_dl/util.py
+++ b/gallery_dl/util.py
@@ -52,10 +52,10 @@ def advance(iterable, num):
return iterator
-def raises(obj):
- """Returns a function that raises 'obj' as exception"""
- def wrap():
- raise obj
+def raises(cls):
+ """Returns a function that raises 'cls' as exception"""
+ def wrap(*args):
+ raise cls(*args)
return wrap
@@ -287,21 +287,21 @@ class UniquePredicate():
class FilterPredicate():
"""Predicate; True if evaluating the given expression returns True"""
- globalsdict = {
- "parse_int": text.parse_int,
- "urlsplit": urllib.parse.urlsplit,
- "datetime": datetime.datetime,
- "abort": raises(exception.StopExtraction()),
- "re": re,
- }
def __init__(self, filterexpr, target="image"):
name = "<{} filter>".format(target)
self.codeobj = compile(filterexpr, name, "eval")
+ self.globals = {
+ "parse_int": text.parse_int,
+ "urlsplit" : urllib.parse.urlsplit,
+ "datetime" : datetime.datetime,
+ "abort" : raises(exception.StopExtraction),
+ "re" : re,
+ }
def __call__(self, url, kwds):
try:
- return eval(self.codeobj, self.globalsdict, kwds)
+ return eval(self.codeobj, self.globals, kwds)
except exception.GalleryDLException:
raise
except Exception as exc:
@@ -528,7 +528,7 @@ class PathFormat():
self.filename_formatter = Formatter(
filename_fmt, kwdefault).format_map
except Exception as exc:
- raise exception.FormatError(exc, "filename")
+ raise exception.FilenameFormatError(exc)
try:
self.directory_formatters = [
@@ -536,7 +536,7 @@ class PathFormat():
for dirfmt in directory_fmt
]
except Exception as exc:
- raise exception.FormatError(exc, "directory")
+ raise exception.DirectoryFormatError(exc)
self.directory = self.realdirectory = ""
self.filename = ""
@@ -616,7 +616,7 @@ class PathFormat():
if segment:
append(self.clean_segment(segment))
except Exception as exc:
- raise exception.FormatError(exc, "directory")
+ raise exception.DirectoryFormatError(exc)
# Join path segements
sep = os.sep
@@ -673,7 +673,7 @@ class PathFormat():
self.filename = filename = self.clean_path(self.clean_segment(
self.filename_formatter(self.kwdict)))
except Exception as exc:
- raise exception.FormatError(exc, "filename")
+ raise exception.FilenameFormatError(exc)
# Combine directory and filename to full paths
self.path = self.directory + filename