aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/Pillow/py3/PIL/ImageMath.py
diff options
context:
space:
mode:
authorAlexSm <alex@ydb.tech>2024-01-26 16:00:50 +0100
committerGitHub <noreply@github.com>2024-01-26 16:00:50 +0100
commit7ebcfd058d924bcc8c23da70e034f7415687885c (patch)
treee4f00d163c77528c1855f2d7af54a8be83fc1ccb /contrib/python/Pillow/py3/PIL/ImageMath.py
parent64ca2dcd06312b9eef624054ceb5f787e11be79a (diff)
parent6d79e7793c2c462134f4b4a7d911abc7b9b0766f (diff)
downloadydb-7ebcfd058d924bcc8c23da70e034f7415687885c.tar.gz
Merge pull request #1260 from ydb-platform/mergelibs10
mergelibs10
Diffstat (limited to 'contrib/python/Pillow/py3/PIL/ImageMath.py')
-rw-r--r--contrib/python/Pillow/py3/PIL/ImageMath.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/contrib/python/Pillow/py3/PIL/ImageMath.py b/contrib/python/Pillow/py3/PIL/ImageMath.py
index eb6bbe6c62..b77f4bce56 100644
--- a/contrib/python/Pillow/py3/PIL/ImageMath.py
+++ b/contrib/python/Pillow/py3/PIL/ImageMath.py
@@ -14,16 +14,13 @@
#
# See the README file for information on usage and redistribution.
#
+from __future__ import annotations
import builtins
from . import Image, _imagingmath
-def _isconstant(v):
- return isinstance(v, (int, float))
-
-
class _Operand:
"""Wraps an image operand, providing standard operators"""
@@ -43,7 +40,7 @@ class _Operand:
raise ValueError(msg)
else:
# argument was a constant
- if _isconstant(im1) and self.im.mode in ("1", "L", "I"):
+ if isinstance(im1, (int, float)) and self.im.mode in ("1", "L", "I"):
return Image.new("I", self.im.size, im1)
else:
return Image.new("F", self.im.size, im1)
@@ -237,9 +234,14 @@ def eval(expression, _dict={}, **kw):
# build execution namespace
args = ops.copy()
+ for k in list(_dict.keys()) + list(kw.keys()):
+ if "__" in k or hasattr(builtins, k):
+ msg = f"'{k}' not allowed"
+ raise ValueError(msg)
+
args.update(_dict)
args.update(kw)
- for k, v in list(args.items()):
+ for k, v in args.items():
if hasattr(v, "im"):
args[k] = _Operand(v)