def check_python(filename):
    filename = os.path.abspath(os.path.expanduser(filename))
    path = os.path.dirname(filename)
    # Allow files from global autoload folder by default. 
    # XXX Good idea?
    if path == os.path.join(Scripter.path, "autoload"):
        return True
    code = open(filename).read()
    h = hash_source(filename, code)
    if runtime_config.has_option("permissions", h):
        return runtime_config.getbool("permissions", h)

    problems = checkCode(code)
    if problems and len(problems) == 1 and isinstance(problems[0], SyntaxError):
        return True # let's ignore it and let excepthook hande the error later
    elif problems:
        ok = permitdlg.ask(filename, problems)
        if ok == -2: # deny and remember
            runtime_config.set("permissions", h, False)
            return False
        elif ok == 2: # deny
            return False
        elif ok == -1: # allow and remember
            runtime_config.set("permissions", h, True)
        elif ok == 1: # allow but now remember
            pass
        else:
            raise ValueError, "Inknown return code for permission dialog: %r" % ok
    return True
Пример #2
0
            self.done(1)

    @pyqtSignature("")
    def on_denyButton_clicked(self):
        if self.ui.rememberCheck.isChecked():
            self.done(-2)
        else:
            self.done(2)

    @pyqtSignature("")
    def on_detailsButton_clicked(self):
        self.ui.problemsBrowser.setVisible(self.ui.detailsButton.isChecked())
        self.resize(self.width(), self.sizeHint().height())


def ask(filename, problems):
    """
    Use this fuction
    """
    return PermitDialog(filename, problems).exec_()


if __name__ == "__main__":
    # Demo:
    import sys
    import safe_eval

    problems = safe_eval.checkCode(open("permitdlg.py").read())
    app = QApplication(sys.argv)
    print ask("permitdlg.py", problems)
    @pyqtSlot()
    def on_denyButton_clicked(self):
        if self.ui.rememberCheck.isChecked():
            self.done(-2)
        else:
            self.done(2)


    @pyqtSlot()
    def on_detailsButton_clicked(self):
        self.ui.problemsBrowser.setVisible(self.ui.detailsButton.isChecked())
        self.resize(self.width(), self.sizeHint().height())



def ask(filename, problems):
    """
    Use this fuction
    """
    return PermitDialog(filename, problems).exec_()



if __name__ == "__main__":
    # Demo:
    import sys
    import safe_eval
    problems = safe_eval.checkCode(open("permitdlg.py").read())
    app = QApplication(sys.argv)
    print(ask("permitdlg.py", problems))