o
    c                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 dd	lm
Z dd
lmZ G dd de	jZG dd deZG dd deZG dd deZe	je e	je e	je dS )z: apacheconfig implementation of the ParserNode interfaces     )Any)Iterable)List)Optional)Tuple)
assertions)
interfaces)parsernode_util)
ParserNodec                       sR   e Zd ZdZdeddf fddZdeddfdd	Zd
eded  fddZ	  Z
S )ApacheParserNodez apacheconfig implementation of ParserNode interface.

        Expects metadata `ac_ast` to be passed in, where `ac_ast` is the AST provided
        by parsing the equivalent configuration text using the apacheconfig library.
    kwargsreturnNc                    sL   t |\}}}}t jdi | || _|| _|| _|| _| jd | _d S )Nac_ast )	utilparsernode_kwargssuper__init__ancestorfilepathdirtymetadata_raw)selfr   r   r   r   r   	__class__r   R/opt/certbot/lib/python3.10/site-packages/certbot_apache/_internal/apacheparser.pyr      s   zApacheParserNode.__init__msgc                 C   s   d S )Nr   )r   r   r   r   r   save   s   zApacheParserNode.savenamec                 C      t tjtj| tj| jdgS )z*Find ancestor BlockNodes with a given namer   
parametersr   r   r   ApacheBlockNoder   PASSr   )r   r   r   r   r   find_ancestors"      zApacheParserNode.find_ancestors)__name__
__module____qualname____doc__r   r   strr   r   r&   __classcell__r   r   r   r   r      s
    
r   c                       s<   e Zd ZdZdeddf fddZdedefdd	Z  ZS )
ApacheCommentNodez6 apacheconfig implementation of CommentNode interface r   r   Nc                    s*   t |\}}t jdi | || _d S Nr   )r   commentnode_kwargsr   r   comment)r   r   r1   r   r   r   r   .   s   
zApacheCommentNode.__init__otherc                 C   sL   t || jr$| j|jko#| j|jko#| j|jko#| j|jko#| j|jkS dS NF)
isinstancer   r1   r   r   r   r   r   r2   r   r   r   __eq__3   s   



zApacheCommentNode.__eq__)	r(   r)   r*   r+   r   r   boolr6   r-   r   r   r   r   r.   +   s    r.   c                       sR   e Zd ZdZdeddf fddZdedefdd	Zd
ee	 ddfddZ
  ZS )ApacheDirectiveNodez8 apacheconfig implementation of DirectiveNode interface r   r   Nc                    s@   t |\}}}}t jdi | || _|| _|| _d | _d S r/   )r   directivenode_kwargsr   r   r   r"   enabledinclude)r   r   r   r"   r:   r   r   r   r   @   s   
zApacheDirectiveNode.__init__r2   c                 C   sd   t || jr0| j|jko/| j|jko/| j|jko/| j|jko/| j|jko/| j|jko/| j|jkS dS r3   )	r4   r   r   r   r"   r:   r   r   r   r5   r   r   r   r6   H   s   





zApacheDirectiveNode.__eq___parametersc                 C      dS )z%Sets the parameters for DirectiveNodeNr   )r   r<   r   r   r   set_parametersS      z"ApacheDirectiveNode.set_parameters)r(   r)   r*   r+   r   r   r7   r6   r   r,   r>   r-   r   r   r   r   r8   =   s
    r8   c                	       sD  e Zd ZdZdeddf fddZdedefdd	Z		d%d
ede	e
e  de	e dd fddZ		d%d
ede	e
e  de	e defddZ	d%d
ede	e de	e defddZd&d
edede
d  fddZd&d
edede
e fddZd'dedede
e fddZdeddfdd Zde
e fd!d"Zde
e fd#d$Z  ZS )(r$   z4 apacheconfig implementation of BlockNode interface r   r   Nc                    s   t  jdi | d| _d S r/   )r   r   children)r   r   r   r   r   r   [   s   
zApacheBlockNode.__init__r2   c                 C   sp   t || jr6| j|jko5| j|jko5| j|jko5| j|jko5| j|jko5| j|jko5| j|jko5| j	|j	kS dS r3   )
r4   r   r   r   r"   r@   r:   r   r   r   r5   r   r   r   r6   _   s"   






zApacheBlockNode.__eq__r   r"   positionc                 C   .   t tjtj| tj| jd}|  j|f7  _|S )z0Adds a new BlockNode to the sequence of childrenr!   )r$   r   r%   r   r@   )r   r   r"   rA   	new_blockr   r   r   add_child_blockl   s   zApacheBlockNode.add_child_blockc                 C   rB   )z4Adds a new DirectiveNode to the sequence of childrenr!   )r8   r   r%   r   r@   )r   r   r"   rA   new_dirr   r   r   add_child_directivex   s   z#ApacheBlockNode.add_child_directivec                 C   s*   t tj| tj| jd}|  j|f7  _|S )z2Adds a new CommentNode to the sequence of childrenr1   r   r   r   )r.   r   r%   r   r@   )r   r   r"   rA   new_commentr   r   r   add_child_comment   s   z!ApacheBlockNode.add_child_commentTexcludec                 C   r    )z<Recursive search of BlockNodes from the sequence of childrenr!   r#   r   r   rJ   r   r   r   find_blocks   r'   zApacheBlockNode.find_blocksc                 C   r    )@Recursive search of DirectiveNodes from the sequence of childrenr!   )r8   r   r%   r   rK   r   r   r   find_directives   r'   zApacheBlockNode.find_directivesFr1   exactc                 C   s   t tj| tj| jdgS )rM   rG   )r.   r   r%   r   )r   r1   rO   r   r   r   find_comments   s
   zApacheBlockNode.find_commentschildc                 C   r=   )z2Deletes a ParserNode from the sequence of childrenNr   )r   rQ   r   r   r   delete_child   r?   zApacheBlockNode.delete_childc                 C      t jgS )z#Returns a list of unsaved filepathsr   r%   r   r   r   r   unsaved_files      zApacheBlockNode.unsaved_filesc                 C   rS   )z1Returns a list of parsed configuration file pathsrT   rU   r   r   r   parsed_paths   rW   zApacheBlockNode.parsed_paths)NN)T)F)r(   r)   r*   r+   r   r   r7   r6   r,   r   r   intrD   r8   rF   r.   rI   rL   rN   rP   r
   rR   rV   rX   r-   r   r   r   r   r$   X   sD    


	r$   N)r+   typingr   r   r   r   r   certbot_apache._internalr   r   r	   r   #certbot_apache._internal.interfacesr
   r   r.   r8   r$   CommentNoderegisterDirectiveNode	BlockNoder   r   r   r   <module>   s"    ^