diff --git a/.gitignore b/.gitignore index 79c2a512..6b7ca594 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ node_modules -*.pyx +*.py[co] *~ .DS_Store diff --git a/README.md b/README.md index 862b22d1..863274dd 100644 --- a/README.md +++ b/README.md @@ -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`). diff --git a/multiuser_notebook/__init__.py b/multiuser_notebook/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/multiuser_notebook/__main__.py b/multiuser_notebook/__main__.py new file mode 100644 index 00000000..b8d64103 --- /dev/null +++ b/multiuser_notebook/__main__.py @@ -0,0 +1,2 @@ +from .multiuser import main +main() diff --git a/multiuser_notebook/headers.py b/multiuser_notebook/headers.py new file mode 100644 index 00000000..7ba83582 --- /dev/null +++ b/multiuser_notebook/headers.py @@ -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("
%s
" % ( + xhtml_escape(json.dumps(headers, indent=1)) + )) + diff --git a/lib/configproxy.js b/multiuser_notebook/js/configproxy.js similarity index 100% rename from lib/configproxy.js rename to multiuser_notebook/js/configproxy.js diff --git a/proxy.js b/multiuser_notebook/js/main.js similarity index 51% rename from proxy.js rename to multiuser_notebook/js/main.js index b451a85c..acba0870 100644 --- a/proxy.js +++ b/multiuser_notebook/js/main.js @@ -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); diff --git a/multiuser.py b/multiuser_notebook/multiuser.py similarity index 97% rename from multiuser.py rename to multiuser_notebook/multiuser.py index 113c7dce..dae35fea 100644 --- a/multiuser.py +++ b/multiuser_notebook/multiuser.py @@ -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: diff --git a/singleuser.py b/multiuser_notebook/singleuser.py similarity index 98% rename from singleuser.py rename to multiuser_notebook/singleuser.py index 17820aa2..38c77eff 100644 --- a/singleuser.py +++ b/multiuser_notebook/singleuser.py @@ -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 diff --git a/login.html b/multiuser_notebook/templates/login.html similarity index 100% rename from login.html rename to multiuser_notebook/templates/login.html