Skip to content

Python3 - HTML Text ausgeben

Python3
1 1 184
  •                 # Wir bauen den Text, den wir ausgeben wollen!
                    text = """
                    <table>
                    <tr>
                    <td style="padding: 4px;"><b>Backup_Name</b></td>
                    <td style="padding: 4px;">""" + backup_data[row].name + """ </td>
                    </tr>
                    <tr>
                        <td style="padding: 4px;"><b>Repository</b></td>
                        <td style="padding: 4px;">""" + backup_data[row].repository + """ </td>
                    </tr>
                    <tr>
                        <td style="padding: 4px;"><b>Source</b></td>
                        <td style="padding: 4px;">""" + backup_data[row].source + """ </td>
                    </tr>
                    <tr>
                        <td style="padding: 4px;"><b>Password</b></td>
                        <td style="padding: 4px;">""" + password_x +""" </td>
                    </tr>
                    <tr>
                        <td style="padding: 4px;"><b>Init_Status</b></td>
                        <td style="padding: 4px;">""" + backup_data[row].init + """ </td>
                    </tr>
                    <tr>
                        <td style="padding: 4px;"><b>Exclude List</b></td>
                        <td style="padding: 4px;">""" + backup_data[row].exclude + """ </td>
                    </tr>
                    </table>
                    """
    

    Und dasselbe als mehrzeilige Textausgabe für ein QPlainTextEdit

    text = """Backup_Name:\t %s\n
    Repository:\t\t %s\n\n Source:\t\t %s\n\n Password:\t\t %s\n\n Init_Status:\t\t %s\n\n Exclude List:\t\t %s"""%(backup_data[row].name, backup_data[row].repository, backup_data[row].source, password_x, backup_data[row].init, backup_data[row].exclude)
    
  • Python3 - pyqtSignal

    Python3 python3 restic-ui
    1
    0 Stimmen
    1 Beiträge
    136 Aufrufe
    Niemand hat geantwortet
  • Python - mehrsprachiges GUI

    Python3 python3
    1
    1
    0 Stimmen
    1 Beiträge
    235 Aufrufe
    Niemand hat geantwortet
  • Python3 - PyQt5 QIcon

    Python3 pyqt5 python3
    2
    2
    0 Stimmen
    2 Beiträge
    208 Aufrufe
    FrankMF
    Die Suchpfade findet man hiermit print(QIcon.themeSearchPaths()) Ausgabe ['/home/frank/.icons', '/usr/share/cinnamon/icons', '/var/lib/flatpak/exports/share/icons', '/usr/share/icons', ':/icons']
  • Restic UI - Changelog

    Angeheftet Restic UI restic-ui python3 pyqt5
    3
    0 Stimmen
    3 Beiträge
    401 Aufrufe
    FrankMF
    v1.5.0 - Release for restic v0.14.0 with compression and migration tool
  • Restic UI - Documentation

    Restic UI restic-ui python3 pyqt5
    1
    1
    0 Stimmen
    1 Beiträge
    372 Aufrufe
    Niemand hat geantwortet
  • Python3 - Global variable 'widget' undefined at the module level

    Python3 python3
    3
    0 Stimmen
    3 Beiträge
    481 Aufrufe
    FrankMF
    Kein globalen Variablen mehr im Projekt Das Widget ließ sich relativ einfach erledigen. Vorher #----QPlainTextEdit ----# layout = QVBoxLayout() widget = QTextEdit() widget.setReadOnly(True) widget.setLayout(layout) setCentralWidget(widget) Nachher #----QPlainTextEdit ----# layout = QVBoxLayout() self.widget = QTextEdit() self.widget.setReadOnly(True) self.widget.setLayout(layout) self.setCentralWidget(self.widget) Aufruf dann nicht mehr mit # UI widget.setHtml("") sondern mit # UI mainWin.widget.setHtml("") Problem erledeigt und hoffentlich auch verstanden
  • Python3 - subprocess.run

    Python3 python3
    2
    0 Stimmen
    2 Beiträge
    297 Aufrufe
    FrankMF
    Ich möchte das Thema noch mal ausgraben. Bin beim Recherchieren über diese Links gestolpert, die mein Interesse geweckt haben. https://security.openstack.org/guidelines/dg_avoid-shell-true.html https://bandit.readthedocs.io/en/latest/plugins/b603_subprocess_without_shell_equals_true.html Da ich aktuell nur eine Desktop Anwendung entwickle, ist das Thema Sicherheit nicht ganz so wichtig, weil wer hackt sich schon selber!? Aber, da man ja nie weiß, wie so ein Tool evt. mal benutzt wird, sollte man von Anfang an auf ein paar Dinge achten. Ok, schauen wir uns das mal genauer an. Link 1 - shell=True Ich kopiere mal das Beispiel aus dem Link. def count_lines(website): return subprocess.check_output('curl %s | wc -l' % website, shell=True) Ok, das Problem ist shell=True Ein Beispiel aus meinem Projekt result = subprocess.run(['restic', '-r', backup_data[row].repository, 'stats'], input=pass_word.pw[0], capture_output=True, text=True) Gesetzt wird der in meinem Beispiel nicht. Besuchen wir mal die Webseite vom subprocess.run https://docs.python.org/3/library/subprocess.html?highlight=subprocess run#subprocess.run Wenn ich das jetzt richtig verstehe, subprocess.run(args, *, stdin=None, input=None, stdout=None, stderr=None, capture_output=False, shell=False, cwd=None, timeout=None, check=False, encoding=None, errors=None, text=None, env=None, universal_newlines=None, **other_popen_kwargs) dann ist standardmäßig shell=False gesetzt. Damit ist das in meinem Projekt kein Problem. Link 2 - B603: subprocess_without_shell_equals_true Ein Tool auf gitlab.com wirft Security Warnings aus, dabei war diese. Schauen wir mal, was uns das sagen möchte. Python possesses many mechanisms to invoke an external executable. However, doing so may present a security issue if appropriate care is not taken to sanitize any user provided or variable input. Ok, es geht also um die Prüfung von Eingaben bzw. Variablen. Der Merksatz "Keine Benutzereingabe wird ungeprüft übernommen!" ist doch mit das Wichtigste, wenn man irgendwas programmiert. Nochmal mein Beispiel von oben. result = subprocess.run(['restic', '-r', backup_data[row].repository, 'stats'], input=pass_word.pw[0], capture_output=True, text=True) Ich übergebe dem Prozess einige Eingaben / Variablen. backup_data[row].repository pass_word.pw[0] Lesen wir wieder ein wenig in der Dokumentation von subprocess.run args is required for all calls and should be a string, or a sequence of program arguments. Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names). If passing a single string, either shell must be True (see below) or else the string must simply name the program to be executed without specifying any arguments. Das Wichtigste in Kürze Providing a sequence of arguments is generally preferred Der Aufruf von subprocess.run erwartet als erste Übergabe args subprocess.run(args, *, .... Mein Beispiel result = subprocess.run(['restic', '-r', backup_data[row].repository, 'stats'], .... Das zwischen den eckigen Klammern ist args. Laut der Anleitung ist es empfohlen, das als ein Argument zu übergeben, also so. Somit ist dafür gesorgt, das das Modul die Argumente selbst ein wenig "überwacht". as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names). Somit hätten man schon mal was für sie "Sicherheit" getan. args = ['restic', '-r', backup_data[row].repository, 'stats'] result = subprocess.run(args, .... Man sollte trotzdem auf diese beiden Variablen * backup_data[row].repository * pass_word.pw[0] ein Auge behalten. Ich denke, das habe ich in meinem Projekt eingehalten, indem ich Pfadangabe mit den Systemwerkzeugen auswählbar mache, keine Texteingaben! Passwörter und andere Bezeichnung werden mit regex auf korrekte Eingaben geprüft usw. Fazit Wieder viel gelernt und ich denke, es passt so weit alles. Bei der ganzen Spielerei, dann noch entdeckt, das ich im Code dieses Argument drin hatte. check=False Das ist aber Standard, somit kann das weg. Habe das im kompletten Projekt dann entfernt und mir fällt gerade auf, da der Code immer gleich ist, muss das jetzt eigentlich alles in eine Funktion Mal auf die ToDo-Liste drauf schreiben.
  • Python3 - zwei Webseiten als Empfehlung

    Python3 pyqt5 python3
    1
    0 Stimmen
    1 Beiträge
    207 Aufrufe
    Niemand hat geantwortet