Exemplo n.º 1
0
    def create(cls, app, **kwargs):
        try:
            content = kwargs['content'].strip()
        except KeyError:
            raise ValueError('content_missing')
        if not content:
            raise ValueError('content_empty')

        title = truncate(content.splitlines()[0])

        post = TextPost(app, 'text_post:' + randstr(), title, None, content)
        app.db.hmset(post.id, post.json())
        return post
Exemplo n.º 2
0
    def on_message(self, msgstr):
        msg = Message.parse(msgstr, self)
        self.app.logger.debug('received message %s from %s', truncate(str(msg)),
            self.request.remote_ip)

        handle = self.app.msg_handlers[msg.type]
        try:
            # TODO: support Future for asynchronous handlers (see
            # https://code.google.com/p/pythonfutures/ )
            response = handle(msg)
        except Error as e:
            response = Message(msg.type, e.json())

        if response:
            msg.frm.send(response)
Exemplo n.º 3
0
 def send(self, msg):
     self.write_message(str(msg))
     self.app.logger.debug('sent message %s to %s', truncate(str(msg)),
         self.request.remote_ip)