Exemplo n.º 1
0
    def _resolveImportLibArgs(module_name, package_name):
        # Relative imports need to be resolved by package name.
        if module_name.startswith("."):
            if not package_name:
                return None

                # TODO: Static exception should be created and warned about, Python2/Python3 differ
                # raise TypeError("relative imports require the 'package' argument")
                # msg = ("the 'package' argument is required to perform a relative import for {!r}")
                # raise TypeError(msg.format(name))

            level = 0
            for character in module_name:
                if character != ".":
                    break
                level += 1
            module_name = module_name[level:]

            dot = len(package_name)
            for _i in xrange(level, 1, -1):
                try:
                    dot = package_name.rindex(".", 0, dot)
                except ValueError:
                    return None
                    # TODO: Static exception should be created and warned about.
                    # raise ValueError("attempted relative import beyond top-level package")
            return "%s.%s" % (package_name[:dot], module_name)

        if package_name:
            return "%s.%s" % (package_name, module_name)
        else:
            return module_name
Exemplo n.º 2
0
Arquivo: PGO.py Projeto: psydox/Nuitka
def readPGOInputFile(input_filename):
    """Read PGO information produced by a PGO run."""

    # Using global here, as this is really a singleton, in the form of a module,
    # pylint: disable=global-statement
    global _pgo_strings, _pgo_active

    with open(input_filename, "rb") as input_file:
        header = input_file.read(7)

        if header != b"KAY.PGO":
            pgo_logger.sysexit(
                "Error, file '%s' is not a valid PGO input for this version of Nuitka."
                % input_filename)

        input_file.seek(-7, os.SEEK_END)
        header = input_file.read(7)

        if header != b"YAK.PGO":
            pgo_logger.sysexit(
                "Error, file '%s' was not completed correctly." %
                input_filename)

        input_file.seek(-8 - 7, os.SEEK_END)
        count, offset = struct.unpack("ii", input_file.read(8))

        input_file.seek(offset, os.SEEK_SET)

        _pgo_strings = [None] * count

        for i in xrange(count):
            _pgo_strings[i] = _readCString(input_file)

        input_file.seek(7, os.SEEK_SET)

        while True:
            # Which probe is it.
            probe_name = _readStringValue(input_file)

            if probe_name == "ModuleEnter":
                module_name = _readStringValue(input_file)
                arg = _readCIntValue(input_file)

                _module_entries[module_name] = arg
            elif probe_name == "ModuleExit":
                module_name = _readStringValue(input_file)
                had_error = _readCIntValue(input_file) != 0

                _module_exits[module_name] = had_error
            elif probe_name == "END":
                break
            else:
                pgo_logger.sysexit("Error, unknown problem '%s' encountered." %
                                   probe_name)

    _pgo_active = True
Exemplo n.º 3
0
 def __init__(self, low_value, high_value, step_value, source_ref):
     RangeIterationHandleBase.__init__(
         self, low_value, xrange(low_value, high_value, step_value), source_ref
     )
     self.high = high_value
     self.step = step_value
Exemplo n.º 4
0
 def __init__(self, low_value, source_ref):
     RangeIterationHandleBase.__init__(
         self, low_value, xrange(low_value), source_ref
     )
Exemplo n.º 5
0
    def __init__(self, low_value, high_value, source_ref):
        ConstantRangeIterationHandleBase.__init__(
            self, low_value, xrange(low_value, high_value), source_ref)

        self.high = high_value