Ejemplo n.º 1
0
    def create_module(self, spec):
        fullname = self.fullname
        mod = sys.modules.get(fullname)
        if mod is None:
            with warnings.catch_warnings(record=True) as w:
                try:
                    mod = _extensionsimporter.module_from_binary(
                        fullname, spec)
                except ImportError:
                    try:
                        price = str(Python.shared.environment["UPGRADE_PRICE"])
                    except KeyError:
                        price = "5.99$"

                    try:
                        script_path = threading.current_thread().script_path
                    except AttributeError:
                        script_path = None

                    PyOutputHelper.printLink(
                        f"Upgrade to import C extensions {price}\n",
                        url="pyto://upgrade",
                        script=script_path,
                    )

                    raise __UpgradeException__()

                mod.__repr__ = self.mod_repr
                mod = Extension(mod)
                sys.modules[fullname] = mod
            return mod

        mod.__repr__ = self.mod_repr
        return mod
Ejemplo n.º 2
0
        def load_module(self, fullname):
            self.__is_importing__ = True

            try:
                mod = importlib.__import__(fullname)
                self.__is_importing__ = False
                return mod
            except ModuleNotFoundError:

                if not have_internet():
                    msg = f"The internet connection seems to be offline and the imported library {fullname.split('.')[0].lower()} is not downloaded. Make sure you are connected to internet. Once downloaded, the library will be available offline."
                    raise ImportError(msg)

                paths = Python.shared.access(fullname.split(".")[0].lower())
                for path in paths:
                    if str(path) == "error":
                        self.__is_importing__ = False

                        if len(paths) == 3 and str(paths[2]) == "upgrade":
                            import threading
                            from pyto import PyOutputHelper

                            try:
                                price = str(
                                    Python.shared.environment["UPGRADE_PRICE"])
                            except KeyError:
                                price = "5.99$"

                            try:
                                script_path = threading.current_thread(
                                ).script_path
                            except AttributeError:
                                script_path = None

                            PyOutputHelper.printLink(
                                f"Upgrade {price}\n",
                                url="pyto://upgrade",
                                script=script_path,
                            )

                            raise __UpgradeException__(str(paths[1]))

                        raise ImportError(str(paths[1]))
                    if not str(path) in sys.path:
                        sys.path.insert(0, str(path))

                try:
                    return importlib.__import__(fullname)
                finally:
                    self.__is_importing__ = False

            self.__is_importing__ = False