예제 #1
0
파일: basics.py 프로젝트: troolee/rohrpost
def handler_b2(router, channel, msg):
    logger.debug('handler_b2')


def intercom_handler(client, msg):
    logger.debug('intercom_handler %s %s', msg.name, msg.data)
    if msg.name == 'hello':
        msg = IncomeMessage('foo', {1:1}, client)
        router.process_message('channel_b', msg)

    
router = make_router({
    'channel_a': {
        'message_a1': handler_a1,
        'message_a2': handler_a2,
    },
    'channel_b': {
        '*': [handler_b1, handler_b2],
    },
})
router.get_channel('channel_a').connect(IntercomClient({'id': 'intercom-client'}, intercom_handler))


class BasicTests(unittest.TestCase):

    def test_make_router(self):
        router.process_message('channel_a', ('foo', {'bar': True}))
        router.process_message('channel_a', IncomeMessage('message_a1', {'param1': 1}))
        for x in xrange(2):
            router.process_message('channel_b', ('foo', {'bar': True}))
            router.process_message('channel_b', ('foo', {'bar': False}))
예제 #2
0
파일: chat.py 프로젝트: troolee/rohrpost
import os
import tornado
import tornado.websocket
from tornado import httpserver, ioloop, web

from rohrpost import make_router
from rohrpost.channels.tornadoweb import rohrpost_route

logging.getLogger().setLevel(logging.DEBUG)


router = make_router({
    'chat': {
        'message': 'handlers.on_message',
        'dm': 'handlers.on_direct_message',
        '*': 'handlers.on_def_message',
    }
})

class IndexHandler(tornado.web.RequestHandler):
    def get(self, *args, **kwargs):
        self.render("index.html")

ROOT = os.path.abspath(os.path.dirname(__file__))

application = tornado.web.Application(
    [
            (r"/", IndexHandler),
            (r'/(.*\.js)', web.StaticFileHandler, {"path": ROOT}),
            rohrpost_route(r'/ws', router, ['chat']),