示例#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
示例#2
0
 def runCode_(self, code):
     Python.shared.handleCrashesForCurrentThread()
     try:
         exec(str(code))
     except:
         error = traceback.format_exc()
         PyOutputHelper.printError(error, script=None)
         Python.shared.codeToRun = None
示例#3
0
def displayhook(value):
    if value is None:
        return

    json = dumps(get_variables_hierarchy(value))
    try:
        PyOutputHelper.printValue(
            repr(value) + "\n",
            value=json,
            script=threading.current_thread().script_path)
    except AttributeError:
        PyOutputHelper.printValue(repr(value) + "\n", value=json, script=None)
示例#4
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
示例#5
0
    script_path = None
    """
    The script that the thread is running.
    """


while True:

    try:
        code = str(Python.shared.codeToRun)
        exec(code)
        if code == Python.shared.codeToRun:
            Python.shared.codeToRun = None
    except:
        error = traceback.format_exc()
        PyOutputHelper.printError(error, script=None)
        Python.shared.codeToRun = None

    if Python.shared.scriptToRun != None:

        script = Python.shared.scriptToRun

        thread = ScriptThread(target=run_script,
                              args=(str(script.path), False, script.debug,
                                    script.breakpoints))
        thread.script_path = str(script.path)
        thread.start()

        Python.shared.scriptToRun = None

    sys.stdout.write("")