def write(self, output, resources, **kw): """ Consume and write Jinja output. See base for more... """ io.unicode_std_stream().write(output)
def unicode_std_stream(stream='stdout'): """DEPRECATED, moved to nbconvert.utils.io""" warn( "yap_ipython.utils.io.unicode_std_stream has moved to nbconvert.utils.io", stacklevel=2) from nbconvert.utils.io import unicode_std_stream return unicode_std_stream(stream)
def unicode_std_stream(stream='stdout'): """DEPRECATED, moved to nbconvert.utils.io""" warn( "IPython.utils.io.unicode_std_stream has moved to nbconvert.utils.io since IPython 4.0", DeprecationWarning, stacklevel=2) from nbconvert.utils.io import unicode_std_stream return unicode_std_stream(stream)
def unicode_std_stream(stream='stdout'): """DEPRECATED, moved to nbconvert.utils.io""" warn("IPython.utils.io.unicode_std_stream has moved to nbconvert.utils.io", stacklevel=2) from nbconvert.utils.io import unicode_std_stream return unicode_std_stream(stream)
def unicode_std_stream(stream='stdout'): """DEPRECATED, moved to nbconvert.utils.io""" warn("IPython.utils.io.unicode_std_stream has moved to nbconvert.utils.io") from nbconvert.utils.io import unicode_std_stream return unicode_std_stream(stream)
def main(args, help=''): if args.debug: logging.basicConfig(level=logging.DEBUG) if args.version: print(__version__) sys.exit() if args.examples: print(examples) sys.exit() # if no stdin and no input file if args.input_file == '-' and sys.stdin.isatty(): sys.stdout.write(help) sys.exit() elif args.input_file == '-': input_file = sys.stdin elif args.input_file != '-': input_file = io.open(args.input_file, 'r', encoding='utf-8') else: sys.exit('malformed input') # pre-process markdown by using knitr on it if args.knit: knitr = Knitr() input_file = knitr.knit(input_file, opts_chunk=args.knit) if args.rmagic: args.precode.append(r"%load_ext rpy2.ipython") if args.render: template_file = markdown_figure_template else: template_file = markdown_template template_file = args.template or template_file # reader and writer classes with args and kwargs to # instantiate with readers = {'notebook': nbformat, 'markdown': MarkdownReader(precode='\n'.join(args.precode), magic=args.magic, match=args.match, caption_comments=args.render) } writers = {'notebook': nbformat, 'markdown': MarkdownWriter(template_file, strip_outputs=args.strip_outputs) } informat = args.informat or ftdetect(input_file.name) or 'markdown' outformat = args.outformat or ftdetect(args.output) or 'notebook' if args.render: outformat = 'markdown' reader = readers[informat] writer = writers[outformat] with input_file as ip: notebook = reader.read(ip, as_version=4) if args.run: run(notebook, timeout=args.timeout) if args.strip_outputs: strip(notebook) output_ext = {'markdown': '.md', 'notebook': '.ipynb'} if not args.output and args.input_file != '-': # overwrite fout = os.path.splitext(args.input_file)[0] + output_ext[outformat] # grab the output here so we don't obliterate the file if # there is an error output = writer.writes(notebook) with io.open(fout, 'w', encoding='utf-8') as op: op.write(output) elif not args.output and args.input_file == '-': # overwrite error (input is stdin) sys.exit('Cannot overwrite with no input file given.') elif args.output == '-': # write stdout writer.write(notebook, unicode_std_stream('stdout')) elif args.output != '-': # write to filename with io.open(args.output, 'w', encoding='utf-8') as op: writer.write(notebook, op)
def main(args, help=''): if args.debug: logging.basicConfig(level=logging.DEBUG) if args.version: print(__version__) sys.exit() if args.examples: print(examples) sys.exit() # if no stdin and no input file if args.input_file == '-' and sys.stdin.isatty(): sys.stdout.write(help) sys.exit() elif args.input_file == '-': input_file = sys.stdin elif args.input_file != '-': input_file = io.open(args.input_file, 'r', encoding='utf-8') else: sys.exit('malformed input') # pre-process markdown by using knitr on it if args.knit: knitr = Knitr() input_file = knitr.knit(input_file, opts_chunk=args.knit) if args.rmagic: args.precode.append(r"%load_ext rpy2.ipython") if args.render: template_file = markdown_figure_template else: template_file = markdown_template template_file = args.template or template_file # reader and writer classes with args and kwargs to # instantiate with readers = { 'notebook': nbformat, 'markdown': MarkdownReader(precode='\n'.join(args.precode), magic=args.magic, match=args.match, caption_comments=args.render) } writers = { 'notebook': nbformat, 'markdown': MarkdownWriter(template_file, strip_outputs=args.strip_outputs) } informat = args.informat or ftdetect(input_file.name) or 'markdown' outformat = args.outformat or ftdetect(args.output) or 'notebook' if args.render: outformat = 'markdown' reader = readers[informat] writer = writers[outformat] with input_file as ip: notebook = reader.read(ip, as_version=4) if args.run: run(notebook, timeout=args.timeout) if args.strip_outputs: strip(notebook) output_ext = {'markdown': '.md', 'notebook': '.ipynb'} if not args.output and args.input_file != '-': # overwrite fout = os.path.splitext(args.input_file)[0] + output_ext[outformat] # grab the output here so we don't obliterate the file if # there is an error output = writer.writes(notebook) with io.open(fout, 'w', encoding='utf-8') as op: op.write(output) elif not args.output and args.input_file == '-': # overwrite error (input is stdin) sys.exit('Cannot overwrite with no input file given.') elif args.output == '-': # write stdout writer.write(notebook, unicode_std_stream('stdout')) elif args.output != '-': # write to filename with io.open(args.output, 'w', encoding='utf-8') as op: writer.write(notebook, op)
def unicode_std_stream(stream='stdout'): """DEPRECATED, moved to nbconvert.utils.io""" warn("IPython.utils.io.unicode_std_stream has moved to nbconvert.utils.io since IPython 4.0", DeprecationWarning, stacklevel=2) from nbconvert.utils.io import unicode_std_stream return unicode_std_stream(stream)