本文整理汇总了Python中nuitka.SyntaxErrors.raiseSyntaxError方法的典型用法代码示例。如果您正苦于以下问题:Python SyntaxErrors.raiseSyntaxError方法的具体用法?Python SyntaxErrors.raiseSyntaxError怎么用?Python SyntaxErrors.raiseSyntaxError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nuitka.SyntaxErrors
的用法示例。
在下文中一共展示了SyntaxErrors.raiseSyntaxError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buildReturnNode
# 需要导入模块: from nuitka import SyntaxErrors [as 别名]
# 或者: from nuitka.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 makeTryFinallyIndicator(
provider = provider,
statement = StatementReturn(
expression = expression,
source_ref = source_ref
),
is_loop_exit = False
)
示例2: buildReturnNode
# 需要导入模块: from nuitka import SyntaxErrors [as 别名]
# 或者: from nuitka.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
)
)
if node.value is not None:
return StatementReturn(
expression = buildNode( provider, node.value, source_ref ),
source_ref = source_ref
)
else:
return StatementReturn(
expression = ExpressionConstantRef(
constant = None,
source_ref = source_ref,
user_provided = True
),
source_ref = source_ref
)
示例3: handleNonlocalDeclarationNode
# 需要导入模块: from nuitka import SyntaxErrors [as 别名]
# 或者: from nuitka.SyntaxErrors import raiseSyntaxError [as 别名]
def handleNonlocalDeclarationNode(provider, node, source_ref):
# The source reference of the nonlocal really doesn't matter.
# pylint: disable=W0613
# 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
示例4: buildStatementContinueLoop
# 需要导入模块: from nuitka import SyntaxErrors [as 别名]
# 或者: from nuitka.SyntaxErrors import raiseSyntaxError [as 别名]
def buildStatementContinueLoop(provider, 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
)
return makeTryFinallyIndicator(
provider = provider,
statement = StatementContinueLoop(
source_ref = source_ref
),
is_loop_exit = True
)
示例5: buildParameterSpec
# 需要导入模块: from nuitka import SyntaxErrors [as 别名]
# 或者: from nuitka.SyntaxErrors import raiseSyntaxError [as 别名]
def buildParameterSpec( name, node, source_ref ):
kind = getKind( node )
assert kind in ( "FunctionDef", "Lambda" ), "unsupported for kind " + kind
def extractArg( arg ):
if getKind( arg ) == "Name":
return arg.id
elif getKind( arg ) == "arg":
return arg.arg
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 = node.args.vararg,
dict_star_arg = node.args.kwarg,
default_count = len( node.args.defaults )
)
message = result.checkValid()
if message is not None:
SyntaxErrors.raiseSyntaxError(
message,
source_ref
)
return result
示例6: _handleNonLocal
# 需要导入模块: from nuitka import SyntaxErrors [as 别名]
# 或者: from nuitka.SyntaxErrors import raiseSyntaxError [as 别名]
def _handleNonLocal(self, 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
)
node.registerProvidedVariable( variable )
if variable.isModuleVariableReference():
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
)
示例7: handleGlobalDeclarationNode
# 需要导入模块: from nuitka import SyntaxErrors [as 别名]
# 或者: from nuitka.SyntaxErrors import raiseSyntaxError [as 别名]
def handleGlobalDeclarationNode( provider, node, source_ref ):
if not source_ref.isExecReference():
# On the module level, there is nothing to do.
if provider.isPythonModule():
return None
# Need to catch the error of declaring a parameter variable as global ourselves
# here. The AST parsing doesn't catch it.
try:
parameters = provider.getParameters()
for variable_name in node.names:
if variable_name in parameters.getParameterNames():
SyntaxErrors.raiseSyntaxError(
reason = "name '%s' is %s and global" % (
variable_name,
"local" if Utils.python_version < 300 else "parameter"
),
source_ref = provider.getSourceReference()
)
except AttributeError:
pass
module = provider.getParentModule()
for variable_name in node.names:
closure_variable = None
# Re-use already taken global variables, in order to avoid creating yet
# another instance, esp. as the markups could then potentially not be
# shared.
if provider.hasTakenVariable( variable_name ):
closure_variable = provider.getTakenVariable( variable_name )
if not closure_variable.isModuleVariableReference():
closure_variable = None
if closure_variable is None:
module_variable = module.getVariableForAssignment(
variable_name = variable_name
)
closure_variable = provider.addClosureVariable(
variable = module_variable
)
assert closure_variable.isModuleVariableReference()
closure_variable.markFromGlobalStatement()
if source_ref.isExecReference():
closure_variable.markFromExecStatement()
provider.registerProvidedVariable(
variable = closure_variable
)
return None
示例8: _markAsGenerator
# 需要导入模块: from nuitka import SyntaxErrors [as 别名]
# 或者: from nuitka.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()
示例9: _readSourceCodeFromFilename3
# 需要导入模块: from nuitka import SyntaxErrors [as 别名]
# 或者: from nuitka.SyntaxErrors import raiseSyntaxError [as 别名]
def _readSourceCodeFromFilename3(source_filename):
with open(source_filename, "rb") as source_file:
source_code = source_file.read()
if source_code.startswith(b'\xef\xbb\xbf'):
source_code = source_code[3:]
new_line = source_code.find(b"\n")
if new_line is not -1:
line = source_code[: new_line]
line_match = re.search(b"coding[:=]\\s*([-\\w.]+)", line)
if line_match:
encoding = line_match.group(1).decode("ascii")
# Detect encoding problem, as decode won't raise the compatible
# thing.
try:
import codecs
codecs.lookup(encoding)
except LookupError:
if Utils.python_version >= 341 or \
(Utils.python_version >= 335 and \
Utils.python_version < 340) or \
(Utils.python_version >= 323 and \
Utils.python_version < 330):
reason = "encoding problem: %s" % encoding
else:
reason = "unknown encoding: %s" % encoding
SyntaxErrors.raiseSyntaxError(
reason = reason,
source_ref = SourceCodeReferences.fromFilename(
source_filename,
None
),
display_line = False
)
return source_code[ new_line : ].decode(encoding)
new_line = source_code.find(b"\n", new_line+1)
if new_line is not -1:
line = source_code[ : new_line ]
line_match = re.search(b"coding[:=]\\s*([-\\w.]+)", line)
if line_match:
encoding = line_match.group(1).decode("ascii")
return "\n" + source_code[ new_line : ].decode(encoding)
return source_code.decode("utf-8")
示例10: _readSourceCodeFromFilename2
# 需要导入模块: from nuitka import SyntaxErrors [as 别名]
# 或者: from nuitka.SyntaxErrors import raiseSyntaxError [as 别名]
def _readSourceCodeFromFilename2(source_filename):
# Detect the encoding.
encoding = _detectEncoding2(source_filename)
with open(source_filename, "rU") as 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,
None
).atLineNumber(count+1),
display_line = False
)
return source_code
示例11: onEnterNode
# 需要导入模块: from nuitka import SyntaxErrors [as 别名]
# 或者: from nuitka.SyntaxErrors import raiseSyntaxError [as 别名]
def onEnterNode(self, node):
assert python_version < 300
if node.isStatementDelVariable():
variable = node.getTargetVariableRef().getVariable()
if variable.isSharedLogically():
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()
)
示例12: _readSourceCodeFromFilename3
# 需要导入模块: from nuitka import SyntaxErrors [as 别名]
# 或者: from nuitka.SyntaxErrors import raiseSyntaxError [as 别名]
def _readSourceCodeFromFilename3( source_filename ):
source_code = open( source_filename, "rb" ).read()
if source_code.startswith( b'\xef\xbb\xbf' ):
return source_code[3:]
new_line = source_code.find( b"\n" )
if new_line is not -1:
line = source_code[ : new_line ]
line_match = re.search( b"coding[:=]\s*([-\w.]+)", line )
if line_match:
encoding = line_match.group(1).decode( "ascii" )
# Detect encoding problem, as decode won't raise the compatible thing.
try:
import codecs
codecs.lookup( encoding )
except LookupError:
SyntaxErrors.raiseSyntaxError(
reason = "unknown encoding: %s" % encoding,
source_ref = SourceCodeReferences.fromFilename( source_filename, None ),
display_line = False
)
return source_code[ new_line + 1 : ].decode( encoding )
new_line = source_code.find( b"\n", new_line+1 )
if new_line is not -1:
line = source_code[ : new_line ]
line_match = re.search( b"coding[:=]\s*([-\w.]+)", line )
if line_match:
encoding = line_match.group(1).decode( "ascii" )
return source_code[ new_line + 1 : ].decode( encoding )
return source_code.decode( "utf-8" )
示例13: handleGlobalDeclarationNode
# 需要导入模块: from nuitka import SyntaxErrors [as 别名]
# 或者: from nuitka.SyntaxErrors import raiseSyntaxError [as 别名]
def handleGlobalDeclarationNode( provider, node, source_ref ):
# The source reference of the global really doesn't matter, pylint: disable=W0613
# On the module level, there is nothing to do.
if provider.isPythonModule():
return None
# Need to catch the error of declaring a parameter variable as global ourselves
# here. The AST parsing doesn't catch it.
try:
parameters = provider.getParameters()
for variable_name in node.names:
if variable_name in parameters.getParameterNames():
SyntaxErrors.raiseSyntaxError(
reason = "name '%s' is %s and global" % (
variable_name,
"local" if Utils.python_version < 300 else "parameter"
),
source_ref = provider.getSourceReference()
)
except AttributeError:
pass
module = provider.getParentModule()
for variable_name in node.names:
module_variable = module.getVariableForAssignment(
variable_name = variable_name
)
closure_variable = provider.addClosureVariable(
variable = module_variable,
global_statement = True
)
provider.registerProvidedVariable(
variable = closure_variable
)
return None
示例14: _attachVariable
# 需要导入模块: from nuitka import SyntaxErrors [as 别名]
# 或者: from nuitka.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
)
示例15: buildYieldNode
# 需要导入模块: from nuitka import SyntaxErrors [as 别名]
# 或者: from nuitka.SyntaxErrors import raiseSyntaxError [as 别名]
def buildYieldNode( 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()
if node.value is not None:
return ExpressionYield(
expression = buildNode( provider, node.value, source_ref ),
source_ref = source_ref
)
else:
return ExpressionYield(
expression = ExpressionConstantRef(
constant = None,
source_ref = source_ref
),
source_ref = source_ref
)