# Path: mfr/core/extension.py
# class BaseExporter(metaclass=abc.ABCMeta):
# class BaseRenderer(metaclass=abc.ABCMeta):
#     def __init__(self, ext, source_file_path, output_file_path, format, metadata):
#     def export(self):
#     def _get_module_name(self):
#     def __init__(self, metadata, file_path, url, assets_url, export_url):
#     def render(self):
#     def file_required(self):
#     def cache_result(self):
#     def _get_module_name(self):
# 
# Path: mfr/extensions/ipynb/exceptions.py
# class InvalidFormatError(RendererError):
#     __TYPE = 'ipynb_invalid_format'
#     def __init__(self, message, *args, code: int=400, download_url: str='',
#                  original_exception: Exception=None, **kwargs):


import os
import nbformat
import nbconvert
from traitlets.config import Config
from mako.lookup import TemplateLookup
from nbconvert.exporters import HTMLExporter
from mfr.core import extension
from mfr.extensions.ipynb import exceptions




class IpynbRenderer(extension.BaseRenderer):

    TEMPLATE = TemplateLookup(
        directories=[
            os.path.join(os.path.dirname(__file__), 'templates')
        ]).get_template('viewer.mako')

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.metrics.add('nbformat_version', nbformat.__version__)
        self.metrics.add('nbconvert_version', nbconvert.__version__)

    def render(self):
        try:
            with open(self.file_path, 'r') as file_pointer:
                notebook = nbformat.reads(file_pointer.read(), as_version=4)
        except ValueError as err:

# Path: mfr/core/extension.py
# class BaseExporter(metaclass=abc.ABCMeta):
# class BaseRenderer(metaclass=abc.ABCMeta):
#     def __init__(self, ext, source_file_path, output_file_path, format, metadata):
#     def export(self):
#     def _get_module_name(self):
#     def __init__(self, metadata, file_path, url, assets_url, export_url):
#     def render(self):
#     def file_required(self):
#     def cache_result(self):
#     def _get_module_name(self):
# 
# Path: mfr/extensions/ipynb/exceptions.py
# class InvalidFormatError(RendererError):
#     __TYPE = 'ipynb_invalid_format'
#     def __init__(self, message, *args, code: int=400, download_url: str='',
#                  original_exception: Exception=None, **kwargs):


# Path: mfr/extensions/ipynb/render.py
import os
import nbformat
import nbconvert
from traitlets.config import Config
from mako.lookup import TemplateLookup
from nbconvert.exporters import HTMLExporter
from mfr.core import extension
from mfr.extensions.ipynb import exceptions





class IpynbRenderer(extension.BaseRenderer):

    TEMPLATE = TemplateLookup(
        directories=[
            os.path.join(os.path.dirname(__file__), 'templates')
        ]).get_template('viewer.mako')

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.metrics.add('nbformat_version', nbformat.__version__)
        self.metrics.add('nbconvert_version', nbconvert.__version__)

    def render(self):
        try:
            with open(self.file_path, 'r') as file_pointer:
                notebook = nbformat.reads(file_pointer.read(), as_version=4)
        except ValueError as err:

            raise exceptions.InvalidFormatError(