
    PiX                        d Z ddlmZ ddlZddlmZmZ dgZ eh d          Z	 ej
        d          Z ej
        d          ZddZddZddZdS )aJ  
Fzf command handler for Dippy.

Fzf is a fuzzy finder that reads from stdin and outputs selected items.
Most operations are safe (read-only filtering and display).

Unsafe operations:
- --listen-unsafe: Allows remote process execution via HTTP server
- --bind with execute/execute-silent/become: Delegates to inner command check
    )annotationsN)ClassificationHandlerContextfzf>   execute-silentbecomeexecutez'(execute|execute-silent|become)\((.+)\)z%(execute|execute-silent|become):(\S+)
bind_valuestrreturn
str | Nonec                    t                               |           }|r|                    d          S t                              |           }|r|                    d          S dS )z?Extract the command from execute/execute-silent/become actions.   N)PAREN_PATTERNsearchgroupCOLON_PATTERN)r
   matchs     ./root/projects/gits/Dippy/src/dippy/cli/fzf.py_extract_exec_commandr   $   sa       ,,E {{1~~   ,,E {{1~~4    boolc                    t           D ]b}| d| v r dS | d| v r dS |                     dd                              dd                              d          }|D ]}||k    r  dS cdS )zECheck if a bind value contains execute/execute-silent/become actions.(T:,+F)EXEC_BIND_ACTIONSreplacesplit)r
   actionpartsparts       r   _has_exec_bind_actionr$   3   s    #  <<<:%%44<<<:%%44""3,,44S#>>DDSII 	 	Dv~~ttt 	 5r   ctxr   r   c                   | j         }|r|d         nd}t          |          D ]\  }}|dk    s|                    d          rt          d| d          c S |dk    s|                    d	          r|dk    r#|d
z   t	          |          k     r||d
z            }nz|dd         }t          |          r>t          |          }|rt          d|| d          c S t          d| d          c S t          d|          S )zClassify fzf command.r   r   z--listen-unsafez--listen-unsafe=askz --listen-unsafe)descriptionz--bindz--bind=      Ndelegatez --bind)inner_commandr(   allow)tokens	enumerate
startswithr   lenr$   r   )r%   r.   baseitokenr
   	inner_cmds          r   classifyr6   A   sj   ZF)6!99EDf%% K K5%%%)9)9:L)M)M%!%5N5N5NOOOOOO H 0 0 ; ;  q53v;;&&!'AJJ"122Y
$Z00 
K1*==	 )"&/'+$4$4$4      &eD9I9I9IJJJJJJ't4444r   )r
   r   r   r   )r
   r   r   r   )r%   r   r   r   )__doc__
__future__r   re	dippy.clir   r   COMMANDS	frozensetr   compiler   r   r   r$   r6    r   r   <module>r?      s   	 	 # " " " " " 				 4 4 4 4 4 4 4 47 I     
EFF 
CDD       5  5  5  5  5  5r   