Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"%s = NULL;" % exception_tb,
]
else:
set_exception = [
"%s = %s;" % (exception_type, exception),
"Py_INCREF( %s );" % exception_type,
"%s = Py%s_FromFormat( %s );"
% (
exception_value,
"String" if python_version < 300 else "Unicode",
", ".join('"%s"' % arg for arg in args),
),
"%s = NULL;" % exception_tb,
]
if python_version >= 300:
keeper_vars = context.getExceptionKeeperVariables()
if keeper_vars[0] is not None:
set_exception.append(
"ADD_EXCEPTION_CONTEXT( &%s, &%s );" % (keeper_vars[0], keeper_vars[1])
)
else:
set_exception.append(
"NORMALIZE_EXCEPTION( &%s, &%s, &%s );"
% (exception_type, exception_value, exception_tb)
)
set_exception.append("CHAIN_EXCEPTION( %s );" % exception_value)
emit(
template_error_format_string_exception
% {
def generateSpecialUnpackCode(to_name, expression, emit, context):
value_name = context.allocateTempName("unpack")
generateExpressionCode(
to_name=value_name, expression=expression.getValue(), emit=emit, context=context
)
count = expression.getCount()
with withObjectCodeTemporaryAssignment(
to_name, "unpack_value", expression, emit, context
) as result_name:
if python_version < 350:
emit("%s = UNPACK_NEXT( %s, %s );" % (result_name, value_name, count - 1))
else:
starred = expression.getStarred()
expected = expression.getExpected()
emit(
"%s = UNPACK_NEXT%s( %s, %s, %s );"
% (
result_name,
"_STARRED" if starred else "",
value_name,
count - 1,
expected,
)
)
import subprocess
process = subprocess.Popen(
args=["/sbin/ldconfig", "-p"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
stdout, _stderr = process.communicate()
dll_map = {}
for line in stdout.splitlines()[1:]:
assert line.count(b"=>") == 1, line
left, right = line.strip().split(b" => ")
assert b" (" in left, line
left = left[: left.rfind(b" (")]
if python_version >= 300:
left = left.decode(sys.getfilesystemencoding())
right = right.decode(sys.getfilesystemencoding())
if left not in dll_map:
dll_map[left] = right
return dll_map[dll_name]
def computeExpressionFloat(self, float_node, trace_collection):
shape = self.getTypeShape()
if shape.hasShapeSlotFloat() is False:
return makeRaiseTypeErrorExceptionReplacementFromTemplateAndValue(
"float() argument must be a string or a number"
if isFullCompat() and python_version < 300
else "float() argument must be a string or a number, not '%s'",
operation="long",
original_node=float_node,
value_node=self,
)
self.onContentEscapes(trace_collection)
# Any code could be run, note that.
trace_collection.onControlFlowEscape(self)
# Any exception may be raised.
trace_collection.onExceptionRaiseExit(BaseException)
return float_node, None, None
def buildSequenceCreationNode(provider, node, source_ref):
if python_version >= 300:
for element in node.elts:
if getKind(element) == "Starred":
if python_version < 350:
SyntaxErrors.raiseSyntaxError(
"can use starred expression only as assignment target",
source_ref.atColumnNumber(element.col_offset),
)
else:
return _buildSequenceUnpacking(
provider=provider, node=node, source_ref=source_ref
)
return makeSequenceCreationOrConstant(
sequence_kind=getKind(node).upper(),
elements=buildNodeList(provider, node.elts, source_ref),
source_ref=source_ref,
# Standard
ShapeUnknown: operation_result_unknown,
ShapeTypeLongDerived: operation_result_unknown,
ShapeTypeIntOrLongDerived: operation_result_unknown,
ShapeTypeStrDerived: operation_result_unknown,
ShapeTypeUnicodeDerived: operation_result_unknown,
ShapeTypeBytesDerived: operation_result_unknown,
# Int is sequence repeat
ShapeTypeInt: operation_result_unsupported_add,
ShapeTypeLong: operation_result_unsupported_add,
ShapeTypeIntOrLong: operation_result_unsupported_add,
ShapeTypeBool: operation_result_unsupported_add,
ShapeTypeFloat: operation_result_unsupported_add,
# Sequence repeat is not allowed
ShapeTypeStr: operation_result_bytearray_noescape
if python_version < 300
else operation_result_unsupported_add,
ShapeTypeBytes: operation_result_bytearray_noescape,
ShapeTypeBytearray: operation_result_bytearray_noescape,
ShapeTypeUnicode: operation_result_unsupported_add,
ShapeTypeTuple: operation_result_unsupported_add,
ShapeTypeList: operation_result_unsupported_add,
# Unsupported:
ShapeTypeSet: operation_result_unsupported_add,
ShapeTypeDict: operation_result_unsupported_add,
ShapeTypeNoneType: operation_result_unsupported_add,
}
)
sub_shapes_bytearray.update(
{
# Standard
if shebang is not None:
binary, _args = parseShebang(shebang)
if getOS() != "Windows":
try:
if os.path.samefile(sys.executable, binary):
return True
except OSError: # Might not exist
pass
basename = os.path.basename(binary)
# Not sure if we should do that.
if basename == "python":
result = python_version < 300
elif basename == "python3":
result = python_version > 300
elif basename == "python2":
result = python_version < 300
elif basename == "python2.7":
result = python_version < 300
elif basename == "python2.6":
result = python_version < 270
elif basename == "python3.2":
result = 330 > python_version >= 300
elif basename == "python3.3":
result = 340 > python_version >= 330
elif basename == "python3.4":
result = 350 > python_version >= 340
elif basename == "python3.5":
result = 360 > python_version >= 350
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Kay Hayen did some changes for Nuitka, and put everything he added under the same
# modified BSD license.
from nuitka.PythonVersions import python_version
# pylint: disable=E0611,W0141
try:
if python_version >= 360:
OrderedDict = dict
else:
from collections import OrderedDict
except ImportError:
from itertools import izip, imap
from copy import deepcopy
missing = object()
class OrderedDict(dict):
def __init__(self, *args, **kwargs):
dict.__init__(self)
self._keys = []
self.update(*args, **kwargs)
if code_object_key.co_new_locals:
co_flags.append("CO_NEWLOCALS")
if code_object_key.co_has_starlist:
co_flags.append("CO_VARARGS")
if code_object_key.co_has_stardict:
co_flags.append("CO_VARKEYWORDS")
if not code_object_key.has_closure:
co_flags.append("CO_NOFREE")
co_flags.extend(code_object_key.future_flags)
if python_version < 300:
code = "%s = MAKE_CODEOBJ( %s, %s, %d, %s, %d, %s );" % (
code_identifier,
filename_code,
context.getConstantCode(constant=code_object_key.co_name),
code_object_key.line_number,
context.getConstantCode(constant=code_object_key.co_varnames),
code_object_key.co_argcount,
" | ".join(co_flags) or "0",
)
elif python_version < 380:
code = "%s = MAKE_CODEOBJ( %s, %s, %d, %s, %d, %d, %s );" % (
code_identifier,
filename_code,
context.getConstantCode(constant=code_object_key.co_name),
code_object_key.line_number,
context.getConstantCode(constant=code_object_key.co_varnames),
if unassigned:
num_required = num_args - num_defaults
# Special case required arguments.
if num_required > 0 or improved:
if num_defaults == 0 and num_args != 1:
raise TooManyArguments(
TypeError(
"%s expected %d arguments, got %d"
% (func_name, num_args, num_total)
)
)
if num_required == 1:
arg_desc = "1 argument" if python_version < 350 else "one argument"
else:
arg_desc = "%d arguments" % num_required
raise TooManyArguments(
TypeError(
"%s() takes %s %s (%d given)"
% (
func_name,
"at least" if num_defaults > 0 else "exactly",
arg_desc,
num_total,
)
)
)
raise TooManyArguments(