workflow_tools.py - fixed sevveral bugs in wait_position where eval would cause an exception but shouldnt
This commit is contained in:
1 parent
cc2c339210
commit
2e89d6d1ec
1 file changed
+8
-5
@@ -6,14 +6,17 @@ from epics import poll
|
||||
def wait_position(motor, target, tolerance=None, timeout=60.0):
|
||||
position = motor.readback
|
||||
if isinstance(position, float) and tolerance is None:
|
||||
tst = "%f %s"
|
||||
ltst = lambda x, y, z: eval(tst % (x, y)) # noqa: E731
|
||||
tst = "%f == %s"
|
||||
ltst = lambda x, y, z: x == y # noqa: E731
|
||||
elif isinstance(position, float) and tolerance is not None:
|
||||
tst = "abs(%f - %f) < %f"
|
||||
ltst = lambda x, y, z: eval(tst % (x, y, z)) # noqa: E731
|
||||
elif isinstance(position, bytes):
|
||||
ltst = lambda x, y, z: abs(x - y) < z # noqa: E731
|
||||
elif isinstance(position, (bytes, str)):
|
||||
tst = "'%s' == '%s'"
|
||||
ltst = lambda x, y, z: eval(tst % (x.lower(), y.lower())) # noqa: E731
|
||||
if isinstance(position, bytes):
|
||||
ltst = lambda x, y, z: x.lower() == y.lower().encode() if isinstance(y, str) else x.lower() == y.lower()
|
||||
else:
|
||||
ltst = lambda x, y, z: x.lower() == y.lower()
|
||||
else:
|
||||
raise RuntimeError("BUG: could not understand arguments: ")
|
||||
|
||||
|
||||
Reference in new issue
Block a user