
    @OOfy                     T    d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ  G d d      Zy)    N)Sequence)command)ctxc                      e Zd ZdZddZd Zedej                  fd       Z	d Z
d Zd	 Z ej                  d
      deddfd       Z ej                  d      dee   fd       Z ej                  d      d        Z ej                  d      deddfd       Z ej                  d      defd       Z ej                  d      defd       Zy)CommandHistoryi   returnNc                 0    g | _         dg| _        d| _        y )N r   )historyfiltered_historycurrent_indexselfs    a/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/mitmproxy/addons/command_history.py__init__zCommandHistory.__init__   s    "$,.4"#    c                 4    |j                  dt        dd       y )Ncommand_historyTz6Persist command history between mitmproxy invocations.)
add_optionbool)r   loaders     r   loadzCommandHistory.load   s    H		
r   c                     t        j                  t        j                  j	                  t
        j                  j                              dz  S Nr   )pathlibPathospath
expanduserr   optionsconfdirr   s    r   history_filezCommandHistory.history_file   s0    ||BGG..s{{/B/BCDGXXXr   c                 &    | j                  d       y r   )	configurer   s    r   runningzCommandHistory.running   s     	()r   c                     d|v sd|v rut         j                  j                  rZ| j                  j	                         r?| j                  j                         j                         | _        | j                  d       y y y y )Nr   r!   r
   )	r   r    r   r"   is_file	read_text
splitlinesr   
set_filter)r   updateds     r   r$   zCommandHistory.configure#   si    '9+?{{**t/@/@/H/H/J#00::<GGI# 0K* ,@r   c                    t         j                  j                  rot        | j                        | j
                  k\  rLdj                  | j                  | j
                   dz  d        dz   }	 | j                  j                  |       y y y # t        $ r/}t        j                  d| j                   d|        Y d }~y d }~ww xY w)N
   Failed writing to : )r   r    r   lenr   VACUUM_SIZEjoinr"   
write_text	Exceptionloggingwarning)r   history_stres      r   donezCommandHistory.done)   s    ;;&&3t||+<@P@P+P))DLL$2B2B1Ba1G1I$JKdRKO!!,,[9	 ,Q&
  O"4T5F5F4Gr! MNNOs   -B 	C%B>>Czcommands.history.addr   c                     |j                          sy | j                  j                  |       t        j                  j
                  r9	 | j                  j                  d      5 }|j                  | d       d d d        | j                  d       y # 1 sw Y   xY w# t        $ r/}t        j                  d| j                   d|        Y d }~Qd }~ww xY w)Nar-   r/   r0   r
   )stripr   appendr   r    r   r"   openwriter5   r6   r7   r*   )r   r   fr9   s       r   add_commandzCommandHistory.add_command2   s    w}}G$;;&&O&&++C0 ,AGGwirN+,
 	, , O"4T5F5F4Gr! MNNOs0   	B $B9B BB 	C(%CCzcommands.history.getc                 6    | j                   j                         S )zGet the entire command history.)r   copyr   s    r   get_historyzCommandHistory.get_historyA   s     ||  ""r   zcommands.history.clearc                    | j                   j                         r	 | j                   j                          g | _        | j                  d       y # t        $ r/}t	        j
                  d| j                    d|        Y d }~Ld }~ww xY w)NzFailed deleting r0   r
   )r"   existsunlinkr5   r6   r7   r   r*   )r   r9   s     r   clear_historyzCommandHistory.clear_historyF   sy    ##%M!!((*   M"243D3D2ERs KLLMs   A 	B%BBzcommands.history.filterprefixc                     | j                   D cg c]  }|j                  |      s| c}| _        | j                  j                  |       t	        | j                        dz
  | _        y c c}w N   )r   
startswithr   r>   r1   r   )r   rJ   cmds      r   r*   zCommandHistory.set_filterR   sV    04 Wv@V W$$V, !6!67!; !Xs
   A+A+zcommands.history.nextc                     t        | j                  dz   t        | j                        dz
        | _        | j                  | j                     S rL   )minr   r1   r   r   s    r   get_nextzCommandHistory.get_nextX   sD     !3!3a!7T=R=R9SVW9WX$$T%7%788r   zcommands.history.prevc                 p    t        d| j                  dz
        | _        | j                  | j                     S )Nr   rM   )maxr   r   r   s    r   get_prevzCommandHistory.get_prev]   s3     D$6$6$:;$$T%7%788r   )r   N)__name__
__module____qualname__r2   r   r   propertyr   r   r"   r%   r$   r:   r   strrB   r   rE   rI   r*   rR   rU    r   r   r   r   
   s8   K$

 Ygll Y Y*
$O W__+,3 4  - W__+,#Xc] # -# W__-. / W__./< < < 0<
 W__,-9# 9 .9 W__,-9# 9 .9r   r   )	r6   r   r   collections.abcr   	mitmproxyr   r   r   r[   r   r   <module>r^      s#     	  $  V9 V9r   