Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def listdir(cls, path):
raise PapermillException('listdir is not supported by HttpHandler')
def get_engine(self, name=None):
"""Retrieves an engine by name."""
engine = self._engines.get(name)
if not engine:
raise PapermillException("No engine named '{}' found".format(name))
return engine
def get_handler(self, path):
local_handler = None
for scheme, handler in self._handlers:
if scheme == 'local':
local_handler = handler
if path.startswith(scheme):
return handler
if local_handler is None:
raise PapermillException(
"Could not find a registered schema handler for: {}".format(path)
)
return local_handler
from ansiwrap import strip_color
class AwsError(Exception):
"""Raised when an AWS Exception is encountered."""
class FileExistsError(AwsError):
"""Raised when a File already exists on S3."""
class PapermillException(Exception):
"""Raised when an exception is encountered when operating on a notebook."""
class PapermillMissingParameterException(PapermillException):
"""Raised when a parameter without a value is required to operate on a notebook."""
class PapermillExecutionError(PapermillException):
"""Raised when an exception is encountered in a notebook."""
def __init__(self, exec_count, source, ename, evalue, traceback):
self.exec_count = exec_count
self.source = source
self.ename = ename
self.evalue = evalue
self.traceback = traceback
message = "\n" + 75 * "-" + "\n"
message += 'Exception encountered at "In [%s]":\n' % str(exec_count)
message += strip_color("\n".join(traceback))
message += "\n"
def find_translator(self, kernel_name, language):
if kernel_name in self._translators:
return self._translators[kernel_name]
elif language in self._translators:
return self._translators[language]
raise PapermillException(
"No parameter translator functions specified for kernel '{}' or language '{}'".format(
kernel_name, language
)
def __init__(self, exec_count, source, ename, evalue, traceback):
self.exec_count = exec_count
self.source = source
self.ename = ename
self.evalue = evalue
self.traceback = traceback
message = "\n" + 75 * "-" + "\n"
message += 'Exception encountered at "In [%s]":\n' % str(exec_count)
message += strip_color("\n".join(traceback))
message += "\n"
super(PapermillExecutionError, self).__init__(message)
class PapermillRateLimitException(PapermillException):
"""Raised when an io request has been rate limited"""
class PapermillOptionalDependencyException(PapermillException):
"""Raised when an exception is encountered when an optional plugin is missing."""
def missing_dependency_generator(package, dep):
def missing_dep():
raise PapermillOptionalDependencyException(
"The {package} optional dependency is missing. "
"Please run pip install papermill[{dep}] to install this dependency".format(
package=package, dep=dep
)
)
def read_notebook(path):
"""
Returns a Notebook object loaded from the location specified at 'path'.
Args:
path (str): Path to notebook ".ipynb" file.
Returns:
A Notebook object.
"""
if not path.endswith(".ipynb"):
raise PapermillException(
"Notebooks should have an '.ipynb' file extension. Provided path: '%s'", path)
nb = Notebook()
nb.path = path
nb.node = load_notebook_node(path)
return nb
def display_output(self, name):
"""Display the output from this notebook in the running notebook."""
outputs = _get_notebook_outputs(self.node)
if name not in outputs:
raise PapermillException("Output Name '%s' is not available in this notebook.")
output = outputs[name]
ip_display(output.data, metadata=output.metadata, raw=True)
"""Raised when an AWS Exception is encountered."""
class FileExistsError(AwsError):
"""Raised when a File already exists on S3."""
class PapermillException(Exception):
"""Raised when an exception is encountered when operating on a notebook."""
class PapermillMissingParameterException(PapermillException):
"""Raised when a parameter without a value is required to operate on a notebook."""
class PapermillExecutionError(PapermillException):
"""Raised when an exception is encountered in a notebook."""
def __init__(self, exec_count, source, ename, evalue, traceback):
self.exec_count = exec_count
self.source = source
self.ename = ename
self.evalue = evalue
self.traceback = traceback
message = "\n" + 75 * "-" + "\n"
message += 'Exception encountered at "In [%s]":\n' % str(exec_count)
message += strip_color("\n".join(traceback))
message += "\n"
super(PapermillExecutionError, self).__init__(message)