mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Allow ops
This commit is contained in:
		
							parent
							
								
									45c726fd4d
								
							
						
					
					
						commit
						0ca3c33c59
					
				| 
						 | 
					@ -64,6 +64,11 @@ def test_prevent_exec(expression):
 | 
				
			||||||
        ImageMath.eval(expression)
 | 
					        ImageMath.eval(expression)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_prevent_double_underscores():
 | 
				
			||||||
 | 
					    with pytest.raises(ValueError):
 | 
				
			||||||
 | 
					        ImageMath.eval("1", {"__": None})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_logical():
 | 
					def test_logical():
 | 
				
			||||||
    assert pixel(ImageMath.eval("not A", images)) == 0
 | 
					    assert pixel(ImageMath.eval("not A", images)) == 0
 | 
				
			||||||
    assert pixel(ImageMath.eval("A and B", images)) == "L 2"
 | 
					    assert pixel(ImageMath.eval("A and B", images)) == "L 2"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -234,13 +234,14 @@ def eval(expression, _dict={}, **kw):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # build execution namespace
 | 
					    # build execution namespace
 | 
				
			||||||
    args = ops.copy()
 | 
					    args = ops.copy()
 | 
				
			||||||
    args.update(_dict)
 | 
					    for k in list(_dict.keys()) + list(kw.keys()):
 | 
				
			||||||
    args.update(kw)
 | 
					        if "__" in k or hasattr(__builtins__, k):
 | 
				
			||||||
    for k, v in args.items():
 | 
					 | 
				
			||||||
        if '__' in k or hasattr(__builtins__, k):
 | 
					 | 
				
			||||||
            msg = f"'{k}' not allowed"
 | 
					            msg = f"'{k}' not allowed"
 | 
				
			||||||
            raise ValueError(msg)
 | 
					            raise ValueError(msg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    args.update(_dict)
 | 
				
			||||||
 | 
					    args.update(kw)
 | 
				
			||||||
 | 
					    for k, v in args.items():
 | 
				
			||||||
        if hasattr(v, "im"):
 | 
					        if hasattr(v, "im"):
 | 
				
			||||||
            args[k] = _Operand(v)
 | 
					            args[k] = _Operand(v)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user