Uploaded Test files
This commit is contained in:
parent
f584ad9d97
commit
2e81cb7d99
16627 changed files with 2065359 additions and 102444 deletions
|
@ -0,0 +1,7 @@
|
|||
from .base import PostProcessorBase
|
||||
|
||||
# protect against unavailable tornado
|
||||
try:
|
||||
from .serve import ServePostProcessor
|
||||
except ImportError:
|
||||
pass
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
35
venv/Lib/site-packages/nbconvert/postprocessors/base.py
Normal file
35
venv/Lib/site-packages/nbconvert/postprocessors/base.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
"""
|
||||
Basic post processor
|
||||
"""
|
||||
#-----------------------------------------------------------------------------
|
||||
#Copyright (c) 2013, the IPython Development Team.
|
||||
#
|
||||
#Distributed under the terms of the Modified BSD License.
|
||||
#
|
||||
#The full license is in the file COPYING.txt, distributed with this software.
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Imports
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
from ..utils.base import NbConvertBase
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Classes
|
||||
#-----------------------------------------------------------------------------
|
||||
class PostProcessorBase(NbConvertBase):
|
||||
|
||||
def __call__(self, input):
|
||||
"""
|
||||
See def postprocess() ...
|
||||
"""
|
||||
self.postprocess(input)
|
||||
|
||||
|
||||
def postprocess(self, input):
|
||||
"""
|
||||
Post-process output from a writer.
|
||||
"""
|
||||
raise NotImplementedError('postprocess')
|
115
venv/Lib/site-packages/nbconvert/postprocessors/serve.py
Normal file
115
venv/Lib/site-packages/nbconvert/postprocessors/serve.py
Normal file
|
@ -0,0 +1,115 @@
|
|||
"""PostProcessor for serving reveal.js HTML slideshows."""
|
||||
|
||||
# Copyright (c) Jupyter Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import webbrowser
|
||||
import threading
|
||||
|
||||
from tornado import web, ioloop, httpserver, log, gen
|
||||
from tornado.httpclient import AsyncHTTPClient
|
||||
from traitlets import Bool, Unicode, Int
|
||||
|
||||
from .base import PostProcessorBase
|
||||
|
||||
|
||||
class ProxyHandler(web.RequestHandler):
|
||||
"""handler the proxies requests from a local prefix to a CDN"""
|
||||
@gen.coroutine
|
||||
def get(self, prefix, url):
|
||||
"""proxy a request to a CDN"""
|
||||
proxy_url = "/".join([self.settings['cdn'], url])
|
||||
client = self.settings['client']
|
||||
response = yield client.fetch(proxy_url)
|
||||
|
||||
for header in ["Content-Type", "Cache-Control", "Date", "Last-Modified", "Expires"]:
|
||||
if header in response.headers:
|
||||
self.set_header(header, response.headers[header])
|
||||
self.finish(response.body)
|
||||
|
||||
|
||||
class ServePostProcessor(PostProcessorBase):
|
||||
"""Post processor designed to serve files
|
||||
|
||||
Proxies reveal.js requests to a CDN if no local reveal.js is present
|
||||
"""
|
||||
|
||||
|
||||
open_in_browser = Bool(True,
|
||||
help="""Should the browser be opened automatically?"""
|
||||
).tag(config=True)
|
||||
|
||||
browser = Unicode(u'',
|
||||
help="""Specify what browser should be used to open slides. See
|
||||
https://docs.python.org/3/library/webbrowser.html#webbrowser.register
|
||||
to see how keys are mapped to browser executables. If
|
||||
not specified, the default browser will be determined
|
||||
by the `webbrowser`
|
||||
standard library module, which allows setting of the BROWSER
|
||||
environment variable to override it.
|
||||
""").tag(config=True)
|
||||
|
||||
reveal_cdn = Unicode("https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.5.0",
|
||||
help="""URL for reveal.js CDN.""").tag(config=True)
|
||||
reveal_prefix = Unicode("reveal.js",
|
||||
help="URL prefix for reveal.js").tag(config=True)
|
||||
ip = Unicode("127.0.0.1",
|
||||
help="The IP address to listen on.").tag(config=True)
|
||||
port = Int(8000, help="port for the server to listen on.").tag(config=True)
|
||||
|
||||
def postprocess(self, input):
|
||||
"""Serve the build directory with a webserver."""
|
||||
dirname, filename = os.path.split(input)
|
||||
handlers = [
|
||||
(r"/(.+)", web.StaticFileHandler, {'path' : dirname}),
|
||||
(r"/", web.RedirectHandler, {"url": "/%s" % filename})
|
||||
]
|
||||
|
||||
if ('://' in self.reveal_prefix or self.reveal_prefix.startswith("//")):
|
||||
# reveal specifically from CDN, nothing to do
|
||||
pass
|
||||
elif os.path.isdir(os.path.join(dirname, self.reveal_prefix)):
|
||||
# reveal prefix exists
|
||||
self.log.info("Serving local %s", self.reveal_prefix)
|
||||
else:
|
||||
self.log.info("Redirecting %s requests to %s", self.reveal_prefix, self.reveal_cdn)
|
||||
handlers.insert(0, (r"/(%s)/(.*)" % self.reveal_prefix, ProxyHandler))
|
||||
|
||||
app = web.Application(handlers,
|
||||
cdn=self.reveal_cdn,
|
||||
client=AsyncHTTPClient(),
|
||||
)
|
||||
|
||||
# hook up tornado logging to our logger
|
||||
log.app_log = self.log
|
||||
|
||||
http_server = httpserver.HTTPServer(app)
|
||||
http_server.listen(self.port, address=self.ip)
|
||||
url = "http://%s:%i/%s" % (self.ip, self.port, filename)
|
||||
print("Serving your slides at %s" % url)
|
||||
print("Use Control-C to stop this server")
|
||||
if self.open_in_browser:
|
||||
try:
|
||||
browser = webbrowser.get(self.browser or None)
|
||||
b = lambda: browser.open(url, new=2)
|
||||
threading.Thread(target=b).start()
|
||||
except webbrowser.Error as e:
|
||||
self.log.warning('No web browser found: %s.' % e)
|
||||
browser = None
|
||||
|
||||
try:
|
||||
ioloop.IOLoop.instance().start()
|
||||
except KeyboardInterrupt:
|
||||
print("\nInterrupted")
|
||||
|
||||
def main(path):
|
||||
"""allow running this module to serve the slides"""
|
||||
server = ServePostProcessor()
|
||||
server(path)
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
main(sys.argv[1])
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,24 @@
|
|||
"""
|
||||
Module with tests for the serve post-processor
|
||||
"""
|
||||
|
||||
# Copyright (c) Jupyter Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
import pytest
|
||||
from ...tests.base import TestsBase
|
||||
|
||||
|
||||
class TestServe(TestsBase):
|
||||
"""Contains test functions for serve.py"""
|
||||
|
||||
def test_constructor(self):
|
||||
"""Can a ServePostProcessor be constructed?"""
|
||||
pytest.importorskip("tornado")
|
||||
try:
|
||||
from ..serve import ServePostProcessor
|
||||
except ImportError:
|
||||
print("Something weird is happening.\n"
|
||||
"Tornado is sometimes present, sometimes not.")
|
||||
raise
|
||||
ServePostProcessor()
|
Loading…
Add table
Add a link
Reference in a new issue