black formatting
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
from enum import Enum
|
||||
|
||||
ParamConstraint_oper = Enum(
|
||||
'ParamConstraint_oper',
|
||||
'param_entity true l_and l_or l_not lt le eq ge gt')
|
||||
"ParamConstraint_oper", "param_entity true l_and l_or l_not lt le eq ge gt"
|
||||
)
|
||||
|
||||
|
||||
class ParamConstraint(object):
|
||||
|
||||
def __init__(self, f_type, L_oper=None, R_oper=None, param=None, entity=""):
|
||||
self.f_type = f_type
|
||||
self.left_operand = L_oper
|
||||
@@ -21,9 +21,13 @@ class ParamConstraint(object):
|
||||
if self.f_type == ParamConstraint_oper.true:
|
||||
return "TRUE"
|
||||
if self.f_type == ParamConstraint_oper.l_and:
|
||||
return "(" + repr(self.left_operand) + " & " + repr(self.right_operand) + ")"
|
||||
return (
|
||||
"(" + repr(self.left_operand) + " & " + repr(self.right_operand) + ")"
|
||||
)
|
||||
if self.f_type == ParamConstraint_oper.l_or:
|
||||
return "(" + repr(self.left_operand) + " | " + repr(self.right_operand) + ")"
|
||||
return (
|
||||
"(" + repr(self.left_operand) + " | " + repr(self.right_operand) + ")"
|
||||
)
|
||||
if self.f_type == ParamConstraint_oper.l_not:
|
||||
return "~(" + repr(self.left_operand) + ")"
|
||||
if self.f_type == ParamConstraint_oper.lt:
|
||||
@@ -41,17 +45,18 @@ class ParamConstraint(object):
|
||||
"""Sanity checks"""
|
||||
for operand in (self.left_operand, self.right_operand):
|
||||
if operand:
|
||||
if not(
|
||||
isinstance(operand, ParamConstraint)
|
||||
or isinstance(operand, int)):
|
||||
if not (
|
||||
isinstance(operand, ParamConstraint) or isinstance(operand, int)
|
||||
):
|
||||
raise RuntimeError(
|
||||
"Unexpected operand type for a bag: {:s} (type: {:s})".format(
|
||||
str(operand), str(type(operand))))
|
||||
str(operand), str(type(operand))
|
||||
)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def f_param_ent(cls, param, entity_name):
|
||||
return cls(ParamConstraint_oper.param_entity, param=param,
|
||||
entity=entity_name)
|
||||
return cls(ParamConstraint_oper.param_entity, param=param, entity=entity_name)
|
||||
|
||||
@classmethod
|
||||
def f_TRUE(cls):
|
||||
@@ -66,34 +71,28 @@ class ParamConstraint(object):
|
||||
return cls(ParamConstraint_oper.l_not, L_oper=arg)
|
||||
|
||||
def __lt__(self, other):
|
||||
return ParamConstraint(
|
||||
ParamConstraint_oper.lt, L_oper=self, R_oper=other)
|
||||
return ParamConstraint(ParamConstraint_oper.lt, L_oper=self, R_oper=other)
|
||||
|
||||
def __le__(self, other):
|
||||
return ParamConstraint(
|
||||
ParamConstraint_oper.le, L_oper=self, R_oper=other)
|
||||
return ParamConstraint(ParamConstraint_oper.le, L_oper=self, R_oper=other)
|
||||
|
||||
def __eq__(self, other):
|
||||
return ParamConstraint(
|
||||
ParamConstraint_oper.eq, L_oper=self, R_oper=other)
|
||||
return ParamConstraint(ParamConstraint_oper.eq, L_oper=self, R_oper=other)
|
||||
|
||||
def __ge__(self, other):
|
||||
return ParamConstraint(
|
||||
ParamConstraint_oper.ge, L_oper=self, R_oper=other)
|
||||
return ParamConstraint(ParamConstraint_oper.ge, L_oper=self, R_oper=other)
|
||||
|
||||
def __gt__(self, other):
|
||||
return ParamConstraint(
|
||||
ParamConstraint_oper.gt, L_oper=self, R_oper=other)
|
||||
return ParamConstraint(ParamConstraint_oper.gt, L_oper=self, R_oper=other)
|
||||
|
||||
def __and__(self, other):
|
||||
return ParamConstraint(
|
||||
ParamConstraint_oper.l_and, L_oper=self, R_oper=other)
|
||||
return ParamConstraint(ParamConstraint_oper.l_and, L_oper=self, R_oper=other)
|
||||
|
||||
def __or__(self, other):
|
||||
return ParamConstraint(
|
||||
ParamConstraint_oper.l_or, L_oper=self, R_oper=other)
|
||||
return ParamConstraint(ParamConstraint_oper.l_or, L_oper=self, R_oper=other)
|
||||
|
||||
def __invert__(self):
|
||||
return ParamConstraint(ParamConstraint_oper.l_not, L_oper=self)
|
||||
|
||||
|
||||
# EOF
|
||||
|
||||
Reference in New Issue
Block a user