Merge branch 'testing' into entrypoints

This commit is contained in:
Valentin Lorentz 2023-04-26 18:04:21 +02:00
commit 6f663e4140
111 changed files with 1571 additions and 839 deletions

View File

@ -4,21 +4,58 @@ on:
push:
pull_request:
# Sources of supported versions:
# * https://github.com/actions/python-versions/blob/main/versions-manifest.json
# * https://downloads.python.org/pypy/versions.json
jobs:
build:
runs-on: ${{ matrix.runs-on }}
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11.0-alpha.2", "pypy-3.6", "pypy-3.7"]
with-opt-deps: [false, true]
runs-on: [ubuntu-latest]
exclude:
# Some of the dependencies don't work on old Python versions
include:
- python-version: "3.12.0-alpha.3"
with-opt-deps: true
runs-on: ubuntu-22.04
- python-version: "3.11"
with-opt-deps: true
runs-on: ubuntu-22.04
- python-version: "3.10"
with-opt-deps: true
runs-on: ubuntu-22.04
- python-version: "3.10"
with-opt-deps: false
runs-on: ubuntu-22.04
- python-version: "3.9"
with-opt-deps: true
runs-on: ubuntu-22.04
- python-version: "pypy-3.9"
with-opt-deps: true
runs-on: ubuntu-22.04
- python-version: "3.8"
with-opt-deps: true
runs-on: ubuntu-22.04
- python-version: "3.7"
with-opt-deps: true
runs-on: ubuntu-22.04
- python-version: "3.7"
with-opt-deps: false
runs-on: ubuntu-22.04
- python-version: "pypy-3.7"
with-opt-deps: false
runs-on: ubuntu-22.04
- python-version: "3.6"
with-opt-deps: true
with-opt-deps: false
runs-on: ubuntu-20.04
- python-version: "pypy-3.6"
with-opt-deps: true
with-opt-deps: false
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
@ -46,7 +83,7 @@ jobs:
supybot-test test -v --plugins-dir=./plugins/ --no-network
- name: Test with irctest
if: "${{ matrix.with-opt-deps && matrix.python-version != 'pypy-3.7' }}"
if: "${{ matrix.with-opt-deps && matrix.python-version != 'pypy-3.7' && matrix.python-version != 'pypy-3.9' }}"
run: |
git clone https://github.com/ProgVal/irctest.git
cd irctest

3
.gitignore vendored
View File

@ -23,6 +23,9 @@ supybot.egg-info/
test-conf/
test-data/
test-logs/
doc-conf/
doc-data/
doc-logs/
src/version.py
INSTALL
README.txt

View File

@ -46,7 +46,7 @@ Now you can use Aka as you used Alias before.
Trout
^^^^^
Add an aka, trout, which expects a word as an argument::
Add an aka, ``trout``, which expects a word as an argument::
<jamessan> @aka add trout "reply action slaps $1 with a large trout"
<bot> jamessan: The operation succeeded.
@ -56,23 +56,19 @@ Add an aka, trout, which expects a word as an argument::
This ``trout`` aka requires the plugin ``Reply`` to be loaded since it
provides the ``action`` command.
LastFM
^^^^^^
Random percentage
^^^^^^^^^^^^^^^^^
Add an aka, ``lastfm``, which expects a last.fm username and replies with
their most recently played item::
Add an aka, ``randpercent``, which returns a random percentage value::
@aka add lastfm "rss [format concat http://ws.audioscrobbler.com/1.0/user/ [format concat [web urlquote $1] /recenttracks.rss]]"
@aka add randpercent "squish [dice 1d100]%"
This ``lastfm`` aka requires the following plugins to be loaded: ``RSS``,
``Format`` and ``Web``.
This requires the ``Filter`` and ``Games`` plugins to be loaded.
``RSS`` provides ``rss``, ``Format`` provides ``concat`` and ``Web`` provides
``urlquote``.
Note that if the nested commands being aliased hadn't been quoted, then
those commands would have been run immediately, and ``@lastfm`` would always
reply with the same information, the result of those commands.
Note that nested commands in an alias should be quoted, or they will only
run once when you create the alias, and not each time the alias is
called. (In this case, not quoting the nested command would mean that
``@randpercent`` always responds with the same value!)
.. _commands-Aka:

View File

@ -532,7 +532,7 @@ class Aka(callbacks.Plugin):
Trout
^^^^^
Add an aka, trout, which expects a word as an argument::
Add an aka, ``trout``, which expects a word as an argument::
<jamessan> @aka add trout "reply action slaps $1 with a large trout"
<bot> jamessan: The operation succeeded.
@ -542,23 +542,19 @@ class Aka(callbacks.Plugin):
This ``trout`` aka requires the plugin ``Reply`` to be loaded since it
provides the ``action`` command.
LastFM
^^^^^^
Random percentage
^^^^^^^^^^^^^^^^^
Add an aka, ``lastfm``, which expects a last.fm username and replies with
their most recently played item::
Add an aka, ``randpercent``, which returns a random percentage value::
@aka add lastfm "rss [format concat http://ws.audioscrobbler.com/1.0/user/ [format concat [web urlquote $1] /recenttracks.rss]]"
@aka add randpercent "squish [dice 1d100]%"
This ``lastfm`` aka requires the following plugins to be loaded: ``RSS``,
``Format`` and ``Web``.
This requires the ``Filter`` and ``Games`` plugins to be loaded.
``RSS`` provides ``rss``, ``Format`` provides ``concat`` and ``Web`` provides
``urlquote``.
Note that if the nested commands being aliased hadn't been quoted, then
those commands would have been run immediately, and ``@lastfm`` would always
reply with the same information, the result of those commands.
Note that nested commands in an alias should be quoted, or they will only
run once when you create the alias, and not each time the alias is
called. (In this case, not quoting the nested command would mean that
``@randpercent`` always responds with the same value!)
"""
def __init__(self, irc):

View File

@ -18,21 +18,23 @@ This plugin is only kept for backward compatibility, you should use the
built-in Aka plugin instead (you can migrate your existing aliases using
the 'importaliasdatabase' command.
To add an alias, `trout`, which expects a word as an argument::
To add an alias, ``trout``, which expects a word as an argument::
<jamessan> @alias add trout "action slaps $1 with a large trout"
<bot> jamessan: The operation succeeded.
<jamessan> @trout me
* bot slaps me with a large trout
To add an alias, `lastfm`, which expects a last.fm user and replies with
their recently played items::
Add an alias, ``randpercent``, which returns a random percentage value::
@alias add lastfm "rss [format concat http://ws.audioscrobbler.com/1.0/user/ [format concat [urlquote $1] /recenttracks.rss]]"
@alias add randpercent "squish [dice 1d100]%"
Note that if the nested commands being aliased hadn't been quoted, then
those commands would have been run immediately, and `@lastfm` would always
reply with the same information, the result of those commands.
This requires the ``Filter`` and ``Games`` plugins to be loaded.
Note that nested commands in an alias should be quoted, or they will only
run once when you create the alias, and not each time the alias is
called. (In this case, not quoting the nested command would mean that
``@randpercent`` always responds with the same value!)
.. _commands-Alias:

View File

@ -243,21 +243,23 @@ class Alias(callbacks.Plugin):
built-in Aka plugin instead (you can migrate your existing aliases using
the 'importaliasdatabase' command.
To add an alias, `trout`, which expects a word as an argument::
To add an alias, ``trout``, which expects a word as an argument::
<jamessan> @alias add trout "action slaps $1 with a large trout"
<bot> jamessan: The operation succeeded.
<jamessan> @trout me
* bot slaps me with a large trout
To add an alias, `lastfm`, which expects a last.fm user and replies with
their recently played items::
Add an alias, ``randpercent``, which returns a random percentage value::
@alias add lastfm "rss [format concat http://ws.audioscrobbler.com/1.0/user/ [format concat [urlquote $1] /recenttracks.rss]]"
@alias add randpercent "squish [dice 1d100]%"
Note that if the nested commands being aliased hadn't been quoted, then
those commands would have been run immediately, and `@lastfm` would always
reply with the same information, the result of those commands.
This requires the ``Filter`` and ``Games`` plugins to be loaded.
Note that nested commands in an alias should be quoted, or they will only
run once when you create the alias, and not each time the alias is
called. (In this case, not quoting the nested command would mean that
``@randpercent`` always responds with the same value!)
"""
def __init__(self, irc):
self.__parent = super(Alias, self)

View File

@ -111,7 +111,7 @@ class AliasTestCase(ChannelPluginTestCase):
self.assertResponse('foobar', 'sbbone')
self.assertRaises(Alias.AliasError, cb.removeAlias, 'foobar')
cb.removeAlias('foobar', evenIfLocked=True)
self.assertFalse('foobar' in cb.aliases)
self.assertNotIn('foobar', cb.aliases)
self.assertError('foobar')
self.assertRegexp('alias add abc\x07 ignore', 'Error.*Invalid')

View File

@ -39,7 +39,7 @@ class AnonymousTestCase(ChannelPluginTestCase):
with conf.supybot.plugins.Anonymous.requireRegistration.context(False):
m = self.assertNotError('anonymous say %s foo!' % self.channel)
self.assertTrue(m.args[1] == 'foo!')
self.assertEqual(m.args[1], 'foo!')
def testTell(self):
self.assertError('anonymous tell %s I love you!' % self.nick)
@ -48,7 +48,7 @@ class AnonymousTestCase(ChannelPluginTestCase):
self.assertError('anonymous tell %s foo!' % self.channel)
with conf.supybot.plugins.Anonymous.allowPrivateTarget.context(True):
m = self.assertNotError('anonymous tell %s foo!' % self.nick)
self.assertTrue(m.args[1] == 'foo!')
self.assertEqual(m.args[1], 'foo!')
def testAction(self):
m = self.assertError('anonymous do %s loves you!' % self.channel)

View File

@ -61,6 +61,7 @@ from . import config
from . import plugin
from importlib import reload
# In case we're being reloaded.
reload(config)
reload(plugin)

View File

@ -99,6 +99,14 @@ supybot.plugins.BadWords.requireWordBoundaries
Determines whether the bot will require bad words to be independent words, or whether it will censor them within other words. For instance, if 'darn' is a bad word, then if this is true, 'darn' will be censored, but 'darnit' will not. You probably want this to be false. After changing this setting, the BadWords regexp needs to be regenerated by adding/removing a word to the list, or reloading the plugin.
.. _conf-supybot.plugins.BadWords.selfCensor:
supybot.plugins.BadWords.selfCensor
This config variable defaults to "True", is network-specific, and is channel-specific.
Determines whether the bot will filter its own messages.
.. _conf-supybot.plugins.BadWords.simpleReplacement:

View File

@ -113,6 +113,9 @@ conf.registerGlobalValue(BadWords, 'stripFormatting',
filtering. If it's True, however, it will interact poorly with other
plugins that do coloring or bolding of text.""")))
conf.registerChannelValue(BadWords, 'selfCensor',
registry.Boolean(True, _("""Determines whether the bot will filter its own
messages.""")))
conf.registerChannelValue(BadWords, 'kick',
registry.Boolean(False, _("""Determines whether the bot will kick people with
a warning when they use bad words.""")))

View File

@ -81,18 +81,24 @@ msgstr ""
#: config.py:117
msgid ""
"Determines whether the bot will filter its own\n"
" messages."
msgstr ""
#: config.py:120
msgid ""
"Determines whether the bot will kick people with\n"
" a warning when they use bad words."
msgstr ""
#: config.py:120
#: config.py:123
msgid ""
"You have been kicked for using a word\n"
" prohibited in the presence of this bot. Please use more appropriate\n"
" language in the future."
msgstr ""
#: config.py:122
#: config.py:125
msgid ""
"Determines the kick message used by the\n"
" bot when kicking users for saying bad words."

View File

@ -104,9 +104,10 @@ class BadWords(callbacks.Privmsg):
self.lastModified = time.time()
def outFilter(self, irc, msg):
channel = msg.channel
if self.filtering and msg.command == 'PRIVMSG' \
and (self.words() or self.phrases()):
channel = msg.channel
and (self.words() or self.phrases()) \
and self.registryValue('selfCensor', channel, irc.network):
self.updateRegexp(channel, irc.network)
s = msg.args[1]
if self.registryValue('stripFormatting'):

View File

@ -114,7 +114,7 @@ halfop [<channel>] [<nick> ...]
.. _command-channel-iban:
iban [<channel>] [--{exact,nick,user,host}] <nick> [<seconds>]
If you have the #channel,op capability, this will ban <nick> for as many seconds as you specify, otherwise (if you specify 0 seconds or don't specify a number of seconds) it will ban the person indefinitely. --exact can be used to specify an exact hostmask. You can combine the exact, nick, user, and host options as you choose. <channel> is only necessary if the message isn't sent in the channel itself.
If you have the #channel,op capability, this will ban <nick> for as many seconds as you specify, otherwise (if you specify 0 seconds or don't specify a number of seconds) it will ban the person indefinitely. --exact can be used to specify an exact hostmask. You can combine the --nick, --user, and --host options as you choose. <channel> is only necessary if the message isn't sent in the channel itself.
.. _command-channel-ignore.add:
@ -138,8 +138,8 @@ invite [<channel>] <nick>
.. _command-channel-kban:
kban [<channel>] [--{exact,nick,user,host}] <nick> [<seconds>] [<reason>]
If you have the #channel,op capability, this will kickban <nick> for as many seconds as you specify, or else (if you specify 0 seconds or don't specify a number of seconds) it will ban the person indefinitely. --exact bans only the exact hostmask; --nick bans just the nick; --user bans just the user, and --host bans just the host. You can combine these options as you choose. <reason> is a reason to give for the kick. <channel> is only necessary if the message isn't sent in the channel itself.
kban [<channel>] [--{exact,nick,user,host,account}] <nick> [<seconds>] [<reason>]
If you have the #channel,op capability, this will kickban <nick> for as many seconds as you specify, or else (if you specify 0 seconds or don't specify a number of seconds) it will ban the person indefinitely. --exact bans only the exact hostmask; --nick bans just the nick; --user bans just the user, and --host bans just the host You can combine the --nick, --user, and --host options as you choose. <channel> is only necessary if the message isn't sent in the channel itself.
.. _command-channel-key:

View File

@ -313,17 +313,15 @@ class Channel(callbacks.Plugin):
@internationalizeDocstring
def kban(self, irc, msg, args,
channel, optlist, bannedNick, expiry, reason):
"""[<channel>] [--{exact,nick,user,host}] <nick> [<seconds>] [<reason>]
"""[<channel>] [--{exact,nick,user,host,account}] <nick> [<seconds>] [<reason>]
If you have the #channel,op capability, this will kickban <nick> for
as many seconds as you specify, or else (if you specify 0 seconds or
don't specify a number of seconds) it will ban the person indefinitely.
--exact bans only the exact hostmask; --nick bans just the nick;
--user bans just the user, and --host bans just the host. You can
combine these options as you choose. <reason> is a reason to give for
the kick.
<channel> is only necessary if the message isn't sent in the channel
itself.
--user bans just the user, and --host bans just the host
You can combine the --nick, --user, and --host options as you choose.
<channel> is only necessary if the message isn't sent in the channel itself.
"""
self._ban(irc, msg, args,
channel, optlist, bannedNick, expiry, reason, True)
@ -343,9 +341,9 @@ class Channel(callbacks.Plugin):
If you have the #channel,op capability, this will ban <nick> for
as many seconds as you specify, otherwise (if you specify 0 seconds or
don't specify a number of seconds) it will ban the person indefinitely.
--exact can be used to specify an exact hostmask. You can combine the
exact, nick, user, and host options as you choose. <channel> is only
necessary if the message isn't sent in the channel itself.
--exact can be used to specify an exact hostmask.
You can combine the --nick, --user, and --host options as you choose.
<channel> is only necessary if the message isn't sent in the channel itself.
"""
self._ban(irc, msg, args,
channel, optlist, bannedNick, expiry, None, False)
@ -381,8 +379,12 @@ class Channel(callbacks.Plugin):
msg.prefix, bannedNick)
raise callbacks.ArgumentError
elif bannedNick == irc.nick:
self.log.warning('%q tried to make me kban myself.', msg.prefix)
irc.error(_('I cowardly refuse to kickban myself.'))
if kick:
self.log.warning('%q tried to make me kban myself.', msg.prefix)
irc.error(_('I cowardly refuse to kickban myself.'))
else:
self.log.warning('%q tried to make me ban myself.', msg.prefix)
irc.error(_('I cowardly refuse to ban myself.'))
return
if not reason:
reason = msg.nick

View File

@ -46,19 +46,19 @@ class ChannelTestCase(ChannelPluginTestCase):
def testLobotomies(self):
self.assertRegexp('lobotomy list', 'not.*any')
## def testCapabilities(self):
## self.prefix = 'foo!bar@baz'
## self.irc.feedMsg(ircmsgs.privmsg(self.irc.nick, 'register foo bar',
## prefix=self.prefix))
## u = ircdb.users.getUser(0)
## u.addCapability('%s.op' % self.channel)
## ircdb.users.setUser(u)
## self.assertNotError(' ')
## self.assertResponse('user capabilities foo', '[]')
## self.assertNotError('channel addcapability foo op')
## self.assertRegexp('channel capabilities foo', 'op')
## self.assertNotError('channel removecapability foo op')
## self.assertResponse('user capabilities foo', '[]')
def testCapabilities(self):
self.prefix = 'foo!bar@baz'
self.irc.feedMsg(ircmsgs.privmsg(self.irc.nick, 'register foo bar',
prefix=self.prefix))
u = ircdb.users.getUser(0)
u.addCapability('%s.op' % self.channel)
ircdb.users.setUser(u)
self.assertNotError(' ')
self.assertResponse('user capabilities foo', '[]')
self.assertNotError('channel addcapability foo op')
self.assertRegexp('channel capabilities foo', 'op')
self.assertNotError('channel removecapability foo op')
self.assertResponse('user capabilities foo', '[]')
def testCapabilities(self):
self.assertNotError('channel capability list')
@ -185,28 +185,39 @@ class ChannelTestCase(ChannelPluginTestCase):
self.assertBan('iban $a:nyuszika7h', '$a:nyuszika7h')
self.assertNotError('unban $a:nyuszika7h')
## def testKban(self):
## self.irc.prefix = 'something!else@somehwere.else'
## self.irc.nick = 'something'
## self.irc.feedMsg(ircmsgs.join(self.channel,
## prefix='foobar!user@host.domain.tld'))
## self.assertError('kban foobar')
## self.irc.feedMsg(ircmsgs.op(self.channel, self.irc.nick))
## self.assertError('kban foobar -1')
## self.assertKban('kban foobar', '*!*@*.domain.tld')
## self.assertKban('kban --exact foobar', 'foobar!user@host.domain.tld')
## self.assertKban('kban --host foobar', '*!*@host.domain.tld')
## self.assertKban('kban --user foobar', '*!user@*')
## self.assertKban('kban --nick foobar', 'foobar!*@*')
## self.assertKban('kban --nick --user foobar', 'foobar!user@*')
## self.assertKban('kban --nick --host foobar',
## 'foobar!*@host.domain.tld')
## self.assertKban('kban --user --host foobar', '*!user@host.domain.tld')
## self.assertKban('kban --nick --user --host foobar',
## 'foobar!user@host.domain.tld')
## self.assertNotRegexp('kban adlkfajsdlfkjsd', 'KeyError')
## self.assertNotRegexp('kban foobar time', 'ValueError')
## self.assertError('kban %s' % self.irc.nick)
def testKban(self):
self.irc.prefix = 'something!else@somehwere.else'
self.irc.nick = 'something'
def join():
self.irc.feedMsg(ircmsgs.join(
self.channel, prefix='foobar!user@host.domain.tld'))
join()
self.assertError('kban foobar')
self.irc.feedMsg(ircmsgs.op(self.channel, self.irc.nick))
#self.assertError('kban foobar -1')
#self.assertKban('kban foobar', '*!*@*.domain.tld')
#join()
self.assertKban('kban --exact foobar', 'foobar!user@host.domain.tld')
join()
self.assertKban('kban --host foobar', '*!*@host.domain.tld')
join()
self.assertKban('kban --user foobar', '*!user@*')
join()
self.assertKban('kban --nick foobar', 'foobar!*@*')
join()
self.assertKban('kban --nick --user foobar', 'foobar!user@*')
join()
self.assertKban('kban --nick --host foobar',
'foobar!*@host.domain.tld')
join()
self.assertKban('kban --user --host foobar', '*!user@host.domain.tld')
join()
self.assertKban('kban --nick --user --host foobar',
'foobar!user@host.domain.tld')
join()
self.assertKban('kban foobar', '*!*@host.domain.tld')
self.assertRegexp('kban adlkfajsdlfkjsd', 'adlkfajsdlfkjsd is not in')
def testBan(self):
with conf.supybot.protocols.irc.banmask.context(['exact']):

View File

@ -47,7 +47,7 @@ help <name>
.. _command-config-list:
list <group>
Returns the configuration variables available under the given configuration <group>. If a variable has values under it, it is preceded by an '@' sign. If a variable is a 'ChannelValue', that is, it can be separately configured for each channel using the 'channel' command in this plugin, it is preceded by an '#' sign. And if a variable is a 'NetworkValue', it is preceded by a ':' sign.
Returns the configuration variables available under the given configuration <group>. If a variable has values under it, it is preceded by an '@' sign. If a variable is channel-specific, that is, it can be separately configured for each channel using the 'channel' command in this plugin, it is preceded by an '#' sign. And if a variable is a network-specific, it is preceded by a ':' sign.
.. _command-config-network:

View File

@ -1,7 +1,7 @@
###
# Copyright (c) 2002-2005, Jeremiah Fincher
# Copyright (c) 2009, James McCoy
# Copyright (c) 2010-2021, Valentin Lorentz
# Copyright (c) 2010-2022, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -33,11 +33,20 @@ import random
from supybot.test import *
import supybot.conf as conf
import supybot.registry as registry
_letters = 'abcdefghijklmnopqrstuvwxyz'
def random_string():
return ''.join(random.choice(_letters) for _ in range(16))
class Fruit(registry.OnlySomeStrings):
validStrings = ('Apple', 'Orange')
group = conf.registerGroup(conf.supybot.plugins.Config, 'test')
conf.registerGlobalValue(group, 'fruit',
Fruit('Orange', '''Must be a fruit'''))
class ConfigTestCase(ChannelPluginTestCase):
# We add utilities so there's something in supybot.plugins.
plugins = ('Config', 'User', 'Utilities', 'Web')
@ -50,6 +59,16 @@ class ConfigTestCase(ChannelPluginTestCase):
self.assertNotRegexp('config get supybot.reply', r'registry\.Group')
self.assertResponse('config supybot.protocols.irc.throttleTime', '0.0')
def testSetOnlysomestrings(self):
self.assertResponse('config supybot.plugins.Config.test.fruit Apple',
'The operation succeeded.')
self.assertResponse('config supybot.plugins.Config.test.fruit orange',
'The operation succeeded.')
self.assertResponse('config supybot.plugins.Config.test.fruit Tomatoe',
"Error: Valid values include 'Apple' and "
"'Orange', not 'Tomatoe'.")
def testList(self):
self.assertError('config list asldfkj')
self.assertError('config list supybot.asdfkjsldf')

View File

@ -64,7 +64,7 @@ class Ctcp(callbacks.PluginRegexp):
def callCommand(self, command, irc, msg, *args, **kwargs):
if conf.supybot.abuse.flood.ctcp():
now = time.time()
for (ignore, expiration) in self.ignores.items():
for (ignore, expiration) in list(self.ignores.items()):
if expiration < now:
del self.ignores[ignore]
elif ircutils.hostmaskPatternEqual(ignore, msg.prefix):

View File

@ -53,6 +53,7 @@ from . import config
from . import plugin
from importlib import reload
# In case we're being reloaded.
reload(config)
reload(plugin)

View File

@ -61,10 +61,6 @@ class ProtocolError(ActivityPubError):
pass
class HostmetaError(ProtocolError):
pass
class ActivityPubProtocolError(ActivityPubError):
pass
@ -118,7 +114,7 @@ def convert_exceptions(to_class, msg="", from_none=False):
@sandbox
def _get_webfinger_url(hostname):
with convert_exceptions(HostmetaError):
try:
doc = ET.fromstring(
web.getUrlContent("https://%s/.well-known/host-meta" % hostname)
)
@ -126,8 +122,9 @@ def _get_webfinger_url(hostname):
for link in doc.iter(XRD_URI + "Link"):
if link.attrib["rel"] == "lrdd":
return link.attrib["template"]
return "https://%s/.well-known/webfinger?resource={uri}"
except web.Error:
# Fall back to the default Webfinger URL
return "https://%s/.well-known/webfinger?resource={uri}" % hostname
def has_webfinger_support(hostname):
@ -232,7 +229,9 @@ def get_public_key_pem():
def signed_request(url, headers=None, data=None):
method = "get" if data is None else "post"
instance_actor_url = get_instance_actor_url()
headers = gen.InsensitivePreservingDict(headers or {})
headers = gen.InsensitivePreservingDict(
{**web.defaultHeaders, **(headers or {})}
)
if "Date" not in headers:
headers["Date"] = email.utils.formatdate(usegmt=True)

View File

@ -38,6 +38,7 @@ from supybot.commands import urlSnarfer, wrap
from supybot.i18n import PluginInternationalization
from . import activitypub as ap
from .utils import parse_xsd_duration
importlib.reload(ap)
@ -49,6 +50,10 @@ _ = PluginInternationalization("Fediverse")
_username_regexp = re.compile("@(?P<localuser>[^@ ]+)@(?P<hostname>[^@ ]+)")
def html_to_text(html):
return utils.web.htmlToText(html).split("\n", 1)[0].strip()
class FediverseHttp(httpserver.SupyHTTPServerCallback):
name = "minimal ActivityPub server"
defaultResponse = _(
@ -222,18 +227,40 @@ class Fediverse(callbacks.PluginRegexp):
name = actor.get("name", username)
return "\x02%s\x02 (@%s@%s)" % (name, username, hostname)
def _format_author(self, irc, author):
if isinstance(author, str):
# it's an URL
try:
author = self._get_actor(irc, author)
except ap.ActivityPubError as e:
return _("<error: %s>") % str(e)
else:
return self._format_actor_fullname(author)
elif isinstance(author, dict):
if author.get("type") == "Group":
# Typically, there is an actor named "Default <username> channel"
# on PeerTube, which we do not want to show.
return None
if author.get("id"):
return self._format_author(irc, author["id"])
elif isinstance(author, list):
return format(
"%L",
filter(
bool, [self._format_author(irc, item) for item in author]
),
)
else:
return "<unknown>"
def _format_status(self, irc, msg, status):
if status["type"] == "Create":
return self._format_status(irc, msg, status["object"])
elif status["type"] == "Note":
author_url = status["attributedTo"]
try:
author = self._get_actor(irc, author_url)
except ap.ActivityPubError as e:
author_fullname = _("<error: %s>") % str(e)
else:
author_fullname = self._format_actor_fullname(author)
cw = status.get("summary")
author_fullname = self._format_author(
irc, status.get("attributedTo")
)
if cw:
if self.registryValue(
"format.statuses.showContentWithCW",
@ -246,7 +273,7 @@ class Fediverse(callbacks.PluginRegexp):
% (
author_fullname,
cw,
utils.web.htmlToText(status["content"]),
html_to_text(status["content"]),
)
]
else:
@ -258,7 +285,7 @@ class Fediverse(callbacks.PluginRegexp):
_("%s: %s")
% (
author_fullname,
utils.web.htmlToText(status["content"]),
html_to_text(status["content"]),
)
]
@ -275,6 +302,17 @@ class Fediverse(callbacks.PluginRegexp):
return self._format_status(irc, msg, status)
except ap.ActivityPubProtocolError as e:
return "<Could not fetch status: %s>" % e.args[0]
elif status["type"] == "Video":
author_fullname = self._format_author(
irc, status.get("attributedTo")
)
return format(
_("\x02%s\x02 (%T) by %s: %s"),
status["name"],
abs(parse_xsd_duration(status["duration"]).total_seconds()),
author_fullname,
html_to_text(status["content"]),
)
else:
assert False, "Unknown status type %s: %r" % (
status["type"],
@ -292,14 +330,14 @@ class Fediverse(callbacks.PluginRegexp):
_("%s: %s")
% (
self._format_actor_fullname(actor),
utils.web.htmlToText(actor["summary"]),
html_to_text(actor["summary"]),
)
)
def _format_profile(self, irc, msg, actor):
return _("%s: %s") % (
self._format_actor_fullname(actor),
utils.web.htmlToText(actor["summary"]),
html_to_text(actor["summary"]),
)
def usernameSnarfer(self, irc, msg, match):

View File

@ -60,6 +60,10 @@ from .test_data import (
BOOSTED_DATA,
BOOSTED_ACTOR_URL,
BOOSTED_ACTOR_DATA,
PEERTUBE_VIDEO_URL,
PEERTUBE_VIDEO_DATA,
PEERTUBE_ACTOR_URL,
PEERTUBE_ACTOR_DATA,
)
@ -251,6 +255,19 @@ class NetworklessFediverseTestCase(BaseFediverseTestCase):
"\x02someuser\x02 (@someuser@example.org): My Biography",
)
def testProfileNoHostmeta(self):
expected_requests = [
(HOSTMETA_URL, utils.web.Error("blah")),
(WEBFINGER_URL, WEBFINGER_DATA),
(ACTOR_URL, ACTOR_DATA),
]
with self.mockRequests(expected_requests):
self.assertResponse(
"profile @someuser@example.org",
"\x02someuser\x02 (@someuser@example.org): My Biography",
)
def testProfileSnarfer(self):
with self.mockWebfingerSupport("not called"), self.mockRequests([]):
self.assertSnarfNoResponse("aaa @nonexistinguser@example.org bbb")
@ -430,6 +447,20 @@ class NetworklessFediverseTestCase(BaseFediverseTestCase):
+ "<https://example.net/system/media_attachments/image.png>",
)
def testVideo(self):
expected_requests = [
(PEERTUBE_VIDEO_URL, PEERTUBE_VIDEO_DATA),
(PEERTUBE_ACTOR_URL, PEERTUBE_ACTOR_DATA),
]
with self.mockRequests(expected_requests):
self.assertResponse(
"status https://example.org/w/gABde9e210FGHre",
"\x02name of video\x02 (1 hour, 26 minutes, and 0 seconds) "
"by \x02chocobozzz\x02 (@chocobozzz@peertube.cpy.re): "
"description of the video with a second line",
)
def testStatusUrlSnarferDisabled(self):
with self.mockWebfingerSupport("not called"), self.mockRequests([]):
self.assertSnarfNoResponse(

View File

@ -384,3 +384,124 @@ BOOSTED_ACTOR_VALUE = {
"endpoints": {"sharedInbox": "https://example.net/inbox"},
}
BOOSTED_ACTOR_DATA = json.dumps(BOOSTED_ACTOR_VALUE).encode()
PEERTUBE_ACTOR_VALUE = {
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
{"RsaSignature2017": "https://w3id.org/security#RsaSignature2017"},
{
"pt": "https://joinpeertube.org/ns#",
"sc": "http://schema.org/",
"playlists": {"@id": "pt:playlists", "@type": "@id"},
},
],
"type": "Person",
"id": "https://peertube.cpy.re/accounts/chocobozzz",
"following": "https://peertube.cpy.re/accounts/chocobozzz/following",
"followers": "https://peertube.cpy.re/accounts/chocobozzz/followers",
"playlists": "https://peertube.cpy.re/accounts/chocobozzz/playlists",
"inbox": "https://peertube.cpy.re/accounts/chocobozzz/inbox",
"outbox": "https://peertube.cpy.re/accounts/chocobozzz/outbox",
"preferredUsername": "chocobozzz",
"url": "https://peertube.cpy.re/accounts/chocobozzz",
"name": "chocobozzz",
"published": "2017-11-28T08:48:24.271Z",
"summary": None,
}
PEERTUBE_ACTOR_DATA = json.dumps(PEERTUBE_ACTOR_VALUE).encode()
PEERTUBE_ACTOR_URL = "https://peertube.cpy.re/accounts/chocobozzz"
PEERTUBE_VIDEO_VALUE = {
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
{"RsaSignature2017": "https://w3id.org/security#RsaSignature2017"},
{
"pt": "https://joinpeertube.org/ns#",
"sc": "http://schema.org/",
"Hashtag": "as:Hashtag",
"uuid": "sc:identifier",
"category": "sc:category",
"licence": "sc:license",
"subtitleLanguage": "sc:subtitleLanguage",
"sensitive": "as:sensitive",
"language": "sc:inLanguage",
"icons": "as:icon",
"isLiveBroadcast": "sc:isLiveBroadcast",
"liveSaveReplay": {
"@type": "sc:Boolean",
"@id": "pt:liveSaveReplay",
},
"permanentLive": {
"@type": "sc:Boolean",
"@id": "pt:permanentLive",
},
"latencyMode": {"@type": "sc:Number", "@id": "pt:latencyMode"},
"Infohash": "pt:Infohash",
"originallyPublishedAt": "sc:datePublished",
"views": {"@type": "sc:Number", "@id": "pt:views"},
"state": {"@type": "sc:Number", "@id": "pt:state"},
"size": {"@type": "sc:Number", "@id": "pt:size"},
"fps": {"@type": "sc:Number", "@id": "pt:fps"},
"commentsEnabled": {
"@type": "sc:Boolean",
"@id": "pt:commentsEnabled",
},
"downloadEnabled": {
"@type": "sc:Boolean",
"@id": "pt:downloadEnabled",
},
"waitTranscoding": {
"@type": "sc:Boolean",
"@id": "pt:waitTranscoding",
},
"support": {"@type": "sc:Text", "@id": "pt:support"},
"likes": {"@id": "as:likes", "@type": "@id"},
"dislikes": {"@id": "as:dislikes", "@type": "@id"},
"shares": {"@id": "as:shares", "@type": "@id"},
"comments": {"@id": "as:comments", "@type": "@id"},
},
],
"to": ["https://www.w3.org/ns/activitystreams#Public"],
"type": "Video",
"name": "name of video",
"duration": "PT5160S",
"tag": [{"type": "Hashtag", "name": "vostfr"}],
"category": {"identifier": "2", "name": "Films"},
"licence": {"identifier": "4", "name": "Attribution - Non Commercial"},
"language": {"identifier": "en", "name": "English"},
"views": 13718,
"sensitive": False,
"waitTranscoding": False,
"state": 1,
"commentsEnabled": True,
"downloadEnabled": True,
"published": "2017-10-23T07:54:38.155Z",
"originallyPublishedAt": None,
"updated": "2022-07-13T07:03:12.373Z",
"mediaType": "text/markdown",
"content": "description of <strong>the</strong> video\r\nwith a second line",
"support": None,
"subtitleLanguage": [],
"icon": [
# redacted
],
"url": [
# redacted
],
"attributedTo": [
{"type": "Person", "id": PEERTUBE_ACTOR_URL},
{
"type": "Group",
"id": ACTOR_URL,
},
],
"isLiveBroadcast": False,
"liveSaveReplay": None,
"permanentLive": None,
"latencyMode": None,
}
PEERTUBE_VIDEO_DATA = json.dumps(PEERTUBE_VIDEO_VALUE).encode()
PEERTUBE_VIDEO_URL = "https://example.org/w/gABde9e210FGHre"

View File

@ -0,0 +1,63 @@
###
# Copyright (c) 2022, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
import re
import datetime
# Credits for the regexp and function: https://stackoverflow.com/a/2765366/539465
_XSD_DURATION_RE = re.compile(
"(?P<sign>-?)P"
"(?:(?P<years>\d+)Y)?"
"(?:(?P<months>\d+)M)?"
"(?:(?P<days>\d+)D)?"
"(?:T(?:(?P<hours>\d+)H)?(?:(?P<minutes>\d+)M)?(?:(?P<seconds>\d+)S)?)?"
)
def parse_xsd_duration(s):
"""Parses this format to a timedelta:
https://www.w3.org/TR/xmlschema11-2/#duration"""
# Fetch the match groups with default value of 0 (not None)
duration = _XSD_DURATION_RE.match(s).groupdict(0)
# Create the timedelta object from extracted groups
delta = datetime.timedelta(
days=int(duration["days"])
+ (int(duration["months"]) * 30)
+ (int(duration["years"]) * 365),
hours=int(duration["hours"]),
minutes=int(duration["minutes"]),
seconds=int(duration["seconds"]),
)
if duration["sign"] == "-":
delta *= -1
return delta

View File

@ -43,8 +43,11 @@ class GamesTestCase(ChannelPluginTestCase):
'Got a msg without bang|click|spin: %r' % m)
elif m.command == 'KICK':
sawKick = True
self.assertTrue('bang' in m.args[2].lower(),
'Got a KICK without bang in it.')
self.assertIn(
'bang',
m.args[2].lower(),
'Got a KICK without bang in it.'
)
else:
self.fail('Got something other than a kick or a privmsg.')
self.assertTrue(sawKick, 'Didn\'t get a kick in %s iterations!' % i)

View File

@ -150,7 +150,8 @@ class Geography(callbacks.Plugin):
continue
offset_seconds = int(
datetime.datetime.now(tz=timezone).utcoffset().total_seconds())
datetime.datetime.now(tz=timezone).utcoffset().total_seconds()
)
offset = self._format_utc_offset(offset_seconds)
# Extract a human-friendly name, depending on the type of

View File

@ -83,7 +83,7 @@ class GeographyTimezoneTestCase(PluginTestCase):
with patch.object(wikidata, "timezone_from_uri", return_value=tz):
self.assertRegexp(
"timezone Newfoundland",
r"Canada/Newfoundland \(currently UTC-[23]:30\)"
r"Canada/Newfoundland \(currently UTC-[23]:30\)",
)
tz = pytz.timezone("Asia/Kolkata")
@ -111,7 +111,7 @@ class GeographyTimezoneTestCase(PluginTestCase):
with patch.object(wikidata, "timezone_from_uri", return_value=tz):
self.assertRegexp(
"timezone Newfoundland",
r"Canada/Newfoundland \(currently UTC-[23]:30\)"
r"Canada/Newfoundland \(currently UTC-[23]:30\)",
)
tz = zoneinfo.ZoneInfo("Asia/Kolkata")
@ -144,9 +144,7 @@ class GeographyTimezoneTestCase(PluginTestCase):
self.assertRegexp(
"timezone Delhi", r"Asia/Kolkata \(currently UTC\+5:30\)"
)
self.assertRegexp(
"timezone Newfoundland", r"UTC-[23]:30"
)
self.assertRegexp("timezone Newfoundland", r"UTC-[23]:30")
class GeographyLocaltimeTestCase(PluginTestCase):

View File

@ -134,10 +134,12 @@ def timezone_from_uri(location_uri):
"""Returns a :class:datetime.tzinfo object, given a Wikidata Q-ID.
eg. ``"Q60"`` for New York City."""
for tztype in [
"http://www.wikidata.org/entity/Q17272692", # IANA timezones first
"http://www.wikidata.org/entity/Q12143", # any timezone as a fallback
"http://www.wikidata.org/entity/Q17272692", # IANA timezones first
"http://www.wikidata.org/entity/Q12143", # any timezone as a fallback
]:
data = _query_sparql(TIMEZONE_QUERY.substitute(subject=location_uri, tztype=tztype))
data = _query_sparql(
TIMEZONE_QUERY.substitute(subject=location_uri, tztype=tztype)
)
results = data["results"]["bindings"]
for result in results:
if "tzid" in result:

View File

@ -43,21 +43,6 @@ Check: `Supported language codes`_
Commands
--------
.. _command-google-cache:
cache <url>
Returns a link to the cached version of <url> if it is available.
.. _command-google-calc:
calc <expression>
Uses Google's calculator to calculate the value of <expression>.
.. _command-google-fight:
fight <search string> <search string> [<search string> ...]
Returns the results of each search, in order, from greatest number of results to least.
.. _command-google-google:
google <search> [--{filter,language} <value>]
@ -68,11 +53,6 @@ google <search> [--{filter,language} <value>]
lucky [--snippet] <search>
Does a google search, but only returns the first result. If option --snippet is given, returns also the page text snippet.
.. _command-google-phonebook:
phonebook <phone number>
Looks <phone number> up on Google.
.. _command-google-translate:
translate <source language> [to] <target language> <text>

View File

@ -231,52 +231,6 @@ class Google(callbacks.PluginRegexp):
'filter':''}),
'text'])
@internationalizeDocstring
def cache(self, irc, msg, args, url):
"""<url>
Returns a link to the cached version of <url> if it is available.
"""
data = self.search(url, msg.channel, irc.network, {'smallsearch': True})
if data:
m = data[0]
if m['cacheUrl']:
url = m['cacheUrl'].encode('utf-8')
irc.reply(url)
return
irc.error(_('Google seems to have no cache for that site.'))
cache = wrap(cache, ['url'])
_fight_re = re.compile(r'id="resultStats"[^>]*>(?P<stats>[^<]*)')
@internationalizeDocstring
def fight(self, irc, msg, args):
"""<search string> <search string> [<search string> ...]
Returns the results of each search, in order, from greatest number
of results to least.
"""
channel = msg.channel
network = irc.network
results = []
for arg in args:
text = self.search(arg, channel, network, {'smallsearch': True})
i = text.find('id="resultStats"')
stats = utils.web.htmlToText(self._fight_re.search(text).group('stats'))
if stats == '':
results.append((0, args))
continue
count = ''.join(filter('0123456789'.__contains__, stats))
results.append((int(count), arg))
results.sort()
results.reverse()
if self.registryValue('bold', channel, network):
bold = ircutils.bold
else:
bold = repr
s = ', '.join([format('%s: %i', bold(s), i) for (i, s) in results])
irc.reply(s)
def _translate(self, sourceLang, targetLang, text):
headers = dict(utils.web.defaultHeaders)
headers['User-agent'] = ('Mozilla/5.0 (X11; U; Linux i686) '
@ -339,59 +293,6 @@ class Google(callbacks.PluginRegexp):
(self.registryValue('baseUrl', channel, network), s)
return url
_calcRe1 = re.compile(r'<span class="cwcot".*?>(.*?)</span>', re.I)
_calcRe2 = re.compile(r'<div class="vk_ans.*?>(.*?)</div>', re.I | re.S)
_calcRe3 = re.compile(r'<div class="side_div" id="rhs_div">.*?<input class="ucw_data".*?value="(.*?)"', re.I)
@internationalizeDocstring
def calc(self, irc, msg, args, expr):
"""<expression>
Uses Google's calculator to calculate the value of <expression>.
"""
url = self._googleUrl(expr, msg.channel, irc.network)
h = {"User-Agent":"Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36"}
html = utils.web.getUrl(url, headers=h).decode('utf8')
match = self._calcRe1.search(html)
if not match:
match = self._calcRe2.search(html)
if not match:
match = self._calcRe3.search(html)
if not match:
irc.reply("I could not find an output from Google Calc for: %s" % expr)
return
else:
s = match.group(1)
else:
s = match.group(1)
else:
s = match.group(1)
# do some cleanup of text
s = re.sub(r'<sup>(.*)</sup>&#8260;<sub>(.*)</sub>', r' \1/\2', s)
s = re.sub(r'<sup>(.*)</sup>', r'^\1', s)
s = utils.web.htmlToText(s)
irc.reply("%s = %s" % (expr, s))
calc = wrap(calc, ['text'])
_phoneRe = re.compile(r'Phonebook.*?<font size=-1>(.*?)<a href')
@internationalizeDocstring
def phonebook(self, irc, msg, args, phonenumber):
"""<phone number>
Looks <phone number> up on Google.
"""
url = self._googleUrl(phonenumber, msg.channel, irc.network)
html = utils.web.getUrl(url).decode('utf8')
m = self._phoneRe.search(html)
if m is not None:
s = m.group(1)
s = s.replace('<b>', '')
s = s.replace('</b>', '')
s = utils.web.htmlToText(s)
irc.reply(s)
else:
irc.reply(_('Google\'s phonebook didn\'t come up with anything.'))
phonebook = wrap(phonebook, ['text'])
Class = Google

View File

@ -34,21 +34,6 @@ from supybot.test import *
class GoogleTestCase(ChannelPluginTestCase):
plugins = ('Google', 'Config')
if network:
def testCalcHandlesMultiplicationSymbol(self):
self.assertNotRegexp('google calc seconds in a century', r'215')
def testCalc(self):
self.assertNotRegexp('google calc e^(i*pi)+1', r'didn\'t')
self.assertNotRegexp('google calc 1 usd in gbp', r'didn\'t')
def testHtmlHandled(self):
self.assertNotRegexp('google calc '
'the speed of light '
'in microns / fortnight', '<sup>')
self.assertNotRegexp('google calc '
'the speed of light '
'in microns / fortnight', '&times;')
def testSearch(self):
self.assertNotError('google foo')
self.assertRegexp('google dupa', r'dupa')
@ -76,14 +61,7 @@ class GoogleTestCase(ChannelPluginTestCase):
self.assertNotError('config plugins.Google.oneToOne True')
self.assertNotRegexp('google dupa', ';')
def testFight(self):
self.assertRegexp('fight supybot moobot', r'.*supybot.*: \d+')
self.assertNotError('fight ... !')
def testTranslate(self):
self.assertRegexp('translate en es hello world', 'Hola mundo')
def testCalcDoesNotHaveExtraSpaces(self):
self.assertNotRegexp('google calc 1000^2', r'\s+,\s+')
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -209,7 +209,7 @@ class SqliteKarmaDB(object):
def load(self, channel, filename):
filename = conf.supybot.directories.data.dirize(filename)
fd = open(filename)
fd = open(filename, encoding='utf8')
reader = csv.reader(fd)
db = self._getDb(channel)
cursor = db.cursor()

View File

@ -44,7 +44,7 @@ class LimiterTestCase(ChannelPluginTestCase):
self.assertEqual(m, ircmsgs.limit('#foo', 1+10))
self.irc.feedMsg(ircmsgs.join('#foo', prefix='bar!root@host'))
m = self.irc.takeMsg()
self.assertFalse(m is not None)
self.assertIsNone(m)
conf.supybot.plugins.Limiter.maximumExcess.setValue(7)
self.irc.feedMsg(ircmsgs.part('#foo', prefix='bar!root@host'))
m = self.irc.takeMsg()

View File

@ -166,8 +166,8 @@ class Math(callbacks.Plugin):
"""
try:
self.log.info('evaluating %q from %s', text, msg.prefix)
x = safe_eval(text, allow_ints=True)
irc.reply(str(x))
result = safe_eval(text, allow_ints=True)
float(result) # fail early if it is too large to be displayed
except OverflowError:
maxFloat = math.ldexp(0.9999999999999999, 1024)
irc.error(_('The answer exceeded %s or so.') % maxFloat)
@ -177,6 +177,17 @@ class Math(callbacks.Plugin):
irc.error(_('%s is not a defined function.') % str(e).split()[1])
except Exception as e:
irc.error(utils.exnToString(e))
else:
try:
result_str = str(result)
except ValueError as e:
# Probably too large to be converted to string; go through
# floats instead.
# https://docs.python.org/3/library/stdtypes.html#int-max-str-digits
# (Depending on configuration, this may be dead code because it
# is caught by the float() check above.
result_str = str(float(result))
irc.reply(result_str)
icalc = wrap(icalc, [('checkCapability', 'trusted'), 'text'])
_rpnEnv = {

View File

@ -112,7 +112,10 @@ class MathTestCase(PluginTestCase):
self.assertNotError('calc (1600 * 1200) - 2*(1024*1280)')
self.assertNotError('calc 3-2*4')
self.assertNotError('calc (1600 * 1200)-2*(1024*1280)')
self.assertError('calc factorial(20000)')
self.assertResponse('calc factorial(20000)',
'Error: factorial argument too large')
self.assertResponse('calc factorial(20000) / factorial(19999)',
'Error: factorial argument too large')
def testCalcNoNameError(self):
self.assertRegexp('calc foobar(x)', 'foobar is not a defined function')
@ -147,7 +150,10 @@ class MathTestCase(PluginTestCase):
self.assertResponse('icalc 1^1', '0')
self.assertResponse('icalc 10**24', '1' + '0'*24)
self.assertRegexp('icalc 49/6', '8.16')
self.assertNotError('icalc factorial(20000)')
self.assertRegexp('icalc factorial(20000)',
'Error: The answer exceeded')
self.assertResponse('icalc factorial(20000) / factorial(19999)',
'20000.0')
def testRpn(self):
self.assertResponse('rpn 5 2 +', '7')

View File

@ -163,6 +163,20 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
channel = msg.channel
if not channel:
return
if 'batch' in msg.server_tags:
parent_batches = irc.state.getParentBatches(msg)
parent_batch_types = [batch.type for batch in parent_batches]
if 'chathistory' in parent_batch_types:
# Either sent automatically by the server upon join,
# or triggered by a plugin (why?!)
# Either way, replying to messages from the history would
# look weird, because they may have been sent a while ago,
# and we may have already answered them.
# (this is the same behavior as in Owner.doPrivmsg and
# PluginRegexp.doPrivmsg)
return
if self.registryValue('enable', channel, irc.network):
actions = []
results = []

View File

@ -116,10 +116,31 @@ class MessageParserTestCase(ChannelPluginTestCase):
def testTrigger(self):
self.assertNotError('messageparser add "stuff" "echo i saw some stuff"')
self.feedMsg('this message has some stuff in it')
self.irc.feedMsg(ircmsgs.IrcMsg(
prefix=self.prefix,
command='PRIVMSG',
args=(self.channel, 'this message has some stuff in it')))
m = self.getMsg(' ')
self.assertTrue(str(m).startswith('PRIVMSG #test :i saw some stuff'))
def testIgnoreChathistory(self):
self.assertNotError('messageparser add "stuff" "echo i saw some stuff"')
self.irc.feedMsg(ircmsgs.IrcMsg(
command='BATCH',
args=('+123', 'chathistory', self.channel)))
self.irc.feedMsg(ircmsgs.IrcMsg(
server_tags={'batch': '123'},
prefix=self.prefix,
command='PRIVMSG',
args=(self.channel, 'this message has some stuff in it')))
self.irc.feedMsg(ircmsgs.IrcMsg(
command='BATCH',
args=('-123',)))
m = self.getMsg(' ')
self.assertFalse(m)
def testMaxTriggers(self):
self.assertNotError('messageparser add "stuff" "echo i saw some stuff"')
self.assertNotError('messageparser add "sbd" "echo i saw somebody"')

View File

@ -130,7 +130,7 @@ class MiscTestCase(ChannelPluginTestCase):
def testHelpIncludeFullCommandName(self):
self.assertHelp('help channel capability add')
m = self.getMsg('help channel capability add')
self.assertTrue('channel capability add' in m.args[1])
self.assertIn('channel capability add', m.args[1])
def testHelpDoesAmbiguityWithDefaultPlugins(self):
m = self.getMsg('help list') # Misc.list and User.list.
@ -189,12 +189,12 @@ class MiscTestCase(ChannelPluginTestCase):
oldprefix, self.prefix = self.prefix, 'tester!foo@bar__no_testcap__baz'
self.nick = 'tester'
m = self.getMsg('tell aljsdkfh [plugin tell]')
self.assertTrue('let you do' in m.args[1])
self.assertIn('let you do', m.args[1])
m = self.getMsg('tell #foo [plugin tell]')
self.assertTrue('No need for' in m.args[1])
self.assertIn('No need for', m.args[1])
m = self.getMsg('tell me you love me')
m = self.irc.takeMsg()
self.assertTrue(m.args[0] == self.nick)
self.assertEqual(m.args[0], self.nick)
def testNoNestedTell(self):
self.assertRegexp('echo [tell %s foo]' % self.nick, 'nested')
@ -271,7 +271,7 @@ class MiscTestCase(ChannelPluginTestCase):
self.assertResponse('more',
'abc '*112 + ' \x02(2 more messages)\x02')
m = self.irc.takeMsg()
self.assertIsNot(m, None)
self.assertIsNotNone(m)
self.assertEqual(
m.args[1],
'abc '*112 + ' \x02(1 more message)\x02')

View File

@ -20,13 +20,24 @@ To add factoid say
``@something is something`` And when you call ``@something`` the bot says
``something is something``.
If you want factoid to be in different format say (for example):
If you want the factoid to be in different format say (for example):
``@Hi is <reply> Hello`` And when you call ``@hi`` the bot says ``Hello.``
If you want the bot to use /mes with Factoids, that is possible too.
``@test is <action> tests.`` and everytime when someone calls for
``test`` the bot answers ``* bot tests.``
If you want the factoid to have random answers say (for example):
``@fruit is <reply> (orange|apple|banana)``. So when ``@fruit`` is called
the bot will reply with one of the listed fruits (random): ``orange``.
If you want to replace the value of the factoid, for example:
``@no Hi is <reply> Hey`` when you call ``@hi`` the bot says ``Hey``.
If you want to append to the current value of a factoid say:
``@Hi is also Hello``, so that when you call ``@hi`` the
bot says ``Hey, or Hello.``
.. _commands-MoobotFactoids:
Commands

View File

@ -293,12 +293,23 @@ class MoobotFactoids(callbacks.Plugin):
``@something is something`` And when you call ``@something`` the bot says
``something is something``.
If you want factoid to be in different format say (for example):
If you want the factoid to be in different format say (for example):
``@Hi is <reply> Hello`` And when you call ``@hi`` the bot says ``Hello.``
If you want the bot to use /mes with Factoids, that is possible too.
``@test is <action> tests.`` and everytime when someone calls for
``test`` the bot answers ``* bot tests.``
If you want the factoid to have random answers say (for example):
``@fruit is <reply> (orange|apple|banana)``. So when ``@fruit`` is called
the bot will reply with one of the listed fruits (random): ``orange``.
If you want to replace the value of the factoid, for example:
``@no Hi is <reply> Hey`` when you call ``@hi`` the bot says ``Hey``.
If you want to append to the current value of a factoid say:
``@Hi is also Hello``, so that when you call ``@hi`` the
bot says ``Hey, or Hello.``
"""
callBefore = ['Dunno']
def __init__(self, irc):

View File

@ -54,8 +54,11 @@ class OptionListTestCase(SupyTestCase):
while max and L:
max -= 1
option = plugin.pickOptions(s)
self.assertTrue(option in original,
'Option %s not in %s' % (option, original))
self.assertIn(
option,
original,
'Option %s not in %s' % (option, original)
)
if option in L:
L.remove(option)
self.assertFalse(L, 'Some options never seen: %s' % L)

View File

@ -309,8 +309,9 @@ class Owner(callbacks.Plugin):
# Either sent automatically by the server upon join,
# or triggered by a plugin (why?!)
# Either way, replying to commands from the history would
# look weird, because it may have been sent a while ago,
# and we may have already answered to it.
# look weird, because they may have been sent a while ago,
# and we may have already answered to them.
# (this is the same behavior as in PluginRegexp.doPrivmsg)
return
self._doPrivmsgs(irc, msg)

View File

@ -121,11 +121,11 @@ class GithubRepository(GitRepository):
assert directory is not None, \
'No valid directory in supybot.directories.plugins.'
possibly_incompatible = False
try:
assert archive.getmember(prefix + dirname).isdir(), \
'This is not a valid plugin (it is a file, not a directory).'
run_2to3 = minisix.PY3
for file in archive.getmembers():
if file.name.startswith(prefix + dirname):
extractedFile = archive.extractfile(file)
@ -140,42 +140,18 @@ class GithubRepository(GitRepository):
os.mkdir(newFileName)
else:
with open(newFileName, 'ab') as fd:
reload_imported = False
for line in extractedFile.readlines():
if minisix.PY3:
if b'import reload' in line:
reload_imported = True
elif not reload_imported and \
b'reload(' in line:
fd.write(b'from importlib import reload\n')
reload_imported = True
if file.name.endswith('__init__.py') and \
line.startswith((b'import config', b'import plugin')):
possibly_incompatible = True
fd.write(line)
if newFileName.endswith('__init__.py'):
with open(newFileName) as fd:
lines = list(filter(lambda x:'import plugin' in x,
fd.readlines()))
if lines and lines[0].startswith('from . import'):
# This should be already Python 3-compatible
run_2to3 = False
finally:
archive.close()
del archive
if run_2to3:
try:
import lib2to3
except ImportError:
return _('Plugin is probably not compatible with your '
'Python version (3.x) and could not be converted '
'because 2to3 is not installed.')
import subprocess
fixers = []
subprocess.Popen(['2to3', '-wn', os.path.join(directory, plugin)]) \
.wait()
return _('Plugin was designed for Python 2, but an attempt to '
'convert it to Python 3 has been made. There is no '
'guarantee it will work, though.')
else:
return _('Plugin successfully installed.')
if possibly_incompatible:
return _('Plugin installed. However, it may be incompatible with '
'Python 3 and require manual code changes to work correctly.')
return _('Plugin successfully installed.')
def getInfo(self, plugin):
archive = self._download(plugin)
@ -201,65 +177,11 @@ repositories = utils.InsensitivePreservingDict({
'progval',
'Supybot-plugins'
),
'quantumlemur': GithubRepository(
'quantumlemur',
'Supybot-plugins',
),
'stepnem': GithubRepository(
'stepnem',
'supybot-plugins',
),
'code4lib-snapshot':GithubRepository(
'code4lib',
'supybot-plugins',
'Supybot-plugins-20060723',
),
'code4lib-edsu': GithubRepository(
'code4lib',
'supybot-plugins',
'edsu-plugins',
),
'code4lib': GithubRepository(
'code4lib',
'supybot-plugins',
'plugins',
),
'nanotube-bitcoin': GithubRepository(
'nanotube',
'supybot-bitcoin-'
'marketmonitor',
),
'mtughan-weather': GithubRepository(
'mtughan',
'Supybot-Weather',
),
'SpiderDave': GithubRepository(
'SpiderDave',
'spidey-supybot-plugins',
'Plugins',
),
'doorbot': GithubRepository(
'hacklab',
'doorbot',
),
'boombot': GithubRepository(
'nod',
'boombot',
'plugins',
),
'mailed-notifier': GithubRepository(
'tbielawa',
'supybot-mailed-notifier',
),
'pingdom': GithubRepository(
'rynop',
'supyPingdom',
'plugins',
),
'scrum': GithubRepository(
'amscanne',
'supybot-scrum',
),
'Hoaas': GithubRepository(
'Hoaas',
'Supybot-plugins'
@ -268,23 +190,11 @@ repositories = utils.InsensitivePreservingDict({
'nyuszika7h',
'limnoria-plugins'
),
'nyuszika7h-old': GithubRepository(
'nyuszika7h',
'Supybot-plugins'
),
'resistivecorpse': GithubRepository(
'resistivecorpse',
'supybot-plugins'
),
'frumious': GithubRepository(
'frumiousbandersnatch',
'sobrieti-plugins',
'plugins',
),
'jonimoose': GithubRepository(
'Jonimoose',
'Supybot-plugins',
),
'skgsergio': GithubRepository(
'skgsergio',
'Limnoria-plugins',

View File

@ -29,11 +29,9 @@
###
import os
import sys
import shutil
from supybot.test import *
import supybot.utils.minisix as minisix
pluginsPath = '%s/test-plugins' % os.getcwd()
@ -62,7 +60,7 @@ class PluginDownloaderTestCase(PluginTestCase):
def testRepolist(self):
self.assertRegexp('repolist', '(.*, )?progval(, .*)?')
self.assertRegexp('repolist', '(.*, )?quantumlemur(, .*)?')
self.assertRegexp('repolist', '(.*, )?jlu5(, .*)?')
self.assertRegexp('repolist progval', '(.*, )?AttackProtector(, .*)?')
def testInstallprogval(self):
@ -76,44 +74,19 @@ class PluginDownloaderTestCase(PluginTestCase):
self.assertRegexp('plugindownloader install progval Darcs',
'Error:.*not available.*supybot.commands.allowShell')
def testInstallQuantumlemur(self):
self.assertError('plugindownloader install quantumlemur AttackProtector')
self.assertNotError('plugindownloader install quantumlemur Listener')
self.assertError('plugindownloader install quantumlemur AttackProtector')
self._testPluginInstalled('Listener')
def testInstallStepnem(self):
self.assertNotError('plugindownloader install stepnem Freenode')
self._testPluginInstalled('Freenode')
def testInstallNanotubeBitcoin(self):
self.assertNotError('plugindownloader install nanotube-bitcoin GPG')
self._testPluginInstalled('GPG')
def testInstallMtughanWeather(self):
self.assertNotError('plugindownloader install mtughan-weather '
'WunderWeather')
self._testPluginInstalled('WunderWeather')
def testInstallSpiderDave(self):
self.assertNotError('plugindownloader install SpiderDave Pastebin')
self._testPluginInstalled('Pastebin')
def testInstallNonAsciiInit(self):
self.assertNotError('plugindownloader install Hoaas DuckDuckGo')
self._testPluginInstalled('DuckDuckGo')
def testInstallLegacyWarning(self):
self.assertRegexp('plugindownloader install frumious Codepoints',
'may be incompatible')
def testInfo(self):
self.assertResponse('plugindownloader info progval Twitter',
'Advanced Twitter plugin for Supybot, with capabilities '
'handling, and per-channel user account.')
if minisix.PY3:
def test_2to3(self):
self.assertRegexp('plugindownloader install SpiderDave Pastebin',
'convert')
self.assertNotError('load Pastebin')
if not network:
class PluginDownloaderTestCase(PluginTestCase):
pass

View File

@ -61,6 +61,11 @@ add [<channel>] <question> <answer1> [<answer2> [<answer3> [...]]]
close [<channel>] <poll_id>
Closes the specified poll.
.. _command-poll-list:
list [<channel>]
Lists open polls in the <channel>.
.. _command-poll-results:
results [<channel>] <poll_id>

View File

@ -53,6 +53,7 @@ from . import config
from . import plugin
from importlib import reload
# In case we're being reloaded.
reload(config)
reload(plugin)

View File

@ -131,7 +131,7 @@ class Poll_(callbacks.Plugin):
poll_id = max(self._polls[(irc.network, channel)], default=0) + 1
answers = [(answer.split()[0], answer) for answer in answers]
answers = [(answer.split()[0].casefold(), answer) for answer in answers]
answer_id_counts = collections.Counter(
id_ for (id_, _) in answers
@ -149,7 +149,10 @@ class Poll_(callbacks.Plugin):
)
self._polls[(irc.network, channel)][poll_id] = Poll(
question=question, answers=dict(answers), votes={}, open=True
question=question,
answers=dict(answers),
votes=ircutils.IrcDict(),
open=True,
)
irc.replySuccess(_("Poll # %d created.") % poll_id)
@ -191,6 +194,8 @@ class Poll_(callbacks.Plugin):
if msg.nick in poll.votes:
irc.error(_("You already voted on this poll."), Raise=True)
answer_id = answer_id.casefold()
if answer_id not in poll.answers:
irc.error(
format(
@ -218,11 +223,32 @@ class Poll_(callbacks.Plugin):
counts.update({answer_id: 0 for answer_id in poll.answers})
results = [
format(_("%n for %s"), (v, "vote"), k)
format(_("%n for %s"), (v, _("vote")), poll.answers[k].split()[0])
for (k, v) in counts.most_common()
]
irc.replies(results)
@wrap(["channel"])
def list(self, irc, msg, args, channel):
"""[<channel>]
Lists open polls in the <channel>."""
results = [
format(
_("%i: %s (%n)"),
poll_id,
poll.question,
(len(poll.votes), _("vote")),
)
for (poll_id, poll) in self._polls[(irc.network, channel)].items()
if poll.open
]
if results:
irc.replies(results)
else:
irc.reply(_("There are no open polls."))
Class = Poll_

View File

@ -49,6 +49,17 @@ class PollTestCase(ChannelPluginTestCase):
"2 votes for No, 1 vote for Yes, and 0 votes for Maybe",
)
def testNoResults(self):
self.assertResponse(
'poll add "Is this a test?" "Yes" "No" "Maybe"',
"The operation succeeded. Poll # 1 created.",
)
self.assertResponse(
"results 1",
"0 votes for Yes, 0 votes for No, and 0 votes for Maybe",
)
def testDoubleVoting(self):
self.assertResponse(
'poll add "Is this a test?" "Yes" "No" "Maybe"',
@ -62,6 +73,11 @@ class PollTestCase(ChannelPluginTestCase):
"voter1: Error: You already voted on this poll.",
frm="voter1!foo@bar",
)
self.assertResponse(
"vote 1 Yes",
"VOTER1: Error: You already voted on this poll.",
frm="VOTER1!foo@bar",
)
self.assertRegexp(
"results 1",
@ -115,10 +131,58 @@ class PollTestCase(ChannelPluginTestCase):
def testDuplicateId(self):
self.assertResponse(
'poll add "Is this a test?" "Yes" "Yes" "Maybe"',
"Error: Duplicate answer identifier(s): Yes",
"Error: Duplicate answer identifier(s): yes",
)
self.assertResponse(
'poll add "Is this a test?" "Yes totally" "Yes and no" "Maybe"',
"Error: Duplicate answer identifier(s): Yes",
"Error: Duplicate answer identifier(s): yes",
)
def testCaseInsensitive(self):
self.assertResponse(
'poll add "Is this a test?" "Yeß" "No" "Maybe"',
"The operation succeeded. Poll # 1 created.",
)
self.assertNotError("vote 1 Yeß", frm="voter1!foo@bar")
self.assertNotError("vote 1 yESS", frm="voter2!foo@bar")
self.assertNotError("vote 1 no", frm="voter3!foo@bar")
self.assertResponse(
"results 1",
"2 votes for Yeß, 1 vote for No, and 0 votes for Maybe",
)
def testList(self):
self.assertResponse("poll list", "There are no open polls.")
self.assertResponse(
'poll add "Is this a test?" "Yes" "No" "Maybe"',
"The operation succeeded. Poll # 1 created.",
)
self.assertResponse("poll list", "1: Is this a test? (0 votes)")
self.assertNotError("vote 1 Yes", frm="voter1!foo@bar")
self.assertResponse("poll list", "1: Is this a test? (1 vote)")
self.assertNotError("vote 1 No", frm="voter2!foo@bar")
self.assertResponse("poll list", "1: Is this a test? (2 votes)")
self.assertResponse(
'poll add "Is this another test?" "Yes" "No" "Maybe"',
"The operation succeeded. Poll # 2 created.",
)
self.assertResponse(
"poll list",
"1: Is this a test? (2 votes) and 2: Is this another test? (0 votes)",
)
self.assertNotError("poll close 1")
self.assertResponse(
"poll list",
"2: Is this another test? (0 votes)",
)
self.assertNotError("poll close 2")
self.assertResponse("poll list", "There are no open polls.")

View File

@ -50,6 +50,7 @@ conf.registerChannelValue(Protector, 'enable',
class ImmuneNicks(conf.ValidNicks):
List = ircutils.IrcSet
sorted = True
conf.registerChannelValue(Protector, 'immune',
ImmuneNicks([], _("""Determines what nicks the bot will consider to

View File

@ -43,7 +43,7 @@ def configure(advanced):
conf.registerPlugin('RSS', True)
class FeedNames(registry.SpaceSeparatedListOfStrings):
class FeedNames(registry.SpaceSeparatedSetOfStrings):
List = callbacks.CanonicalNameSet
class FeedItemSortOrder(registry.OnlySomeStrings):

View File

@ -356,8 +356,17 @@ class RSS(callbacks.Plugin):
handlers.append(ProxyHandler(
{'https': utils.force(utils.web.proxy())}))
with feed.lock:
d = feedparser.parse(feed.url, etag=feed.etag,
modified=feed.modified, handlers=handlers)
try:
d = feedparser.parse(feed.url, etag=feed.etag,
modified=feed.modified, handlers=handlers)
except socket.error as e:
self.log.warning("Network error while fetching <%s>: %s",
feed.url, e)
feed.last_exception = e
return
except Exception as e:
self.log.error("Failed to fetch <%s>: %s", feed.url, e)
raise # reraise so @log.firewall prints the traceback
if 'status' not in d or d.status != 304: # Not modified
if 'etag' in d:
feed.etag = d.etag
@ -484,7 +493,7 @@ class RSS(callbacks.Plugin):
template = self.registryValue(key_name, channel, network)
date = entry.get('published_parsed')
date = utils.str.timestamp(date)
s = string.Template(template).substitute(
s = string.Template(template).safe_substitute(
entry,
feed_name=feed.name,
date=date)

View File

@ -31,6 +31,7 @@
import functools
from unittest.mock import patch
import socket
import sys
import feedparser
@ -362,7 +363,22 @@ class RSSTestCase(ChannelPluginTestCase):
timeFastForward(1.1)
mock._data = not_well_formed
self.assertRegexp('rss http://example.com/',
'Parser error')
'Parser error: .*mismatch')
def testSocketError(self):
class MockResponse:
headers = {}
url = ''
def read(self):
raise socket.error("oh no")
def close(self):
pass
mock = MockResponse()
with patch("urllib.request.OpenerDirector.open", return_value=mock):
timeFastForward(1.1)
self.assertRegexp('rss http://example.com/',
'Parser error: .*oh no')
if network:
timeout = 5 # Note this applies also to the above tests
@ -398,7 +414,7 @@ class RSSTestCase(ChannelPluginTestCase):
timeFastForward(1.1)
self.assertNotError('rss %s' % url)
m = self.assertNotError('rss %s 2' % url)
self.assertTrue(m.args[1].count(' | ') == 1)
self.assertEqual(m.args[1].count(' | '), 1)
def testRssAdd(self):
timeFastForward(1.1)

View File

@ -50,10 +50,12 @@ def configure(advanced):
class Ignores(registry.SpaceSeparatedListOf):
List = ircutils.IrcSet
Value = conf.ValidHostmask
sorted = True
class Networks(registry.SpaceSeparatedListOf):
List = ircutils.IrcSet
Value = registry.String
sorted = True
Relay = conf.registerPlugin('Relay')
conf.registerChannelValue(Relay, 'color',

View File

@ -63,6 +63,6 @@ class ReplyNonChannelTestCase(PluginTestCase):
self.prefix = 'something!else@somewhere.else'
self.nick = 'something'
m = self.assertAction('action foo', 'foo')
self.assertFalse(m.args[0] == self.irc.nick)
self.assertNotEqual(m.args[0], self.irc.nick)
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -148,6 +148,13 @@ class Scheduler(callbacks.Plugin):
channel=msg.channel, network=irc.network)
if remove:
del self.events[str(f.eventId)]
# A previous run of the command may have set 'ignored' to True,
# causing this run to not include response from nested commands;
# as NestedCommandsIrcProxy.reply() would confuse it with the
# subcommand setting 'ignored' to True itself.
msg.tag('ignored', False)
self.Proxy(irc, msg, tokens)
return f

View File

@ -89,7 +89,6 @@ class SchedulerTestCase(ChannelPluginTestCase):
self.assertResponse(
'scheduler list', 'There are currently no scheduled commands.')
def testRepeat(self):
self.assertRegexp('scheduler repeat repeater 5 echo testRepeat',
'testRepeat')
@ -132,6 +131,32 @@ class SchedulerTestCase(ChannelPluginTestCase):
timeFastForward(5)
self.assertNoResponse(' ', timeout=1)
def testRepeatWorksWithNestedCommandsWithNoReply(self):
# the 'trylater' command uses ircmsgs.privmsg + irc.noReply(),
# similar to how the Anonymous plugin implements sending messages
# to channels/users without .reply() (as it is technically not a
# reply to the origin message)
count = 0
class TryLater(callbacks.Plugin):
def trylater(self, irc, msg, args):
nonlocal count
msg = ircmsgs.privmsg(msg.nick, "%d %s" % (count, args))
irc.queueMsg(msg)
irc.noReply()
count += 1
cb = TryLater(self.irc)
self.irc.addCallback(cb)
try:
self.assertResponse('scheduler repeat foo 5 "trylater [echo foo]"',
"0 ['foo']")
timeFastForward(5)
self.assertResponse(' ', "1 ['foo']")
timeFastForward(5)
self.assertResponse(' ', "2 ['foo']")
finally:
self.irc.removeCallback('TryLater')
def testRepeatDisallowsIntegerNames(self):
self.assertError('scheduler repeat 1234 1234 "echo NoIntegerNames"')
@ -187,7 +212,5 @@ class SchedulerTestCase(ChannelPluginTestCase):
self.assertResponse(' ', 'testRepeat', timeout=1) # T+106
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -86,7 +86,7 @@ class ChannelDBTestCase(ChannelPluginTestCase):
self.assertError('seen *')
self.assertNotError('seen %s' % self.nick)
m = self.assertNotError('seen %s' % self.nick.upper())
self.assertTrue(self.nick.upper() in m.args[1])
self.assertIn(self.nick.upper(), m.args[1])
self.assertRegexp('seen user %s' % self.nick,
'^%s was last seen' % self.nick)
self.assertNotError('config plugins.Seen.minimumNonWildcard 0')

View File

@ -153,6 +153,14 @@ supybot.plugins.Services.disabledNetworks
Determines what networks this plugin will be disabled on.
.. _conf-supybot.plugins.Services.ghostCommand:
supybot.plugins.Services.ghostCommand
This config variable defaults to "GHOST", is network-specific, and is not channel-specific.
Determines the NickServ command to use for GHOST. If the network you're using runs Anope, set this to "RECOVER". If the network you're using runs Atheme, set this to "GHOST" or "REGAIN".
.. _conf-supybot.plugins.Services.ghostDelay:
@ -167,7 +175,7 @@ supybot.plugins.Services.ghostDelay
supybot.plugins.Services.nicks
This config variable defaults to " ", is network-specific, and is not channel-specific.
Determines what nicks the bot will use with services.
Space-separated list of nicks the bot will use with services.
.. _conf-supybot.plugins.Services.noJoinsUntilIdentified:

View File

@ -64,10 +64,11 @@ class ValidNickOrEmptyString(registry.String):
class ValidNickSet(conf.ValidNicks):
List = ircutils.IrcSet
sorted = True
Services = conf.registerPlugin('Services')
conf.registerNetworkValue(Services, 'nicks',
ValidNickSet([], _("""Determines what nicks the bot will use with
ValidNickSet([], _("""Space-separated list of nicks the bot will use with
services.""")))
class Networks(registry.SpaceSeparatedSetOfStrings):
@ -85,6 +86,10 @@ conf.registerNetworkValue(Services, 'noJoinsUntilIdentified',
conf.registerNetworkValue(Services, 'ghostDelay',
registry.NonNegativeInteger(60, _("""Determines how many seconds the bot will
wait between successive GHOST attempts. Set this to 0 to disable GHOST.""")))
conf.registerNetworkValue(Services, 'ghostCommand',
registry.String("GHOST", _("""Determines the NickServ command to use for GHOST. If the network
you're using runs Anope, set this to "RECOVER". If the network you're using runs Atheme,
set this to "GHOST" or "REGAIN".""")))
conf.registerNetworkValue(Services, 'NickServ',
ValidNickOrEmptyString('NickServ', _("""Determines what nick the 'NickServ' service
has.""")))

View File

@ -162,7 +162,8 @@ class Services(callbacks.Plugin):
else:
self.log.info('Sending ghost (current nick: %s; ghosting: %s)',
irc.nick, nick)
ghost = 'GHOST %s %s' % (nick, password)
ghostCommand = self.registryValue('ghostCommand', network=irc.network)
ghost = '%s %s %s' % (ghostCommand, nick, password)
# Ditto about the sendMsg (see _doIdentify).
irc.sendMsg(ircmsgs.privmsg(nickserv, ghost))
state.sentGhost = time.time()
@ -297,7 +298,7 @@ class Services(callbacks.Plugin):
elif irc.isChannel(msg.args[0]):
# Atheme uses channel-wide notices for alerting channel access
# changes if the FANTASY or VERBOSE setting is on; we can suppress
# these 'unexpected notice' warnings since they're not really
# these 'unexpected notice' warnings since they're not really
# important.
pass
else:

View File

@ -50,12 +50,12 @@ class ServicesTestCase(PluginTestCase):
try:
self.assertNotError('services password %s baz' % self.nick)
m = self.assertNotError('services identify')
self.assertTrue(m.args[0] == 'NickServ')
self.assertTrue(m.args[1].lower() == 'identify baz')
self.assertEqual(m.args[0], 'NickServ')
self.assertEqual(m.args[1].lower(), 'identify baz')
self.assertNotError('services password %s biff' % self.nick)
m = self.assertNotError('services identify')
self.assertTrue(m.args[0] == 'NickServ')
self.assertTrue(m.args[1].lower() == 'identify biff')
self.assertEqual(m.args[0], 'NickServ')
self.assertEqual(m.args[1].lower(), 'identify biff')
finally:
self.assertNotError('services password %s ""' % self.nick)
@ -84,8 +84,8 @@ class ServicesTestCase(PluginTestCase):
'Global: bar; test: bar2')
m = self.assertNotError('services identify')
self.assertTrue(m.args[0] == 'NickServ')
self.assertTrue(m.args[1].lower() == 'identify bar2')
self.assertEqual(m.args[0], 'NickServ')
self.assertEqual(m.args[1].lower(), 'identify bar2')
finally:
self.assertNotError('services password %s ""' % self.nick)

View File

@ -41,8 +41,8 @@ class StatusTestCase(PluginTestCase):
def testCpu(self):
m = self.assertNotError('status cpu')
self.assertFalse('kB kB' in m.args[1])
self.assertFalse('None' in m.args[1], 'None in cpu output: %r.' % m)
self.assertNotIn('kB kB', m.args[1])
self.assertNotIn('None', m.args[1], 'None in cpu output: %r.' % m)
for s in ['linux', 'freebsd', 'openbsd', 'netbsd', 'darwin']:
if sys.platform.startswith(s):
self.assertTrue('B' in m.args[1] or 'KB' in m.args[1] or

View File

@ -50,8 +50,8 @@ md5 <text>
.. _command-string-ord:
ord <letter>
Returns the unicode codepoint of <letter>.
ord <string>
Returns the unicode codepoint of characters in <string>.
.. _command-string-re:
@ -70,8 +70,8 @@ soundex <string> [<length>]
.. _command-string-unicodename:
unicodename <character>
Returns the name of the given unicode <character>.
unicodename <string>
Returns the name of characters in <string>. This will error if any character is not a valid Unicode character.
.. _command-string-unicodesearch:

View File

@ -51,13 +51,13 @@ import multiprocessing
class String(callbacks.Plugin):
"""Provides useful commands for manipulating characters and strings."""
def ord(self, irc, msg, args, letter):
"""<letter>
def ord(self, irc, msg, args, s):
"""<string>
Returns the unicode codepoint of <letter>.
Returns the unicode codepoint of characters in <string>.
"""
irc.reply(str(ord(letter)))
ord = wrap(ord, ['letter'])
irc.replies([str(ord(char)) for char in s])
ord = wrap(ord, ['text'])
def chr(self, irc, msg, args, i):
"""<number>
@ -70,17 +70,20 @@ class String(callbacks.Plugin):
irc.error(_('That number doesn\'t map to a unicode character.'))
chr = wrap(chr, ['int'])
def unicodename(self, irc, msg, args, character):
"""<character>
def unicodename(self, irc, msg, args, s):
"""<string>
Returns the name of the given unicode <character>."""
if len(character) != 1:
irc.errorInvalid('character', character)
try:
irc.reply(unicodedata.name(character))
except ValueError:
irc.error(_('No name found for this character.'))
unicodename = wrap(unicodename, ['something'])
Returns the name of characters in <string>.
This will error if any character is not a valid Unicode character."""
replies = []
for idx, char in enumerate(s):
try:
replies.append(unicodedata.name(char))
except ValueError:
irc.error(_('No name found for character %r at position %d.') %
(char, idx), Raise=True)
irc.replies(replies)
unicodename = wrap(unicodename, ['text'])
def unicodesearch(self, irc, msg, args, name):
"""<name>

View File

@ -103,13 +103,21 @@ class StringTestCase(PluginTestCase):
for c in map(chr, range(256)):
i = ord(c)
self.assertResponse('ord %s' % utils.str.dqrepr(c), str(i))
self.assertResponse('ord é', '233')
self.assertResponse('ord 🆒', '127378')
self.assertResponse('ord 🇦🇶', '127462 and 127478')
def testUnicode(self):
self.assertResponse('unicodename ☃', 'SNOWMAN')
self.assertResponse('unicodesearch SNOWMAN', '')
#self.assertResponse('unicodename ?',
# 'No name found for this character.')
self.assertResponse('unicodename ?', 'QUESTION MARK')
# multi-char strings and ZWJ sequences
self.assertResponse('unicodename :O', 'COLON and LATIN CAPITAL LETTER O')
self.assertResponse('unicodename 🤷‍♂️', 'SHRUG, ZERO WIDTH JOINER, MALE SIGN, and VARIATION SELECTOR-16')
self.assertError('unicodename "\\uFFFF"')
self.assertError('unicodename "!@#\\uFFFF$"')
self.assertResponse('unicodesearch FOO',
'Error: No character found with this name.')

View File

@ -72,10 +72,16 @@ try:
except ImportError:
tzlocal = None
# Note: Python 3.6 does not support empty pattern matches, see:
# https://docs.python.org/3/library/re.html#re.split
_SECONDS_SPLIT_RE = re.compile('(?<=[a-z]) ?')
class Time(callbacks.Plugin):
"""This plugin allows you to use different time-related functions."""
@internationalizeDocstring
def seconds(self, irc, msg, args):
def seconds(self, irc, msg, args, text):
"""[<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s]
Returns the number of seconds in the number of <years>, <weeks>,
@ -84,11 +90,13 @@ class Time(callbacks.Plugin):
Useful for scheduling events at a given number of seconds in the
future.
"""
if not args:
raise callbacks.ArgumentError
seconds = 0
for arg in args:
if not arg or arg[-1] not in 'ywdhms':
if not text:
raise callbacks.ArgumentError
for arg in _SECONDS_SPLIT_RE.split(text):
if not arg:
continue
if arg[-1] not in 'ywdhms':
raise callbacks.ArgumentError
(s, kind) = arg[:-1], arg[-1]
try:
@ -108,6 +116,7 @@ class Time(callbacks.Plugin):
elif kind == 's':
seconds += i
irc.reply(str(seconds))
seconds = wrap(seconds, ['text'])
@internationalizeDocstring
def at(self, irc, msg, args, s=None):

View File

@ -88,6 +88,17 @@ class TimeTestCase(PluginTestCase):
self.assertResponse('seconds 1y 1s', '31536001')
self.assertResponse('seconds 1w 1s', '604801')
@skipIf(sys.version_info < (3, 7, 0),
"Python 3.6 does not support empty pattern matches, see: "
"https://docs.python.org/3/library/re.html#re.split")
def testSecondsNoSpace(self):
self.assertResponse('seconds 1m1s', '61')
self.assertResponse('seconds 1h1s', '3601')
self.assertResponse('seconds 1d1s', '86401')
self.assertResponse('seconds 2d2h2m2s', '180122')
self.assertResponse('seconds 1y1s', '31536001')
self.assertResponse('seconds 1w1s', '604801')
def testNoErrors(self):
self.assertNotError('ctime')
self.assertNotError('time %Y')

View File

@ -129,7 +129,7 @@ class TopicTestCase(ChannelPluginTestCase):
conf.supybot.plugins.Topic.separator.setValue(' <==> ')
_ = self.getMsg('topic add foo')
m = self.getMsg('topic add bar')
self.assertTrue('<==>' in m.args[1])
self.assertIn('<==>', m.args[1])
finally:
conf.supybot.plugins.Topic.separator.setValue(original)

View File

@ -1,7 +1,7 @@
###
# Copyright (c) 2002-2004, Jeremiah Fincher
# Copyright (c) 2010, James McCoy
# Copyright (c) 2010-2021, Valentin Lorentz
# Copyright (c) 2010-2022, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -29,6 +29,8 @@
# POSSIBILITY OF SUCH DAMAGE.
###
import itertools
import supybot.dbi as dbi
import supybot.conf as conf
import supybot.utils as utils
@ -57,9 +59,7 @@ class DbiUrlDB(plugins.DbiChannelDB):
near=msg.args[1], at=msg.receivedAt)
super(self.__class__, self).add(record)
def urls(self, p):
L = list(self.select(p))
L.reverse()
return L
return self.select(p, reverse=True)
URLDB = plugins.DB('URL', {'flat': DbiUrlDB})
@ -142,16 +142,18 @@ class URL(callbacks.Plugin):
if not predicate(record):
return False
return True
urls = [record.url for record in self.db.urls(channel, predicate)]
if not urls:
urls = (record.url for record in self.db.urls(channel, predicate))
(urls, urls_copy) = itertools.tee(urls)
first_url = next(urls_copy, None)
if first_url is None:
irc.reply(_('No URLs matched that criteria.'))
else:
if nolimit:
urls = [format('%u', url) for url in urls]
urls = (format('%u', url) for url in urls)
s = ', '.join(urls)
else:
# We should optimize this with another URLDB method eventually.
s = urls[0]
s = first_url
irc.reply(s)
last = wrap(last, ['channeldb',
getopts({'from': 'something', 'with': 'something',

View File

@ -448,7 +448,8 @@ class User(callbacks.Plugin):
irc.errorNotRegistered()
else:
if u == user or u._checkCapability('admin'):
irc.reply('[%s]' % '; '.join(user.capabilities), private=True)
irc.reply('[%s]' % '; '.join(sorted(user.capabilities)),
private=True)
else:
irc.error(conf.supybot.replies.incorrectAuthentication(),
Raise=True)

View File

@ -104,7 +104,7 @@ class UserTestCase(PluginTestCase):
self.assertResponse('hostmask', self.prefix)
self.assertError('@hostmask asdf')
m = self.irc.takeMsg()
self.assertFalse(m is not None, m)
self.assertIsNone(m, m)
def testRegisterPasswordLength(self):
self.assertRegexp('register foo aa', 'at least 3 characters long.')
@ -131,7 +131,7 @@ class UserTestCase(PluginTestCase):
try:
self.assertError('unregister foo')
m = self.irc.takeMsg()
self.assertFalse(m is not None, m)
self.assertIsNone(m, m)
self.assertTrue(ircdb.users.getUserId('foo'))
finally:
conf.supybot.databases.users.allowUnregistration.setValue(orig)

View File

@ -154,7 +154,7 @@ class Web(callbacks.PluginRegexp):
if parsed_url.netloc == 'youtube.com' \
or parsed_url.netloc.endswith(('.youtube.com')):
# there is a lot of Javascript before the <title>
size = 409600
size = max(409600, size)
if parsed_url.netloc in ('reddit.com', 'www.reddit.com', 'new.reddit.com'):
# Since 2022-03, New Reddit has 'Reddit - Dive into anything' as
# <title> on every page.
@ -164,8 +164,17 @@ class Web(callbacks.PluginRegexp):
timeout = self.registryValue('timeout')
headers = conf.defaultHttpHeaders(irc.network, msg.channel)
try:
(target, text) = utils.web.getUrlTargetAndContent(url, size=size,
timeout=timeout, headers=headers)
fd = utils.web.getUrlFd(url, timeout=timeout, headers=headers)
target = fd.geturl()
text = fd.read(size)
response_headers = fd.headers
fd.close()
except socket.timeout:
if raiseErrors:
irc.error(_('Connection to %s timed out') % url, Raise=True)
else:
selg.log.info('Web plugins TitleSnarfer: URL <%s> timed out',
url)
except Exception as e:
if raiseErrors:
irc.error(_('That URL raised <' + str(e)) + '>',
@ -174,9 +183,19 @@ class Web(callbacks.PluginRegexp):
self.log.info('Web plugin TitleSnarfer: URL <%s> raised <%s>',
url, str(e))
return
encoding = None
if 'Content-Type' in fd.headers:
mime_params = [p.split('=', 1)
for p in fd.headers['Content-Type'].split(';')[1:]]
mime_params = {k.strip(): v.strip() for (k, v) in mime_params}
if mime_params.get('charset'):
encoding = mime_params['charset']
encoding = encoding or utils.web.getEncoding(text) or 'utf8'
try:
text = text.decode(utils.web.getEncoding(text) or 'utf8',
'replace')
text = text.decode(encoding, 'replace')
except UnicodeDecodeError:
if minisix.PY3:
if raiseErrors:

View File

@ -1,10 +1,17 @@
# mandatory:
setuptools
chardet
pytz;python_version<'3.9'
python-dateutil
python-gnupg
feedparser
PySocks
mock
cryptography
pyxmpp2-scram
# optional core dependencies:
chardet # to detect encoding of incoming IRC lines, if they are not in UTF-8
python-gnupg # for authenticated based on GPG tokens
PySocks # for SOCKS proxy (typically used to connect to IRC via Tor)
pyxmpp2-scram # for the scram-sha-256 SASL mechanism
# optional plugin dependencies:
cryptography # required to load the Fediverse plugin (used to implement HTTP signatures to support Mastodon instances with AUTHORIZED_FETCH=true)
feedparser # required to load the RSS plugin
pytz;python_version<'3.9' # enables timezone manipulation in the Time and Geography plugins. On Python >=3.9, the standard library is used instead
python-dateutil # enable fancy time string parsing in the Time plugin

View File

@ -990,10 +990,12 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
self.error(_('You\'ve attempted more nesting than is '
'currently allowed on this bot.'))
return
# The deepcopy here is necessary for Scheduler; it re-runs already
# tokenized commands. There's a possibility a simple copy[:] would
# work, but we're being careful.
self.args = copy.deepcopy(args)
self.counter = 0
self._resetReplyAttributes()
if not args:
@ -1804,6 +1806,19 @@ class PluginRegexp(Plugin):
def doPrivmsg(self, irc, msg):
if msg.isError:
return
if 'batch' in msg.server_tags:
parent_batches = irc.state.getParentBatches(msg)
parent_batch_types = [batch.type for batch in parent_batches]
if 'chathistory' in parent_batch_types:
# Either sent automatically by the server upon join,
# or triggered by a plugin (why?!)
# Either way, replying to messages from the history would
# look weird, because they may have been sent a while ago,
# and we may have already answered them.
# (this is the same behavior as in Owner.doPrivmsg)
return
proxy = self.Proxy(irc, msg)
if not msg.addressed:
for (r, name) in self.unaddressedRes:

View File

@ -50,6 +50,13 @@ from .utils import minisix
from .i18n import PluginInternationalization, internationalizeDocstring
_ = PluginInternationalization()
LOG_CONVERTERS = world.testing
"""Defines whether converters and contexts should log the argument stack
while parsing it.
Disabled by default (unless running via supybot-test) as it is very noisy
and rarely needs to be debugged.
"""
###
# Non-arg wrappers -- these just change the behavior of a command without
# changing the arguments given to it.
@ -509,7 +516,8 @@ def getChannel(irc, msg, args, state):
elif msg.channel:
channel = msg.channel
else:
state.log.debug('Raising ArgumentError because there is no channel.')
if LOG_CONVERTERS:
state.log.debug('Raising ArgumentError because there is no channel.')
raise callbacks.ArgumentError
state.channel = channel
state.args.append(channel)
@ -520,7 +528,8 @@ def getChannels(irc, msg, args, state):
elif msg.channel:
channels = [msg.channel]
else:
state.log.debug('Raising ArgumentError because there is no channel.')
if LOG_CONVERTERS:
state.log.debug('Raising ArgumentError because there is no channel.')
raise callbacks.ArgumentError
state.args.append(channels)
@ -898,9 +907,11 @@ class context(object):
self.converter = spec
def __call__(self, irc, msg, args, state):
log.debug('args before %r: %r', self, args)
if LOG_CONVERTERS:
log.debug('args before %r: %r', self, args)
self.converter(irc, msg, args, state, *self.args)
log.debug('args after %r: %r', self, args)
if LOG_CONVERTERS:
log.debug('args after %r: %r', self, args)
def __repr__(self):
return '<%s for %s>' % (self.__class__.__name__, self.spec)
@ -929,7 +940,8 @@ class additional(context):
try:
self.__parent.__call__(irc, msg, args, state)
except IndexError:
log.debug('Got IndexError, returning default.')
if LOG_CONVERTERS:
log.debug('Got IndexError, returning default.')
setDefault(state, self.default)
# optional means: Look for this, but if it's not the type I'm expecting or
@ -939,7 +951,8 @@ class optional(additional):
try:
super(optional, self).__call__(irc, msg, args, state)
except (callbacks.ArgumentError, callbacks.Error) as e:
log.debug('Got %s, returning default.', utils.exnToString(e))
if LOG_CONVERTERS:
log.debug('Got %s, returning default.', utils.exnToString(e))
state.errored = False
setDefault(state, self.default)
@ -960,7 +973,8 @@ class any(context):
if not self.continueOnError:
raise
else:
log.debug('Got %s, returning default.', utils.exnToString(e))
if LOG_CONVERTERS:
log.debug('Got %s, returning default.', utils.exnToString(e))
pass
state.args.append(st.args)
@ -1041,11 +1055,13 @@ class getopts(context):
self.getopts[name] = contextify(spec)
self.getoptL.append(name + '=')
self.getopts[name] = contextify(spec)
log.debug('getopts: %r', self.getopts)
log.debug('getoptL: %r', self.getoptL)
if LOG_CONVERTERS:
log.debug('getopts: %r', self.getopts)
log.debug('getoptL: %r', self.getoptL)
def __call__(self, irc, msg, args, state):
log.debug('args before %r: %r', self, args)
if LOG_CONVERTERS:
log.debug('args before %r: %r', self, args)
(optlist, rest) = getopt.getopt(args, self.getoptLs, self.getoptL)
getopts = []
for (opt, arg) in optlist:
@ -1053,7 +1069,8 @@ class getopts(context):
opt = opt[2:] # Strip --
else:
opt = opt[1:]
log.debug('opt: %r, arg: %r', opt, arg)
if LOG_CONVERTERS:
log.debug('opt: %r, arg: %r', opt, arg)
context = self.getopts[opt]
if context is not None:
st = state.essence()
@ -1064,7 +1081,8 @@ class getopts(context):
getopts.append((opt, True))
state.args.append(getopts)
args[:] = rest
log.debug('args after %r: %r', self, args)
if LOG_CONVERTERS:
log.debug('args after %r: %r', self, args)
###
# This is our state object, passed to converters along with irc, msg, and args.
@ -1123,7 +1141,8 @@ class Spec(object):
except IndexError:
raise callbacks.ArgumentError
if args and not state.allowExtra:
log.debug('args and not self.allowExtra: %r', args)
if LOG_CONVERTERS:
log.debug('args and not self.allowExtra: %r', args)
raise callbacks.ArgumentError
return state
@ -1134,9 +1153,11 @@ def _wrap(f, specList=[], name=None, checkDoc=True, **kw):
spec = Spec(specList, **kw)
def newf(self, irc, msg, args, **kwargs):
state = spec(irc, msg, args, stateAttrs={'cb': self, 'log': self.log})
self.log.debug('State before call: %s', state)
if LOG_CONVERTERS:
self.log.debug('State before call: %s', state)
if state.errored:
self.log.debug('Refusing to call %s due to state.errored.', f)
if LOG_CONVERTERS:
self.log.debug('Refusing to call %s due to state.errored.', f)
else:
try:
f(self, irc, msg, args, *state.args, **state.kwargs)

View File

@ -1318,7 +1318,7 @@ registerGlobalValue(supybot.protocols.irc.queuing.rateLimit, 'join',
###
registerGroup(supybot.protocols, 'http')
registerGlobalValue(supybot.protocols.http, 'peekSize',
registry.PositiveInteger(8192, _("""Determines how many bytes the bot will
registry.PositiveInteger(16384, _("""Determines how many bytes the bot will
'peek' at when looking through a URL for a doctype or title or something
similar. It'll give up after it reads this many bytes, even if it hasn't
found what it was looking for.""")))

View File

@ -1,6 +1,6 @@
###
# Copyright (c) 2002-2005, Jeremiah Fincher
# Copyright (c) 2010-2021, Valentin Lorentz
# Copyright (c) 2010-2022, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -150,7 +150,7 @@ class FlatfileMapping(MappingInterface):
def __init__(self, filename, maxSize=10**6):
self.filename = filename
try:
fd = open(self.filename)
fd = open(self.filename, encoding='utf8')
strId = fd.readline().rstrip()
self.maxSize = len(strId)
try:
@ -175,7 +175,7 @@ class FlatfileMapping(MappingInterface):
def _incrementCurrentId(self, fd=None):
fdWasNone = fd is None
if fdWasNone:
fd = open(self.filename, 'a')
fd = open(self.filename, 'a', encoding='utf8')
fd.seek(0)
self.currentId += 1
fd.write(self._canonicalId(self.currentId))
@ -193,7 +193,7 @@ class FlatfileMapping(MappingInterface):
def add(self, s):
line = self._joinLine(self.currentId, s)
fd = open(self.filename, 'r+')
fd = open(self.filename, 'r+', encoding='utf8')
try:
fd.seek(0, 2) # End.
fd.write(line)
@ -205,7 +205,7 @@ class FlatfileMapping(MappingInterface):
def get(self, id):
strId = self._canonicalId(id)
try:
fd = open(self.filename)
fd = open(self.filename, encoding='utf8')
fd.readline() # First line, nextId.
for line in fd:
(lineId, s) = self._splitLine(line)
@ -221,7 +221,7 @@ class FlatfileMapping(MappingInterface):
def set(self, id, s):
strLine = self._joinLine(id, s)
try:
fd = open(self.filename, 'r+')
fd = open(self.filename, 'r+', encoding='utf8')
self.remove(id, fd)
fd.seek(0, 2) # End.
fd.write(strLine)
@ -233,7 +233,7 @@ class FlatfileMapping(MappingInterface):
strId = self._canonicalId(id)
try:
if fdWasNone:
fd = open(self.filename, 'r+')
fd = open(self.filename, 'r+', encoding='utf8')
fd.seek(0)
fd.readline() # First line, nextId
pos = fd.tell()
@ -262,7 +262,7 @@ class FlatfileMapping(MappingInterface):
fd.close()
def vacuum(self):
infd = open(self.filename)
infd = open(self.filename, encoding='utf8')
outfd = utils.file.AtomicFile(self.filename,makeBackupIfSmaller=False)
outfd.write(infd.readline()) # First line, nextId.
for line in infd:
@ -358,12 +358,30 @@ class DB(object):
self.map.remove(id)
def __iter__(self):
for (id, s) in self.map:
yield from self._iter()
def _iter(self, *, reverse=False):
if reverse:
if hasattr(self.map, "__reversed__"):
# neither FlatfileMapping nor CdbMapping support __reversed__
# and DirMapping does not support iteration at all, but
# there is no harm in allowing this short-path in case
# plugins use their own mapping.
it = reversed(self.map)
else:
# This does load the whole database in memory instead of
# iterating lazily, but plugins requesting a reverse list
# would probably need do it themselves otherwise, so it does
# not make matters worse to do it here.
it = reversed(list(self.map))
else:
it = self.map
for (id, s) in it:
# We don't need to yield the id because it's in the record.
yield self._newRecord(id, s)
def select(self, p):
for record in self:
def select(self, p, reverse=False):
for record in self._iter(reverse=reverse):
if p(record):
yield record

View File

@ -70,8 +70,6 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
self._attempt = -1
self.servers = ()
self.eagains = 0
self.inbuffer = b''
self.outbuffer = ''
self.zombie = False
self.connected = False
self.writeCheckTime = None
@ -248,6 +246,8 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
def reconnect(self, wait=False, reset=True, server=None):
self._attempt += 1
self.inbuffer = b''
self.outbuffer = ''
self.nextReconnectTime = None
if self.connected:
self.onDisconnect()

View File

@ -1314,7 +1314,7 @@ def checkCapabilities(hostmask, capabilities, requireAll=False):
# supybot.capabilities
###
class SpaceSeparatedListOfCapabilities(registry.SpaceSeparatedListOfStrings):
class SpaceSeparatedListOfCapabilities(registry.SpaceSeparatedSetOfStrings):
__slots__ = ()
List = CapabilitySet

View File

@ -624,7 +624,7 @@ class IrcState(IrcCommandDispatcher, log.Firewalled):
:type: Set[str]
.. attribute:: capabilities_acq
.. attribute:: capabilities_ack
Set of all capabilities requested from and acknowledged by the
server. See <https://ircv3.net/specs/core/capability-negotiation>
@ -676,7 +676,7 @@ class IrcState(IrcCommandDispatcher, log.Firewalled):
:type: ircutils.IrcDict[str, ChannelState]
.. attribute:: nickToHostmask
.. attribute:: nicksToHostmasks
Stores the last hostmask of a seen nick.
@ -1731,20 +1731,41 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
self.sasl_current_mechanism = None
for mechanism in network_config.sasl.mechanisms():
if mechanism == 'ecdsa-nist256p-challenge' and \
crypto and self.sasl_username and \
self.sasl_ecdsa_key:
self.sasl_next_mechanisms.append(mechanism)
elif mechanism == 'external' and (
network_config.certfile() or
conf.supybot.protocols.irc.certfile()):
self.sasl_next_mechanisms.append(mechanism)
elif mechanism.startswith('scram-') and scram and \
self.sasl_username and self.sasl_password:
self.sasl_next_mechanisms.append(mechanism)
elif mechanism == 'plain' and \
self.sasl_username and self.sasl_password:
self.sasl_next_mechanisms.append(mechanism)
if mechanism == 'ecdsa-nist256p-challenge':
if not crypto:
log.debug('Skipping SASL %s, crypto module '
'is not available',
mechanism)
elif not self.sasl_username or not self.sasl_ecdsa_key:
log.debug('Skipping SASL %s, missing username and/or key',
mechanism)
else:
self.sasl_next_mechanisms.append(mechanism)
elif mechanism == 'external':
if not network_config.certfile() and \
not conf.supybot.protocols.irc.certfile():
log.debug('Skipping SASL %s, missing cert file',
mechanism)
else:
self.sasl_next_mechanisms.append(mechanism)
elif mechanism.startswith('scram-'):
if not scram:
log.debug('Skipping SASL %s, scram module '
'is not available',
mechanism)
elif not self.sasl_username or not self.sasl_password:
log.debug('Skipping SASL %s, missing username and/or '
'password',
mechanism)
else:
self.sasl_next_mechanisms.append(mechanism)
elif mechanism == 'plain':
if not self.sasl_username or not self.sasl_password:
log.debug('Skipping SASL %s, missing username and/or '
'password',
mechanism)
else:
self.sasl_next_mechanisms.append(mechanism)
if self.sasl_next_mechanisms:
self.REQUEST_CAPABILITIES.add('sasl')
@ -1755,7 +1776,8 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
'multi-prefix', 'metadata-notify', 'account-tag',
'userhost-in-names', 'invite-notify', 'server-time',
'chghost', 'batch', 'away-notify', 'message-tags',
'msgid', 'setname', 'labeled-response', 'echo-message'])
'msgid', 'setname', 'labeled-response', 'echo-message',
'standard-replies'])
"""IRCv3 capabilities requested when they are available.
echo-message is special-cased to be requested only with labeled-response.
@ -1862,6 +1884,7 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
IrcStateFsm.States.INIT_SASL,
IrcStateFsm.States.CONNECTED_SASL,
])
log.debug('Next SASL mechanisms: %s', self.sasl_next_mechanisms)
if self.sasl_next_mechanisms:
self.sasl_current_mechanism = self.sasl_next_mechanisms.pop(0)
self.sendMsg(ircmsgs.IrcMsg(command='AUTHENTICATE',
@ -1905,7 +1928,7 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
mechanism = self.sasl_current_mechanism
if mechanism == 'ecdsa-nist256p-challenge':
self._doAuthenticateEcdsa(string)
self._doAuthenticateEcdsa(msg, string)
elif mechanism == 'external':
self.sendSaslString(b'')
elif mechanism.startswith('scram-'):
@ -1914,7 +1937,7 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
if step == 'uninitialized':
log.debug('%s: starting SCRAM.',
self.network)
self._doAuthenticateScramFirst(mechanism)
self._doAuthenticateScramFirst(msg, mechanism)
elif step == 'first-sent':
log.debug('%s: received SCRAM challenge.',
self.network)
@ -1922,13 +1945,13 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
elif step == 'final-sent':
log.debug('%s: finishing SCRAM.',
self.network)
self._doAuthenticateScramFinish(string)
self._doAuthenticateScramFinish(msg, string)
else:
assert False
except scram.ScramException:
self.sendMsg(ircmsgs.IrcMsg(command='AUTHENTICATE',
args=('*',)))
self.tryNextSaslMechanism()
self.tryNextSaslMechanism(msg)
elif mechanism == 'plain':
authstring = b'\0'.join([
self.sasl_username.encode('utf-8'),
@ -1937,7 +1960,7 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
])
self.sendSaslString(authstring)
def _doAuthenticateEcdsa(self, string):
def _doAuthenticateEcdsa(self, msg, string):
if string == b'':
self.sendSaslString(self.sasl_username.encode('utf-8'))
return
@ -1952,9 +1975,9 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
except (OSError, ValueError):
self.sendMsg(ircmsgs.IrcMsg(command='AUTHENTICATE',
args=('*',)))
self.tryNextSaslMechanism()
self.tryNextSaslMechanism(msg)
def _doAuthenticateScramFirst(self, mechanism):
def _doAuthenticateScramFirst(self, msg, mechanism):
"""Handle sending the client-first message of SCRAM auth."""
hash_name = mechanism[len('scram-'):]
if hash_name.endswith('-plus'):
@ -1963,7 +1986,7 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
if hash_name not in scram.HASH_FACTORIES:
log.debug('%s: SCRAM hash %r not supported, aborting.',
self.network, hash_name)
self.tryNextSaslMechanism()
self.tryNextSaslMechanism(msg)
return
authenticator = scram.SCRAMClientAuthenticator(hash_name,
channel_binding=False)
@ -1981,14 +2004,16 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
self.sendSaslString(client_final)
self.sasl_scram_state['step'] = 'final-sent'
def _doAuthenticateScramFinish(self, data):
def _doAuthenticateScramFinish(self, msg, data):
try:
res = self.sasl_scram_state['authenticator'] \
.finish(data)
except scram.BadSuccessException as e:
log.warning('%s: SASL authentication failed with SCRAM error: %e',
self.network, e)
self.tryNextSaslMechanism()
self.sendMsg(ircmsgs.IrcMsg(command='AUTHENTICATE',
args=('*',)))
self.tryNextSaslMechanism(msg)
else:
self.sendSaslString(b'')
self.sasl_scram_state['step'] = 'authenticated'

View File

@ -84,7 +84,7 @@ def open_registry(filename, clear=False):
global _lastModified
if clear:
_cache.clear()
_fd = open(filename)
_fd = open(filename, encoding='utf8')
fd = utils.file.nonCommentNonEmptyLines(_fd)
acc = ''
slashEnd = re.compile(r'\\*$')
@ -710,7 +710,7 @@ class OnlySomeStrings(String):
def setValue(self, s):
v = self.normalize(s)
if s in self.validStrings:
if v in self.validStrings:
self.__parent.setValue(v)
else:
self.error(v)
@ -875,6 +875,7 @@ class SpaceSeparatedListOfStrings(SpaceSeparatedListOf):
class SpaceSeparatedSetOfStrings(SpaceSeparatedListOfStrings):
__slots__ = ()
List = set
sorted = True
class CommaSeparatedListOfStrings(SeparatedListOf):
__slots__ = ()
@ -887,6 +888,7 @@ class CommaSeparatedSetOfStrings(SeparatedListOf):
__slots__ = ()
List = set
Value = String
sorted = True
def splitter(self, s):
return re.split(r'\s*,\s*', s)
joiner = ', '.join

View File

@ -297,7 +297,7 @@ def main():
'with the plugin\'s name and "$format" with the value '
'if --format.')
parser.add_option('-f', '--format', dest='format', choices=['rst', 'stx'],
default='stx', help='Specifies which output format to '
default='rst', help='Specifies which output format to '
'use.')
parser.add_option('--plugins-dir',
action='append', dest='pluginsDirs', default=[],

View File

@ -79,7 +79,14 @@ if setuptools:
break
module_name = kwargs['name'].replace('-', '_')
kwargs.setdefault('packages', [module_name])
if 'packages' not in kwargs:
kwargs["packages"] = [module_name] + [
"%s.%s" % (module_name, package_name.replace('-', '_'))
for package_name
in setuptools.find_packages(where=".")
]
kwargs.setdefault('package_dir', {module_name: '.'})
kwargs.setdefault('entry_points', {
'limnoria.plugins': '%s = %s' % (capitalized_name, module_name)})

View File

@ -70,7 +70,7 @@ class Reader(object):
return s.lower()
def readFile(self, filename):
self.read(open(filename))
self.read(open(filename, encoding='utf8'))
def read(self, fd):
lineno = 0

View File

@ -130,7 +130,9 @@ def chunks(fd, size):
class AtomicFile(object):
"""Used for files that need to be atomically written -- i.e., if there's a
failure, the original file remains, unmodified. mode must be 'w' or 'wb'"""
failure, the original file remains, unmodified. mode must be 'w' or 'wb'.
If ``encoding`` is None (or not provided), files are open in `utf8` regardless
of the system locale."""
class default(object): # Holder for values.
# Callables?
tmpDir = None

View File

@ -1,6 +1,6 @@
###
# Copyright (c) 2002-2009, Jeremiah Fincher
# Copyright (c) 2010-2021, Valentin Lorentz
# Copyright (c) 2010-2022, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -349,7 +349,10 @@ class TimeoutQueue(object):
return self.queue.dequeue()[1]
def __iter__(self):
# We could _clearOldElements here, but what happens if someone stores
self._clearOldElements()
# You may think re-checking _getTimeout() after we just called
# _clearOldElements is redundant, but what happens if someone stores
# the resulting generator and elements that should've timed out are
# yielded? Hmm? What happens then, smarty-pants?
for (t, elt) in self.queue:

View File

@ -226,6 +226,8 @@ def getEncoding(s):
# From beautifulsoup (version 4.10.0, bs4/builder/__init__.py, line 391)
_block_elements = set(["address", "article", "aside", "blockquote", "canvas", "dd", "div", "dl", "dt", "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hr", "li", "main", "nav", "noscript", "ol", "output", "p", "pre", "section", "table", "tfoot", "ul", "video"])
_block_elements.update({"br"})
class HtmlToText(HTMLParser, object):
"""Taken from some eff-bot code on c.l.p."""
entitydefs = entitydefs.copy()

View File

@ -1,6 +1,6 @@
###
# Copyright (c) 2005, Jeremiah Fincher
# Copyright (c) 2010-2021, The Limnoria Contributors
# Copyright (c) 2010-2021, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

17
test/messages.pot Normal file
View File

@ -0,0 +1,17 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2022-02-05 23:49+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"

View File

@ -1,6 +1,6 @@
###
# Copyright (c) 2005, Jeremiah Fincher
# Copyright (c) 2010-2021, The Limnoria Contributors
# Copyright (c) 2010-2021, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@ -1,7 +1,7 @@
# -*- coding: utf8 -*-
###
# Copyright (c) 2002-2005, Jeremiah Fincher
# Copyright (c) 2010-2021, The Limnoria Contributors
# Copyright (c) 2010-2021, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -417,14 +417,14 @@ class PrivmsgTestCase(ChannelPluginTestCase):
def testReplyWithNickPrefix(self):
self.feedMsg('@len foo')
m = self.irc.takeMsg()
self.assertTrue(m is not None, 'm: %r' % m)
self.assertIsNotNone(m, 'm: %r' % m)
self.assertTrue(m.args[1].startswith(self.nick))
try:
original = conf.supybot.reply.withNickPrefix()
conf.supybot.reply.withNickPrefix.setValue(False)
self.feedMsg('@len foobar')
m = self.irc.takeMsg()
self.assertTrue(m is not None)
self.assertIsNotNone(m)
self.assertFalse(m.args[1].startswith(self.nick))
finally:
conf.supybot.reply.withNickPrefix.setValue(original)
@ -448,7 +448,7 @@ class PrivmsgTestCase(ChannelPluginTestCase):
conf.supybot.reply.error.withNotice.setValue(True)
m = self.getMsg("eval irc.error('foo')")
self.assertTrue(m, 'No message returned.')
self.assertTrue(m.command == 'NOTICE')
self.assertEqual(m.command, 'NOTICE')
finally:
conf.supybot.reply.error.withNotice.setValue(original)
@ -975,16 +975,50 @@ class MultilinePrivmsgTestCase(ChannelPluginTestCase):
'-' + batch_name,)))
class PluginRegexpTestCase(PluginTestCase):
class PluginRegexpTestCase(ChannelPluginTestCase):
plugins = ()
class PCAR(callbacks.PluginRegexp):
regexps = ("test", "test2")
def test(self, irc, msg, args):
"<foo>"
raise callbacks.ArgumentError
def testNoEscapingArgumentError(self):
def test2(self, irc, msg, args):
"<bar>"
irc.reply("hello")
def setUp(self):
super().setUp()
self.irc.addCallback(self.PCAR(self.irc))
def testNoEscapingArgumentError(self):
self.assertResponse('test', 'test <foo>')
def testReply(self):
self.irc.feedMsg(ircmsgs.IrcMsg(
prefix=self.prefix,
command='PRIVMSG',
args=(self.channel, 'foo <bar> baz')))
self.assertResponse(' ', 'hello')
def testIgnoreChathistory(self):
self.irc.feedMsg(ircmsgs.IrcMsg(
command='BATCH',
args=('+123', 'chathistory', self.channel)))
self.irc.feedMsg(ircmsgs.IrcMsg(
server_tags={'batch': '123'},
prefix=self.prefix,
command='PRIVMSG',
args=(self.channel, 'foo <bar> baz')))
self.irc.feedMsg(ircmsgs.IrcMsg(
command='BATCH',
args=('-123',)))
self.assertNoResponse(' ')
class RichReplyMethodsTestCase(PluginTestCase):
plugins = ('Config',)
class NoCapability(callbacks.Plugin):
@ -1078,10 +1112,10 @@ class WithPrivateNoticeTestCase(ChannelPluginTestCase):
self.irc.addCallback(self.WithPrivateNotice(self.irc))
# Check normal behavior.
m = self.assertNotError('normal')
self.assertFalse(m.command == 'NOTICE')
self.assertNotEqual(m.command, 'NOTICE')
self.assertTrue(ircutils.isChannel(m.args[0]))
m = self.assertNotError('explicit')
self.assertFalse(m.command == 'NOTICE')
self.assertNotEqual(m.command, 'NOTICE')
self.assertTrue(ircutils.isChannel(m.args[0]))
# Check abnormal behavior.
originalInPrivate = conf.supybot.reply.inPrivate()
@ -1090,10 +1124,10 @@ class WithPrivateNoticeTestCase(ChannelPluginTestCase):
conf.supybot.reply.inPrivate.setValue(True)
conf.supybot.reply.withNotice.setValue(True)
m = self.assertNotError('normal')
self.assertTrue(m.command == 'NOTICE')
self.assertEqual(m.command, 'NOTICE')
self.assertFalse(ircutils.isChannel(m.args[0]))
m = self.assertNotError('explicit')
self.assertFalse(m.command == 'NOTICE')
self.assertNotEqual(m.command, 'NOTICE')
self.assertTrue(ircutils.isChannel(m.args[0]))
finally:
conf.supybot.reply.inPrivate.setValue(originalInPrivate)
@ -1102,10 +1136,10 @@ class WithPrivateNoticeTestCase(ChannelPluginTestCase):
try:
conf.supybot.reply.withNoticeWhenPrivate.setValue(True)
m = self.assertNotError('implicit')
self.assertTrue(m.command == 'NOTICE')
self.assertEqual(m.command, 'NOTICE')
self.assertFalse(ircutils.isChannel(m.args[0]))
m = self.assertNotError('normal')
self.assertFalse(m.command == 'NOTICE')
self.assertNotEqual(m.command, 'NOTICE')
self.assertTrue(ircutils.isChannel(m.args[0]))
finally:
conf.supybot.reply.withNoticeWhenPrivate.setValue(orig)
@ -1115,10 +1149,10 @@ class WithPrivateNoticeTestCase(ChannelPluginTestCase):
try:
conf.supybot.reply.withNoticeWhenPrivate.setValue(True)
m = self.assertNotError("eval irc.reply('y',to='x',private=True)")
self.assertTrue(m.command == 'NOTICE')
self.assertEqual(m.command, 'NOTICE')
m = self.getMsg(' ')
m = self.assertNotError("eval irc.reply('y',to='#x',private=True)")
self.assertFalse(m.command == 'NOTICE')
self.assertNotEqual(m.command, 'NOTICE')
finally:
conf.supybot.reply.withNoticeWhenPrivate.setValue(original)
@ -1130,28 +1164,28 @@ class ProxyTestCase(SupyTestCase):
irc = irclib.Irc('test')
proxy = callbacks.SimpleProxy(irc, msg)
# First one way...
self.assertFalse(proxy != irc)
self.assertTrue(proxy == irc)
self.assertEqual(proxy, irc)
self.assertEqual(proxy, irc)
self.assertEqual(hash(proxy), hash(irc))
# Then the other!
self.assertFalse(irc != proxy)
self.assertTrue(irc == proxy)
self.assertEqual(irc, proxy)
self.assertEqual(irc, proxy)
self.assertEqual(hash(irc), hash(proxy))
# And now dictionaries...
d = {}
d[irc] = 'foo'
self.assertTrue(len(d) == 1)
self.assertTrue(d[irc] == 'foo')
self.assertTrue(d[proxy] == 'foo')
self.assertEqual(len(d), 1)
self.assertEqual(d[irc], 'foo')
self.assertEqual(d[proxy], 'foo')
d[proxy] = 'bar'
self.assertTrue(len(d) == 1)
self.assertTrue(d[irc] == 'bar')
self.assertTrue(d[proxy] == 'bar')
self.assertEqual(len(d), 1)
self.assertEqual(d[irc], 'bar')
self.assertEqual(d[proxy], 'bar')
d[irc] = 'foo'
self.assertTrue(len(d) == 1)
self.assertTrue(d[irc] == 'foo')
self.assertTrue(d[proxy] == 'foo')
self.assertEqual(len(d), 1)
self.assertEqual(d[irc], 'foo')
self.assertEqual(d[proxy], 'foo')

View File

@ -1,7 +1,7 @@
###
# Copyright (c) 2002-2005, Jeremiah Fincher
# Copyright (c) 2015, James McCoy
# Copyright (c) 2010-2021, The Limnoria Contributors
# Copyright (c) 2010-2021, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
##
# Copyright (c) 2019-2021, The Limnoria Contributors
# Copyright (c) 2019-2021, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,6 @@
###
# Copyright (c) 2005, Jeremiah Fincher
# Copyright (c) 2010-2021, The Limnoria Contributors
# Copyright (c) 2010-2021, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,6 @@
###
# Copyright (c) 2008, Jeremiah Fincher
# Copyright (c) 2010-2021, The Limnoria Contributors
# Copyright (c) 2010-2021, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,6 @@
###
# Copyright (c) 2005, Jeremiah Fincher
# Copyright (c) 2010-2021, The Limnoria Contributors
# Copyright (c) 2010-2021, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,6 @@
# -*- coding: utf8 -*-
###
# Copyright (c) 2012-2021, The Limnoria Contributors
# Copyright (c) 2012-2021, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,6 @@
###
# Copyright (c) 2002-2005, Jeremiah Fincher
# Copyright (c) 2010-2021, The Limnoria Contributors
# Copyright (c) 2010-2021, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -122,17 +122,17 @@ class CapabilitySetTestCase(SupyTestCase):
def testContains(self):
s = ircdb.CapabilitySet()
self.assertFalse('foo' in s)
self.assertFalse('-foo' in s)
self.assertNotIn('foo', s)
self.assertNotIn('-foo', s)
s.add('foo')
self.assertTrue('foo' in s)
self.assertTrue('-foo' in s)
self.assertIn('foo', s)
self.assertIn('-foo', s)
s.remove('foo')
self.assertFalse('foo' in s)
self.assertFalse('-foo' in s)
self.assertNotIn('foo', s)
self.assertNotIn('-foo', s)
s.add('-foo')
self.assertTrue('foo' in s)
self.assertTrue('-foo' in s)
self.assertIn('foo', s)
self.assertIn('-foo', s)
def testCheck(self):
s = ircdb.CapabilitySet()
@ -170,8 +170,8 @@ class UserCapabilitySetTestCase(SupyTestCase):
def testOwnerIsAlwaysPresent(self):
d = ircdb.UserCapabilitySet()
self.assertTrue('owner' in d)
self.assertTrue('-owner' in d)
self.assertIn('owner', d)
self.assertIn('-owner', d)
self.assertFalse(d.check('owner'))
d.add('owner')
self.assertTrue(d.check('owner'))
@ -187,8 +187,8 @@ class UserCapabilitySetTestCase(SupyTestCase):
def testOwner(self):
s = ircdb.UserCapabilitySet()
s.add('owner')
self.assertTrue('foo' in s)
self.assertTrue('-foo' in s)
self.assertIn('foo', s)
self.assertIn('-foo', s)
self.assertTrue(s.check('owner'))
self.assertFalse(s.check('-owner'))
self.assertFalse(s.check('-foo'))
@ -265,7 +265,7 @@ class IrcUserTestCase(IrcdbTestCase):
self.assertTrue(u.checkHostmask('foo!bar@baz'))
u.addAuth('foo!bar@baz')
self.assertTrue(u.checkHostmask('foo!bar@baz'))
self.assertTrue(len(u.auth) == 1)
self.assertEqual(len(u.auth), 1)
u.addAuth('boo!far@fizz')
self.assertTrue(u.checkHostmask('boo!far@fizz'))
timeFastForward(2.1)

View File

@ -1,6 +1,6 @@
##
# Copyright (c) 2002-2005, Jeremiah Fincher
# Copyright (c) 2010-2021, The Limnoria Contributors
# Copyright (c) 2010-2021, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -52,21 +52,21 @@ class CapNegMixin:
def startCapNegociation(self, caps='sasl'):
m = self.irc.takeMsg()
self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertTrue(m.args == ('LS', '302'), 'Expected CAP LS 302, got %r.' % m)
self.assertEqual(m.command, 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args, ('LS', '302'), 'Expected CAP LS 302, got %r.' % m)
m = self.irc.takeMsg()
self.assertTrue(m.command == 'NICK', 'Expected NICK, got %r.' % m)
self.assertEqual(m.command, 'NICK', 'Expected NICK, got %r.' % m)
m = self.irc.takeMsg()
self.assertTrue(m.command == 'USER', 'Expected USER, got %r.' % m)
self.assertEqual(m.command, 'USER', 'Expected USER, got %r.' % m)
self.irc.feedMsg(ircmsgs.IrcMsg(command='CAP',
args=('*', 'LS', caps)))
if caps:
m = self.irc.takeMsg()
self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.command, 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args[0], 'REQ', m)
self.assertEqual(m.args[1], 'sasl')
@ -75,7 +75,7 @@ class CapNegMixin:
def endCapNegociation(self):
m = self.irc.takeMsg()
self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.command, 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args, ('END',), m)
@ -204,13 +204,13 @@ class IrcMsgQueueTestCase(SupyTestCase):
q.enqueue(self.msg)
q.enqueue(self.msg)
q.enqueue(self.msg)
self.assertTrue(self.msg in q)
self.assertIn(self.msg, q)
q.dequeue()
self.assertTrue(self.msg in q)
self.assertIn(self.msg, q)
q.dequeue()
self.assertTrue(self.msg in q)
self.assertIn(self.msg, q)
q.dequeue()
self.assertFalse(self.msg in q)
self.assertNotIn(self.msg, q)
def testRepr(self):
q = irclib.IrcMsgQueue()
@ -313,39 +313,39 @@ class ChannelStateTestCase(SupyTestCase):
c1 = pickle.loads(pickle.dumps(c))
self.assertEqual(c, c1)
c.removeUser('jemfinch')
self.assertFalse('jemfinch' in c.users)
self.assertTrue('jemfinch' in c1.users)
self.assertNotIn('jemfinch', c.users)
self.assertIn('jemfinch', c1.users)
def testCopy(self):
c = irclib.ChannelState()
c.addUser('jemfinch')
c1 = copy.deepcopy(c)
c.removeUser('jemfinch')
self.assertFalse('jemfinch' in c.users)
self.assertTrue('jemfinch' in c1.users)
self.assertNotIn('jemfinch', c.users)
self.assertIn('jemfinch', c1.users)
def testAddUser(self):
c = irclib.ChannelState()
c.addUser('foo')
self.assertTrue('foo' in c.users)
self.assertFalse('foo' in c.ops)
self.assertFalse('foo' in c.voices)
self.assertFalse('foo' in c.halfops)
self.assertIn('foo', c.users)
self.assertNotIn('foo', c.ops)
self.assertNotIn('foo', c.voices)
self.assertNotIn('foo', c.halfops)
c.addUser('+bar')
self.assertTrue('bar' in c.users)
self.assertTrue('bar' in c.voices)
self.assertFalse('bar' in c.ops)
self.assertFalse('bar' in c.halfops)
self.assertIn('bar', c.users)
self.assertIn('bar', c.voices)
self.assertNotIn('bar', c.ops)
self.assertNotIn('bar', c.halfops)
c.addUser('%baz')
self.assertTrue('baz' in c.users)
self.assertTrue('baz' in c.halfops)
self.assertFalse('baz' in c.voices)
self.assertFalse('baz' in c.ops)
self.assertIn('baz', c.users)
self.assertIn('baz', c.halfops)
self.assertNotIn('baz', c.voices)
self.assertNotIn('baz', c.ops)
c.addUser('@quuz')
self.assertTrue('quuz' in c.users)
self.assertTrue('quuz' in c.ops)
self.assertFalse('quuz' in c.halfops)
self.assertFalse('quuz' in c.voices)
self.assertIn('quuz', c.users)
self.assertIn('quuz', c.ops)
self.assertNotIn('quuz', c.halfops)
self.assertNotIn('quuz', c.voices)
class IrcStateTestCase(SupyTestCase):
@ -362,7 +362,7 @@ class IrcStateTestCase(SupyTestCase):
st.channels['#foo'] = irclib.ChannelState()
m = ircmsgs.kick('#foo', self.irc.nick, prefix=self.irc.prefix)
st.addMsg(self.irc, m)
self.assertFalse('#foo' in st.channels)
self.assertNotIn('#foo', st.channels)
def testAddMsgRemovesOpsProperly(self):
st = irclib.IrcState()
@ -370,18 +370,18 @@ class IrcStateTestCase(SupyTestCase):
st.channels['#foo'].ops.add('bar')
m = ircmsgs.mode('#foo', ('-o', 'bar'))
st.addMsg(self.irc, m)
self.assertFalse('bar' in st.channels['#foo'].ops)
self.assertNotIn('bar', st.channels['#foo'].ops)
def testNickChangesChangeChannelUsers(self):
st = irclib.IrcState()
st.channels['#foo'] = irclib.ChannelState()
st.channels['#foo'].addUser('@bar')
self.assertTrue('bar' in st.channels['#foo'].users)
self.assertIn('bar', st.channels['#foo'].users)
self.assertTrue(st.channels['#foo'].isOp('bar'))
st.addMsg(self.irc, ircmsgs.IrcMsg(':bar!asfd@asdf.com NICK baz'))
self.assertFalse('bar' in st.channels['#foo'].users)
self.assertNotIn('bar', st.channels['#foo'].users)
self.assertFalse(st.channels['#foo'].isOp('bar'))
self.assertTrue('baz' in st.channels['#foo'].users)
self.assertIn('baz', st.channels['#foo'].users)
self.assertTrue(st.channels['#foo'].isOp('baz'))
def testHistory(self):
@ -478,20 +478,106 @@ class IrcStateTestCase(SupyTestCase):
state = irclib.IrcState()
stateCopy = state.copy()
state.channels['#foo'] = None
self.assertFalse('#foo' in stateCopy.channels)
self.assertNotIn('#foo', stateCopy.channels)
def testJoin(self):
st = irclib.IrcState()
st.addMsg(self.irc, ircmsgs.join('#foo', prefix=self.irc.prefix))
self.assertTrue('#foo' in st.channels)
self.assertTrue(self.irc.nick in st.channels['#foo'].users)
st.addMsg(self.irc, ircmsgs.join('#foo', prefix='foo!bar@baz'))
self.assertTrue('foo' in st.channels['#foo'].users)
st2 = st.copy()
st.addMsg(self.irc, ircmsgs.quit(prefix='foo!bar@baz'))
self.assertFalse('foo' in st.channels['#foo'].users)
self.assertTrue('foo' in st2.channels['#foo'].users)
st.addMsg(self.irc, ircmsgs.join('#foo', prefix=self.irc.prefix))
self.assertIn('#foo', st.channels)
self.assertIn(self.irc.nick, st.channels['#foo'].users)
st.addMsg(self.irc, ircmsgs.join('#foo', prefix='foo!bar@baz'))
self.assertIn('foo', st.channels['#foo'].users)
st2 = st.copy()
st2.addMsg(self.irc, ircmsgs.quit(prefix='foo!bar@baz'))
self.assertNotIn('foo', st2.channels['#foo'].users)
self.assertIn('foo', st.channels['#foo'].users)
def testNickToHostmask(self):
st = irclib.IrcState()
st.addMsg(self.irc, ircmsgs.join('#foo', prefix='foo!bar@baz'))
st.addMsg(self.irc, ircmsgs.join('#foo', prefix='bar!baz@qux'))
self.assertEqual(st.nickToHostmask('foo'), 'foo!bar@baz')
self.assertEqual(st.nickToHostmask('bar'), 'bar!baz@qux')
# QUIT erases the entry
with self.subTest("QUIT"):
st2 = st.copy()
st2.addMsg(self.irc, ircmsgs.quit(prefix='foo!bar@baz'))
with self.assertRaises(KeyError):
st2.nickToHostmask('foo')
self.assertEqual(st2.nickToHostmask('bar'), 'bar!baz@qux')
self.assertEqual(st.nickToHostmask('foo'), 'foo!bar@baz')
self.assertEqual(st.nickToHostmask('bar'), 'bar!baz@qux')
# NICK moves the entry
with self.subTest("NICK"):
st2 = st.copy()
st2.addMsg(self.irc, ircmsgs.IrcMsg(prefix='foo!bar@baz',
command='NICK', args=['foo2']))
with self.assertRaises(KeyError):
st2.nickToHostmask('foo')
self.assertEqual(st2.nickToHostmask('foo2'), 'foo2!bar@baz')
self.assertEqual(st2.nickToHostmask('bar'), 'bar!baz@qux')
self.assertEqual(st.nickToHostmask('foo'), 'foo!bar@baz')
self.assertEqual(st.nickToHostmask('bar'), 'bar!baz@qux')
# NICK moves the entry (and overwrites if needed)
with self.subTest("NICK with overwrite"):
st2 = st.copy()
st2.addMsg(self.irc, ircmsgs.IrcMsg(prefix='foo!bar@baz',
command='NICK', args=['bar']))
with self.assertRaises(KeyError):
st2.nickToHostmask('foo')
self.assertEqual(st2.nickToHostmask('bar'), 'bar!bar@baz')
self.assertEqual(st.nickToHostmask('foo'), 'foo!bar@baz')
self.assertEqual(st.nickToHostmask('bar'), 'bar!baz@qux')
with self.subTest("PRIVMSG"):
st2 = st.copy()
st2.addMsg(self.irc, ircmsgs.IrcMsg(prefix='foo!bar2@baz2',
command='PRIVMSG',
args=['#chan', 'foo']))
self.assertEqual(st2.nickToHostmask('foo'), 'foo!bar2@baz2')
self.assertEqual(st2.nickToHostmask('bar'), 'bar!baz@qux')
self.assertEqual(st.nickToHostmask('foo'), 'foo!bar@baz')
self.assertEqual(st.nickToHostmask('bar'), 'bar!baz@qux')
with self.subTest("PRIVMSG with no host is ignored"):
st2 = st.copy()
st2.addMsg(self.irc, ircmsgs.IrcMsg(prefix='foo',
command='PRIVMSG',
args=['#chan', 'foo']))
self.assertEqual(st2.nickToHostmask('foo'), 'foo!bar@baz')
self.assertEqual(st2.nickToHostmask('bar'), 'bar!baz@qux')
self.assertEqual(st.nickToHostmask('foo'), 'foo!bar@baz')
self.assertEqual(st.nickToHostmask('bar'), 'bar!baz@qux')
def testNickToHostmaskWho(self):
st = irclib.IrcState()
st.addMsg(self.irc, ircmsgs.IrcMsg(command='352', # RPL_WHOREPLY
args=[self.irc.nick, '#chan', 'bar', 'baz', 'server.example',
'foo', 'H', '0 real name']))
self.assertEqual(st.nickToHostmask('foo'), 'foo!bar@baz')
def testNickToHostmaskWhox(self):
st = irclib.IrcState()
st.addMsg(self.irc, ircmsgs.IrcMsg(command='354', # RPL_WHOSPCRPL
args=[self.irc.nick, '1', 'bar', '127.0.0.1', 'baz',
'foo', 'H', '0', 'real name']))
self.assertEqual(st.nickToHostmask('foo'), 'foo!bar@baz')
def testChghost(self):
st = irclib.IrcState()
st.addMsg(self.irc, ircmsgs.IrcMsg(prefix='foo!bar@baz',
command='CHGHOST', args=['bar2', 'baz2']))
self.assertEqual(st.nickToHostmask('foo'), 'foo!bar2@baz2')
def testEq(self):
state1 = irclib.IrcState()
@ -508,23 +594,23 @@ class IrcStateTestCase(SupyTestCase):
def testHandlesModes(self):
st = irclib.IrcState()
st.addMsg(self.irc, ircmsgs.join('#foo', prefix=self.irc.prefix))
self.assertFalse('bar' in st.channels['#foo'].ops)
self.assertNotIn('bar', st.channels['#foo'].ops)
st.addMsg(self.irc, ircmsgs.op('#foo', 'bar'))
self.assertTrue('bar' in st.channels['#foo'].ops)
self.assertIn('bar', st.channels['#foo'].ops)
st.addMsg(self.irc, ircmsgs.deop('#foo', 'bar'))
self.assertFalse('bar' in st.channels['#foo'].ops)
self.assertNotIn('bar', st.channels['#foo'].ops)
self.assertFalse('bar' in st.channels['#foo'].voices)
self.assertNotIn('bar', st.channels['#foo'].voices)
st.addMsg(self.irc, ircmsgs.voice('#foo', 'bar'))
self.assertTrue('bar' in st.channels['#foo'].voices)
self.assertIn('bar', st.channels['#foo'].voices)
st.addMsg(self.irc, ircmsgs.devoice('#foo', 'bar'))
self.assertFalse('bar' in st.channels['#foo'].voices)
self.assertNotIn('bar', st.channels['#foo'].voices)
self.assertFalse('bar' in st.channels['#foo'].halfops)
self.assertNotIn('bar', st.channels['#foo'].halfops)
st.addMsg(self.irc, ircmsgs.halfop('#foo', 'bar'))
self.assertTrue('bar' in st.channels['#foo'].halfops)
self.assertIn('bar', st.channels['#foo'].halfops)
st.addMsg(self.irc, ircmsgs.dehalfop('#foo', 'bar'))
self.assertFalse('bar' in st.channels['#foo'].halfops)
self.assertNotIn('bar', st.channels['#foo'].halfops)
def testDoModeOnlyChannels(self):
st = irclib.IrcState()
@ -572,14 +658,14 @@ class IrcCapsTestCase(SupyTestCase, CapNegMixin):
self.irc = irclib.Irc('test')
m = self.irc.takeMsg()
self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertTrue(m.args == ('LS', '302'), 'Expected CAP LS 302, got %r.' % m)
self.assertEqual(m.command, 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args, ('LS', '302'), 'Expected CAP LS 302, got %r.' % m)
m = self.irc.takeMsg()
self.assertTrue(m.command == 'NICK', 'Expected NICK, got %r.' % m)
self.assertEqual(m.command, 'NICK', 'Expected NICK, got %r.' % m)
m = self.irc.takeMsg()
self.assertTrue(m.command == 'USER', 'Expected USER, got %r.' % m)
self.assertEqual(m.command, 'USER', 'Expected USER, got %r.' % m)
self.irc.REQUEST_CAPABILITIES = set(['a'*400, 'b'*400])
caps = ' '.join(self.irc.REQUEST_CAPABILITIES)
@ -589,12 +675,12 @@ class IrcCapsTestCase(SupyTestCase, CapNegMixin):
args=('*', 'LS', 'b'*400)))
m = self.irc.takeMsg()
self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.command, 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args[0], 'REQ', m)
self.assertEqual(m.args[1], 'a'*400)
m = self.irc.takeMsg()
self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.command, 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args[0], 'REQ', m)
self.assertEqual(m.args[1], 'b'*400)
@ -602,20 +688,20 @@ class IrcCapsTestCase(SupyTestCase, CapNegMixin):
self.irc = irclib.Irc('test')
m = self.irc.takeMsg()
self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertTrue(m.args == ('LS', '302'), 'Expected CAP LS 302, got %r.' % m)
self.assertEqual(m.command, 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args, ('LS', '302'), 'Expected CAP LS 302, got %r.' % m)
m = self.irc.takeMsg()
self.assertTrue(m.command == 'NICK', 'Expected NICK, got %r.' % m)
self.assertEqual(m.command, 'NICK', 'Expected NICK, got %r.' % m)
m = self.irc.takeMsg()
self.assertTrue(m.command == 'USER', 'Expected USER, got %r.' % m)
self.assertEqual(m.command, 'USER', 'Expected USER, got %r.' % m)
self.irc.feedMsg(ircmsgs.IrcMsg(command='CAP',
args=('*', 'LS', 'account-notify echo-message')))
m = self.irc.takeMsg()
self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.command, 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args[0], 'REQ', m)
self.assertEqual(m.args[1], 'account-notify')
@ -626,21 +712,21 @@ class IrcCapsTestCase(SupyTestCase, CapNegMixin):
args=('*', 'ACK', 'account-notify')))
m = self.irc.takeMsg()
self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.command, 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args, ('END',), m)
def testEchomessageLabeledresponseGrouped(self):
self.irc = irclib.Irc('test')
m = self.irc.takeMsg()
self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertTrue(m.args == ('LS', '302'), 'Expected CAP LS 302, got %r.' % m)
self.assertEqual(m.command, 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args, ('LS', '302'), 'Expected CAP LS 302, got %r.' % m)
m = self.irc.takeMsg()
self.assertTrue(m.command == 'NICK', 'Expected NICK, got %r.' % m)
self.assertEqual(m.command, 'NICK', 'Expected NICK, got %r.' % m)
m = self.irc.takeMsg()
self.assertTrue(m.command == 'USER', 'Expected USER, got %r.' % m)
self.assertEqual(m.command, 'USER', 'Expected USER, got %r.' % m)
self.irc.REQUEST_CAPABILITIES = set([
'account-notify', 'a'*490, 'echo-message', 'labeled-response'])
@ -649,17 +735,17 @@ class IrcCapsTestCase(SupyTestCase, CapNegMixin):
'account-notify ' + 'a'*490 + ' echo-message labeled-response')))
m = self.irc.takeMsg()
self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.command, 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args[0], 'REQ', m)
self.assertEqual(m.args[1], 'echo-message labeled-response')
m = self.irc.takeMsg()
self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.command, 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args[0], 'REQ', m)
self.assertEqual(m.args[1], 'a'*490)
m = self.irc.takeMsg()
self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.command, 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args[0], 'REQ', m)
self.assertEqual(m.args[1], 'account-notify')
@ -836,14 +922,14 @@ class IrcTestCase(SupyTestCase):
#self.assertTrue(m.command == 'PASS', 'Expected PASS, got %r.' % m)
m = self.irc.takeMsg()
self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertTrue(m.args == ('LS', '302'), 'Expected CAP LS 302, got %r.' % m)
self.assertEqual(m.command, 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args, ('LS', '302'), 'Expected CAP LS 302, got %r.' % m)
m = self.irc.takeMsg()
self.assertTrue(m.command == 'NICK', 'Expected NICK, got %r.' % m)
self.assertEqual(m.command, 'NICK', 'Expected NICK, got %r.' % m)
m = self.irc.takeMsg()
self.assertTrue(m.command == 'USER', 'Expected USER, got %r.' % m)
self.assertEqual(m.command, 'USER', 'Expected USER, got %r.' % m)
# TODO
self.irc.feedMsg(ircmsgs.IrcMsg(command='CAP',
@ -852,7 +938,7 @@ class IrcTestCase(SupyTestCase):
args=('*', 'LS', 'extended-join')))
m = self.irc.takeMsg()
self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.command, 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args[0], 'REQ', m)
# NOTE: Capabilities are requested in alphabetic order, because
# sets are unordered, and their "order" is nondeterministic.
@ -862,11 +948,11 @@ class IrcTestCase(SupyTestCase):
args=('*', 'ACK', 'account-tag multi-prefix extended-join')))
m = self.irc.takeMsg()
self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.command, 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args, ('END',), m)
m = self.irc.takeMsg()
self.assertTrue(m is None, m)
self.assertIsNone(m, m)
def testPingResponse(self):
self.irc.feedMsg(ircmsgs.ping('123'))
@ -890,9 +976,9 @@ class IrcTestCase(SupyTestCase):
self.irc.queueMsg(ircmsgs.IrcMsg('NOTICE #foo bar'))
self.irc.sendMsg(ircmsgs.IrcMsg('PRIVMSG #foo yeah!'))
msg = self.irc.takeMsg()
self.assertTrue(msg.command == 'PRIVMSG')
self.assertEqual(msg.command, 'PRIVMSG')
msg = self.irc.takeMsg()
self.assertTrue(msg.command == 'NOTICE')
self.assertEqual(msg.command, 'NOTICE')
def testNoMsgLongerThan512(self):
self.irc.queueMsg(ircmsgs.privmsg('whocares', 'x'*1000))
@ -1542,7 +1628,7 @@ class SaslTestCase(SupyTestCase, CapNegMixin):
conf.supybot.networks.test.sasl.password.setValue('')
m = self.irc.takeMsg()
self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.command, 'CAP', 'Expected CAP, got %r.' % m)
self.assertEqual(m.args[0], 'REQ', m)
self.assertEqual(m.args[1], 'sasl')
self.irc.feedMsg(ircmsgs.IrcMsg(command='CAP',

Some files were not shown because too many files have changed in this diff Show More