Пример #1
0
 def testListkeys(self):
     self.assertResponse("listkeys %", 'No keys matching "%" found.')
     self.assertNotError("moo is <reply>moo")
     # With this set, if only one key matches, it should respond with
     # the factoid
     orig = MFconf.showFactoidIfOnlyOneMatch()
     try:
         MFconf.showFactoidIfOnlyOneMatch.setValue(True)
         self.assertResponse("listkeys moo", "moo")
         self.assertResponse("listkeys foo", 'No keys matching "foo" ' "found.")
         # Throw in a bunch more
         for i in range(10):
             self.assertNotError("moo%s is <reply>moo" % i)
         self.assertRegexp("listkeys moo", '^Key search for "moo" ' '\(11 found\): ("moo\d*", )+and "moo9"$')
         self.assertNotError("foo is bar")
         self.assertRegexp("listkeys %", '^Key search for "\%" ' '\(12 found\): "foo", ("moo\d*", )+and ' '"moo9"$')
         # Check quoting
         self.assertNotError("foo' is bar")
         self.assertResponse("listkeys foo", 'Key search for "foo" ' '(2 found): "foo" and "foo\'"')
         # Check unicode stuff
         self.assertResponse(u("listkeys Б"), 'No keys matching "Б" found.')
         self.assertNotError(u("АБВГДЕЖ is foo"))
         self.assertNotError(u("АБВГДЕЖЗИ is foo"))
         self.assertResponse(u("listkeys Б"), 'Key search for "Б" ' '(2 found): "АБВГДЕЖ" and "АБВГДЕЖЗИ"')
     finally:
         MFconf.showFactoidIfOnlyOneMatch.setValue(orig)
Пример #2
0
 def formatData(self, data, bold=True, max=0, onetoone=False):
     if isinstance(data, minisix.string_types):
         return data
     results = []
     if max:
         data = data[:max]
     for result in data:
         title = utils.web.htmlToText(result['titleNoFormatting']\
                                      .encode('utf-8'))
         url = result['unescapedUrl']
         if minisix.PY2:
             url = url.encode('utf-8')
         if title:
             if bold:
                 title = ircutils.bold(title)
             results.append(format('%s: %u', title, url))
         else:
             results.append(url)
     if minisix.PY2:
         repl = lambda x:x if isinstance(x, unicode) else unicode(x, 'utf8')
         results = list(map(repl, results))
     if not results:
         return [_('No matches found.')]
     elif onetoone:
         return results
     else:
         return [minisix.u('; ').join(results)]
Пример #3
0
    def testAliasImport(self):
        self.assertNotError('alias add foo "echo bar"')
        self.assertNotError(u('alias add baz "echo café"'))
        self.assertNotError('aka add qux "echo quux"')
        self.assertResponse('alias foo', 'bar')
        self.assertResponse('alias baz', 'café')
        self.assertRegexp('aka foo', 'there is no command named')
        self.assertResponse('aka qux', 'quux')

        self.assertNotError('aka importaliasdatabase')

        self.assertRegexp('alias foo', 'there is no command named')
        self.assertResponse('aka foo', 'bar')
        self.assertResponse('aka baz', 'café')
        self.assertResponse('aka qux', 'quux')

        self.assertNotError('alias add foo "echo test"')
        self.assertNotError('alias add spam "echo egg"')
        self.assertNotError('alias lock spam')

        self.assertRegexp(
            'aka importaliasdatabase',
            r'the 1 following command: foo \(This Aka already exists.\)$')
        self.assertResponse('aka foo', 'bar')
        self.assertResponse('alias foo', 'test')
        self.assertRegexp('alias spam', 'there is no command named')
        self.assertResponse('aka spam', 'egg')
Пример #4
0
    def testComplicatedNames(self):
        self.assertNotError(u('aka add café "echo coffee"'))
        self.assertResponse(u('café'), 'coffee')

        self.assertNotError('aka add "foo bar" "echo spam"')
        self.assertResponse('foo bar', 'spam')
        self.assertNotError('aka add "foo" "echo egg"')
        self.assertResponse('foo', 'egg')
        # You could expect 'spam' here, but in fact, this is dangerous.
        # Just imagine this session:
        # <evil_user> aka add "echo foo" quit
        # <bot> The operation succeeded.
        # ...
        # <owner> echo foo
        # * bot has quit
        self.assertResponse('foo bar', 'egg')
Пример #5
0
    def testAliasImport(self):
        self.assertNotError('alias add foo "echo bar"')
        self.assertNotError(u('alias add baz "echo café"'))
        self.assertNotError('aka add qux "echo quux"')
        self.assertResponse('alias foo', 'bar')
        self.assertResponse('alias baz', 'café')
        self.assertRegexp('aka foo', 'there is no command named')
        self.assertResponse('aka qux', 'quux')

        self.assertNotError('aka importaliasdatabase')

        self.assertRegexp('alias foo', 'there is no command named')
        self.assertResponse('aka foo', 'bar')
        self.assertResponse('aka baz', 'café')
        self.assertResponse('aka qux', 'quux')

        self.assertNotError('alias add foo "echo test"')
        self.assertNotError('alias add spam "echo egg"')
        self.assertNotError('alias lock spam')

        self.assertRegexp('aka importaliasdatabase',
            r'the 1 following command: foo \(This Aka already exists.\)$')
        self.assertResponse('aka foo', 'bar')
        self.assertResponse('alias foo', 'test')
        self.assertRegexp('alias spam', 'there is no command named')
        self.assertResponse('aka spam', 'egg')
Пример #6
0
    def testComplicatedNames(self):
        self.assertNotError(u('aka add café "echo coffee"'))
        self.assertResponse(u('café'), 'coffee')

        self.assertNotError('aka add "foo bar" "echo spam"')
        self.assertResponse('foo bar', 'spam')
        self.assertNotError('aka add "foo" "echo egg"')
        self.assertResponse('foo', 'egg')
        # You could expect 'spam' here, but in fact, this is dangerous.
        # Just imagine this session:
        # <evil_user> aka add "echo foo" quit
        # <bot> The operation succeeded.
        # ...
        # <owner> echo foo
        # * bot has quit
        self.assertResponse('foo bar', 'egg')
Пример #7
0
    def formatData(self, data, bold=True, max=0, onetoone=False):
        """formats Data for output"""
        data = self.getData(data)
        results = []
        if max:
            data = data[:max]

        for result in data:
            title = result['title']
            url = result['url']
            if minisix.PY2:
                url = url.encode('utf-8')
            if title:
                if bold:
                    title = ircutils.bold(title)
                results.append(format('%s: %u', title, url))
            else:
                results.append(url)
        if minisix.PY2:
            repl = lambda x:x if isinstance(x, unicode) else unicode(x, 'utf8')
            results = list(map(repl, results))
        if not results:
            return [_('No matches found.')]
        elif onetoone:
            return results
        else:
            return [minisix.u('; ').join(results)]
Пример #8
0
    def formatData(self, data, bold=True, max=0, onetoone=False):
        """formats Data for output"""
        data = self.getData(data)
        results = []
        if max:
            data = data[:max]

        for result in data:
            title = result['title']
            url = result['url']
            if minisix.PY2:
                url = url.encode('utf-8')
            if title:
                if bold:
                    title = ircutils.bold(title)
                results.append(format('%s: %u', title, url))
            else:
                results.append(url)
        if minisix.PY2:
            repl = lambda x: x if isinstance(x, unicode) else unicode(
                x, 'utf8')
            results = list(map(repl, results))
        if not results:
            return [_('No matches found.')]
        elif onetoone:
            return results
        else:
            return [minisix.u('; ').join(results)]
Пример #9
0
 def testListkeys(self):
     self.assertResponse('listkeys %', 'No keys matching "%" found.')
     self.assertNotError('moo is <reply>moo')
     # With this set, if only one key matches, it should respond with
     # the factoid
     orig = MFconf.showFactoidIfOnlyOneMatch()
     try:
         MFconf.showFactoidIfOnlyOneMatch.setValue(True)
         self.assertResponse('listkeys moo', 'moo')
         self.assertResponse('listkeys foo', 'No keys matching "foo" '
                             'found.')
         # Throw in a bunch more
         for i in range(10):
             self.assertNotError('moo%s is <reply>moo' % i)
         self.assertRegexp('listkeys moo',
                           r'^Key search for "moo" '
                           r'\(11 found\): ("moo\d*", )+and "moo9"$')
         self.assertNotError('foo is bar')
         self.assertRegexp('listkeys %',
                           r'^Key search for "\%" '
                           r'\(12 found\): "foo", ("moo\d*", )+and '
                           r'"moo9"$')
         # Check quoting
         self.assertNotError('foo\' is bar')
         self.assertResponse('listkeys foo',
                             'Key search for "foo" '
                             '(2 found): "foo" and "foo\'"')
         # Check unicode stuff
         self.assertResponse(u('listkeys Б'),
                 'No keys matching "Б" found.')
         self.assertNotError(u('АБВГДЕЖ is foo'))
         self.assertNotError(u('АБВГДЕЖЗИ is foo'))
         self.assertResponse(u('listkeys Б'),
                             'Key search for "Б" '
                             '(2 found): "АБВГДЕЖ" and "АБВГДЕЖЗИ"')
     finally:
         MFconf.showFactoidIfOnlyOneMatch.setValue(orig)
Пример #10
0
 def testEcho(self):
     self.assertHelp('echo')
     self.assertResponse('echo foo', 'foo')
     self.assertResponse(u('echo 好'), '好')
     self.assertResponse(u('echo "好"'), '好')
Пример #11
0
 def testEcho(self):
     self.assertHelp('echo')
     self.assertResponse('echo foo', 'foo')
     self.assertResponse(u('echo 好'), '好')
     self.assertResponse(u('echo "好"'), '好')
Пример #12
0
    def testUnicode(self):
        self.assertNotError(u('alias add \u200b echo foo'))
        self.assertResponse(u('\u200b'), 'foo')

        self.assertNotError('alias add café echo bar')
        self.assertResponse('café', 'bar')
Пример #13
0
    def testUnicode(self):
        self.assertNotError(u('alias add \u200b echo foo'))
        self.assertResponse(u('\u200b'), 'foo')

        self.assertNotError('alias add café echo bar')
        self.assertResponse('café', 'bar')