self.shell.write = self.write self.start() self.send({ 'id': 0, 'complete': False, 'more': False, 'out': "Python %s on %s\n" % (sys.version, sys.platform) }) def on_message(self, msg): self.commands.put_nowait(json.loads(msg)) def on_closed(self): if self.shell_worker: self.shell_worker.kill() if __name__ == '__main__': """ interactive shell """ from pyramid.config import Configurator from pyramid_sockjs.paster import gevent_server_runner config = Configurator() config.include('pyramid_sockjs') config.add_sockjs_route('shell', '/++shell++', session=InteractiveShell) app = config.make_wsgi_app() gevent_server_runner(app, {}, host='127.0.0.1')
def index(request): return {} class MapSession(Session): def on_message(self, line): print line response = urllib.urlopen("http://isithackday.com/arrpi.php?" + urllib.urlencode({'text': line})).read() print response self.send(response) # our app configuration def application(global_config, **settings): config = Configurator(settings=settings) config.add_static_view(name="static", path="static", cache_max_age=3600) config.add_view(index, renderer='piratechat:app.pt') config.include('pyramid_sockjs') config.add_sockjs_route(session=MapSession) return config.make_wsgi_app() if __name__ == '__main__': from pyramid_sockjs.paster import gevent_server_runner gevent_server_runner(application(None), {}, host='0.0.0.0')
'manager': self.manager}) self.shell.write = self.write self.start() self.send({'id': 0, 'complete': False, 'more': False, 'out': "Python %s on %s\n" % (sys.version, sys.platform)}) def on_message(self, msg): self.commands.put_nowait(json.loads(msg)) def on_closed(self): if self.shell_worker: self.shell_worker.kill() if __name__ == '__main__': """ interactive shell """ from pyramid.config import Configurator from pyramid_sockjs.paster import gevent_server_runner config = Configurator() config.include('pyramid_sockjs') config.add_sockjs_route('shell', '/++shell++', session=InteractiveShell) app = config.make_wsgi_app() gevent_server_runner(app, {}, host='127.0.0.1')
websocket.TIMING = 0.1 jsonp.timing = 0.1 PollingTransport.timing = 0.2 config = Configurator() config.include('pyramid_sockjs') config.add_sockjs_route('echo', '/echo', session=EchoSession) config.add_sockjs_route('wsoff', '/disabled_websocket_echo', session=EchoSession, disable_transports=('websocket', )) config.add_sockjs_route('close', '/close', session=CloseSession) config.add_sockjs_route('broadcast', '/broadcast', session=BroadcastSession) config.add_sockjs_route('cookie', '/cookie_needed_echo', session=EchoSession, cookie_needed=True) app = config.make_wsgi_app() if len(sys.argv) > 1 and (sys.argv[1] == '-g'): from gunicorn.app.pasterapp import paste_server paste_server(app, port=8081, worker_class='gevent', workers=1) else: gevent_server_runner(app, {}, **{'host': '127.0.0.1', 'port': '8081'})
from pyramid_sockjs import Session class EchoSession(Session): def on_message(self, msg): self.send(msg) @classmethod def dump_stats(self): print 'Clients: %d' % (len(self.clients)) if __name__ == '__main__': from pyramid.config import Configurator from pyramid_sockjs.paster import gevent_server_runner config = Configurator() config.include('pyramid_sockjs') config.add_sockjs_route(prefix='/echo', session=EchoSession) app = config.make_wsgi_app() gevent_server_runner(app, {})
from pyramid.config import Configurator from pyramid.view import view_config from pyramid_sockjs.session import Session import urllib def index(request): return {} class MapSession(Session): def on_message(self, line): print line response = urllib.urlopen("http://isithackday.com/arrpi.php?"+urllib.urlencode({'text':line})).read() print response self.send(response) # our app configuration def application(global_config, **settings): config = Configurator(settings=settings) config.add_static_view(name="static",path="static", cache_max_age=3600) config.add_view(index, renderer='piratechat:app.pt') config.include('pyramid_sockjs') config.add_sockjs_route(session=MapSession) return config.make_wsgi_app() if __name__ == '__main__': from pyramid_sockjs.paster import gevent_server_runner gevent_server_runner(application(None), {}, host='0.0.0.0')
from pyramid_sockjs.transports.htmlfile import HTMLFileTransport HTMLFileTransport.maxsize = 4096 EventsourceTransport.maxsize = 4096 XHRStreamingTransport.maxsize = 4096 XHRStreamingTransport.timing = 0.01 websocket.TIMING = 0.1 jsonp.timing = 0.1 PollingTransport.timing = 0.2 config = Configurator() config.include('pyramid_sockjs') config.add_sockjs_route('echo', '/echo', session=EchoSession) config.add_sockjs_route('wsoff', '/disabled_websocket_echo', session=EchoSession, disable_transports=('websocket',)) config.add_sockjs_route('close', '/close', session=CloseSession) config.add_sockjs_route('broadcast', '/broadcast', session=BroadcastSession) config.add_sockjs_route('cookie', '/cookie_needed_echo', session=EchoSession, cookie_needed=True) app = config.make_wsgi_app() if len(sys.argv) > 1 and (sys.argv[1] == '-g'): from gunicorn.app.pasterapp import paste_server paste_server(app, port=8081, worker_class='gevent', workers=1) else: gevent_server_runner(app, {}, **{'host': '127.0.0.1', 'port': '8081'})