plugin XEP-0420: fix exception on missing from or to:
fix exception raised on missing `from` or `to` attribute when the policy doesn't require them. Patch made by Syndace <me@syndace.dev>
This commit is contained in:
parent
1fd553db40
commit
a68564e68f
1 changed files with 8 additions and 8 deletions
|
|
@ -339,26 +339,26 @@ class XEP_0420: # pylint: disable=invalid-name
|
||||||
|
|
||||||
if profile.to_policy is not SCEAffixPolicy.NOT_NEEDED:
|
if profile.to_policy is not SCEAffixPolicy.NOT_NEEDED:
|
||||||
recipient = stanza.getAttribute("to", None)
|
recipient = stanza.getAttribute("to", None)
|
||||||
if recipient is None:
|
if recipient is not None:
|
||||||
|
to_element = envelope.addElement((NS_SCE, "to"))
|
||||||
|
to_element["jid"] = jid.JID(recipient).userhost()
|
||||||
|
elif profile.to_policy is SCEAffixPolicy.REQUIRED:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"<to/> affix requested, but stanza doesn't have the 'to' attribute"
|
"<to/> affix requested, but stanza doesn't have the 'to' attribute"
|
||||||
" set."
|
" set."
|
||||||
)
|
)
|
||||||
|
|
||||||
to_element = envelope.addElement((NS_SCE, "to"))
|
|
||||||
to_element["jid"] = jid.JID(recipient).userhost()
|
|
||||||
|
|
||||||
if profile.from_policy is not SCEAffixPolicy.NOT_NEEDED:
|
if profile.from_policy is not SCEAffixPolicy.NOT_NEEDED:
|
||||||
sender = stanza.getAttribute("from", None)
|
sender = stanza.getAttribute("from", None)
|
||||||
if sender is None:
|
if sender is not None:
|
||||||
|
from_element = envelope.addElement((NS_SCE, "from"))
|
||||||
|
from_element["jid"] = jid.JID(sender).userhost()
|
||||||
|
elif profile.from_policy is SCEAffixPolicy.REQUIRED:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"<from/> affix requested, but stanza doesn't have the 'from'"
|
"<from/> affix requested, but stanza doesn't have the 'from'"
|
||||||
" attribute set."
|
" attribute set."
|
||||||
)
|
)
|
||||||
|
|
||||||
from_element = envelope.addElement((NS_SCE, "from"))
|
|
||||||
from_element["jid"] = jid.JID(sender).userhost()
|
|
||||||
|
|
||||||
for affix, policy in profile.custom_policies.items():
|
for affix, policy in profile.custom_policies.items():
|
||||||
if policy is not SCEAffixPolicy.NOT_NEEDED:
|
if policy is not SCEAffixPolicy.NOT_NEEDED:
|
||||||
envelope.addChild(affix.create(stanza))
|
envelope.addChild(affix.create(stanza))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue