make multiuser_notebook a package

This commit is contained in:
MinRK
2014-06-19 15:36:22 -07:00
parent 9d16154856
commit d3ebeb0cc1
10 changed files with 30 additions and 7 deletions

2
.gitignore vendored
View File

@@ -1,4 +1,4 @@
node_modules
*.pyx
*.py[co]
*~
.DS_Store

View File

@@ -24,7 +24,7 @@ Basic principals:
## to use
$> python multiuser.py
$> python -m multiuser_notebook
visit `http://localhost:8000`, and login (any username, password=`password`).

View File

View File

@@ -0,0 +1,2 @@
from .multiuser import main
main()

View File

@@ -0,0 +1,16 @@
import json
from tornado import web
from tornado.escape import xhtml_escape
class HeadersHandler(web.RequestHandler):
def get(self):
headers = {}
for key, value in self.request.headers.items():
if ';' in value:
value = [ s.strip() for s in value.split(';') ]
headers[key] = value
self.write("<pre>%s</pre>" % (
xhtml_escape(json.dumps(headers, indent=1))
))

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env node
var ConfigurableProxy = require('./lib/configproxy.js').ConfigurableProxy;
var ConfigurableProxy = require('./configproxy.js').ConfigurableProxy;
var proxy = new ConfigurableProxy();
proxy.listen(8000);

View File

@@ -25,7 +25,7 @@ from tornado.options import define, options
from IPython.utils.traitlets import HasTraits, Any, Unicode, Integer, Dict
from IPython.html import utils
from headers import HeadersHandler
from .headers import HeadersHandler
def random_port():
"""get a single random port"""
@@ -37,6 +37,8 @@ def random_port():
auth_header_pat = re.compile(r'^token\s+([^\s]+)$')
here = os.path.dirname(__file__)
def token_authorized(method):
def check_token(self, *args, **kwargs):
auth_header = self.request.headers.get('Authorization', '')
@@ -96,7 +98,7 @@ class UserSession(HasTraits):
def start(self):
assert self.process is None or self.process.poll() is not None
cmd = [sys.executable, 'singleuser.py',
cmd = [sys.executable, '-m', 'multiuser_notebook.singleuser',
'--user=%s' % self.user, '--port=%i' % self.port,
'--cookie-name=%s' % self.cookie_name,
'--multiuser-prefix=%s' % self.multiuser_prefix,
@@ -338,10 +340,11 @@ def main():
'api',
),
login_url=utils.url_path_join(base_url, 'login'),
template_path=os.path.join(here, 'templates'),
)
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(options.port)
proxy = Popen(["node", "proxy.js"])
proxy = Popen(["node", os.path.join(here, 'js', 'main.js')])
try:
tornado.ioloop.IOLoop.instance().start()
finally:

View File

@@ -18,7 +18,9 @@ from tornado.options import define, options
from IPython.html import utils
from headers import HeadersHandler
from .headers import HeadersHandler
here = os.path.dirname(__file__)
class BaseHandler(RequestHandler):
@property