
    VhR                         d dl mZmZmZ eZd dlZd dlZd dlm	Z	 d dl
mZmZ d dlmZ d dlmZ  e       Z G d de      Zy)	    )absolute_importdivisionprint_functionN)AnsibleConnectionFailure)to_bytesto_text)Display)TerminalBasec                   t   e Zd Z ej                  d      gZ ej                  d      Z ej                  d       ej                  dej                         ej                  d       ej                  d       ej                  dej                         ej                  dej                         ej                  d	ej                         ej                  d
       ej                  d       ej                  dej                         ej                  dej                         ej                  dej                         ej                  dej                         ej                  d       ej                  dej                         ej                  dej                         ej                  dej                         ej                  dej                         ej                  dej                         ej                  dej                        gZ	 ej                  d      Z
d Zd ZddZd Zy)TerminalModules7   [\r\n]?[\w\+\-\.:\/\[\]]+(?:\([^\)]+\)){0,3}(?:[>#]) ?$z!Current privilege level is (\d+)$s   % ?Errors   ERROR:s   % ?Bad secrets   [\r\n%] Bad passwordss   invalid inputs    (?:incomplete|ambiguous) commands   connection timed outs   [^\r\n]+ not founds!   '[^']' +returned error code: ?\d+s   Bad masks   % ?(\S+) ?overlaps with ?(\S+)s   % ?(\S+) ?Error: ?[\s]+s   % ?(\S+) ?Informational: ?[\s]+s   Command authorization faileds   Command Rejected: ?[\s]+s?   % General session commands not allowed under the address familys"   % BGP: Error initializing topologys   %SNMP agent not enableds	   % Invalidsm   %You must disable VTPv1 and VTPv2 or switch to VTPv3 before configuring a VLAN name longer than 32 charactersz^.+\(config(-.*)?\)#$c                 F   	 ddi}| j                  t        t        j                  |      d            }| j                  j                  |      }|st	        d|z        t        |j                  d            S # t        $ r}t	        d|j
                  z        d }~ww xY w)Ncommandzshow privilegesurrogate_or_stricterrorsz)unable to fetch privilege, with error: %sz$unable to check privilege level [%s]   )
_exec_cli_commandr   jsondumpsr   messageprivilege_level_researchintgroup)selfcmdresulteprompts        b/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/ios/plugins/terminal/ios.pyget_privilege_levelz"TerminalModule.get_privilege_levelK   s    	./C++C1FGF ((//7*6?  6<<?## ( 	*;qyyI 	s   3A: :	B BB c                 z   d}	 | j                  d       	 |r| j                  d       y | j                  d       	 | j                  d       y # t        $ r0 	 | j                  d       d}n# t        $ r t        d      w xY wY qw xY w# t        $ r Y y w xY w# t        $ r t        j                  d	       Y y w xY w)
NFs   terminal length 0s   screen-length 0Tz!unable to set terminal parameterss   screen-width 512s   terminal width 512s   terminal width 0zPWARNING: Unable to set terminal/screen width, command responses may be truncated)r   r   display)r   	_is_sdWans     r    on_open_shellzTerminalModule.on_open_shell^   s    		T""#78	&&':;&&'<=**+>? ( 	TT&&'9: 	+ T./RSST 	T 0 ' 	OOb	s\   A B B B
 	BA,+B,BBB
	BB BB B:9B:Nc                    | j                         j                  d      r| j                         dk(  ry ddi}|rt        dd      |d<   ||d	<   d
|d<   	 | j	                  t        t        j                  |      d             | j                         }| j                         }||j                  d      r|dk7  rt        d||fz        y # t        $ r0}| j                         }t        d|d|j                        d }~ww xY w)N   #   r   enablez[\r\n]?(?:.*)?[Pp]assword: ?$r   r   r   answerTprompt_retry_checkz7failed to elevate privilege to enable mode, at prompt [z] with error: zOfailed to elevate privilege to enable mode, still at level [%d] and prompt [%s])
_get_promptendswithr!   r   r   r   r   r   r   r   )r   passwdr   r   privilege_levelr   s         r    	on_becomezTerminalModule.on_becomev   s    &&t,1I1I1Kr1Q(# $0,CM #CM(,C$%	""C1FG %%'F"668O >!6/R:O*a"F+,  ;P ( 	%%'F*199& 	s   AC 	D+DDc                     | j                         }|y | j                         dk7  ry d|v r#| j                  d       | j                  d       y |j                  d      r| j                  d       y y )Nr(   s   (configs   ends   disabler'   )r,   r!   r   r-   )r   r   s     r    on_unbecomezTerminalModule.on_unbecome   so    !!#>##%+""6*"":.__T""":. #    )N)__name__
__module____qualname__recompileterminal_stdout_rer   
IGNORECASEIterminal_stderr_reterminal_config_promptr!   r%   r0   r2    r3   r    r   r   $   s   

NO $$HI 	

< 

:r}}-

$%

,-

$bdd+

7>

+RTT2

)*

89

<&

5rtt<

.5

6=

34

/6

ODD	
 	

9244@

.5

="$$'

}DD	
1< (RZZ(@A$&0B/r3   r   )
__future__r   r   r   type__metaclass__r   r7   ansible.errorsr   ansible.module_utils._textr   r   ansible.utils.displayr	   Hansible_collections.ansible.netcommon.plugins.plugin_utils.terminal_baser
   r#   r   r>   r3   r    <module>rF      s>   & A @   	 3 8 ) a )A/\ A/r3   