def reload_document(debug, format): doc = get_document() if doc is None: click.echo('No current document. Use `coreapi get` to fetch a document first.') sys.exit(1) if format: decoders = [codec_plugins.decoders[format]] force_codec = True else: decoders = codec_plugins.decoders.values() force_codec = False client = get_client(debug=debug, decoders=decoders) history = get_history() try: doc = client.reload(doc, force_codec=force_codec) except coreapi.exceptions.ErrorMessage as exc: click.echo(display(exc.error)) sys.exit(1) click.echo(display(doc)) if isinstance(doc, coreapi.Document): history = history.add(doc) set_document(doc) set_history(history)
def reload_document(debug, format): doc = get_document() if doc is None: click.echo( 'No current document. Use `coreapi get` to fetch a document first.' ) sys.exit(1) if format: decoders = [codec_plugins.decoders[format]] force_codec = True else: decoders = codec_plugins.decoders.values() force_codec = False client = get_client(debug=debug, decoders=decoders) history = get_history() try: doc = client.reload(doc, force_codec=force_codec) except coreapi.exceptions.ErrorMessage as exc: click.echo(display(exc.error)) sys.exit(1) click.echo(display(doc)) if isinstance(doc, coreapi.Document): history = history.add(doc) set_document(doc) set_history(history)
def action(path, params, strings, data, files, action, encoding, transform, debug): params = dict(params) params.update(dict(strings)) params.update(dict(data)) params.update(dict(files)) if not path: click.echo('Missing PATH to a link in the document.') sys.exit(1) doc = get_document() if doc is None: click.echo('No current document. Use `coreapi get` to fetch a document first.') sys.exit(1) client = get_client(debug=debug) history = get_history() keys = coerce_key_types(doc, path) try: doc = client.action( doc, keys, params=params, action=action, encoding=encoding, transform=transform ) except coreapi.exceptions.ErrorMessage as exc: click.echo(display(exc.error)) sys.exit(1) except coreapi.exceptions.LinkLookupError as exc: click.echo(exc) sys.exit(1) click.echo(display(doc)) if isinstance(doc, coreapi.Document): history = history.add(doc) set_document(doc) set_history(history)
def action(path, params, strings, data, files, action, encoding, transform, debug): params = dict(params) params.update(dict(strings)) params.update(dict(data)) params.update(dict(files)) if not path: click.echo('Missing PATH to a link in the document.') sys.exit(1) doc = get_document() if doc is None: click.echo('No current document. Use `coreapi get` to fetch a document first.') sys.exit(1) client = get_client(debug=debug) history = get_history() keys = coerce_key_types(doc, path) try: doc = client.action( doc, keys, params=params, action=action, encoding=encoding, transform=transform ) except coreapi.exceptions.ErrorMessage as exc: click.echo(display(exc.error)) sys.exit(1) except coreapi.exceptions.LinkLookupError as exc: click.echo(exc) sys.exit(1) click.echo(display(doc)) if isinstance(doc, coreapi.Document): history = history.add(doc) set_document(doc) set_history(history)
def history_forward(): client = get_client() history = get_history() if history.is_at_most_recent: click.echo("Currently at most recent point in history. Cannot navigate forward.") return doc, history = history.forward() try: doc = client.reload(doc) except coreapi.exceptions.ErrorMessage as exc: click.echo(display(exc.error)) sys.exit(1) click.echo(display(doc)) if isinstance(doc, coreapi.Document): set_document(doc) set_history(history)
def history_forward(): client = get_client() history = get_history() if history.is_at_most_recent: click.echo("Currently at most recent point in history. Cannot navigate forward.") return doc, history = history.forward() try: doc = client.reload(doc) except coreapi.exceptions.ErrorMessage as exc: click.echo(display(exc.error)) sys.exit(1) click.echo(display(doc)) if isinstance(doc, coreapi.Document): set_document(doc) set_history(history)
def bookmarks_get(name): bookmarks = get_bookmarks() bookmark = bookmarks.get(name) if bookmark is None: click.echo('Bookmark "%s" does not exist.' % name) return url = bookmark['url'] client = get_client() history = get_history() try: doc = client.get(url) except coreapi.exceptions.ErrorMessage as exc: click.echo(display(exc.error)) sys.exit(1) click.echo(display(doc)) if isinstance(doc, coreapi.Document): history = history.add(doc) set_document(doc) set_history(history)
def get(url, debug, format): if format: decoders = [codec_plugins.decoders[format]] force_codec = True else: decoders = codec_plugins.decoders.values() force_codec = False client = get_client(decoders=decoders, debug=debug) history = get_history() try: doc = client.get(url, force_codec=force_codec) except coreapi.exceptions.ErrorMessage as exc: click.echo(display(exc.error)) sys.exit(1) click.echo(display(doc)) if isinstance(doc, coreapi.Document): history = history.add(doc) set_document(doc) set_history(history)
def bookmarks_get(name): bookmarks = get_bookmarks() bookmark = bookmarks.get(name) if bookmark is None: click.echo('Bookmark "%s" does not exist.' % name) return url = bookmark['url'] client = get_client() history = get_history() try: doc = client.get(url) except coreapi.exceptions.ErrorMessage as exc: click.echo(display(exc.error)) sys.exit(1) click.echo(display(doc)) if isinstance(doc, coreapi.Document): history = history.add(doc) set_document(doc) set_history(history)
def get(url, debug, format): if format: decoders = [codec_plugins.decoders[format]] force_codec = True else: decoders = codec_plugins.decoders.values() force_codec = False client = get_client(decoders=decoders, debug=debug) history = get_history() try: doc = client.get(url, force_codec=force_codec) except coreapi.exceptions.ErrorMessage as exc: click.echo(display(exc.error)) sys.exit(1) click.echo(display(doc)) if isinstance(doc, coreapi.Document): history = history.add(doc) set_document(doc) set_history(history)
def load(input_file, format): input_bytes = input_file.read() input_file.close() decoder = codec_plugins.decoders[format] history = get_history() doc = decoder.load(input_bytes) click.echo(display(doc)) if isinstance(doc, coreapi.Document): history = history.add(doc) set_document(doc) set_history(history)
def load(input_file, format): input_bytes = input_file.read() input_file.close() decoder = codec_plugins.decoders[format] history = get_history() doc = decoder.decode(input_bytes) click.echo(display(doc)) if isinstance(doc, coreapi.Document): history = history.add(doc) set_document(doc) set_history(history)
def show(path): doc = get_document() if doc is None: click.echo('No current document. Use `coreapi get` to fetch a document first.') sys.exit(1) if path: keys = coerce_key_types(doc, path) for key in keys: try: doc = doc[key] except (KeyError, IndexError): click.echo('Key %s not found.' % repr(key).strip('u')) sys.exit(1) click.echo(display(doc))
def show(path): doc = get_document() if doc is None: click.echo('No current document. Use `coreapi get` to fetch a document first.') sys.exit(1) if path: keys = coerce_key_types(doc, path) for key in keys: try: doc = doc[key] except (KeyError, IndexError): click.echo('Key %s not found.' % repr(key).strip('u')) sys.exit(1) click.echo(display(doc))