コード例 #1
0
def confprol_random():
    element = random.randint(0,21)

    if element in [0,1]:
        return BasicExpression(ConfprolObject(bool(element)),"random()",ValueType.BOOLEAN)
    elif element in range(2,6):
        value = random.randint(-10000000000000,10000000000000)
        return BasicExpression(ConfprolObject(value),"random()",ValueType.NUMBER)
    elif element in range(6,10):
        value = random.uniform(-10000000000000, 10000000000000)
        return BasicExpression(ConfprolObject(value), "random()", ValueType.NUMBER)
    elif element == 10:
        return confprol_none
    elif element == 1:
        return TrueExceptFridays()
    elif element == 12:
        return MillionToOneChance()
    elif element in range(13,17):
        axis = random.randint(0,1)
        value = random.randint(0,1)

        return QuanticBoolean(QuanticAxis(axis),bool(value))
    elif element in range(17,19):
        list_ = ListExpression(ConfprolObject([]),"random()")
        element = random.randint(0, 4)
        while element !=0:
            list_.append(confprol_random())
            element = random.randint(0, 4)
        return list_

    else:
        length = random.randint(0, 100)
        value = ''.join(random.choices(string.ascii_uppercase + string.digits + string.ascii_lowercase,k=length))
        return StringExpression(ConfprolObject(value),"random()")
コード例 #2
0
def has_attribute(args):
    expr = args[0]
    attr = args[1].value

    if type(attr)!= str:
        raise ConfprolValueError("The second argument of the function 'has_attribute' must be a string")

    return BasicExpression(ConfprolObject(expr.has_attribute(attr)),f"has_attribute({expr}{attr})",ValueType.BOOLEAN)
コード例 #3
0
def confprol_range(start_expr,end_expr):
    start = start_expr.value
    end = end_expr.value

    if not type(start)==int:
        raise ConfprolValueError(f"The start value in range() must be an integer.")

    if not type(end)==int:
        raise ConfprolValueError(f"The end value in range() must be an integer.")

    range_ = range(start,end)
    list_ = map(lambda x: BasicExpression(ConfprolObject(x),x,ValueType.NUMBER),range_)
    return ListExpression(ConfprolObject(list_),f"range({start},{end})")
コード例 #4
0
def to_float(expression):
    try:
        float_value = float(expression.value)
        return BasicExpression(ConfprolObject(float_value), f"int({expression.value})", ValueType.NUMBER)
    except ValueError:
        raise ConfprolValueError(f"The string/variable '{expression.name}' can't be transformed to float.")
コード例 #5
0
def to_float(expression):
    float_value = float(expression.value)
    return BasicExpression(ConfprolObject(float_value), f"float({expression.value})", ValueType.NUMBER)
コード例 #6
0
def to_integer(expression):
    try:
        int_value = int(float(expression.value))  # First to float to allow strings like "3.2"
        return BasicExpression(ConfprolObject(int_value), f"int({expression.value})", ValueType.NUMBER)
    except ValueError:
        raise ConfprolValueError(f"The string/variable '{expression.name}' can't be transformed to integer.")
コード例 #7
0
def to_integer(expression):
    int_value = int(expression.value)
    return BasicExpression(ConfprolObject(int_value), f"int({expression.value})", ValueType.NUMBER)
コード例 #8
0
ファイル: confprol_handler.py プロジェクト: DanielBV/Confprol
 def load_number(self, number: int):
     a = BasicExpression(ConfprolObject(number), str(number),
                         ValueType.NUMBER)
     return a
コード例 #9
0
ファイル: confprol_handler.py プロジェクト: DanielBV/Confprol
 def load_boolean(self, boolean: bool):
     return BasicExpression(ConfprolObject(boolean), str(boolean),
                            ValueType.BOOLEAN)
コード例 #10
0
ファイル: confprol_handler.py プロジェクト: DanielBV/Confprol
 def load_float(self, float: float):
     return BasicExpression(ConfprolObject(float), str(float),
                            ValueType.NUMBER)