예제 #1
0
 def handle(self):
     prep = Preprocessor().parse(self.rfile.read())
     preprocessed = prep.strip('\n')
     resp = nl.yacc.parse(preprocessed.strip('\n'))
     if preprocessed.endswith('.'):
         nl.extend()
         nl.now()
     self.wfile.write(resp)
예제 #2
0
 def privmsg(self, user, channel, msg):
     if user and self.nickname in msg:
         msg = re.compile(self.nickname + "[:, ]*", re.I).sub('', msg)
         other = user.split('!', 1)[0]
         prefix = other + ': '
         msg = msg.strip()
         self.nl_buff[other] += ' ' + msg
         lastchar = self.nl_buff[other][-1]
         if lastchar in ('.', '?'):
             resp = parse(self.nl_buff[other], self.preprocessor)
             self.nl_buff[other] = ''
             if lastchar == '.':
                 nl.kb.extend()
                 nl.now()
         else:
             resp = '...'
         if resp is None:
             resp = 'Do not understand'
         self.msg(self.factory.channel, prefix + str(resp))
예제 #3
0
    def cms_test(self):
        contexts = ('one', 'two', 'three')
        for c in contexts:
            self._add_context(c)
        self.cms.r_workflow_for_content(self.cms.Document,
                                        self.cms.doc_workflow,
                                        self.cms.Context('one'))
        for n in xrange(0, 100, 3):
            for m, c in enumerate(contexts):
                self._add_content('cpu%d' % (n+m), 'public', c)
        for n in xrange(0, 100, 3):
            for m, c in enumerate(contexts):
                self._add_content('cpr%d' % (n+m), 'private', c)
        for n in xrange(0, 50, 3):
            for m, c in enumerate(contexts):
                self._add_user('m%d' % (n+m), 'manager', c)
        for n in xrange(0, 100, 3):
            for m, c in enumerate(contexts):
                self._add_user('e%d' % (n+m), 'editor', c)
        for n in xrange(0, 300, 3):
            for m, c in enumerate(contexts):
                self._add_user('u%d' % (n+m), 'member', c)

        nl.kb.tell(nl.Fact(self.cms.Person('m3'),
                           self.cms.Wants(
                                   to=self.cms.Publish(
                                             what=self.cms.Content('cpr3'))),
                           self.cms.Instant('now')))

        nl.kb.extend()
        assert nl.kb.ask(nl.Fact(self.cms.Person('m3'),
                                 self.cms.Publish(what=self.cms.Content('cpr3')),
                                 nl.Instant('now')))
        assert nl.kb.ask(nl.Fact(self.cms.Document('cpr3'),
                                 self.cms.Has(what=self.cms.Status('public')),
                                 nl.Duration(start=nl.Instant('now'))))

        nl.now()

        nl.kb.tell(nl.Fact(self.cms.Person('m3'),
                           self.cms.Wants(
                                   to=self.cms.Hide(
                                             what=self.cms.Content('cpu3'))),
                           self.cms.Instant('now')))

        nl.kb.extend()

        assert nl.kb.ask(nl.Fact(self.cms.Document('cpu3'),
                                 self.cms.Has(what=self.cms.Status('private')),
                                 nl.Instant('now')))

        nl.now()

        nl.kb.tell(nl.Fact(self.cms.Person('m6'),
                           self.cms.Wants(
                                   to=self.cms.Publish(
                                             what=self.cms.Content('cpu3'))),
                           self.cms.Instant('now')))

        nl.kb.extend()

        assert nl.kb.ask(nl.Fact(self.cms.Person('m6'),
                                 self.cms.Publish(what=self.cms.Content('cpu3')),
                                 nl.Instant('now')))

        assert nl.kb.ask(nl.Fact(self.cms.Document('cpu3'),
                                 self.cms.Has(what=self.cms.Status('public')),
                                 nl.Instant('now')))

        main_view = self.cms.ActionStep('main_view')
        main_edit = self.cms.ActionStep('main_edit')
        button_edit = self.cms.ActionStep('button_edit')
        nl.kb.tell(main_view, main_edit, button_edit)

        nl.kb.tell(nl.Fact(self.cms.Edit,
                           self.cms.Contains(
                                   what=main_edit),
                           self.cms.Duration(start='now')))

        nl.kb.tell(nl.Fact(self.cms.View,
                           self.cms.Contains(
                                   what=main_view),
                           self.cms.Duration(start='now')))

        nl.kb.tell(nl.Fact(main_view,
                           self.cms.Has(
                                   what=button_edit),
                           self.cms.Duration(start='now')))

        nl.kb.tell(nl.Fact(self.cms.Person('m6'),
                           self.cms.Wants(to=self.cms.View(
                                             what=self.cms.Content('cpu3'))),
                           self.cms.Instant('now')))

        nl.kb.extend()

        assert nl.kb.ask(nl.Fact(self.cms.Person('m6'),
                           self.cms.Has(what=button_edit),
                           self.cms.Instant('now')))

        assert not nl.kb.ask(nl.Fact(self.cms.Person('m6'),
                           self.cms.Has(what=main_edit),
                           self.cms.Instant('now')))
예제 #4
0
파일: compiler.py 프로젝트: enriquepablo/nl
def p_passtime(p):
    """order : PASSTIME DOT
             | NOW DOT"""
    response = nl.now()
    p[0] = str(response)