コード例 #1
0
ファイル: ircmsgs.py プロジェクト: jrabbit/ubotu-fr
def joins(channels, keys=None, prefix="", msg=None):
    """Returns a JOIN to each of channels."""
    if conf.supybot.protocols.irc.strictRfc():
        assert all(isChannel, channels), channels
    if msg and not prefix:
        prefix = msg.prefix
    if keys is None:
        keys = []
    assert len(keys) <= len(channels), "Got more keys than channels."
    if not keys:
        return IrcMsg(prefix=prefix, command="JOIN", args=(",".join(channels),), msg=msg)
    else:
        for key in keys:
            if conf.supybot.protocols.irc.strictRfc():
                assert (
                    key.translate(utils.str.chars, utils.str.chars[128:]) == key
                    and "\x00" not in key
                    and "\r" not in key
                    and "\n" not in key
                    and "\f" not in key
                    and "\t" not in key
                    and "\v" not in key
                    and " " not in key
                )
        return IrcMsg(prefix=prefix, command="JOIN", args=(",".join(channels), ",".join(keys)), msg=msg)
コード例 #2
0
ファイル: ircmsgs.py プロジェクト: MrTiggr/supybot_fixes
def joins(channels, keys=None, prefix='', msg=None):
    """Returns a JOIN to each of channels."""
    if conf.supybot.protocols.irc.strictRfc():
        assert all(isChannel, channels), channels
    if msg and not prefix:
        prefix = msg.prefix
    if keys is None:
        keys = []
    assert len(keys) <= len(channels), 'Got more keys than channels.'
    if not keys:
        return IrcMsg(prefix=prefix,
                      command='JOIN',
                      args=(','.join(channels),), msg=msg)
    else:
        for key in keys:
            if conf.supybot.protocols.irc.strictRfc():
                assert key.translate(utils.str.chars,
                                     utils.str.chars[128:])==key and \
                       '\x00' not in key and \
                       '\r' not in key and \
                       '\n' not in key and \
                       '\f' not in key and \
                       '\t' not in key and \
                       '\v' not in key and \
                       ' ' not in key
        return IrcMsg(prefix=prefix,
                      command='JOIN',
                      args=(','.join(channels), ','.join(keys)), msg=msg)
コード例 #3
0
def joins(channels, keys=None, prefix='', msg=None):
    """Returns a JOIN to each of channels."""
    if conf.supybot.protocols.irc.strictRfc():
        assert all(isChannel, channels), channels
    if msg and not prefix:
        prefix = msg.prefix
    if keys is None:
        keys = []
    assert len(keys) <= len(channels), 'Got more keys than channels.'
    if not keys:
        return IrcMsg(prefix=prefix,
                      command='JOIN',
                      args=(','.join(channels), ),
                      msg=msg)
    else:
        for key in keys:
            if conf.supybot.protocols.irc.strictRfc():
                assert key.translate(utils.str.chars,
                                     utils.str.chars[128:])==key and \
                       '\x00' not in key and \
                       '\r' not in key and \
                       '\n' not in key and \
                       '\f' not in key and \
                       '\t' not in key and \
                       '\v' not in key and \
                       ' ' not in key
        return IrcMsg(prefix=prefix,
                      command='JOIN',
                      args=(','.join(channels), ','.join(keys)),
                      msg=msg)
コード例 #4
0
ファイル: plugin.py プロジェクト: sbrock/Supybot-plugins
    def bug(self, irc, msg, args, bug):
        """<num>

        Returns a description of the bug with bug id <num>.
        """
        url = 'http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s' % bug
        try:
            text = utils.web.getUrl(url).decode()
        except utils.web.Error as e:
            irc.error(str(e), Raise=True)
        if "There is no record of Bug" in text:
            irc.error('I could not find a bug report matching that number.',
                      Raise=True)
        searches = list(map(lambda p: p.search(text), self._searches))
        sev = self._severity.search(text)
        tags = self._tags.search(text)
        # This section should be cleaned up to ease future modifications
        if all(None, searches):
            L = map(self.bold, ('Package', 'Subject', 'Reported'))
            resp = format('%s: %%s; %s: %%s; %s: by %%s on %%s', *L)
            L = map(utils.web.htmlToText, map(lambda p: p.group(1), searches))
            resp = format(resp, *L)
            if sev:
                sev = list(filter(None, sev.groups()))
                if sev:
                    sev = utils.web.htmlToText(sev[0])
                    resp += format('; %s: %s', self.bold('Severity'), sev)
            if tags:
                resp += format('; %s: %s', self.bold('Tags'), tags.group(1))
            resp += format('; %u', url)
            irc.reply(resp)
        else:
            irc.error('I was unable to properly parse the BTS page.')
コード例 #5
0
    def bug(self, irc, msg, args, bug):
        """<num>

        Returns a description of the bug with bug id <num>.
        """
        url = 'http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s' % bug
        try:
            text = utils.web.getUrl(url).decode()
        except utils.web.Error as e:
            irc.error(str(e), Raise=True)
        if "There is no record of Bug" in text:
            irc.error('I could not find a bug report matching that number.',
                      Raise=True)
        searches = map(lambda p: p.search(text), self._searches)
        sev = self._severity.search(text)
        tags = self._tags.search(text)
        # This section should be cleaned up to ease future modifications
        if all(None, searches):
            L = map(self.bold, ('Package', 'Subject', 'Reported'))
            resp = format('%s: %%s; %s: %%s; %s: by %%s on %%s', *L)
            L = map(utils.web.htmlToText, map(lambda p: p.group(1), searches))
            resp = format(resp, *L)
            if sev:
                sev = filter(None, sev.groups())
                if sev:
                    sev = utils.web.htmlToText(sev[0])
                    resp += format('; %s: %s', self.bold('Severity'), sev)
            if tags:
                resp += format('; %s: %s', self.bold('Tags'), tags.group(1))
            resp += format('; %u', url)
            irc.reply(resp)
        else:
            irc.error('I was unable to properly parse the BTS page.')
コード例 #6
0
ファイル: ircmsgs.py プロジェクト: jrabbit/ubotu-fr
def devoices(channel, nicks, prefix="", msg=None):
    """Returns a MODE to devoice each of nicks on channel."""
    if conf.supybot.protocols.irc.strictRfc():
        assert isChannel(channel), repr(channel)
        assert nicks, "Nicks must not be empty."
        assert all(isNick, nicks), nicks
    if msg and not prefix:
        prefix = msg.prefix
    return IrcMsg(prefix=prefix, command="MODE", msg=msg, args=(channel, "-" + ("v" * len(nicks))) + tuple(nicks))
コード例 #7
0
ファイル: ircmsgs.py プロジェクト: jrabbit/ubotu-fr
def unquiets(channel, hostmasks, prefix="", msg=None):
    """Returns a MODE to unquiet each of nicks on channel."""
    if conf.supybot.protocols.irc.strictRfc():
        assert isChannel(channel), repr(channel)
        assert all(isUserHostmask, hostmasks), hostmasks
    modes = [("-q", s) for s in hostmasks]
    if msg and not prefix:
        prefix = msg.prefix
    return IrcMsg(prefix=prefix, command="MODE", args=[channel] + ircutils.joinModes(modes), msg=msg)
コード例 #8
0
ファイル: ircmsgs.py プロジェクト: MrTiggr/supybot_fixes
def unbans(channel, hostmasks, prefix='', msg=None):
    """Returns a MODE to unban each of nicks on channel."""
    if conf.supybot.protocols.irc.strictRfc():
        assert isChannel(channel), repr(channel)
        assert all(isUserHostmask, hostmasks), hostmasks
    if msg and not prefix:
        prefix = msg.prefix
    return IrcMsg(prefix=prefix, command='MODE', msg=msg,
                  args=(channel, '-' + ('b'*len(hostmasks)), hostmasks))
コード例 #9
0
ファイル: ircmsgs.py プロジェクト: majestrate/Limnoria
def devoices(channel, nicks, prefix='', msg=None):
    """Returns a MODE to devoice each of nicks on channel."""
    if conf.supybot.protocols.irc.strictRfc():
        assert isChannel(channel), repr(channel)
        assert nicks, 'Nicks must not be empty.'
        assert all(isNick, nicks), nicks
    if msg and not prefix:
        prefix = msg.prefix
    return IrcMsg(prefix=prefix, command='MODE', msg=msg,
                  args=(channel, '-' + ('v'*len(nicks))) + tuple(nicks))
コード例 #10
0
ファイル: ircmsgs.py プロジェクト: jrabbit/ubotu-fr
def parts(channels, s="", prefix="", msg=None):
    """Returns a PART from each of channels with the message msg."""
    if conf.supybot.protocols.irc.strictRfc():
        assert all(isChannel, channels), channels
    if msg and not prefix:
        prefix = msg.prefix
    if s:
        return IrcMsg(prefix=prefix, command="PART", args=(",".join(channels), s), msg=msg)
    else:
        return IrcMsg(prefix=prefix, command="PART", args=(",".join(channels),), msg=msg)
コード例 #11
0
ファイル: ircmsgs.py プロジェクト: MrTiggr/supybot_fixes
def voices(channel, nicks, prefix='', msg=None):
    """Returns a MODE to voice each of nicks on channel."""
    if conf.supybot.protocols.irc.strictRfc():
        assert isChannel(channel), repr(channel)
        assert nicks, 'Nicks must not be empty.'
        assert all(isNick, nicks)
    if msg and not prefix:
        prefix = msg.prefix
    return IrcMsg(prefix=prefix, command='MODE', msg=msg,
                  args=(channel, '+' + ('v'*len(nicks))) + tuple(nicks))
コード例 #12
0
ファイル: ircmsgs.py プロジェクト: MrTiggr/supybot_fixes
def bans(channel, hostmasks, exceptions=(), prefix='', msg=None):
    """Returns a MODE to ban each of nicks on channel."""
    if conf.supybot.protocols.irc.strictRfc():
        assert isChannel(channel), repr(channel)
        assert all(isUserHostmask, hostmasks), hostmasks
    modes = [('+b', s) for s in hostmasks] + [('+e', s) for s in exceptions]
    if msg and not prefix:
        prefix = msg.prefix
    return IrcMsg(prefix=prefix, command='MODE',
                  args=[channel] + ircutils.joinModes(modes), msg=msg)
コード例 #13
0
ファイル: ircmsgs.py プロジェクト: majestrate/Limnoria
def unbans(channel, hostmasks, prefix='', msg=None):
    """Returns a MODE to unban each of nicks on channel."""
    if conf.supybot.protocols.irc.strictRfc():
        assert isChannel(channel), repr(channel)
        assert all(isUserHostmask, hostmasks), hostmasks
    modes = [('-b', s) for s in hostmasks]
    if msg and not prefix:
        prefix = msg.prefix
    return IrcMsg(prefix=prefix, command='MODE',
                  args=[channel] + ircutils.joinModes(modes), msg=msg)
コード例 #14
0
def unbans(channel, hostmasks, prefix='', msg=None):
    """Returns a MODE to unban each of nicks on channel."""
    if conf.supybot.protocols.irc.strictRfc():
        assert isChannel(channel), repr(channel)
        assert all(isUserHostmask, hostmasks), hostmasks
    if msg and not prefix:
        prefix = msg.prefix
    return IrcMsg(prefix=prefix,
                  command='MODE',
                  msg=msg,
                  args=(channel, '-' + ('b' * len(hostmasks)), hostmasks))
コード例 #15
0
ファイル: ircmsgs.py プロジェクト: jrabbit/ubotu-fr
 def __init__(self, s="", command="", args=(), prefix="", msg=None):
     assert not (msg and s), "IrcMsg.__init__ cannot accept both s and msg"
     if not s and not command and not msg:
         raise MalformedIrcMsg, "IRC messages require a command."
     self._str = None
     self._repr = None
     self._hash = None
     self._len = None
     self.tags = {}
     self.identified = False
     if s:
         originalString = s
         try:
             if not s.endswith("\n"):
                 s += "\n"
             self._str = s
             if s[0] == ":":
                 self.prefix, s = s[1:].split(None, 1)
             else:
                 self.prefix = ""
             if " :" in s:  # Note the space: IPV6 addresses are bad w/o it.
                 s, last = s.split(" :", 1)
                 self.args = s.split()
                 self.args.append(last.rstrip("\r\n"))
             else:
                 self.args = s.split()
             self.command = self.args.pop(0)
         except (IndexError, ValueError):
             raise MalformedIrcMsg, repr(originalString)
     else:
         if msg is not None:
             if prefix:
                 self.prefix = prefix
             else:
                 self.prefix = msg.prefix
             if command:
                 self.command = command
             else:
                 self.command = msg.command
             if args:
                 self.args = args
             else:
                 self.args = msg.args
             self.tags = msg.tags.copy()
         else:
             self.prefix = prefix
             self.command = command
             assert all(ircutils.isValidArgument, args)
             self.args = args
     self.args = tuple(self.args)
     if isUserHostmask(self.prefix):
         (self.nick, self.user, self.host) = ircutils.splitHostmask(self.prefix)
     else:
         (self.nick, self.user, self.host) = (self.prefix,) * 3
コード例 #16
0
 def __init__(self, s='', command='', args=(), prefix='', msg=None):
     assert not (msg and s), 'IrcMsg.__init__ cannot accept both s and msg'
     if not s and not command and not msg:
         raise MalformedIrcMsg, 'IRC messages require a command.'
     self._str = None
     self._repr = None
     self._hash = None
     self._len = None
     self.tags = {}
     if s:
         originalString = s
         try:
             if not s.endswith('\n'):
                 s += '\n'
             self._str = s
             if s[0] == ':':
                 self.prefix, s = s[1:].split(None, 1)
             else:
                 self.prefix = ''
             if ' :' in s:  # Note the space: IPV6 addresses are bad w/o it.
                 s, last = s.split(' :', 1)
                 self.args = s.split()
                 self.args.append(last.rstrip('\r\n'))
             else:
                 self.args = s.split()
             self.command = self.args.pop(0)
         except (IndexError, ValueError):
             raise MalformedIrcMsg, repr(originalString)
     else:
         if msg is not None:
             if prefix:
                 self.prefix = prefix
             else:
                 self.prefix = msg.prefix
             if command:
                 self.command = command
             else:
                 self.command = msg.command
             if args:
                 self.args = args
             else:
                 self.args = msg.args
             self.tags = msg.tags.copy()
         else:
             self.prefix = prefix
             self.command = command
             assert all(ircutils.isValidArgument, args)
             self.args = args
     self.args = tuple(self.args)
     if isUserHostmask(self.prefix):
         (self.nick, self.user,
          self.host) = ircutils.splitHostmask(self.prefix)
     else:
         (self.nick, self.user, self.host) = (self.prefix, ) * 3
コード例 #17
0
ファイル: ircmsgs.py プロジェクト: jrabbit/ubotu-fr
def kicks(channel, nicks, s="", prefix="", msg=None):
    """Returns a KICK to kick each of nicks from channel with the message msg.
    """
    if conf.supybot.protocols.irc.strictRfc():
        assert isChannel(channel), repr(channel)
        assert all(isNick, nicks), nicks
    if msg and not prefix:
        prefix = msg.prefix
    if s:
        return IrcMsg(prefix=prefix, command="KICK", args=(channel, ",".join(nicks), s), msg=msg)
    else:
        return IrcMsg(prefix=prefix, command="KICK", args=(channel, ",".join(nicks)), msg=msg)
コード例 #18
0
ファイル: ircmsgs.py プロジェクト: cnelsonsic/Limnoria
def parts(channels, s='', prefix='', msg=None):
    """Returns a PART from each of channels with the message msg."""
    if conf.supybot.protocols.irc.strictRfc():
        assert all(isChannel, channels), channels
    if msg and not prefix:
        prefix = msg.prefix
    assert isinstance(s, str)
    if s:
        return IrcMsg(prefix=prefix, command='PART',
                      args=(','.join(channels), s), msg=msg)
    else:
        return IrcMsg(prefix=prefix, command='PART',
                      args=(','.join(channels),), msg=msg)
コード例 #19
0
 def _list(self, group):
     L = []
     for (vname, v) in group._children.items():
         if hasattr(group, 'channelValue') and group.channelValue and \
            ircutils.isChannel(vname) and not v._children:
             continue
         if hasattr(v, 'channelValue') and v.channelValue:
             vname = '#' + vname
         if v._added and not all(ircutils.isChannel, v._added):
             vname = '@' + vname
         L.append(vname)
     utils.sortBy(str.lower, L)
     return L
コード例 #20
0
ファイル: plugin.py プロジェクト: GlitterCakes/PoohBot
 def _list(self, group):
     L = []
     for (vname, v) in group._children.iteritems():
         if hasattr(group, 'channelValue') and group.channelValue and \
            ircutils.isChannel(vname) and not v._children:
             continue
         if hasattr(v, 'channelValue') and v.channelValue:
             vname = '#' + vname
         if v._added and not all(ircutils.isChannel, v._added):
             vname = '@' + vname
         L.append(vname)
     utils.sortBy(str.lower, L)
     return L
コード例 #21
0
ファイル: ircmsgs.py プロジェクト: majestrate/Limnoria
def parts(channels, s='', prefix='', msg=None):
    """Returns a PART from each of channels with the message msg."""
    if conf.supybot.protocols.irc.strictRfc():
        assert all(isChannel, channels), channels
    if msg and not prefix:
        prefix = msg.prefix
    if sys.version_info[0] < 3 and isinstance(s, unicode):
        s = s.encode('utf8')
    assert isinstance(s, str)
    if s:
        return IrcMsg(prefix=prefix, command='PART',
                      args=(','.join(channels), s), msg=msg)
    else:
        return IrcMsg(prefix=prefix, command='PART',
                      args=(','.join(channels),), msg=msg)
コード例 #22
0
def parts(channels, s='', prefix='', msg=None):
    """Returns a PART from each of channels with the message msg."""
    if conf.supybot.protocols.irc.strictRfc():
        assert all(isChannel, channels), channels
    if msg and not prefix:
        prefix = msg.prefix
    if s:
        return IrcMsg(prefix=prefix,
                      command='PART',
                      args=(','.join(channels), s),
                      msg=msg)
    else:
        return IrcMsg(prefix=prefix,
                      command='PART',
                      args=(','.join(channels), ),
                      msg=msg)
コード例 #23
0
    def testStandardSubstitute(self):
        irc = getTestIrc()
        irc.state.channels = {'#foo': holder()}

        f = ircutils.standardSubstitute
        msg = ircmsgs.privmsg('#foo', 'filler', prefix='biff!quux@xyzzy')
        irc._tagMsg(msg)
        s = f(irc, msg, '$rand')
        try:
            int(s)
        except ValueError:
            self.fail('$rand wasn\'t an int.')
        s = f(irc, msg, '$randomInt')
        try:
            int(s)
        except ValueError:
            self.fail('$randomint wasn\'t an int.')
        self.assertEqual(f(irc, msg, '$botnick'), irc.nick)
        self.assertEqual(f(irc, msg, '$who'), msg.nick)
        self.assertEqual(f(irc, msg, '$WHO'),
                         msg.nick, 'stand. sub. not case-insensitive.')
        self.assertEqual(f(irc, msg, '$nick'), msg.nick)
        self.assertNotEqual(f(irc, msg, '$randomdate'), '$randomdate')
        q = f(irc,msg,'$randomdate\t$randomdate')
        dl = q.split('\t')
        if dl[0] == dl[1]:
            self.fail ('Two $randomdates in the same string were the same')
        q = f(irc, msg, '$randomint\t$randomint')
        dl = q.split('\t')
        if dl[0] == dl[1]:
            self.fail ('Two $randomints in the same string were the same')
        self.assertNotEqual(f(irc, msg, '$today'), '$today')
        self.assertNotEqual(f(irc, msg, '$now'), '$now')
        n = f(irc, msg, '$randnick')
        self.failUnless(n in irc.state.channels['#foo'].users)
        n = f(irc, msg, '$randomnick')
        self.failUnless(n in irc.state.channels['#foo'].users)
        n = f(irc, msg, '$randomnick '*100)
        L = n.split()
        self.failIf(all(L[0].__eq__, L), 'all $randomnicks were the same')
        c = f(irc, msg, '$channel')
        self.assertEqual(c, msg.args[0])

        net = f(irc, msg, '$network')
        self.assertEqual(net, irc.network)
コード例 #24
0
def kicks(channel, nicks, s='', prefix='', msg=None):
    """Returns a KICK to kick each of nicks from channel with the message msg.
    """
    if conf.supybot.protocols.irc.strictRfc():
        assert isChannel(channel), repr(channel)
        assert all(isNick, nicks), nicks
    if msg and not prefix:
        prefix = msg.prefix
    if s:
        return IrcMsg(prefix=prefix,
                      command='KICK',
                      args=(channel, ','.join(nicks), s),
                      msg=msg)
    else:
        return IrcMsg(prefix=prefix,
                      command='KICK',
                      args=(channel, ','.join(nicks)),
                      msg=msg)
コード例 #25
0
 def _checkForAnnouncements(self, irc):
     start = time.time()
     self.log.info('Checking mailbox for announcements.')
     pop = self._getPop(irc)
     i = None
     for (i, msg) in self._getMsgs(pop):
         message = rfc822.Message(sio(msg))
         frm = message.get('From')
         if not frm:
             self.log.warning('Received message without From header.')
             continue
         else:
             frm = frm.rstrip()
         subject = message.get('Subject', '').rstrip()
         content = message.fp.read()
         self.log.info('Received message with subject %q from %q.',
                       subject, frm)
         if subject == 'all':
             channels = list(irc.state.channels)
         else:
             channels = subject.split()
             if not channels or not all(irc.isChannel, channels):
                 channels = list(self.registryValue('defaultChannels'))
                 if subject:
                     content = '%s: %s' % (subject, content)
             if not channels:
                 self.log.info('Received message with improper subject '
                               'line from %s.', frm)
                 continue
         prefix = self.registryValue('prefix')
         content = utils.str.normalizeWhitespace(content)
         self.log.info('Making announcement to %L.', channels)
         chunks = textwrap.wrap(content, 350)
         for channel in channels:
             if channel in irc.state.channels:
                 maximum = self.registryValue('limit', channel)
                 for chunk in chunks[:maximum]:
                     s = self._formatChunk(
                         self._formatPrefix(prefix + " ")+chunk)
                     irc.queueMsg(ircmsgs.privmsg(channel, s))
             prefix = ''
     self._quit(pop)
     self.log.info('Finished checking mailbox, time elapsed: %s',
                   utils.timeElapsed(time.time() - start))
コード例 #26
0
ファイル: plugin.py プロジェクト: tpapaioa/Limnoria
 def _list(self, irc, group):
     L = []
     for (vname, v) in group._children.items():
         if getattr(group, '_networkValue', False) and \
                 vname.startswith(':'):
             # Skip pseudo-children that are network names
             continue
         if getattr(group, '_channelValue', False) and \
                 irc.isChannel(vname):
             # Skip pseudo-children that are channel names
             continue
         if getattr(v, '_networkValue', False):
             vname = ':' + vname
         if getattr(v, '_channelValue', False):
             vname = '#' + vname
         if v._added and not all(irc.isChannel, v._added):
             vname = '@' + vname
         L.append(vname)
     utils.sortBy(str.lower, L)
     return L
コード例 #27
0
    def testStandardSubstitute(self):
        f = ircutils.standardSubstitute
        msg = ircmsgs.privmsg('#foo', 'filler', prefix='biff!quux@xyzzy')
        s = f(self.irc, msg, '$rand')
        try:
            int(s)
        except ValueError:
            self.fail('$rand wasn\'t an int.')
        s = f(self.irc, msg, '$randomInt')
        try:
            int(s)
        except ValueError:
            self.fail('$randomint wasn\'t an int.')
        self.assertEqual(f(self.irc, msg, '$botnick'), self.irc.nick)
        self.assertEqual(f(self.irc, msg, '$who'), msg.nick)
        self.assertEqual(f(self.irc, msg, '$WHO'),
                         msg.nick, 'stand. sub. not case-insensitive.')
        self.assertEqual(f(self.irc, msg, '$nick'), msg.nick)
        self.assertNotEqual(f(self.irc, msg, '$randomdate'), '$randomdate')
        q = f(self.irc,msg,'$randomdate\t$randomdate')
        dl = q.split('\t')
        if dl[0] == dl[1]:
            self.fail ('Two $randomdates in the same string were the same')
        q = f(self.irc, msg, '$randomint\t$randomint')
        dl = q.split('\t')
        if dl[0] == dl[1]:
            self.fail ('Two $randomints in the same string were the same')
        self.assertNotEqual(f(self.irc, msg, '$today'), '$today')
        self.assertNotEqual(f(self.irc, msg, '$now'), '$now')
        n = f(self.irc, msg, '$randnick')
        self.failUnless(n in self.irc.state.channels['#foo'].users)
        n = f(self.irc, msg, '$randomnick')
        self.failUnless(n in self.irc.state.channels['#foo'].users)
        n = f(self.irc, msg, '$randomnick '*100)
        L = n.split()
        self.failIf(all(L[0].__eq__, L), 'all $randomnicks were the same')
        c = f(self.irc, msg, '$channel')
        self.assertEqual(c, msg.args[0])

        net = f(self.irc, msg, '$network')
        self.assertEqual(net, self.irc.network)
コード例 #28
0
ファイル: ircmsgs.py プロジェクト: majestrate/Limnoria
def joins(channels, keys=None, prefix='', msg=None):
    """Returns a JOIN to each of channels."""
    if conf.supybot.protocols.irc.strictRfc():
        assert all(isChannel, channels), channels
    if msg and not prefix:
        prefix = msg.prefix
    if keys is None:
        keys = []
    assert len(keys) <= len(channels), 'Got more keys than channels.'
    if not keys:
        return IrcMsg(prefix=prefix,
                      command='JOIN',
                      args=(','.join(channels),), msg=msg)
    else:
        if conf.supybot.protocols.irc.strictRfc():
            chars = '\x00\r\n\f\t\v '
            for key in keys:
                assert not any([(ord(x) >= 128 or x in chars) for x in key])
        return IrcMsg(prefix=prefix,
                      command='JOIN',
                      args=(','.join(channels), ','.join(keys)), msg=msg)
コード例 #29
0
ファイル: ircmsgs.py プロジェクト: Athemis/Limnoria
def joins(channels, keys=None, prefix='', msg=None):
    """Returns a JOIN to each of channels."""
    if conf.supybot.protocols.irc.strictRfc():
        assert all(isChannel, channels), channels
    if msg and not prefix:
        prefix = msg.prefix
    if keys is None:
        keys = []
    assert len(keys) <= len(channels), 'Got more keys than channels.'
    if not keys:
        return IrcMsg(prefix=prefix,
                      command='JOIN',
                      args=(','.join(channels),), msg=msg)
    else:
        if conf.supybot.protocols.irc.strictRfc():
            chars = '\x00\r\n\f\t\v '
            for key in keys:
                assert not any([(ord(x) >= 128 or x in chars) for x in key])
        return IrcMsg(prefix=prefix,
                      command='JOIN',
                      args=(','.join(channels), ','.join(keys)), msg=msg)
コード例 #30
0
 def testStandardSubstitute(self):
     f = ircutils.standardSubstitute
     msg = ircmsgs.privmsg("#foo", "filler", prefix="biff!quux@xyzzy")
     s = f(self.irc, msg, "$rand")
     try:
         int(s)
     except ValueError:
         self.fail("$rand wasn't an int.")
     s = f(self.irc, msg, "$randomInt")
     try:
         int(s)
     except ValueError:
         self.fail("$randomint wasn't an int.")
     self.assertEqual(f(self.irc, msg, "$botnick"), self.irc.nick)
     self.assertEqual(f(self.irc, msg, "$who"), msg.nick)
     self.assertEqual(f(self.irc, msg, "$WHO"), msg.nick, "stand. sub. not case-insensitive.")
     self.assertEqual(f(self.irc, msg, "$nick"), msg.nick)
     self.assertNotEqual(f(self.irc, msg, "$randomdate"), "$randomdate")
     q = f(self.irc, msg, "$randomdate\t$randomdate")
     dl = q.split("\t")
     if dl[0] == dl[1]:
         self.fail("Two $randomdates in the same string were the same")
     q = f(self.irc, msg, "$randomint\t$randomint")
     dl = q.split("\t")
     if dl[0] == dl[1]:
         self.fail("Two $randomints in the same string were the same")
     self.assertNotEqual(f(self.irc, msg, "$today"), "$today")
     self.assertNotEqual(f(self.irc, msg, "$now"), "$now")
     n = f(self.irc, msg, "$randnick")
     self.failUnless(n in self.irc.state.channels["#foo"].users)
     n = f(self.irc, msg, "$randomnick")
     self.failUnless(n in self.irc.state.channels["#foo"].users)
     n = f(self.irc, msg, "$randomnick " * 100)
     L = n.split()
     self.failIf(all(L[0].__eq__, L), "all $randomnicks were the same")
     c = f(self.irc, msg, "$channel")
     self.assertEqual(c, msg.args[0])
コード例 #31
0
ファイル: plugin.py プロジェクト: kytvi2p/Supybot-plugins-1
    def incoming(self, irc, msg, args, optlist, globs):
        """[--{regexp,arch} <value>] [<glob> ...]

        Checks debian incoming for a matching package name.  The arch
        parameter defaults to i386; --regexp returns only those package names
        that match a given regexp, and normal matches use standard *nix
        globbing.
        """
        predicates = []
        archPredicate = lambda s: ('_i386.' in s)
        for (option, arg) in optlist:
            if option == 'regexp':
                predicates.append(r.search)
            elif option == 'arch':
                arg = '_%s.' % arg
                archPredicate = lambda s, arg=arg: (arg in s)
        predicates.append(archPredicate)
        for glob in globs:
            glob = fnmatch.translate(glob)
            predicates.append(re.compile(glob).search)
        packages = []
        try:
            fd = utils.web.getUrlFd('http://incoming.debian.org/')
        except utils.web.Error as e:
            irc.error(str(e), Raise=True)
        for line in fd:
            m = self._incomingRe.search(line.decode())
            if m:
                name = m.group(1)
                if all(None, map(lambda p: p(name), predicates)):
                    realname = utils.str.rsplit(name, '_', 1)[0]
                    packages.append(realname)
        if len(packages) == 0:
            irc.error('No packages matched that search.')
        else:
            irc.reply(format('%L', packages))
コード例 #32
0
    def incoming(self, irc, msg, args, optlist, globs):
        """[--{regexp,arch} <value>] [<glob> ...]

        Checks debian incoming for a matching package name.  The arch
        parameter defaults to i386; --regexp returns only those package names
        that match a given regexp, and normal matches use standard *nix
        globbing.
        """
        predicates = []
        archPredicate = lambda s: ('_i386.' in s)
        for (option, arg) in optlist:
            if option == 'regexp':
                predicates.append(r.search)
            elif option == 'arch':
                arg = '_%s.' % arg
                archPredicate = lambda s, arg=arg: (arg in s)
        predicates.append(archPredicate)
        for glob in globs:
            glob = fnmatch.translate(glob)
            predicates.append(re.compile(glob).search)
        packages = []
        try:
            fd = utils.web.getUrlFd('http://incoming.debian.org/')
        except utils.web.Error as e:
            irc.error(str(e), Raise=True)
        for line in fd:
            m = self._incomingRe.search(line.decode())
            if m:
                name = m.group(1)
                if all(None, map(lambda p: p(name), predicates)):
                    realname = utils.str.rsplit(name, '_', 1)[0]
                    packages.append(realname)
        if len(packages) == 0:
            irc.error('No packages matched that search.')
        else:
            irc.reply(format('%L', packages))
コード例 #33
0
                arg = '_%s.' % arg
                archPredicate = lambda s, arg=arg: (arg in s)
        predicates.append(archPredicate)
        for glob in globs:
            glob = fnmatch.translate(glob)
            predicates.append(re.compile(glob).search)
        packages = []
        try:
            fd = utils.web.getUrlFd('http://incoming.debian.org/')
        except utils.web.Error, e:
            irc.error(str(e), Raise=True)
        for line in fd:
            m = self._incomingRe.search(line)
            if m:
                name = m.group(1)
                if all(None, imap(lambda p: p(name), predicates)):
                    realname = utils.str.rsplit(name, '_', 1)[0]
                    packages.append(realname)
        if len(packages) == 0:
            irc.error('No packages matched that search.')
        else:
            irc.reply(format('%L', packages))

    incoming = thread(
        wrap(incoming, [
            getopts({
                'regexp': 'regexpMatcher',
                'arch': 'something'
            }),
            any('glob')
        ]))
コード例 #34
0
ファイル: plugin.py プロジェクト: v2k/Supybot-plugins
                arg = '_%s.' % arg
                archPredicate = lambda s, arg=arg: (arg in s)
        predicates.append(archPredicate)
        for glob in globs:
            glob = fnmatch.translate(glob)
            predicates.append(re.compile(glob).search)
        packages = []
        try:
            fd = utils.web.getUrlFd('http://incoming.debian.org/')
        except utils.web.Error, e:
            irc.error(str(e), Raise=True)
        for line in fd:
            m = self._incomingRe.search(line)
            if m:
                name = m.group(1)
                if all(None, imap(lambda p: p(name), predicates)):
                    realname = utils.str.rsplit(name, '_', 1)[0]
                    packages.append(realname)
        if len(packages) == 0:
            irc.error('No packages matched that search.')
        else:
            irc.reply(format('%L', packages))
    incoming = thread(wrap(incoming,
                           [getopts({'regexp': 'regexpMatcher',
                                     'arch': 'something'}),
                            any('glob')]))

    def bold(self, s):
        if self.registryValue('bold', dynamic.channel):
            return ircutils.bold(s)
        return s
コード例 #35
0
ファイル: plugin.py プロジェクト: Supybot/Debian
                arg = "_%s." % arg
                archPredicate = lambda s, arg=arg: (arg in s)
        predicates.append(archPredicate)
        for glob in globs:
            glob = fnmatch.translate(glob)
            predicates.append(re.compile(glob).search)
        packages = []
        try:
            fd = utils.web.getUrlFd("http://incoming.debian.org/")
        except utils.web.Error, e:
            irc.error(str(e), Raise=True)
        for line in fd:
            m = self._incomingRe.search(line)
            if m:
                name = m.group(1)
                if all(None, imap(lambda p: p(name), predicates)):
                    realname = utils.str.rsplit(name, "_", 1)[0]
                    packages.append(realname)
        if len(packages) == 0:
            irc.error("No packages matched that search.")
        else:
            irc.reply(format("%L", packages))

    incoming = thread(wrap(incoming, [getopts({"regexp": "regexpMatcher", "arch": "something"}), any("glob")]))

    def bold(self, s):
        if self.registryValue("bold", dynamic.channel):
            return ircutils.bold(s)
        return s

    _ptsUri = "http://packages.qa.debian.org/cgi-bin/soap-alpha.cgi"