
    Vh_:                       d dl mZ d dlZd dlZd dlmZ d dlmZmZm	Z	m
Z
mZmZmZmZ d dlmZmZ  G d de      Z G d d	e      Z G d
 de      Z G d dee      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z  G d  d!e      Z! G d" d#e!      Z" G d$ d%e!      Z# G d& d'e!      Z$ G d( d)e      Z% G d* d+e      Z& G d, d-e&      Z' G d. d/e&      Z( G d0 d1e&      Z) G d2 d3e      Z* G d4 d5e*      Z+ G d6 d7e*      Z, G d8 d9e*      Z- G d: d;e!e.      Z/ G d< d=e*      Z0y)>    )annotationsN)Sequence)YAML_COMMON_DICT_ERRORYAML_COMMON_LEADING_TAB_ERROR'YAML_COMMON_PARTIALLY_QUOTED_LINE_ERROR#YAML_COMMON_UNBALANCED_QUOTES_ERROR YAML_COMMON_UNQUOTED_COLON_ERROR#YAML_COMMON_UNQUOTED_VARIABLE_ERRORYAML_POSITION_DETAILSYAML_AND_SHORTHAND_ERROR)	to_nativeto_textc                  p     e Zd ZdZd	 fd	Zed        Zej                  d        Zd Zd Z	d Z
d Z xZS )
AnsibleErrora  
    This is the base class for all errors raised from Ansible code,
    and can be instantiated with two optional parameters beyond the
    error message to control whether detailed information is displayed
    when the error occurred while parsing a data file of some kind.

    Usage:

        raise AnsibleError('some message here', obj=obj, show_content=True)

    Where "obj" is some subclass of ansible.parsing.yaml.objects.AnsibleBaseYAMLObject,
    which should be returned by the DataLoader() class.
    c                    t         t        |   |       || _        || _        t        |      | _        || _        || _        y N)	superr   __init___show_content_suppress_extended_errorr   _messageobjorig_exc)selfmessager   show_contentsuppress_extended_errorr   	__class__s         G/home/dcms/DCMS/lib/python3.12/site-packages/ansible/errors/__init__.pyr   zAnsibleError.__init__5   s<    lD*73)(?%!'*     c                R   ddl m} | j                  g}| j                  r'|j	                  dt        | j                        z         t        | j                  |      r;| j                         }|r)| j                  s|j	                  dt        |      z         dj                  |      S )Nr   )AnsibleBaseYAMLObjectz. %sz

%s )ansible.parsing.yaml.objectsr"   r   r   appendr   
isinstancer   _get_extended_errorr   join)r   r"   r   extended_errors       r   r   zAnsibleError.message>   s     	G==/ ==NN6Idmm$<<= dhh 56!557Nd&C&Cy88 wwwr    c                    || _         y r   )r   )r   vals     r   r   zAnsibleError.messageT   s	    r    c                    | j                   S r   r   r   s    r   __str__zAnsibleError.__str__X       ||r    c                    | j                   S r   r-   r.   s    r   __repr__zAnsibleError.__repr__[   r0   r    c                   d}d}t        |d      5 }|j                         }t        |      }||k\  r|dz
  }||   }|j                         s|dz  }||   }|j                         s|dkD  r||dz
     }ddd       ||fS # 1 sw Y   ||fS xY w)z
        Returns the line in the file which corresponds to the reported error
        location, as well as the line preceding it (if the error did not
        occur on the first line), to provide context to the error.
        r#   r   r   N)open	readlineslenstrip)r   	file_nameline_numbertarget_line	prev_lineflinesfile_lengths           r   _get_error_lines_from_filez'AnsibleError._get_error_lines_from_file^   s     	)S! 	3QKKME
 e*Kk))Ao
  ,K!'')q #K0 "'') Q!+/2	'	3* Y''+	3* Y''s   AB 'B  Bc                x   d}	 | j                   j                  \  }}}|t        |||fz  z  }|dvr]| j                  rP| j	                  ||dz
        \  }}t        |      }t        |      }|r|j                  dd      }t        j                  d|      r]|j                         j                  d      }d|z  dz   }	t        ||dz
  |dz   fz  }|d|j                         d	|	d
z  }|t        z  }n6d|dz
  z  dz   }	|d|j                         d	|j                         d	|	d	z  }d|v r	|t        z  }d|v rd|v rd|vsd|vr|t        z  }|S d|v rd|v r|t        z  }|S t        |      rCt        |      dkD  r5t        |      |kD  r'||   dk(  r|j!                  d      dkD  r|t"        z  }|S |j%                  d      }
t        |
      dkD  r|
d   j'                         }d}d}|j)                  d      r|j+                  d      sd}n$|j)                  d      r|j+                  d      sd}t        |      dkD  r"|d   dv r|d   dv r|j!                  d      dkD  s|j!                  d      dkD  rd}|r	|t,        z  }|r	|t.        z  }|S # t0        t2        f$ r	 |dz  }Y |S t4        $ r	 |dz  }Y |S w xY w)a  
        Given an object reporting the location of the exception in a file, return
        detailed information regarding it including:

          * the line which caused the error as well as the one preceding it
          * causes and suggested remedies for common syntax errors

        If this error was created with show_content=False, the reporting of content
        is suppressed, as the file contents may be sensitive (ie. vault data).
        r#   )z<string>z	<unicode>r5    z\w+(\s+)?=(\s+)?[\w/-]+=z^ herez$
The offending line appears to be:


z

	z{{z}}z"{{z'{{z:{{:F'T"r   )rI   rH      z&
(could not open file to display line)z6
(specified line no longer in file, maybe it changed?))r   ansible_posr   r   rA   r   replaceresearchrstripfindr   r   r
   r   r8   countr	   splitr9   
startswithendswithr   r   IOError	TypeError
IndexError)r   error_messagesrc_filer;   
col_numberr<   r=   stripped_lineerror_position
arrow_linepartsmiddlematch
unbalanceds                 r   r'   z AnsibleError._get_extended_error   sZ    F	W26((2F2F/X{J2hZ5XXXM88T=O=O+/+J+J8U`cdUd+e(i%k2#I.	$/$7$7R$@M yy!;YG)2)9)9);)@)@)E&)N&:h%F
(=;YZ?\jmn\n@o(o%`i`p`p`rt~)%)AA&)Z!^&<%H
%bkbrbrbt  wB  wI  wI  wK  MW  *X  X {*%)FF +0C%WbJbfks~f~%)LLX U -/DM4I%)??R O k*,q0,z9'
3s:'--c2Q6%)IID 9 !, 1 1# 6u:>%*1X^^%5F$)E).J%005fooc>R(,!'!2!23!7PS@T(, #Fa$*1I$;$*2J*$<$/$5$5c$:Q$>$/$5$5c$:Q$>-1
$ -1X X) -1T T  # 	GFFM   	WVVM	Ws,   EJ J &AJ 4CJ J9(J98J9)r#   NTFN)__name__
__module____qualname____doc__r   propertyr   setterr/   r2   rA   r'   __classcell__r   s   @r   r   r   &   sO    !    * ^^ (BVr    r   c                      e Zd ZdZy)AnsiblePromptInterruptzUser interruptNrc   rd   re   rf    r    r   rl   rl      s    r    rl   c                      e Zd ZdZy)AnsiblePromptNoninteractivezUnable to get user inputNrm   rn   r    r   rp   rp      s    "r    rp   c                      e Zd ZdZy)AnsibleAssertionErrorzInvalid assertionNrm   rn   r    r   rr   rr      s    r    rr   c                      e Zd ZdZy)AnsibleOptionsError" bad or incomplete options passed Nrm   rn   r    r   rt   rt          ,r    rt   c                      e Zd ZdZy)AnsibleRequiredOptionErrorru   Nrm   rn   r    r   rx   rx      rv   r    rx   c                      e Zd ZdZy)AnsibleParserErrorzJ something was detected early that is wrong about a playbook or data file Nrm   rn   r    r   rz   rz      s    Tr    rz   c                      e Zd ZdZy)AnsibleInternalErrorzV internal safeguards tripped, something happened in the code that should never happen Nrm   rn   r    r   r|   r|      s    `r    r|   c                      e Zd ZdZy)AnsibleRuntimeErrorz0 ansible had a problem while running a playbook Nrm   rn   r    r   r~   r~      s    :r    r~   c                      e Zd ZdZy)AnsibleModuleErrorz a module failed somehow Nrm   rn   r    r   r   r      s    #r    r   c                      e Zd ZdZy)AnsibleConnectionFailurez5 the transport / connection_plugin had a fatal error Nrm   rn   r    r   r   r     s    ?r    r   c                      e Zd ZdZy)AnsibleAuthenticationFailurezinvalid username/password/keyNrm   rn   r    r   r   r         'r    r   c                      e Zd ZdZy)AnsibleCallbackErrorz a callback failure Nrm   rn   r    r   r   r     s    r    r   c                      e Zd ZdZy)AnsibleTemplateErrorzA template related errorNrm   rn   r    r   r   r     s    "r    r   c                      e Zd ZdZy)AnsibleFilterError a templating failure Nrm   rn   r    r   r   r          r    r   c                      e Zd ZdZy)AnsibleLookupErrorz a lookup failure Nrm   rn   r    r   r   r     s    r    r   c                      e Zd ZdZy)AnsibleUndefinedVariabler   Nrm   rn   r    r   r   r   !  r   r    r   c                  $     e Zd ZdZd fd	Z xZS )AnsibleFileNotFoundz a file missing failure c                v   || _         || _        |r|dz  }| j                   r|dt        | j                         z  z  }n|dz  }| j                  rMt        | j                  t              r3t        dj                  | j                              }|r|dz  }|d|z  z  }|dz  }t        t        | #  |||||       y )NrE   zCould not find or access '%s'zCould not find filez
	zSearched in:
	%sz{ on the Ansible Controller.
If you are using a module and expect the file to exist on the remote, see the remote_src optionr   r   r   r   r   )	r:   pathsr   r&   r   r(   r   r   r   )
r   r   r   r   r   r   r   r:   searchedr   s
            r   r   zAnsibleFileNotFound.__init__)  s    "
tOG>>69PPPG,,G::*TZZ:v{{4::67H4+h66G  R  	R!41'sYeJalt 	2 	vr    )r#   NTFNNNrc   rd   re   rf   r   ri   rj   s   @r   r   r   &  s    "v vr    r   c                  $     e Zd ZdZd fd	Z xZS )AnsibleActionz/ Base Exception for Action plugin flow control c                X    t         t        |   |||||       |i | _        y || _        y )Nr   )r   r   r   resultr   r   r   r   r   r   r   r   s          r   r   zAnsibleAction.__init__G  s8    mT+GS_D[fn 	, 	p>DK DKr    r#   NTFNNr   rj   s   @r   r   r   D  s    9! !r    r   c                  $     e Zd ZdZd fd	Z xZS )AnsibleActionSkipz an action runtime skipc                t    t         t        |   ||||||       | j                  j	                  d|d       y )Nr   r   r   r   r   r   T)skippedmsg)r   r   r   r   updater   s          r   r   zAnsibleActionSkip.__init__T  sD    /SWcH_jr  |B 	0 	CtG<=r    r   r   rj   s   @r   r   r   Q  s    !> >r    r   c                  $     e Zd ZdZd fd	Z xZS )AnsibleActionFailz an action runtime failurec                    t         t        |   ||||||       | j                  j	                  d|t        j                         d       y )Nr   T)failedr   	exception)r   r   r   r   r   	traceback
format_excr   s          r   r   zAnsibleActionFail.__init__\  sO    /SWcH_jr  |B 	0 	Cd7I]I]I_`ar    r   r   rj   s   @r   r   r   Z  s    $b br    r   c                      e Zd ZdZy)_AnsibleActionDonez an action runtime early exitNrm   rn   r    r   r   r   b  r   r    r   c                  $     e Zd ZdZd fd	Z xZS )AnsiblePluginErrorz\ base class for Ansible plugin-related errors that do not need AnsibleError contextual data c                :    t         t        |   |       || _        y r   )r   r   r   plugin_load_context)r   r   r   r   s      r   r   zAnsiblePluginError.__init__i  s     $09#6 r    )NNr   rj   s   @r   r   r   g  s    f7 7r    r   c                      e Zd ZdZy)AnsiblePluginRemovedErrorz% a requested plugin has been removed Nrm   rn   r    r   r   r   n  s    /r    r   c                      e Zd ZdZy)AnsiblePluginCircularRedirectz*a cycle was detected in plugin redirectionNrm   rn   r    r   r   r   s  s    4r    r   c                      e Zd ZdZy)(AnsibleCollectionUnsupportedVersionErrorz8a collection is not supported by this version of AnsibleNrm   rn   r    r   r   r   x  s    Br    r   c                      e Zd ZdZy)AnsibleFilterTypeErrorz2 a Jinja filter templating failure due to bad typeNrm   rn   r    r   r   r   }  s    <r    r   c                      e Zd ZdZy)AnsiblePluginNotFoundz- Indicates we did not find an Ansible plugin Nrm   rn   r    r   r   r     s    7r    r   )1
__future__r   rN   r   collections.abcr   ansible.errors.yaml_stringsr   r   r   r   r	   r
   r   r   +ansible.module_utils.common.text.convertersr   r   	Exceptionr   rl   rp   AssertionErrorrr   rt   rx   rz   r|   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rW   r   r   rn   r    r   <module>r      s  $ # 	  $	 	 	 Ko9 od\ #, #	L. 	
	, 	
	!4 	
	 	
	< 	
	, 	
	, 	
	2 	
	#; 	
	. 	
	. 	
	- 	
	- 	
	3 	
v- v<
!' 
!> >b b	 	
7 7	 2 	
	$6 	
	/A 	
	19 	
	. 	r    