Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(6)  |  Call(4)  |  Derive(0)  |  Import(2)

        def namifyConstant(constant):
    # Many branches, statements and every case has a return, this is a huge case
    # statement, that encodes the naming policy of constants, with often complex
    # decisions to make, pylint: disable=R0911,R0912,R0915

    if type( constant ) is int:
        if constant == 0:
            result = "int_0"
        elif constant > 0:
            result = "int_pos_%d" % constant
        else:
            result = "int_neg_%d" % abs( constant )

        if len( result ) > 32:
            result = _digest( result )

        return result
    elif type( constant ) is long:
        if constant == 0:
            result = "long_0"
        elif constant > 0:
            result = "long_pos_%d" % constant
        else:
            result = "long_neg_%d" % abs( constant )

        if len( result ) > 32:
            result = _digest( result )

        return result
    elif constant is None:
        return "none"
    elif constant is True:
        return "true"
    elif constant is False:
        return "false"
    elif constant is Ellipsis:
        return "ellipsis"
    elif type( constant ) is str:
        return "str_" + _namifyString( constant )
    elif type( constant ) is bytes:
        return "bytes_" + _namifyString( constant )
    elif type( constant ) is unicode:
        if _isAscii( constant ):
            return "unicode_" + _namifyString( str( constant ) )
        else:
            # Others are better digested to not cause compiler trouble
            return "unicode_digest_" + _digest( repr( constant ) )
    elif type( constant ) is float:
        if math.isnan( constant ):
            return "float_%s_nan" % (
                "minus" if math.copysign( 1, constant ) < 0 else "plus"
            )

        return "float_%s" % repr( constant ).replace( ".", "_" ).\
          replace( "-", "_minus_" ).replace( "+", "" )
    elif type( constant ) is complex:
        value = str( constant ).replace( "+", "p" ).replace( "-", "m" ).\
          replace( ".", "_" )

        if value.startswith( "(" ) and value.endswith( ")" ):
            value = value[1:-1]

        return "complex_%s" % value
    elif type( constant ) is dict:
        if constant == {}:
            return "dict_empty"
        else:
            return "dict_" + _digest( repr( constant ) )
    elif type( constant ) is set:
        if constant == set():
            return "set_empty"
        else:
            return "set_" + _digest( repr( constant ) )
    elif type( constant ) is frozenset:
        if constant == frozenset():
            return "frozenset_empty"
        else:
            return "frozenset_" + _digest( repr( constant ) )
    elif type( constant ) is tuple:
        if constant == ():
            return "tuple_empty"
        else:
            try:
                result = "_".join(
                    namifyConstant( value )
                    for value in
                    constant
                )

                if len( result ) > 60:
                    result = _digest( repr( constant ) )

                return "tuple_" + result + "_tuple"
            except ExceptionCannotNamify:
                warning( "Couldn't namify '%r'" % value )

                return "tuple_" + _digest( repr( constant ) )
    elif type( constant ) is list:
        if constant == []:
            return "list_empty"
        else:
            try:
                result = "_".join(
                    namifyConstant( value )
                    for value in
                    constant
                )

                if len( result ) > 60:
                    result = _digest( repr( constant ) )

                return "list_" + result + "_list"
            except ExceptionCannotNamify:
                warning( "Couldn't namify '%r'" % value )

                return "list_" + _digest( repr( constant ) )
    elif type( constant ) is range:
        # Python3 type only.
        return "range_%s" % (
            str( constant )[6:-1].replace( " ", "" ).replace( ",", "_" )
        )

    raise ExceptionCannotNamify( "%r" % constant )
        


src/n/u/Nuitka-0.5.1.5/nuitka/codegen/Contexts.py   Nuitka(Download)
)
 
from .Namify import namifyConstant
from .ConstantCodes import HashableConstant
 
                if key not in self.constants:
                    self.constants[key] = "const_" + namifyConstant(
                        constant
                    )
 
                return ConstantIdentifier(self.constants[ key ], constant)
            else:
                return Identifier("const_" + namifyConstant( constant ), 0)

src/n/u/Nuitka-HEAD/nuitka/codegen/Contexts.py   Nuitka(Download)
"""
 
from .Namify import namifyConstant
from .ConstantCodes import HashableConstant
 
                if key not in self.constants:
                    self.constants[key] = "const_" + namifyConstant(
                        constant
                    )
 
                return self.constants[ key ]
            else:
                return "const_" + namifyConstant( constant )