当前位置: 首页>>代码示例>>Python>>正文


Python SyntaxErrors.raiseSyntaxError方法代码示例

本文整理汇总了Python中nuitka.tree.SyntaxErrors.raiseSyntaxError方法的典型用法代码示例。如果您正苦于以下问题:Python SyntaxErrors.raiseSyntaxError方法的具体用法?Python SyntaxErrors.raiseSyntaxError怎么用?Python SyntaxErrors.raiseSyntaxError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nuitka.tree.SyntaxErrors的用法示例。


在下文中一共展示了SyntaxErrors.raiseSyntaxError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _handleNonLocal

# 需要导入模块: from nuitka.tree import SyntaxErrors [as 别名]
# 或者: from nuitka.tree.SyntaxErrors import raiseSyntaxError [as 别名]
    def _handleNonLocal(node):
        # Take closure variables for non-local declarations.

        for non_local_names, source_ref in node.getNonlocalDeclarations():
            for non_local_name in non_local_names:
                variable = node.getClosureVariable(
                    variable_name = non_local_name
                )

                if variable.isModuleVariable():
                    SyntaxErrors.raiseSyntaxError(
                        "no binding for nonlocal '%s' found" % (
                            non_local_name
                        ),
                        source_ref   = None
                                         if isFullCompat() and \
                                         python_version < 340 else
                                       source_ref,
                        display_file = not isFullCompat() or \
                                       python_version >= 340,
                        display_line = not isFullCompat() or \
                                       python_version >= 340
                    )

                node.registerProvidedVariable(variable)
                addVariableUsage(variable, node)
开发者ID:601040605,项目名称:Nuitka,代码行数:28,代码来源:VariableClosure.py

示例2: _enableFutureFeature

# 需要导入模块: from nuitka.tree import SyntaxErrors [as 别名]
# 或者: from nuitka.tree.SyntaxErrors import raiseSyntaxError [as 别名]
def _enableFutureFeature(object_name, future_spec, source_ref):
    if object_name == "unicode_literals":
        future_spec.enableUnicodeLiterals()
    elif object_name == "absolute_import":
        future_spec.enableAbsoluteImport()
    elif object_name == "division":
        future_spec.enableFutureDivision()
    elif object_name == "print_function":
        future_spec.enableFuturePrint()
    elif object_name == "barry_as_FLUFL" and python_version >= 300:
        future_spec.enableBarry()
    elif object_name == "generator_stop":
        future_spec.enableGeneratorStop()
    elif object_name == "braces":
        SyntaxErrors.raiseSyntaxError(
            "not a chance",
            source_ref
        )
    elif object_name in ("nested_scopes", "generators", "with_statement"):
        # These are enabled in all cases already.
        pass
    else:
        SyntaxErrors.raiseSyntaxError(
            "future feature %s is not defined" % object_name,
            source_ref
        )
开发者ID:fluxer,项目名称:spm,代码行数:28,代码来源:ReformulationImportStatements.py

示例3: buildStatementContinueLoop

# 需要导入模块: from nuitka.tree import SyntaxErrors [as 别名]
# 或者: from nuitka.tree.SyntaxErrors import raiseSyntaxError [as 别名]
def buildStatementContinueLoop(node, source_ref):
    if getBuildContext() == "finally":
        if not Options.isFullCompat() or Utils.python_version >= 300:
            col_offset = node.col_offset - 9
        else:
            col_offset = None

        if Utils.python_version >= 300 and Options.isFullCompat():
            source_line = ""
        else:
            source_line = None

        SyntaxErrors.raiseSyntaxError(
            "'continue' not supported inside 'finally' clause",
            source_ref,
            col_offset  = col_offset,
            source_line = source_line
        )


    statements = makeTryFinallyIndicatorStatements(
        is_loop_exit = True,
        source_ref   = source_ref
    )

    statements.append(
        StatementContinueLoop(
            source_ref = source_ref
        )
    )

    return makeStatementsSequenceOrStatement(
        statements = statements,
        source_ref = source_ref
    )
开发者ID:Xzarh,项目名称:Nuitka,代码行数:37,代码来源:Building.py

示例4: buildReturnNode

# 需要导入模块: from nuitka.tree import SyntaxErrors [as 别名]
# 或者: from nuitka.tree.SyntaxErrors import raiseSyntaxError [as 别名]
def buildReturnNode(provider, node, source_ref):
    if not provider.isExpressionFunctionBody() or \
       provider.isClassDictCreation():
        SyntaxErrors.raiseSyntaxError(
            "'return' outside function",
            source_ref,
            None if Utils.python_version < 300 else (
                node.col_offset
                  if provider.isPythonModule() else
                node.col_offset+4
            )
        )

    expression = buildNode(provider, node.value, source_ref, allow_none = True)

    if expression is None:
        expression = ExpressionConstantRef(
            constant      = None,
            source_ref    = source_ref,
            user_provided = True
        )

    return StatementReturn(
        expression = expression,
        source_ref = source_ref
    )
开发者ID:justus922,项目名称:Nuitka,代码行数:28,代码来源:Building.py

示例5: _handleFutureImport

# 需要导入模块: from nuitka.tree import SyntaxErrors [as 别名]
# 或者: from nuitka.tree.SyntaxErrors import raiseSyntaxError [as 别名]
def _handleFutureImport(provider, node, source_ref):
    # Don't allow future imports in functions or classes.
    if not provider.isCompiledPythonModule():
        SyntaxErrors.raiseSyntaxError(
            reason     = """\
from __future__ imports must occur at the beginning of the file""",
            col_offset = 8
              if python_version >= 300 or \
              not Options.isFullCompat()
            else None,
            source_ref = source_ref
        )


    for import_desc in node.names:
        object_name, _local_name = import_desc.name, import_desc.asname

        _enableFutureFeature(
            object_name = object_name,
            future_spec = source_ref.getFutureSpec(),
            source_ref  = source_ref
        )

    # Remember it for checks to be applied once module is complete, e.g. if
    # they are all at module start.
    node.source_ref = source_ref
    _future_import_nodes.append(node)
开发者ID:fluxer,项目名称:spm,代码行数:29,代码来源:ReformulationImportStatements.py

示例6: onLeaveNode

# 需要导入模块: from nuitka.tree import SyntaxErrors [as 别名]
# 或者: from nuitka.tree.SyntaxErrors import raiseSyntaxError [as 别名]
    def onLeaveNode(self, node):
        # Return statements in generators are not really that, instead they are
        # exception raises, fix that up now. Doing it right from the onset,
        # would be a bit more difficult, as the knowledge that something is a
        # generator, requires a second pass.
        if node.isStatementReturn():
            return_consumer = node.getParentReturnConsumer()

            if return_consumer.isExpressionFunctionBody() and \
               return_consumer.isGenerator():
                return_value = node.getExpression()

                if python_version < 330:
                    if not return_value.isExpressionReturnedValueRef() and \
                       (not return_value.isExpressionConstantRef() or \
                        return_value.getConstant() is not None):
                        SyntaxErrors.raiseSyntaxError(
                            "'return' with argument inside generator",
                            source_ref = node.getSourceReference(),
                        )

                node.replaceWith(
                    StatementGeneratorReturn(
                        expression = return_value,
                        source_ref = node.getSourceReference()
                    )
                )
开发者ID:justus922,项目名称:Nuitka,代码行数:29,代码来源:VariableClosure.py

示例7: _markAsGenerator

# 需要导入模块: from nuitka.tree import SyntaxErrors [as 别名]
# 或者: from nuitka.tree.SyntaxErrors import raiseSyntaxError [as 别名]
def _markAsGenerator(provider, node, source_ref):
    if provider.isPythonModule():
        SyntaxErrors.raiseSyntaxError(
            "'yield' outside function",
            source_ref,
            None if Utils.python_version < 300 else node.col_offset
        )

    provider.markAsGenerator()
开发者ID:FireWalkerX,项目名称:Nuitka,代码行数:11,代码来源:ReformulationYieldExpressions.py

示例8: buildParameterSpec

# 需要导入模块: from nuitka.tree import SyntaxErrors [as 别名]
# 或者: from nuitka.tree.SyntaxErrors import raiseSyntaxError [as 别名]
def buildParameterSpec(provider, name, node, source_ref):
    kind = getKind(node)

    assert kind in ("FunctionDef", "Lambda"), "unsupported for kind " + kind

    def extractArg(arg):
        if arg is None:
            return None
        elif type(arg) is str:
            return mangleName(arg, provider)
        elif getKind(arg) == "Name":
            return mangleName(arg.id, provider)
        elif getKind(arg) == "arg":
            return mangleName(arg.arg, provider)
        elif getKind(arg) == "Tuple":
            return tuple(
                extractArg(arg)
                for arg in
                arg.elts
            )
        else:
            assert False, getKind(arg)

    result = ParameterSpec(
        name          = name,
        normal_args   = [
            extractArg(arg)
            for arg in
            node.args.args
        ],
        kw_only_args  = [
            extractArg(arg)
            for arg in
            node.args.kwonlyargs
            ]
              if Utils.python_version >= 300 else
            [],
        list_star_arg = extractArg(node.args.vararg),
        dict_star_arg = extractArg(node.args.kwarg),
        default_count = len(node.args.defaults)
    )

    message = result.checkValid()

    if message is not None:
        SyntaxErrors.raiseSyntaxError(
            message,
            source_ref
        )

    return result
开发者ID:justus922,项目名称:Nuitka,代码行数:53,代码来源:ReformulationFunctionStatements.py

示例9: checkFutureImportsOnlyAtStart

# 需要导入模块: from nuitka.tree import SyntaxErrors [as 别名]
# 或者: from nuitka.tree.SyntaxErrors import raiseSyntaxError [as 别名]
def checkFutureImportsOnlyAtStart(body):
    # Check if a __future__ imports really were at the beginning of the file.
    for node in body:
        if node in _future_import_nodes:
            _future_import_nodes.remove(node)
        else:
            if _future_import_nodes:
                SyntaxErrors.raiseSyntaxError(
                    reason     = """\
from __future__ imports must occur at the beginning of the file""",
                    col_offset = 1
                      if python_version >= 300 or \
                      not Options.isFullCompat() else
                    None,
                    source_ref = _future_import_nodes[0].source_ref
                )
开发者ID:fluxer,项目名称:spm,代码行数:18,代码来源:ReformulationImportStatements.py

示例10: _checkInsideGenerator

# 需要导入模块: from nuitka.tree import SyntaxErrors [as 别名]
# 或者: from nuitka.tree.SyntaxErrors import raiseSyntaxError [as 别名]
def _checkInsideGenerator(provider, node, source_ref):
    if provider.isCompiledPythonModule():
        SyntaxErrors.raiseSyntaxError(
            "'yield' outside function",
            source_ref,
            None if python_version < 300 else node.col_offset
        )

    if provider.isExpressionCoroutineObjectBody():
        SyntaxErrors.raiseSyntaxError(
            "'%s' inside async function" % (
                "yield" if node.__class__ is ast.Yield else "yield from",
            ),
            source_ref,
            node.col_offset+3
        )

    assert provider.isExpressionGeneratorObjectBody(), provider
开发者ID:fluxer,项目名称:spm,代码行数:20,代码来源:ReformulationYieldExpressions.py

示例11: _readSourceCodeFromFilename2

# 需要导入模块: from nuitka.tree import SyntaxErrors [as 别名]
# 或者: from nuitka.tree.SyntaxErrors import raiseSyntaxError [as 别名]
def _readSourceCodeFromFilename2(source_filename):
    # Detect the encoding.
    with open(source_filename, "rU") as source_file:
        encoding = _detectEncoding2(source_file)

        source_code = source_file.read()

        # Try and detect SyntaxError from missing or wrong encodings.
        if type(source_code) is not unicode and encoding == "ascii":
            try:
                _source_code = source_code.decode(encoding)
            except UnicodeDecodeError as e:
                lines = source_code.split('\n')
                so_far = 0

                for count, line in enumerate(lines):
                    so_far += len(line) + 1

                    if so_far > e.args[2]:
                        break
                else:
                    # Cannot happen, decode error implies non-empty.
                    count = -1

                wrong_byte = re.search(
                    "byte 0x([a-f0-9]{2}) in position",
                    str(e)
                ).group(1)

                SyntaxErrors.raiseSyntaxError(
                    reason       = """\
Non-ASCII character '\\x%s' in file %s on line %d, but no encoding declared; \
see http://python.org/dev/peps/pep-0263/ for details""" % (
                        wrong_byte,
                        source_filename,
                        count+1,
                    ),
                    source_ref   = SourceCodeReferences.fromFilename(
                        source_filename
                    ).atLineNumber(count+1),
                    display_line = False
                )

    return source_code
开发者ID:601040605,项目名称:Nuitka,代码行数:46,代码来源:SourceReading.py

示例12: onEnterNode

# 需要导入模块: from nuitka.tree import SyntaxErrors [as 别名]
# 或者: from nuitka.tree.SyntaxErrors import raiseSyntaxError [as 别名]
    def onEnterNode(self, node):
        if python_version < 300 and node.isStatementDelVariable():
            variable = node.getTargetVariableRef().getVariable()

            if not variable.isModuleVariable() and \
               isSharedAmongScopes(variable):
                SyntaxErrors.raiseSyntaxError(
                    reason       = """\
can not delete variable '%s' referenced in nested scope""" % (
                       variable.getName()
                    ),
                    source_ref   = (
                        None if isFullCompat() else node.getSourceReference()
                    ),
                    display_file = not isFullCompat(),
                    display_line = not isFullCompat()
                )
        elif node.isStatementsFrame():
            node.updateLocalNames()
开发者ID:601040605,项目名称:Nuitka,代码行数:21,代码来源:VariableClosure.py

示例13: _attachVariable

# 需要导入模块: from nuitka.tree import SyntaxErrors [as 别名]
# 或者: from nuitka.tree.SyntaxErrors import raiseSyntaxError [as 别名]
    def _attachVariable(node, provider):
        # print "Late reference", node.getVariableName(), "for", provider, "caused at", node, "of", node.getParent()

        variable_name = node.getVariableName()

        was_taken = provider.hasTakenVariable(variable_name)

        variable = provider.getVariableForReference(
            variable_name = variable_name
        )

        node.setVariable(
            variable
        )

        # Need to catch functions with "exec" and closure variables not allowed.
        if python_version < 300 and \
           not was_taken and \
           provider.isExpressionFunctionBody() and \
           variable.getOwner() is not provider:
            parent_provider = provider.getParentVariableProvider()

            while parent_provider.isExpressionFunctionBody() and \
                  parent_provider.isClassDictCreation():
                parent_provider = parent_provider.getParentVariableProvider()

            if parent_provider.isExpressionFunctionBody() and \
               parent_provider.isUnqualifiedExec():
                SyntaxErrors.raiseSyntaxError(
                    reason       = PythonVersions.\
                                     getErrorMessageExecWithNestedFunction() % \
                                     parent_provider.getName(),
                    source_ref   = parent_provider.getExecSourceRef(),
                    col_offset   = None,
                    display_file = True,
                    display_line = True,
                    source_line  = None
                )
开发者ID:FireWalkerX,项目名称:Nuitka,代码行数:40,代码来源:VariableClosure.py

示例14: handleNonlocalDeclarationNode

# 需要导入模块: from nuitka.tree import SyntaxErrors [as 别名]
# 或者: from nuitka.tree.SyntaxErrors import raiseSyntaxError [as 别名]
def handleNonlocalDeclarationNode(provider, node, source_ref):
    # Need to catch the error of declaring a parameter variable as global
    # ourselves here. The AST parsing doesn't catch it, but we can do it here.
    parameters = provider.getParameters()

    for variable_name in node.names:
        if variable_name in parameters.getParameterNames():
            SyntaxErrors.raiseSyntaxError(
                reason       = "name '%s' is parameter and nonlocal" % (
                    variable_name
                ),
                source_ref   = None
                                 if Options.isFullCompat() and \
                                 Utils.python_version < 340 else
                               source_ref,
                display_file = not Options.isFullCompat() or \
                               Utils.python_version >= 340,
                display_line = not Options.isFullCompat() or \
                               Utils.python_version >= 340
            )

    provider.addNonlocalsDeclaration(node.names, source_ref)

    return None
开发者ID:Xzarh,项目名称:Nuitka,代码行数:26,代码来源:Building.py

示例15: buildStatementContinueLoop

# 需要导入模块: from nuitka.tree import SyntaxErrors [as 别名]
# 或者: from nuitka.tree.SyntaxErrors import raiseSyntaxError [as 别名]
def buildStatementContinueLoop(node, source_ref):
    # Python forbids this, although technically it's probably not much of
    # an issue.
    if getBuildContext() == "finally":
        if not Options.isFullCompat() or Utils.python_version >= 300:
            col_offset = node.col_offset - 9
        else:
            col_offset = None

        if Utils.python_version >= 300 and Options.isFullCompat():
            source_line = ""
        else:
            source_line = None

        SyntaxErrors.raiseSyntaxError(
            "'continue' not supported inside 'finally' clause",
            source_ref,
            col_offset  = col_offset,
            source_line = source_line
        )

    return StatementContinueLoop(
        source_ref = source_ref
    )
开发者ID:justus922,项目名称:Nuitka,代码行数:26,代码来源:Building.py


注:本文中的nuitka.tree.SyntaxErrors.raiseSyntaxError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。