
    恕f-                         d dl Z d dlZd dlmZ d dlmZ d dlmZmZ d dl	m
Z
  e j                  d      Z G d de      Z G d	 d
e      Z G d de      Zy)    N)requestMarkup)BaseViewexpose)gettextzflask-admin.redisc                       e Zd ZdZy)CommandErrorz'
        RedisCli error exception.
    N__name__
__module____qualname____doc__     [/var/www/feuerwehr-webapp/venv/lib/python3.12/site-packages/flask_admin/contrib/rediscli.pyr
   r
      s     	r   r
   c                       e Zd ZdZy)TextWrapperzl
        Small text wrapper for result formatter to distinguish between
        different string types.
    Nr   r   r   r   r   r      s     	r   r   c                        e Zd ZdZddiZ	  ed      Z	 	 d fd	Zd Zd Z	d Z
d	 Zd
 Zd Zd Z ed      d        Z edd      d        Z xZS )RedisClizq
        Simple redis console.

        To use it, simply pass `Redis` connection object to the constructor.
    deldelete)pubsubset_response_callbackfrom_urlc                     t         t        |   ||||       || _        i | _        | j                          | j                          y)a,  
            Constructor.

            :param redis:
                Redis connection
            :param name:
                View name. If not provided, will use the model class name
            :param category:
                View category
            :param endpoint:
                Base endpoint. If not provided, will use the model name + 'view'.
                For example if model name was 'User', endpoint will be
                'userview'
            :param url:
                Base URL. If not provided, will use endpoint as a URL.
        N)superr   __init__rediscommands_inspect_commands_contribute_commands)selfr   namecategoryendpointurl	__class__s         r   r   zRedisCli.__init__2   s@    $ 	h&tXxE
 !!#r   c                    t        | j                        D ]u  }|j                  d      rt        | j                  |      }t	        |      s7|| j
                  vsFt        |dd      xs dj                         }||f| j                  |<   w | j                  j                         D ]!  \  }}| j                  |   | j                  |<   # y)zJ
            Inspect connection object and extract command names.
        _r    N)
dirr   
startswithgetattrcallableexcluded_commandsstripr    remapped_commandsitems)r#   r$   attrdocnewolds         r   r!   zRedisCli._inspect_commandsM   s     

O 	6D??3'tzz40D>d$2H2H&H"4B7=2DDFC+/+DMM$'	6 ..446 	4HC!%s!3DMM#	4r   c                 :    | j                   df| j                  d<   y)z1
            Contribute custom commands.
        zHelp!helpN)	_cmd_helpr    r#   s    r   r"   zRedisCli._contribute_commands[   s     "& 9fr   c                     | j                   j                  |      }|r|}|| j                  vr| j                  t	        d            S | j                  |   \  }}| j                   ||       S )z
            Execute single command.

            :param name:
                Command name
            :param args:
                Command arguments
        zCli: Invalid command.)r2   getr    _errorr   _result)r#   r$   argsnew_cmdhandlerr*   s         r   _execute_commandzRedisCli._execute_commanda   sj     ((,,T2D t}}$;;w'>?@@]]4(
||GTN++r   c                 >    t        t        j                  |            S )zt
            Parse command by using shlex module.

            :param cmd:
                Command to parse
        )tupleshlexsplit)r#   cmds     r   
_parse_cmdzRedisCli._parse_cmdv   s     U[[%&&r   c                     t        d|z        S )zw
            Format error message as HTTP response.

            :param msg:
                Message to format
        z<div class="error">%s</div>r   )r#   msgs     r   r>   zRedisCli._error   s     3c9::r   c                 ,    | j                  dd |      S )zx
            Format result message as HTTP response.

            :param msg:
                Result to format.
        zadmin/rediscli/response.htmlc                 ,    t        |       j                  S N)typer   )ds    r   <lambda>z"RedisCli._result.<locals>.<lambda>   s    tAw/?/? r   )	type_nameresultrender)r#   rS   s     r   r?   zRedisCli._result   s#     {{9%?"(  * 	*r   c                    |s;d}|dj                  d t        | j                        D              z  }t        |      S |d   }|| j                  vrt	        d      | j                  |   d   }|st        d      S t        |      S )z2
            Help command implementation.
        z3Usage: help <command>.
List of supported commands: z, c              3       K   | ]  }|  y wrN   r   ).0ns     r   	<genexpr>z%RedisCli._cmd_help.<locals>.<genexpr>   s     ?Aa?s   r   zInvalid command.   zCommand does not have any help.)joinsortedr    r   r
   )r#   r@   r9   rH   s       r   r:   zRedisCli._cmd_help   s     IDDII?)>???Dt$$1gdmm#122}}S!!$@AA4  r   /c                 $    | j                  d      S )z#
            Console view.
        zadmin/rediscli/console.htmlrT   r;   s    r   console_viewzRedisCli.console_view   s    
 {{899r   z/run/)POST)methodsc                    	 t         j                  j                  d      }|s| j                  d      S | j	                  |      }|s| j                  d      S | j                  |d   |dd       S # t        $ r}| j                  d|z        cY d}~S d}~wt        $ r3}t        j                  |       | j                  d|z        cY d}~S d}~ww xY w)z
            AJAX API.
        rH   zCli: Empty command.zCli: Failed to parse command.r   r[   NzCli: %s)
r   formr=   r>   rI   rC   r
   	Exceptionlog	exception)r#   rH   partserrexs        r   execute_viewzRedisCli.execute_view   s    
	/,,""5)C{{#899OOC(E{{#BCC((q59== 	0;;y3// 	/MM";;y2~..	/s:   1A0 #A0 A0 0	C9BCC(CCC)NNNN)r   r   r   r   r2   setr0   r   r!   r"   rC   rI   r>   r?   r:   r   r`   rk   __classcell__)r(   s   @r   r   r      s     	x KL
 ?C$64:,*';	*!( C[: : GY'/ (/r   r   )loggingrF   flaskr   
markupsafer   flask_admin.baser   r   flask_admin.babelr   	getLoggerrf   re   r
   strr   r   r   r   r   <module>ru      sR        - % g+,	9 		# 	c/x c/r   