payloadpage.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # encoding: utf-8
  2. """A payload based version of page."""
  3. # Copyright (c) IPython Development Team.
  4. # Distributed under the terms of the Modified BSD License.
  5. import warnings
  6. from IPython.core.getipython import get_ipython
  7. def page(strng, start=0, screen_lines=0, pager_cmd=None):
  8. """Print a string, piping through a pager.
  9. This version ignores the screen_lines and pager_cmd arguments and uses
  10. IPython's payload system instead.
  11. Parameters
  12. ----------
  13. strng : str or mime-dict
  14. Text to page, or a mime-type keyed dict of already formatted data.
  15. start : int
  16. Starting line at which to place the display.
  17. """
  18. # Some routines may auto-compute start offsets incorrectly and pass a
  19. # negative value. Offset to 0 for robustness.
  20. start = max(0, start)
  21. shell = get_ipython()
  22. if isinstance(strng, dict):
  23. data = strng
  24. else:
  25. data = {'text/plain' : strng}
  26. payload = dict(
  27. source='page',
  28. data=data,
  29. start=start,
  30. )
  31. shell.payload_manager.write_payload(payload)
  32. def install_payload_page():
  33. """DEPRECATED, use show_in_pager hook
  34. Install this version of page as IPython.core.page.page.
  35. """
  36. warnings.warn("""install_payload_page is deprecated.
  37. Use `ip.set_hook('show_in_pager, page.as_hook(payloadpage.page))`
  38. """)
  39. from IPython.core import page as corepage
  40. corepage.page = page