Esempio 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)
Esempio n. 2
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:
        # TODO: We might start using this for Python2 too.
        assert str is not bytes

        value = ExpressionBuiltinStrP3(value=value,
                                       encoding=None,
                                       errors=None,
                                       source_ref=source_ref)
    elif conversion == 2:
        value = makeExpressionOperationUnary(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,
    )