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_fromstr_print_str(self):
tag = structs.LanguageTag.fromstr("de-Latn-DE-1999")
self.assertEqual(
"de-Latn-DE-1999",
tag.print_str
)
def test_keys(self):
key1 = structs.LanguageTag.fromstr("de-DE")
key2 = structs.LanguageTag.fromstr("en-US")
key3 = structs.LanguageTag.fromstr("en")
mapping = structs.LanguageMap()
mapping[key1] = 10
mapping[key2] = 20
mapping[key3] = 30
self.assertSetEqual(
{key1, key2, key3},
set(mapping.keys())
)
def test_unregister_identity_prohibits_removal_of_last_identity(self):
n = disco_service.Node()
cb = unittest.mock.Mock()
n.on_info_changed.connect(cb)
n.register_identity(
"client", "pc",
names={
structs.LanguageTag.fromstr("en"): "test identity",
structs.LanguageTag.fromstr("de"): "Testidentität",
}
)
cb = unittest.mock.Mock()
n.on_info_changed.connect(cb)
with self.assertRaisesRegex(ValueError,
"cannot remove last identity"):
n.unregister_identity(
"client", "pc",
)
self.assertFalse(cb.mock_calls)
def test_filter_by_language(self):
self.a_s[0].lang = structs.LanguageTag.fromstr("en-GB")
self.a_s[1].lang = structs.LanguageTag.fromstr("en-gb")
self.a_s[2].lang = structs.LanguageTag.fromstr("de-DE")
self.b_s[0].lang = structs.LanguageTag.fromstr("fr")
self.b_s[1].lang = structs.LanguageTag.fromstr("en")
self.assertSequenceEqual(
[self.a_s[0], self.a_s[1]],
self.l.filtered(lang=structs.LanguageRange.fromstr("en-GB"))
)
self.assertSequenceEqual(
[self.b_s[1]],
self.l.filtered(lang=structs.LanguageRange.fromstr("en-us"))
)
self.assertSequenceEqual(
[self.b_s[1]],
def test_set_identity_names_rejects_if_identity_not_registered(self):
n = disco_service.Node()
cb = unittest.mock.Mock()
n.on_info_changed.connect(cb)
with self.assertRaisesRegex(
ValueError,
r"identity not registered"):
n.set_identity_names(
"client", "pc",
names={
structs.LanguageTag.fromstr("en"): "test identity",
structs.LanguageTag.fromstr("de"): "Testidentität",
}
)
cb.assert_not_called()
def test_escaping(self):
identities = [
disco.xso.Identity(category="fnord",
type_="bar"),
disco.xso.Identity(category="client",
type_="bot",
name="aioxmpp library > 0.5"),
disco.xso.Identity(category="client",
type_="bot",
name="aioxmpp Bibliothek <& 0.5",
lang=structs.LanguageTag.fromstr("de-de")),
]
self.assertEqual(
b"client/bot//aioxmpp library > 0.5<"
b"client/bot/de-de/aioxmpp Bibliothek <& 0.5<"
b"fnord/bar//<",
caps115.build_identities_string(identities)
)
def test___str__(self):
tag = structs.LanguageTag.fromstr("zh-Hans")
self.assertEqual(
"zh-Hans",
str(tag)
)
tag = structs.LanguageTag.fromstr("de-Latn-DE-1999")
self.assertEqual(
"de-Latn-DE-1999",
str(tag)
)
def test_handle_message_ignores_subject_if_body_is_present(self):
msg = aioxmpp.stanza.Message(
from_=TEST_MUC_JID.replace(resource="secondwitch"),
type_=aioxmpp.structs.MessageType.GROUPCHAT,
)
msg.subject.update({
None: "foo"
})
msg.body.update({
aioxmpp.structs.LanguageTag.fromstr("de"): "bar"
})
self.jmuc._handle_message(
msg,
msg.from_,
False,
unittest.mock.sentinel.source
)
self.assertDictEqual(
self.jmuc.muc_subject,
{}
)
self.assertIsNone(self.jmuc.muc_subject_setter)
self.base.on_topic_changed.assert_not_called()
import signal
import time
import urllib.parse
from datetime import datetime
from enum import Enum
import aioxmpp
from . import (
worker_pool, state, utils, watcher, scanner, insideman, spokesman, mirror
)
INFO_BODY = {
aioxmpp.structs.LanguageTag.fromstr("en"):
"Hi! I am the bot feeding https://muclumbus.jabbercat.org. Please "
"see there for my Privacy Policy and what I do.",
}
ACK_BODY = {
aioxmpp.structs.LanguageTag.fromstr("en"):
"Hi, and thank you for your invite. I will consider it. It may take a "
"while (approximately two hours) until your suggestion is added to "
"the public list. I will not actually join the room, though.",
}
class Component(Enum):
WATCHER = "watcher"
INSIDEMAN = "insideman"
SCANNER = "scanner"
def parse(self, v):
return structs.LanguageTag.fromstr(v)