a
    Z,_                     @   s   d 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     )
assertions)
interfaces)parsernode_utilc                       s0   e Zd ZdZ fddZdd Z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.
    c                    sP   t |\}}}}tt| jf i | || _|| _|| _|| _| jd | _	d S )NZac_ast)
utilZparsernode_kwargssuperr   __init__ancestorfilepathdirtymetadataZ_raw)selfkwargsr	   r   r
   r   	__class__ G/usr/lib/python3/dist-packages/certbot_apache/_internal/apacheparser.pyr      s    zApacheParserNode.__init__c                 C   s   d S Nr   )r   msgr   r   r   save   s    zApacheParserNode.savec                 C   s   t tjtj| tj| jdgS )z*Find ancestor BlockNodes with a given namename
parametersr	   r
   r   ApacheBlockNoder   PASSr   )r   r   r   r   r   find_ancestors   s    zApacheParserNode.find_ancestors)__name__
__module____qualname____doc__r   r   r   __classcell__r   r   r   r   r      s   	r   c                       s(   e Zd ZdZ fddZdd Z  ZS )ApacheCommentNodez6 apacheconfig implementation of CommentNode interface c                    s.   t |\}}tt| jf i | || _d S r   )r   Zcommentnode_kwargsr   r"   r   comment)r   r   r#   r   r   r   r   '   s    zApacheCommentNode.__init__c                 C   sL   t || jrH| j|jkoF| j|jkoF| j|jkoF| j|jkoF| j|jkS dS NF)
isinstancer   r#   r   r	   r   r
   r   otherr   r   r   __eq__,   s    



zApacheCommentNode.__eq__)r   r   r   r    r   r(   r!   r   r   r   r   r"   $   s   r"   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )ApacheDirectiveNodez8 apacheconfig implementation of DirectiveNode interface c                    sD   t |\}}}}tt| jf i | || _|| _|| _d | _d S r   )	r   Zdirectivenode_kwargsr   r)   r   r   r   enabledZinclude)r   r   r   r   r*   r   r   r   r   9   s    zApacheDirectiveNode.__init__c                 C   sd   t || jr`| 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 r$   )	r%   r   r   r
   r   r*   r   r	   r   r&   r   r   r   r(   A   s    





zApacheDirectiveNode.__eq__c                 C   s   dS )z%Sets the parameters for DirectiveNodeNr   )r   Z_parametersr   r   r   set_parametersL   s    z"ApacheDirectiveNode.set_parameters)r   r   r   r    r   r(   r+   r!   r   r   r   r   r)   6   s   r)   c                       s|   e Zd ZdZ fddZdd ZdddZdd	d
ZdddZdddZ	d ddZ
d!ddZdd Zdd Zdd Z  ZS )"r   z4 apacheconfig implementation of BlockNode interface c                    s    t t| jf i | d| _d S )Nr   )r   r   r   children)r   r   r   r   r   r   T   s    zApacheBlockNode.__init__c                 C   sp   t || jrl| j|jkoj| j|jkoj| j|jkoj| j|jkoj| j|jkoj| j|jkoj| j|jkoj| j	|j	kS dS r$   )
r%   r   r   r
   r   r,   r*   r   r	   r   r&   r   r   r   r(   X   s"    






zApacheBlockNode.__eq__Nc                 C   s.   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   positionZ	new_blockr   r   r   add_child_blocke   s    zApacheBlockNode.add_child_blockc                 C   s.   t tjtj| tj| jd}|  j|f7  _|S )z4Adds a new DirectiveNode to the sequence of childrenr   )r)   r   r   r   r,   )r   r   r   r-   Znew_dirr   r   r   add_child_directivep   s    z#ApacheBlockNode.add_child_directive c                 C   s*   t tj| tj| jd}|  j|f7  _|S )z2Adds a new CommentNode to the sequence of childrenr#   r	   r
   r   )r"   r   r   r   r,   )r   r#   r-   Znew_commentr   r   r   add_child_comment{   s    z!ApacheBlockNode.add_child_commentTc                 C   s   t tjtj| tj| jdgS )z<Recursive search of BlockNodes from the sequence of childrenr   r   r   r   Zexcluder   r   r   find_blocks   s    zApacheBlockNode.find_blocksc                 C   s   t tjtj| tj| jdgS )@Recursive search of DirectiveNodes from the sequence of childrenr   )r)   r   r   r   r3   r   r   r   find_directives   s    zApacheBlockNode.find_directivesFc                 C   s   t tj| tj| jdgS )r5   r1   )r"   r   r   r   )r   r#   exactr   r   r   find_comments   s
    zApacheBlockNode.find_commentsc                 C   s   dS )z2Deletes a ParserNode from the sequence of childrenNr   )r   childr   r   r   delete_child   s    zApacheBlockNode.delete_childc                 C   s   t jgS )z#Returns a list of unsaved filepathsr   r   r   r   r   r   unsaved_files   s    zApacheBlockNode.unsaved_filesc                 C   s   t jgS )z1Returns a list of parsed configuration file pathsr;   r<   r   r   r   parsed_paths   s    zApacheBlockNode.parsed_paths)NN)NN)r0   N)T)T)F)r   r   r   r    r   r(   r.   r/   r2   r4   r6   r8   r:   r=   r>   r!   r   r   r   r   r   Q   s   





	
r   N)r    Zcertbot_apache._internalr   r   r   r   Z
ParserNoder   r"   r)   r   ZCommentNoderegisterZDirectiveNodeZ	BlockNoder   r   r   r   <module>   s   Y