Exemplo n.º 1
0
def buildFormattedValueNode(provider, node, source_ref):
    value = buildNode(provider, node.value, source_ref)

    conversion = node.conversion % 4 if node.conversion > 0 else 0

    if conversion == 0:
        pass
    elif conversion == 3:
        value = ExpressionBuiltinStr(value=value,
                                     encoding=None,
                                     errors=None,
                                     source_ref=source_ref)
    elif conversion == 2:
        value = ExpressionOperationUnary(operator="Repr",
                                         operand=value,
                                         source_ref=source_ref)
    elif conversion == 1:
        value = ExpressionBuiltinAscii(value=value, source_ref=source_ref)
    else:
        assert False, conversion

    return ExpressionBuiltinFormat(value=value,
                                   format_spec=buildNode(provider,
                                                         node.format_spec,
                                                         source_ref,
                                                         allow_none=True),
                                   source_ref=source_ref)
    def wrapValue(value):
        if value.isExpressionConstantRef():
            str_value = value.getStrValue()

            if str_value is not None:
                return str_value

        return ExpressionBuiltinStr(value=value,
                                    source_ref=value.getSourceReference())
 def wrapValue(value):
     if value.isExpressionConstantRef():
         return value.getStrValue(None)
     else:
         return ExpressionBuiltinStr(value=value,
                                     source_ref=value.getSourceReference())