plugin XEP-0050: use Enums and add type hints:
- Replaces namedtuple with enums which are more appropriate here. - Add docstrings and type hints to `AdHocCommand` rel 465
This commit is contained in:
parent
a37101adc7
commit
a32b8bf9e8
1 changed files with 241 additions and 157 deletions
|
|
@ -16,6 +16,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from typing import cast
|
||||
from twisted.words.protocols.jabber import jid
|
||||
from twisted.words.xish import domish
|
||||
from wokkel import data_form
|
||||
|
|
@ -24,6 +25,7 @@ from libervia.backend.core.constants import Const as C
|
|||
from libervia.backend.core.core_types import SatXMPPEntity
|
||||
from libervia.backend.core.i18n import _
|
||||
from libervia.backend.core.log import getLogger
|
||||
from libervia.backend.plugins.plugin_xep_0050 import XEP_0050, Note, Status
|
||||
|
||||
|
||||
log = getLogger(__name__)
|
||||
|
|
@ -36,7 +38,7 @@ class APAdHocService:
|
|||
def __init__(self, apg):
|
||||
self.host = apg.host
|
||||
self.apg = apg
|
||||
self._c = self.host.plugins["XEP-0050"]
|
||||
self._c = cast(XEP_0050, self.host.plugins["XEP-0050"])
|
||||
|
||||
def init(self, client: SatXMPPEntity) -> None:
|
||||
self._c.add_ad_hoc_command(
|
||||
|
|
@ -62,7 +64,7 @@ class APAdHocService:
|
|||
command_form = None
|
||||
if command_form is None or len(command_form.fields) == 0:
|
||||
# root request
|
||||
status = self._c.STATUS.EXECUTING
|
||||
status = Status.EXECUTING
|
||||
form = data_form.Form(
|
||||
"form",
|
||||
title="XMPP JID/node to AP actor conversion",
|
||||
|
|
@ -81,7 +83,7 @@ class APAdHocService:
|
|||
xmpp_jid = jid.JID(command_form["jid"])
|
||||
xmpp_node = command_form.get("node")
|
||||
actor = await self.apg.get_ap_account_from_jid_and_node(xmpp_jid, xmpp_node)
|
||||
note = (self._c.NOTE.INFO, actor)
|
||||
status = self._c.STATUS.COMPLETED
|
||||
note = (Note.INFO, actor)
|
||||
status = Status.COMPLETED
|
||||
payload = None
|
||||
return (payload, status, None, note)
|
||||
|
|
|
|||
Loading…
Reference in a new issue