Esempio n. 1
0
    def re(self, irc, msg, args, ff, text):
        """<regexp> <text>

        If <regexp> is of the form m/regexp/flags, returns the portion of
        <text> that matches the regexp.  If <regexp> is of the form
        s/regexp/replacement/flags, returns the result of applying such a
        regexp to <text>.
        """
        if isinstance(ff, (types.FunctionType, types.MethodType)):
            f = ff
        else:
            f = lambda s: ff.search(s) and ff.search(s).group(0) or ''
        if f('') and len(f(' ')) > len(f('')) + 1:  # Matches the empty string.
            s = 'You probably don\'t want to match the empty string.'
            irc.error(s)
        else:
            t = self.registryValue('re.timeout')
            try:
                v = commands.process(f,
                                     text,
                                     timeout=t,
                                     pn=self.name(),
                                     cn='re')
                irc.reply(v)
            except commands.ProcessTimeoutError, e:
                irc.error("ProcessTimeoutError: %s" % (e, ))
Esempio n. 2
0
File: plugin.py Progetto: totte/aide
                def f(m, arg=arg):
                    def f1(s, arg):
                        """Since we can't enqueue match objects into the multiprocessing queue,
                        we'll just wrap the function to return bools."""
                        if arg.search(s) is not None:
                            return True
                        else:
                            return False

                    if ircmsgs.isAction(m):
                        m1 = ircmsgs.unAction(m)
                        #return arg.search(ircmsgs.unAction(m))
                    else:
                        m1 = m.args[1]
                        #return arg.search(m.args[1])
                    try:
                        # use a subprocess here, since specially crafted regexps can
                        # take exponential time and hang up the bot.
                        # timeout of 0.1 should be more than enough for any normal regexp.
                        v = commands.process(f1,
                                             m1,
                                             arg,
                                             timeout=0.1,
                                             pn=self.name(),
                                             cn='last')
                        return v
                    except commands.ProcessTimeoutError:
                        return False
Esempio n. 3
0
 def safe_getUrl(url):
     try:
         return commands.process(utils.web.getUrl, url,
                 timeout=10, heap_size=10*1024*1024,
                 pn='GPG')
     except (commands.ProcessTimeoutError, MemoryError):
         raise utils.web.Error(_('Page is too big or the server took '
                 'too much time to answer the request.'))
Esempio n. 4
0
 def safe_getUrl(url):
     try:
         return commands.process(utils.web.getUrl, url,
                 timeout=10, heap_size=10*1024*1024,
                 pn='GPG')
     except (commands.ProcessTimeoutError, MemoryError):
         raise utils.web.Error(_('Page is too big or the server took '
                 'too much time to answer the request.'))
Esempio n. 5
0
 def newf(self, irc, *args):
     try:
         replies = commands.process(
             process, self, irc, *args, timeout=10, heap_size=1024 * 1024, pn=self.name(), cn=f.__name__
         )
     except commands.ProcessTimeoutError:
         raise utils.web.Error(_("Page is too big or the server took " "too much time to answer the request."))
     else:
         for (method, args, kwargs) in replies:
             getattr(irc, method)(*args, **kwargs)
Esempio n. 6
0
 def newf(self, irc, *args):
     try:
         replies = commands.process(process, self, irc, *args,
                 timeout=5, heap_size=1024*1024,
                 pn=self.name(), cn=f.func_name)
     except commands.ProcessTimeoutError:
         raise utils.web.Error(_('Page is too big.'))
     else:
         for reply in replies:
             irc.queueMsg(reply)
Esempio n. 7
0
 def newf(self, irc, *args):
     try:
         replies = commands.process(process, self, irc, *args,
                 timeout=5, heap_size=1024*1024,
                 pn=self.name(), cn=f.__name__)
     except commands.ProcessTimeoutError:
         raise utils.web.Error(_('Page is too big.'))
     else:
         for (method, args, kwargs) in replies:
             getattr(irc, method)(*args, **kwargs)
Esempio n. 8
0
 def newf(self, irc, *args):
     try:
         replies = commands.process(process, self, irc, *args,
                 timeout=10, heap_size=10*1024*1024,
                 pn=self.name(), cn=f.__name__)
     except (commands.ProcessTimeoutError, MemoryError):
         raise utils.web.Error(_('Page is too big or the server took '
                 'too much time to answer the request.'))
     else:
         for (method, args, kwargs) in replies:
             getattr(irc, method)(*args, **kwargs)
Esempio n. 9
0
 def newf(*args, **kwargs):
     try:
         return commands.process(f,
                                 *args,
                                 timeout=10,
                                 heap_size=100 * 1024 * 1024,
                                 pn="Fediverse",
                                 cn=f.__name__,
                                 **kwargs)
     except (commands.ProcessTimeoutError, MemoryError):
         raise web.Error("Page is too big or the server took "
                         "too much time to answer the request.")
Esempio n. 10
0
 def newf(self, irc, *args):
     try:
         replies = commands.process(process,
                                    self,
                                    irc,
                                    *args,
                                    timeout=5,
                                    heap_size=1024 * 1024,
                                    pn=self.name(),
                                    cn=f.__name__)
     except commands.ProcessTimeoutError:
         raise utils.web.Error(_('Page is too big.'))
     else:
         for (method, args, kwargs) in replies:
             getattr(irc, method)(*args, **kwargs)
Esempio n. 11
0
 def f(m, arg=arg):
     def f1(s, arg):
         """Since we can't enqueue match objects into the multiprocessing queue,
         we'll just wrap the function to return bools."""
         if arg.search(s) is not None:
             return True
         else:
             return False
     if ircmsgs.isAction(m):
         m1 = ircmsgs.unAction(m)
         #return arg.search(ircmsgs.unAction(m))
     else:
         m1 = m.args[1]
         #return arg.search(m.args[1])
     try:
         # use a subprocess here, since specially crafted regexps can
         # take exponential time and hang up the bot.
         # timeout of 0.1 should be more than enough for any normal regexp.
         v = commands.process(f1, m1, arg, timeout=0.1, pn=self.name(), cn='last')
         return v
     except commands.ProcessTimeoutError:
         return False
Esempio n. 12
0
    def re(self, irc, msg, args, ff, text):
        """<regexp> <text>

        If <regexp> is of the form m/regexp/flags, returns the portion of
        <text> that matches the regexp.  If <regexp> is of the form
        s/regexp/replacement/flags, returns the result of applying such a
        regexp to <text>.
        """
        if isinstance(ff, (types.FunctionType, types.MethodType)):
            f = ff
        else:
            f = lambda s: ff.search(s) and ff.search(s).group(0) or ''
        if f('') and len(f(' ')) > len(f(''))+1: # Matches the empty string.
            s = 'You probably don\'t want to match the empty string.'
            irc.error(s)
        else:
            t = self.registryValue('re.timeout')
            try:
                v = commands.process(f, text, timeout=t, pn=self.name(), cn='re')
                irc.reply(v)
            except commands.ProcessTimeoutError, e:
                irc.error("ProcessTimeoutError: %s" % (e,))