Format: application/x-python-code
⬇ Download File (8.1 KB)
   1  o
   2  
   3  ��h.�@sFdZddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
   4  mZddlm
   5  Z
   6  ddlmZddlmZdd	lmZdd
   7  lmZddlmZd*d
   8  d�Zdd�Ze�d�Zd*dd�Zdd�Zd+d,dd�Zd+dedefdd�Z d-dd�Z!d.dd �Z"d!d"�Z#ej$d#kr�ej%�&d$d%�d&kr�ddl'Z'd'd(�Z(dSd)d(�Z(dS)/z�
   9  Paging capabilities for IPython.core
  10  
  11  Notes
  12  -----
  13  
  14  For now this uses IPython hooks, so it can't be in IPython.utils.  If we can get
  15  rid of that dependency, we could move it there.
  16  -----
  17  �N)�UnsupportedOperation)�Path)�get_ipython)�display)�TryNext)�chop)�system)�get_terminal_size)�	py3compat�cCsBt|t�r|}n|rd�|��|d��}d|i}t|dd�dS)z1Just display, no paging. screen_lines is ignored.�
  18  N�
  19  text/plainT)�raw)�
  20  isinstance�dict�join�
  21  splitlinesr)�strng�start�screen_lines�data�r�Gc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/page.py�display_page$s
  22  rcs�fdd�S)zRWrap a pager func to strip the `self` arg
  23  
  24      so it can be called as a hook.
  25      cs�|i|��S�Nr)�self�args�kwargs�Z	page_funcrr�<lambda>4szas_hook.<locals>.<lambda>rrrrr�as_hook/sr z(\x1b[^m]+m)c	Cs�t|t�r|�dd�}|��|d�}t||d�}t|�dkr,ttj�	|d��dSd}|dd�D]#}tj�	|�}t||�t
  26  �sHdSt�|�}t|�dkrW|d}q4t|tj�	|d��dS)z�Very dumb 'pager' in Python, for when nothing else works.
  27  
  28      Only moves forward, same interface as page(), except for pager_cmd and
  29      mode.
  30      r
  31  �N�r�����)
  32  rr�getrr�len�print�os�linesepr�	page_more�esc_re�findall)	rrrZout_lnZscreensZlast_escape�scrZhunkZesc_listrrr�	page_dumb9s"
  33  
  34  �r-c	
  35  Cs�tj�dd�}|dks|dkrtjdks|Sz
  36  ddl}ddl}Wnty+|YSwz|�tj	�}Wn|j
  37  yI}ztd�|��|�d}~wwz|�
  38  �}Wnty[|YSw|��\}}|��|�tj	|j|�|S)z�Attempt to work out the number of lines on the screen.
  39  
  40      This is called by page(). It can raise an error (e.g. when run in the
  41      test suite), so it's separated out so it can easily be called in a try block.
  42      �TERMNZxtermzxterm-color�sunos5rztermios error: {0})r'�environr$�sys�platform�termios�curses�ImportError�	tcgetattr�stdout�error�	TypeError�formatZinitscr�AttributeErrorZgetmaxyxZendwin�	tcsetattrZTCSANOW)	�screen_lines_defr.r3r4Z
  43  term_flags�errr,Zscreen_lines_realZscreen_colsrrr�_detect_screen_sizeQs0�
  44  ���r?�returnc
  45  Csxt|t�r	|d}tj�dd�}|dvrtjdkrt|�dS|��|d�}tj�	|�}t
  46  |�}t
  47  |�}t|t|d�d�}	t
  48  �d}
  49  |d	krbz|t|
  50  �7}Wnttfyat|�YdSw|	|krlt|�dSt|�}|d
  51  t||�7}tjdkr�|�d�r�d}n�t�d�\}}
  52  t|
  53  �}z8t�|�|jd
  54  dd��}|�|�d||f}Wd�n1s�wYt�|�r�d}nd}Wt�|�nct�|�wz3d}tj|dtjtjd�}t� t!j"|j#dd�|�}z|j$p�t%j&j$}|�|�W|��}n|��}wWn)t'�y!}z|j(dk�rd}nd}WYd}~nd}~wt)�y,d}Ynw|du�r:t*||d�dSdS)aDisplay a string, piping through a pager after a certain length.
  55  
  56      strng can be a mime-bundle dict, supplying multiple representations,
  57      keyed by mime-type.
  58  
  59      The screen_lines parameter specifies the number of *usable* lines of your
  60      terminal screen (total lines minus lines you need to reserve to show other
  61      information).
  62  
  63      If you set screen_lines to a number <=0, page() will try to auto-determine
  64      your screen size and will only use up to (screen_size+screen_lines) for
  65      printing, paging after that. That is, if you want auto-detection but need
  66      to reserve the bottom 3 lines of the screen, use screen_lines = -3, and for
  67      auto-detection without any lines reserved simply use screen_lines = 0.
  68  
  69      If a string won't fit in the allowed lines, it is sent through the
  70      specified pager command. If none given, look for PAGER in the environment,
  71      and ultimately default to less.
  72  
  73      If no system pager works, the string is sent through a 'dumb pager'
  74      written in python, very simplistic.
  75      r
  76  r.�dumb)rA�emacs�ntN�Pr"r� �typez.txt�wt�utf-8��encodingz%s < %sT)�shell�stdin�stderr)� zBroken pipe)r)+rrr'r0r$�namer&rr(rr%�max�intr	r?r9r�
  77  get_pager_cmd�get_pager_start�
  78  startswith�tempfile�mkstempr�close�open�writer�unlink�
  79  subprocess�Popen�PIPE�DEVNULL�_wrap_close�io�
  80  TextIOWrapperrLrJr1r7�IOErrorr�OSErrorr-)rrr�	pager_cmdr.Z	str_linesZstr_toprintZnum_newlines�len_strZnumlinesr=�retval�fdZtmpnameZtmppathZtmpfile�cmd�proc�pagerZpager_encoding�msgrrr�
  81  pager_page�s�
  82  
  83  �
  84  
  85  
  86  
  87  �
  88  �����
  89  �rlrrcCsNtd|�}t�}|r z|jj|||d�WdStyYnwt||||�S)a1Display content in a pager, piping through a pager after a certain length.
  90  
  91      data can be a mime-bundle dict, supplying multiple representations,
  92      keyed by mime-type, or text.
  93  
  94      Pager is dispatched via the `show_in_pager` IPython hook.
  95      If no hook is registered, `pager_page` will be used.
  96      r)rrN)rPr�hooksZ
  97  show_in_pagerrrl)rrrrd�iprrr�page�s
  98  �roc
  99  Cs�t|�}|dt||�7}ztjddvrt�t|d|�Wd	Sz|dkr.|d8}tt|dd���|�WYd	St	dt
 100  |��YYd	S)
 101  zDPage a file, using an optional pager command and starting line.
 102      rEr.)rBrArr"rHrIzUnable to show fileN)rRrSr'r0�EnvironmentErrorrrorX�readr&�repr)�fnamerrdrrr�	page_filesrtcCsltjdkrd}ntjdvrd}|dur!ztjd}Wn|}Y|dkr4dtj�d	d
 103  ���vr4|d7}|S)zSReturn a pager command.
 104  
 105      Makes some attempts at finding an OS-correct one.
 106      �posixzless -R)rC�dosrFNZPAGER�lessz-r�LESSr!z -R)r'rOr0r$�lower)rdZdefault_pager_cmdrrrrR s
 107  
 108  rRcCs,|dvr|rdt|�}|Sd}|Sd}|S)zReturn the string for paging files with an offset.
 109  
 110      This is the '+N' argument which less and more (under Unix) accept.
 111      )rw�more�+r!)�str)rjrZstart_stringrrrrS6s��rSrCr.rArBcCs6tj�d�t��}|dvrd}nd}tj�d�|S)zg Smart pausing between pages
 112  
 113          @return:    True if need print more lines, False if quit
 114          �$---Return to continue, q to quit--- )�q�QFTzo                                     )r1r7rY�msvcrt�getwch)�ans�resultrrrr)Isr)cCs t�d�}|���d�rdSdS)Nr}r~FT)r
 115  �inputryrT)r�rrrr)Ws
 116  )rr)rrN)r@N)rNr))�__doc__r'r`�rer1rUr[r�pathlibrZIPythonr�IPython.displayrZIPython.core.errorrZIPython.utils.datarZIPython.utils.processrZIPython.utils.terminalr	Z
 117  IPython.utilsr
 118  rr �compiler*r-r?rlrQrortrRrSrOr0r$r�r)rrrr�<module>s<
 119  
 120  
 121  /r
 122  
 123