def __init__(self, ignore=False, password='', name='', capabilities=(), hostmasks=None, nicks=None, secure=False, hashed=False): self.id = None self.auth = [] # The (time, hostmask) list of auth crap. self.name = name # The name of the user. self.ignore = ignore # A boolean deciding if the person is ignored. self.secure = secure # A boolean describing if hostmasks *must* match. self.hashed = hashed # True if the password is hashed on disk. self.password = password # password (plaintext? hashed?) self.capabilities = UserCapabilitySet() for capability in capabilities: self.capabilities.add(capability) if hostmasks is None: self.hostmasks = ircutils.IrcSet( ) # hostmasks used for recognition else: self.hostmasks = hostmasks if nicks is None: self.nicks = {} # {'network1': ['foo', 'bar'], 'network': ['baz']} else: self.nicks = nicks
def __init__(self, irc): self.__parent = super(Topic, self) self.__parent.__init__(irc) self.undos = ircutils.IrcDict() self.redos = ircutils.IrcDict() self.lastTopics = ircutils.IrcDict() self.watchingFor332 = ircutils.IrcSet()
def testJoinToOneChannel(self): orig = conf.supybot.networks.test.channels() channels = ircutils.IrcSet() channels.add("#bar") conf.supybot.networks.test.channels.setValue(channels) msgs = conf.supybot.networks.test.channels.joins() self.assertEqual(msgs[0].args, ("#bar", )) conf.supybot.networks.test.channels.setValue(orig)
def getChannels(self): """Get a list of channels in the database""" cursor = self._conn.cursor() cursor.execute("""SELECT DISTINCT(chan) FROM chans_cache""") results = ircutils.IrcSet() for row in cursor: results.add(row[0]) cursor.close() return results
def test(self): s = ircutils.IrcSet() s.add('foo') s.add('bar') self.failUnless('foo' in s) self.failUnless('FOO' in s) s.discard('alfkj') s.remove('FOo') self.failIf('foo' in s) self.failIf('FOo' in s)
def test(self): s = ircutils.IrcSet() s.add('foo') s.add('bar') self.assertTrue('foo' in s) self.assertTrue('FOO' in s) s.discard('alfkj') s.remove('FOo') self.assertFalse('foo' in s) self.assertFalse('FOo' in s)
def testJoinToManyChannels(self): orig = conf.supybot.networks.test.channels() channels = ircutils.IrcSet() input_list = [] for x in range(1, 30): name = "#verylongchannelname" + str(x) channels.add(name) input_list.append(name) conf.supybot.networks.test.channels.setValue(channels) msgs = conf.supybot.networks.test.channels.joins() # Double check we split the messages self.assertEqual(len(msgs), 2) # Ensure all channel names are present chan_list = (msgs[0].args[0] + ',' + msgs[1].args[0]).split(',') self.assertCountEqual(input_list, chan_list) conf.supybot.networks.test.channels.setValue(orig)
def __init__(self, irc): self.__parent = super(Topic, self) self.__parent.__init__(irc) self.undos = ircutils.IrcDict() self.redos = ircutils.IrcDict() self.lastTopics = ircutils.IrcDict() self.watchingFor332 = ircutils.IrcSet() try: pkl = open(filename, 'rb') try: self.undos = pickle.load(pkl) self.redos = pickle.load(pkl) self.lastTopics = pickle.load(pkl) self.watchingFor332 = pickle.load(pkl) except Exception, e: self.log.debug('Unable to load pickled data: %s', e) pkl.close()
def testCopy(self): s = ircutils.IrcSet() s.add('foo') s.add('bar') s1 = copy.deepcopy(s) self.failUnless('foo' in s) self.failUnless('FOO' in s) s.discard('alfkj') s.remove('FOo') self.failIf('foo' in s) self.failIf('FOo' in s) self.failUnless('foo' in s1) self.failUnless('FOO' in s1) s1.discard('alfkj') s1.remove('FOo') self.failIf('foo' in s1) self.failIf('FOo' in s1)
def testCopy(self): s = ircutils.IrcSet() s.add('foo') s.add('bar') s1 = copy.deepcopy(s) self.assertTrue('foo' in s) self.assertTrue('FOO' in s) s.discard('alfkj') s.remove('FOo') self.assertFalse('foo' in s) self.assertFalse('FOo' in s) self.assertTrue('foo' in s1) self.assertTrue('FOO' in s1) s1.discard('alfkj') s1.remove('FOo') self.assertFalse('foo' in s1) self.assertFalse('FOo' in s1)
def seenWildcard(self, channel, nick): nicks = ircutils.IrcSet() nickRe = re.compile('^%s$' % '.*'.join(nick.split('*')), re.I) for (searchChan, searchNick) in self.keys(): #print 'chan: %s ... nick: %s' % (searchChan, searchNick) if isinstance(searchNick, int): # We need to skip the reponses that are keyed by id as they # apparently duplicate the responses for the same person that # are keyed by nick-string continue if ircutils.strEqual(searchChan, channel): if nickRe.search(searchNick) is not None: nicks.add(searchNick) L = [[nick, self.seen(channel, nick)] for nick in nicks] def negativeTime(x): return -x[1][0] utils.sortBy(negativeTime, L) return L
def testNick(self): self.irc.reset() self.irc.feedMsg(ircmsgs.IrcMsg(':someuser JOIN #foo')) self.irc.feedMsg(ircmsgs.IrcMsg(':someuser JOIN #bar')) self.irc.feedMsg(ircmsgs.IrcMsg(':someuser2 JOIN #bar2')) class Callback(irclib.IrcCallback): channels_set = None def name(self): return 'testcallback' def doNick(self2, irc, msg): self2.channels_set = msg.tagged('channels') c = Callback() self.irc.addCallback(c) try: self.irc.feedMsg(ircmsgs.IrcMsg(':someuser NICK newuser')) finally: self.irc.removeCallback(c.name()) self.assertEqual(c.channels_set, ircutils.IrcSet(['#foo', '#bar']))