
    %                         S SK Jr  S SKJrJr  S SKJr  S SKrS SKrSr	 " S S\" \\
5      5      r " S S	\5      r " S
 S\5      rg)    )unicode_literals)ABCMetaabstractmethod)with_metaclassN)FileHistoryHistoryInMemoryHistoryc                   b    \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	S r
\
rSrg	)
r      z
Base ``History`` interface.
c                     g)zAppend string to history. N selfstrings     )lib/third_party/prompt_toolkit/history.pyappendHistory.append           c                     g)zGReturn one item of the history. It should be accessible like a `list`. Nr   r   keys     r   __getitem__History.__getitem__   r   r   c                     g)z>Iterate through all the items of the history. Cronologically. Nr   r   s    r   __iter__History.__iter__   r   r   c                     g)z#Return the length of the history.  Nr   r   s    r   __len__History.__len__   r   r   c                     g)z
Never evaluate to False, even when the history is empty.
(Python calls __len__ if __bool__ is not implemented.)
This is mainly to allow lazy evaluation::

    x = history or InMemoryHistory()
Tr   r   s    r   __bool__History.__bool__#   s     r   r   N)__name__
__module____qualname____firstlineno____doc__r   r   r   r   r    r#   __nonzero____static_attributes__r   r   r   r   r      sg     & & S S J J / / Kr   r   c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
r	   0   zE
:class:`.History` class that keeps a list of all strings in memory.
c                     / U l         g Nstringsr   s    r   __init__InMemoryHistory.__init__4   s	    r   c                 :    U R                   R                  U5        g r/   )r1   r   r   s     r   r   InMemoryHistory.append7   s    F#r   c                      U R                   U   $ r/   r0   r   s     r   r   InMemoryHistory.__getitem__:       ||C  r   c                 ,    [        U R                  5      $ r/   iterr1   r   s    r   r   InMemoryHistory.__iter__=       DLL!!r   c                 ,    [        U R                  5      $ r/   lenr1   r   s    r   r    InMemoryHistory.__len__@       4<<  r   r0   N)r%   r&   r'   r(   r)   r2   r   r   r   r    r+   r   r   r   r	   r	   0   s     $!"!r   r	   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)r   D   z<
:class:`.History` class that stores all strings in a file.
c                 >    / U l         Xl        U R                  5         g r/   )r1   filename_load)r   rF   s     r   r2   FileHistory.__init__H   s     

r   c                   ^ ^ / mUU 4S jn[         R                  R                  T R                  5      (       av  [	        T R                  S5       nU HI  nUR                  S5      nUR                  S5      (       a  TR                  USS  5        M@  U" 5         / mMK     U" 5         S S S 5        g g ! , (       d  f       g = f)Nc                  t   > T(       a0  SR                  T5      S S n TR                  R                  U 5        g g )N )joinr1   r   )r   linesr   s    r   addFileHistory._load.<locals>.addQ   s1    ,##F+	 r   rbutf-8+   )ospathexistsrF   opendecode
startswithr   )r   rO   flinerN   s   `   @r   rG   FileHistory._loadN   s    	, 77>>$--((dmmT*aD;;w/Ds++T!"X. "   +* )**s   AB11
B?c                 <  ^ U R                   R                  U5        [        U R                  S5       mU4S jnU" S[        R                  R                  5       -  5        UR                  S5       H  nU" SU-  5        M     S S S 5        g ! , (       d  f       g = f)Nabc                 F   > TR                  U R                  S5      5        g )NrR   )writeencode)tr[   s    r   ra   !FileHistory.append.<locals>.writej   s    )*r   z
# %s

z+%s
)r1   r   rX   rF   datetimenowsplit)r   r   ra   r\   r[   s       @r   r   FileHistory.appende   su    F# $--&!+ *x0044667T*gn% + '&&s   AB
Bc                      U R                   U   $ r/   r0   r   s     r   r   FileHistory.__getitem__q   r8   r   c                 ,    [        U R                  5      $ r/   r:   r   s    r   r   FileHistory.__iter__t   r=   r   c                 ,    [        U R                  5      $ r/   r?   r   s    r   r    FileHistory.__len__w   rB   r   )rF   r1   N)r%   r&   r'   r(   r)   r2   rG   r   r   r   r    r+   r   r   r   r   r   D   s%    .
&!"!r   r   )
__future__r   abcr   r   sixr   rf   rU   __all__objectr   r	   r   r   r   r   <module>ru      sG    ' '   	nWf- B!g !(4!' 4!r   