Reformatted code base using black.
This commit is contained in:
parent
56319cbad3
commit
53fdaa9d09
1 changed files with 12604 additions and 8966 deletions
|
|
@ -46,11 +46,15 @@ PLUGIN_INFO = {
|
|||
C.PI_DEPENDENCIES: ["XEP-0334"],
|
||||
C.PI_MAIN: "XEP_0372",
|
||||
C.PI_HANDLER: "yes",
|
||||
C.PI_DESCRIPTION: _(dedent("""\
|
||||
C.PI_DESCRIPTION: _(
|
||||
dedent(
|
||||
"""\
|
||||
XEP-0372 (References) implementation
|
||||
|
||||
This plugin implement generic references and mentions.
|
||||
""")),
|
||||
"""
|
||||
)
|
||||
),
|
||||
}
|
||||
|
||||
NS_REFS = "urn:xmpp:reference:0"
|
||||
|
|
@ -79,12 +83,11 @@ class XEP_0372:
|
|||
return XEP_0372_Handler()
|
||||
|
||||
def ref_element_to_ref_data(
|
||||
self,
|
||||
reference_elt: domish.Element
|
||||
self, reference_elt: domish.Element
|
||||
) -> Dict[str, Union[str, int, dict]]:
|
||||
ref_data: Dict[str, Union[str, int, dict]] = {
|
||||
"uri": reference_elt["uri"],
|
||||
"type": reference_elt["type"]
|
||||
"type": reference_elt["type"],
|
||||
}
|
||||
|
||||
if ref_data["uri"].startswith("xmpp:"):
|
||||
|
|
@ -107,7 +110,7 @@ class XEP_0372:
|
|||
self,
|
||||
client: SatXMPPEntity,
|
||||
message_elt: domish.Element,
|
||||
post_treat: defer.Deferred
|
||||
post_treat: defer.Deferred,
|
||||
) -> bool:
|
||||
"""Check if a direct invitation is in the message, and handle it"""
|
||||
reference_elt = next(message_elt.elements(NS_REFS, "reference"), None)
|
||||
|
|
@ -137,8 +140,7 @@ class XEP_0372:
|
|||
if type_ not in ALLOWED_TYPES:
|
||||
raise ValueError(f"Unknown type: {type_!r}")
|
||||
reference_elt = domish.Element(
|
||||
(NS_REFS, "reference"),
|
||||
attribs={"uri": uri, "type": type_}
|
||||
(NS_REFS, "reference"), attribs={"uri": uri, "type": type_}
|
||||
)
|
||||
if begin is not None:
|
||||
reference_elt["begin"] = str(begin)
|
||||
|
|
@ -149,22 +151,13 @@ class XEP_0372:
|
|||
return reference_elt
|
||||
|
||||
def _send_reference(
|
||||
self,
|
||||
recipient: str,
|
||||
anchor: str,
|
||||
type_: str,
|
||||
extra_s: str,
|
||||
profile_key: str
|
||||
self, recipient: str, anchor: str, type_: str, extra_s: str, profile_key: str
|
||||
) -> defer.Deferred:
|
||||
recipient_jid = jid.JID(recipient)
|
||||
client = self.host.get_client(profile_key)
|
||||
extra: dict = data_format.deserialise(extra_s, default={})
|
||||
self.send_reference(
|
||||
client,
|
||||
uri=extra.get("uri"),
|
||||
type_=type_,
|
||||
anchor=anchor,
|
||||
to_jid=recipient_jid
|
||||
client, uri=extra.get("uri"), type_=type_, anchor=anchor, to_jid=recipient_jid
|
||||
)
|
||||
|
||||
def send_reference(
|
||||
|
|
@ -176,7 +169,7 @@ class XEP_0372:
|
|||
end: Optional[int] = None,
|
||||
anchor: Optional[str] = None,
|
||||
message_elt: Optional[domish.Element] = None,
|
||||
to_jid: Optional[jid.JID] = None
|
||||
to_jid: Optional[jid.JID] = None,
|
||||
) -> None:
|
||||
"""Build and send a reference_elt
|
||||
|
||||
|
|
@ -197,9 +190,7 @@ class XEP_0372:
|
|||
"""
|
||||
if uri is None:
|
||||
if to_jid is None:
|
||||
raise exceptions.InternalError(
|
||||
'"to_jid" must be set if "uri is None"'
|
||||
)
|
||||
raise exceptions.InternalError('"to_jid" must be set if "uri is None"')
|
||||
uri = xmpp_uri.build_xmpp_uri(path=to_jid.full())
|
||||
if message_elt is None:
|
||||
message_elt = domish.Element((None, "message"))
|
||||
|
|
@ -212,7 +203,7 @@ class XEP_0372:
|
|||
except (KeyError, RuntimeError):
|
||||
raise exceptions.InternalError(
|
||||
'invalid "to" attribute in given message element: '
|
||||
'{message_elt.toXml()}'
|
||||
"{message_elt.toXml()}"
|
||||
)
|
||||
|
||||
message_elt.addChild(self.build_ref_element(uri, type_, begin, end, anchor))
|
||||
|
|
|
|||
Loading…
Reference in a new issue