aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'gallery_dl/util.py')
-rw-r--r--gallery_dl/util.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/gallery_dl/util.py b/gallery_dl/util.py
index e76ddf3..5744ef3 100644
--- a/gallery_dl/util.py
+++ b/gallery_dl/util.py
@@ -540,10 +540,14 @@ class CustomNone():
def __bool__():
return False
+ def __eq__(self, other):
+ return self is other
+
+ def __ne__(self, other):
+ return self is not other
+
__lt__ = true
__le__ = true
- __eq__ = false
- __ne__ = true
__gt__ = false
__ge__ = false
@@ -616,11 +620,28 @@ else:
Popen = subprocess.Popen
-def compile_expression(expr, name="<expr>", globals=None):
+def compile_expression_raw(expr, name="<expr>", globals=None):
code_object = compile(expr, name, "eval")
return functools.partial(eval, code_object, globals or GLOBALS)
+def compile_expression_tryexcept(expr, name="<expr>", globals=None):
+ code_object = compile(expr, name, "eval")
+
+ def _eval(locals=None, globals=(globals or GLOBALS), co=code_object):
+ try:
+ return eval(co, globals, locals)
+ except exception.GalleryDLException:
+ raise
+ except Exception:
+ return False
+
+ return _eval
+
+
+compile_expression = compile_expression_tryexcept
+
+
def import_file(path):
"""Import a Python module from a filesystem path"""
path, name = os.path.split(path)