<commit_before>import asyncio
import aiohttp
import logging
from duniterpy.api import errors
from duniterpy.api import bma
from duniterpy.documents import MalformedDocumentError
from duniterpy.documents.certification import Revocation
from sakia.core.net import Node
from PyQt5.QtWidgets import QDialog, QFileDialog, QMessageBox
from PyQt5.QtCore import QObject

from .widgets.dialogs import QAsyncMessageBox
from ..tools.decorators import asyncify
from ..gen_resources.revocation_uic import Ui_RevocationDialog


class RevocationDialog(QObject):
    """
    A dialog to revoke an identity
    """

    def __init__(self, app, account, widget, ui):
        """
        Constructor if a certification dialog

        :param sakia.core.Application app:
        :param sakia.core.Account account:
        :param PyQt5.QtWidgets widget: the widget of the dialog
        :param sakia.gen_resources.revocation_uic.Ui_RevocationDialog ui: the view of the certification dialog
        :return:
        """
        super().__init__()
        self.widget = widget
        self.ui = ui
        self.ui.setupUi(self.widget)
        self.app = app
        self.account = account
        self.revocation_document = None
        self.revoked_selfcert = None
        self._steps = (
            {
                'page': self.ui.page_load_file,
                'init': self.init_dialog,
                'next': self.revocation_selected
            },
            {
                'page': self.ui.page_destination,
                'init': self.init_publication_page,
                'next': self.publish
            }
        )
        self._current_step = 0
        self.handle_next_step(init=True)
        self.ui.button_next.clicked.connect(lambda checked: self.handle_next_step(False))

    def handle_next_step(self, init=False):
        if self._current_step < len(self._steps) - 1:
            if not init:
                self.ui.button_next.clicked.disconnect(self._steps[self._current_step]['next'])
                self._current_step += 1
            self._steps[self._current_step]['init']()
            self.ui.stackedWidget.setCurrentWidget(self._steps[self._current_step]['page'])
            self.ui.button_next.clicked.connect(self._steps[self._current_step]['next'])

    def init_dialog(self):
        self.ui.button_next.setEnabled(False)
        self.ui.button_load.clicked.connect(self.load_from_file)

        self.ui.radio_address.toggled.connect(lambda c: self.publication_mode_changed("address"))
        self.ui.radio_community.toggled.connect(lambda c: self.publication_mode_changed("community"))
        self.ui.edit_address.textChanged.connect(self.refresh)
        self.ui.spinbox_port.valueChanged.connect(self.refresh)
        self.ui.combo_community.currentIndexChanged.connect(self.refresh)

    def publication_mode_changed(self, radio):
        self.ui.edit_address.setEnabled(radio == "address")
        self.ui.spinbox_port.setEnabled(radio == "address")
        self.ui.combo_community.setEnabled(radio == "community")
        self.refresh()

    def load_from_file(self):
        selected_files = QFileDialog.getOpenFileName(self.widget,
                                          self.tr("Load a revocation file"),
                                          "",
                                          self.tr("All text files (*.txt)"))
        selected_file = selected_files[0]
        try:<commit_msg>[fix] #489: bug when no revocation file are choosen.<commit_after>import asyncio
import aiohttp
import logging
from duniterpy.api import errors
from duniterpy.api import bma
from duniterpy.documents import MalformedDocumentError
from duniterpy.documents.certification import Revocation
from sakia.core.net import Node
from PyQt5.QtWidgets import QDialog, QFileDialog, QMessageBox
from PyQt5.QtCore import QObject

from .widgets.dialogs import QAsyncMessageBox
from ..tools.decorators import asyncify
from ..gen_resources.revocation_uic import Ui_RevocationDialog


class RevocationDialog(QObject):
    """
    A dialog to revoke an identity
    """

    def __init__(self, app, account, widget, ui):
        """
        Constructor if a certification dialog

        :param sakia.core.Application app:
        :param sakia.core.Account account:
        :param PyQt5.QtWidgets widget: the widget of the dialog
        :param sakia.gen_resources.revocation_uic.Ui_RevocationDialog ui: the view of the certification dialog
        :return:
        """
        super().__init__()
        self.widget = widget
        self.ui = ui
        self.ui.setupUi(self.widget)
        self.app = app
        self.account = account
        self.revocation_document = None
        self.revoked_selfcert = None
        self._steps = (
            {
                'page': self.ui.page_load_file,
                'init': self.init_dialog,
                'next': self.revocation_selected
            },
            {
                'page': self.ui.page_destination,
                'init': self.init_publication_page,
                'next': self.publish
            }
        )
        self._current_step = 0
        self.handle_next_step(init=True)
        self.ui.button_next.clicked.connect(lambda checked: self.handle_next_step(False))

    def handle_next_step(self, init=False):
        if self._current_step < len(self._steps) - 1:
            if not init:
                self.ui.button_next.clicked.disconnect(self._steps[self._current_step]['next'])
                self._current_step += 1
            self._steps[self._current_step]['init']()
            self.ui.stackedWidget.setCurrentWidget(self._steps[self._current_step]['page'])
            self.ui.button_next.clicked.connect(self._steps[self._current_step]['next'])

    def init_dialog(self):
        self.ui.button_next.setEnabled(False)
        self.ui.button_load.clicked.connect(self.load_from_file)

        self.ui.radio_address.toggled.connect(lambda c: self.publication_mode_changed("address"))
        self.ui.radio_community.toggled.connect(lambda c: self.publication_mode_changed("community"))
        self.ui.edit_address.textChanged.connect(self.refresh)
        self.ui.spinbox_port.valueChanged.connect(self.refresh)
        self.ui.combo_community.currentIndexChanged.connect(self.refresh)

    def publication_mode_changed(self, radio):
        self.ui.edit_address.setEnabled(radio == "address")
        self.ui.spinbox_port.setEnabled(radio == "address")
        self.ui.combo_community.setEnabled(radio == "community")
        self.refresh()

    def load_from_file(self):
        selected_files = QFileDialog.getOpenFileName(self.widget,
                                          self.tr("Load a revocation file"),
                                          "",
                                          self.tr("All text files (*.txt)"))
        selected_file = selected_files[0]
        if (selected_file == ''):
            return;
        try:
{'fraction_non_alphanumeric': 0.09710832973672853, 'fraction_numerical': 0.0024456912674435333, 'mean_word_length': 2.3961895456766, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7630856', 'n_tokens_mistral': 1993, 'n_tokens_neox': 1924, 'n_words': 366}