Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_uses_compat_mixin(self):
self.assertTrue(
issubclass(
structs.ErrorType,
structs.CompatibilityMixin,
)
import aioxmpp
import aioxmpp.forms
import aioxmpp.disco.xso as disco_xso
import aioxmpp.pep as pep
import aioxmpp.pep.service as pep_service
import aioxmpp.pubsub.xso as pubsub_xso
from aioxmpp.testutils import (
make_connected_client,
CoroutineMock,
run_coroutine,
)
TEST_FROM = aioxmpp.structs.JID.fromstr("foo@bar.example/baz")
TEST_JID1 = aioxmpp.structs.JID.fromstr("bar@bar.example/baz")
class TestPEPClient(unittest.TestCase):
def setUp(self):
self.cc = make_connected_client()
self.cc.local_jid = TEST_FROM
self.disco_client = aioxmpp.DiscoClient(self.cc)
self.disco_server = aioxmpp.DiscoServer(self.cc)
self.pubsub = aioxmpp.PubSubClient(self.cc, dependencies={
aioxmpp.DiscoClient: self.disco_client
})
self.s = pep.PEPClient(self.cc, dependencies={
def test_hash_case_insensitively(self):
tag1 = structs.LanguageTag.fromstr("de-DE")
tag2 = structs.LanguageTag.fromstr("de-de")
self.assertEqual(hash(tag1), hash(tag2))
def test_is_error(self):
for member in structs.MessageType:
self.assertEqual(
member == structs.MessageType.ERROR,
member.is_error,
)
the publish options attempt to assert a restrictive access model).
Return the ID of the item as published (or :data:`None` if the server
does not inform us; this is unfortunately common).
"""
publish = pubsub_xso.Publish()
publish.node = node
if payload is not None:
item = pubsub_xso.Item()
item.id_ = id_
item.registered_payload = payload
publish.item = item
iq = aioxmpp.stanza.IQ(to=jid, type_=aioxmpp.structs.IQType.SET)
iq.payload = pubsub_xso.Request(
publish
)
if publish_options is not None:
features = yield from self.get_features(jid)
if pubsub_xso.Feature.PUBLISH_OPTIONS not in features:
raise RuntimeError(
"publish-options given, but not supported by server"
)
iq.payload.publish_options = pubsub_xso.PublishOptions()
iq.payload.publish_options.data = publish_options
response = yield from self.client.send(iq)
def _on_unsubscribe(self, stanza):
""" """
if self.approve_all:
self.client.stream.enqueue(
aioxmpp.Presence(
type_=aioxmpp.structs.PresenceType.UNSUBSCRIBED,
to=stanza.from_.bare(),
)
)
else:
self.on_unsubscribe(str(stanza.from_))
def handle_presence(self, st):
if st.from_ is None:
if st.type_ != aioxmpp.structs.PresenceType.ERROR:
self.logger.debug(
"dropping unhandled presence from account"
)
return
bare = st.from_.bare()
resource = st.from_.resource
if st.type_ == aioxmpp.structs.PresenceType.UNAVAILABLE:
try:
dest_dict = self._presences[bare]
except KeyError:
return
dest_dict.pop(None, None)
if resource in dest_dict:
self.on_unavailable(st.from_, st)
def __init__(self, *,
type_=structs.PresenceType.AVAILABLE,
show=structs.PresenceShow.NONE, **kwargs):
super().__init__(**kwargs)
self.type_ = type_
self.show = show
aioxmpp.structs.IQType.GET,
disco_xso.InfoQuery)
@asyncio.coroutine
def handle_info_request(self, iq):
request = iq.payload
try:
node = self._node_mounts[request.node]
except KeyError:
raise errors.XMPPModifyError(
condition=(namespaces.stanzas, "item-not-found")
)
response = node.as_info_xso(iq)
response.node = request.node
if not response.identities:
def handle_outbound_presence(self, presence):
if (presence.type_ == aioxmpp.structs.PresenceType.AVAILABLE
and self.__active_hashsets):
current_hashset = self.__active_hashsets[-1]
try:
keys = current_hashset[self.__115]
except KeyError:
pass
else:
self.__115.put_keys(keys, presence)
try:
keys = current_hashset[self.__390]
except KeyError:
pass
else:
self.__390.put_keys(keys, presence)