# Path: metakernel/magic.py
# class Magic(object):
#     """
#     Base class to define magics for MetaKernel based kernels.
# 
#     Users can redefine the default magics provided by Metakernel
#     by creating a module with the exact same name as the
#     Metakernel magic.
# 
#     For example, you can override %matplotlib in your kernel by
#     writing a new magic inside magics/matplotlib_magic.py
#     """
# 
#     def __init__(self, kernel):
#         self.kernel = kernel
#         self.evaluate = True
#         self.code = ''
# 
#     def get_args(self, mtype, name, code, args) :
#         self.code = code
#         old_args = args
#         mtype = mtype.replace('sticky', 'cell')
# 
#         func = getattr(self, mtype + '_' + name)
#         try:
#             args, kwargs = _parse_args(func, args, usage=self.get_help(mtype, name))
#         except Exception as e:
#             self.kernel.Error(str(e))
#             return self
#         arg_spec = inspect.getfullargspec(func) if PY3 \
#                    else inspect.getargspec(func)
#         fargs = arg_spec.args
#         if fargs[0] == 'self':
#             fargs = fargs[1:]
# 
#         fargs = [f for f in fargs if not f in kwargs.keys()]
#         if len(args) > len(fargs) and not arg_spec.varargs:
#             extra = ' '.join(str(s) for s in (args[len(fargs) - 1:]))
#             args = args[:len(fargs) - 1] + [extra]
# 
#         return (args, kwargs, old_args)
# 
#     def call_magic(self, mtype, name, code, args):
#         self.code = code
#         old_args = args
#         mtype = mtype.replace('sticky', 'cell')
# 
#         func = getattr(self, mtype + '_' + name)
#         try:
#             args, kwargs = _parse_args(func, args, usage=self.get_help(mtype, name))
#         except Exception as e:
#             self.kernel.Error(str(e))
#             return self
# 
#         arg_spec = inspect.getfullargspec(func) if PY3 \
#                    else inspect.getargspec(func)
#         fargs = arg_spec.args
#         if fargs[0] == 'self':
#             fargs = fargs[1:]
# 
#         fargs = [f for f in fargs if not f in kwargs.keys()]
#         if len(args) > len(fargs) and not arg_spec.varargs:
#             extra = ' '.join(str(s) for s in (args[len(fargs) - 1:]))
#             args = args[:len(fargs) - 1] + [extra]
# 
#         try:
#             try:
#                 func(*args, **kwargs)
#             except TypeError:
#                 func(old_args)
#         except Exception as exc:
#             msg = "Error in calling magic '%s' on %s:\n    %s\n    args: %s\n    kwargs: %s" % (
#                 name, mtype, str(exc), args, kwargs)
#             self.kernel.Error(msg)
#             self.kernel.Error(traceback.format_exc())
#             self.kernel.Error(self.get_help(mtype, name))
#             # return dummy magic to end processing:
#             return Magic(self.kernel)
#         return self
# 
#     def get_help(self, mtype, name, level=0):
#         if hasattr(self, mtype + '_' + name):
#             func = getattr(self, mtype + '_' + name)
#             if level == 0:
#                 if func.__doc__:
#                     return _trim(func.__doc__)
#                 else:
#                     return "No help available for magic '%s' for %ss." % (name, mtype)
#             else:
#                 filename = inspect.getfile(func)
#                 if filename and os.path.exists(filename):
#                     with open(filename) as f: return f.read()
#                 else:
#                     return "No help available for magic '%s' for %ss." % (name, mtype)
#         else:
#             return "No such magic '%s' for %ss." % (name, mtype)
# 
#     def get_help_on(self, info, level=0):
#         return "Sorry, no help is available on '%s'." % info['code']
# 
#     def get_completions(self, info):
#             """
#             Get completions based on info dict from magic.
#             """
#             return []
# 
#     def get_magics(self, mtype):
#         magics = []
#         for name in dir(self):
#             if name.startswith(mtype + '_'):
#                 magics.append(name.replace(mtype + '_', ''))
#         return magics
# 
#     def get_code(self):
#         return self.code
# 
#     def post_process(self, retval):
#         return retval
# 
# def option(*args, **kwargs):
#     """Return decorator that adds a magic option to a function.
#     """
#     def decorator(func):
#         help_text = ""
#         if not getattr(func, 'has_options', False):
#             func.has_options = True
#             func.options = []
#             help_text += 'Options:\n-------\n'
#         try:
#             option = optparse.Option(*args, **kwargs)
#         except optparse.OptionError:
#             help_text += args[0] + "\n"
#         else:
#             help_text += _format_option(option) + "\n"
#             func.options.append(option)
#         if func.__doc__:
#             func.__doc__ += _indent(func.__doc__, help_text)
#         else:
#             func.__doc__ = help_text
#         return func
#     return decorator


from metakernel import Magic, option
from IPython.display import IFrame, Javascript
    from metakernel import IPythonKernel
    from IPython.core.magic import register_line_magic
                    import urllib.request
                    import urllib
# Copyright (c) Metakernel Development Team.
# Distributed under the terms of the Modified BSD License.
# @author ChrisJaunes



class BlocklyMagic(Magic):

    @option(
        '-o', '--page_from_origin', action='store', default=None,
        help='Load remote page about blockly'
    )
    @option(
        '-l', '--page_from_local', action='store', default=None,
        help='Load local page about blockly'
    )
    @option(
        '-t', '--template_data', action='store', default=None,
        help='generate page based on template and load, must be used with parameters(-o or -l)'
     )

# Path: metakernel/magic.py
# class Magic(object):
#     """
#     Base class to define magics for MetaKernel based kernels.
# 
#     Users can redefine the default magics provided by Metakernel
#     by creating a module with the exact same name as the
#     Metakernel magic.
# 
#     For example, you can override %matplotlib in your kernel by
#     writing a new magic inside magics/matplotlib_magic.py
#     """
# 
#     def __init__(self, kernel):
#         self.kernel = kernel
#         self.evaluate = True
#         self.code = ''
# 
#     def get_args(self, mtype, name, code, args) :
#         self.code = code
#         old_args = args
#         mtype = mtype.replace('sticky', 'cell')
# 
#         func = getattr(self, mtype + '_' + name)
#         try:
#             args, kwargs = _parse_args(func, args, usage=self.get_help(mtype, name))
#         except Exception as e:
#             self.kernel.Error(str(e))
#             return self
#         arg_spec = inspect.getfullargspec(func) if PY3 \
#                    else inspect.getargspec(func)
#         fargs = arg_spec.args
#         if fargs[0] == 'self':
#             fargs = fargs[1:]
# 
#         fargs = [f for f in fargs if not f in kwargs.keys()]
#         if len(args) > len(fargs) and not arg_spec.varargs:
#             extra = ' '.join(str(s) for s in (args[len(fargs) - 1:]))
#             args = args[:len(fargs) - 1] + [extra]
# 
#         return (args, kwargs, old_args)
# 
#     def call_magic(self, mtype, name, code, args):
#         self.code = code
#         old_args = args
#         mtype = mtype.replace('sticky', 'cell')
# 
#         func = getattr(self, mtype + '_' + name)
#         try:
#             args, kwargs = _parse_args(func, args, usage=self.get_help(mtype, name))
#         except Exception as e:
#             self.kernel.Error(str(e))
#             return self
# 
#         arg_spec = inspect.getfullargspec(func) if PY3 \
#                    else inspect.getargspec(func)
#         fargs = arg_spec.args
#         if fargs[0] == 'self':
#             fargs = fargs[1:]
# 
#         fargs = [f for f in fargs if not f in kwargs.keys()]
#         if len(args) > len(fargs) and not arg_spec.varargs:
#             extra = ' '.join(str(s) for s in (args[len(fargs) - 1:]))
#             args = args[:len(fargs) - 1] + [extra]
# 
#         try:
#             try:
#                 func(*args, **kwargs)
#             except TypeError:
#                 func(old_args)
#         except Exception as exc:
#             msg = "Error in calling magic '%s' on %s:\n    %s\n    args: %s\n    kwargs: %s" % (
#                 name, mtype, str(exc), args, kwargs)
#             self.kernel.Error(msg)
#             self.kernel.Error(traceback.format_exc())
#             self.kernel.Error(self.get_help(mtype, name))
#             # return dummy magic to end processing:
#             return Magic(self.kernel)
#         return self
# 
#     def get_help(self, mtype, name, level=0):
#         if hasattr(self, mtype + '_' + name):
#             func = getattr(self, mtype + '_' + name)
#             if level == 0:
#                 if func.__doc__:
#                     return _trim(func.__doc__)
#                 else:
#                     return "No help available for magic '%s' for %ss." % (name, mtype)
#             else:
#                 filename = inspect.getfile(func)
#                 if filename and os.path.exists(filename):
#                     with open(filename) as f: return f.read()
#                 else:
#                     return "No help available for magic '%s' for %ss." % (name, mtype)
#         else:
#             return "No such magic '%s' for %ss." % (name, mtype)
# 
#     def get_help_on(self, info, level=0):
#         return "Sorry, no help is available on '%s'." % info['code']
# 
#     def get_completions(self, info):
#             """
#             Get completions based on info dict from magic.
#             """
#             return []
# 
#     def get_magics(self, mtype):
#         magics = []
#         for name in dir(self):
#             if name.startswith(mtype + '_'):
#                 magics.append(name.replace(mtype + '_', ''))
#         return magics
# 
#     def get_code(self):
#         return self.code
# 
#     def post_process(self, retval):
#         return retval
# 
# def option(*args, **kwargs):
#     """Return decorator that adds a magic option to a function.
#     """
#     def decorator(func):
#         help_text = ""
#         if not getattr(func, 'has_options', False):
#             func.has_options = True
#             func.options = []
#             help_text += 'Options:\n-------\n'
#         try:
#             option = optparse.Option(*args, **kwargs)
#         except optparse.OptionError:
#             help_text += args[0] + "\n"
#         else:
#             help_text += _format_option(option) + "\n"
#             func.options.append(option)
#         if func.__doc__:
#             func.__doc__ += _indent(func.__doc__, help_text)
#         else:
#             func.__doc__ = help_text
#         return func
#     return decorator


# Path: metakernel/magics/blockly_magic.py
from metakernel import Magic, option
from IPython.display import IFrame, Javascript
    from metakernel import IPythonKernel
    from IPython.core.magic import register_line_magic
                    import urllib.request
                    import urllib

# Copyright (c) Metakernel Development Team.
# Distributed under the terms of the Modified BSD License.
# @author ChrisJaunes



class BlocklyMagic(Magic):

    @option(
        '-o', '--page_from_origin', action='store', default=None,
        help='Load remote page about blockly'
    )
    @option(
        '-l', '--page_from_local', action='store', default=None,
        help='Load local page about blockly'
    )
    @option(
        '-t', '--template_data', action='store', default=None,
        help='generate page based on template and load, must be used with parameters(-o or -l)'
     )

    @option(