o
    c                     @   s  d Z ddl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 ddlmZ dZdededdfddZdededdfddZdededdfddZdededdfddZdedefddZdedefddZdedefd d!Zd"eeeef  defd#d$Zdededdfd%d&Zdededefd'd(Zdee dee ddfd)d*ZdS )+zDual parser node assertions    N)Any)Iterable)List)Optional)Union)
interfaces)CommentNode)DirectiveNode)
ParserNode)VirtualHostCERTBOT_PASS_ASSERTfirstsecondreturnc                 C   s   t | tjrt| | nt | tjrt| | t | tjr%t |tjs%J t| js?t|jsA| j	|j	ks7J | j|jksCJ dS dS dS )z Equality assertion N)

isinstancer   r   assertEqualCommentr	   assertEqualDirective	BlockNodeisPassfilepathdirtyr   r    r   P/opt/certbot/lib/python3.10/site-packages/certbot_apache/_internal/assertions.pyassertEqual   s   
r   c                 C   sP   t | tjsJ t |tjsJ t| js"t|js$| j|jks&J dS dS dS )z$ Equality assertion for CommentNode N)r   r   r   r   commentr   r   r   r   r   *   s   r   c                 C   sp   t | tsJ t |tsJ t| js t|js | j|jks J t| js2t|js4| j|jks6J dS dS dS )zI Handles assertion for instance variables for DirectiveNode and BlockNodeN)r   r	   r   name
parametersr   r   r   r   _assertEqualDirectiveComponents4   s   r   c                 C   s.   t | tjsJ t |tjsJ t| | dS )z& Equality assertion for DirectiveNode N)r   r   r	   r   r   r   r   r   r   E   s   r   valuec                 C   s   t | trdS t| v S )z"Checks if the value is set to PASST)r   boolPASS)r   r   r   r   r   M   s   
r   blockc                 C   s.   t | jrdS t | jrdS t | jrdS dS )z@ Checks if BlockNode or DirectiveNode should pass the assertion TF)r   r   r   r   )r"   r   r   r   isPassDirectiveT   s   


r#   r   c                 C   s    t | jrdS t | jrdS dS )z1 Checks if CommentNode should pass the assertion TF)r   r   r   )r   r   r   r   isPassComment`   s
   

r$   nodelistc                 C   sH   z| d }W n t y   d}Y nw |sdS t|tjr t|S t|S )z Checks if a ParserNode in the nodelist should pass the assertion,
    this function is used for results of find_* methods. Unimplemented find_*
    methods should return a sequence containing a single ParserNode instance
    with assertion pass string.r   NF)
IndexErrorr   r   r	   r#   r$   )r%   noder   r   r   isPassNodeListj   s   r(   c                 C   s(   t | st |s| |ksJ dS dS dS )z Simple assertion Nr   r   r   r   r   assertEqualSimple~   s   r*   c                 C   s`   | 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o/| j|jkS )a  
    Checks that two VirtualHost objects are similar. There are some built
    in differences with the implementations: VirtualHost created by ParserNode
    implementation doesn't have "path" defined, as it was used for Augeas path
    and that cannot obviously be used in the future. Similarly the legacy
    version lacks "node" variable, that has a reference to the BlockNode for the
    VirtualHost.
    )r   aliasesfilepaddrssslenabledmodmacroancestorr   r   r   r   isEqualVirtualHost   s   







r2   c                    sx   t dd | D rdS t dd |D rdS | D ] t  fdd|D s'J q|D ]t fdd| D s9J q*dS )zf
    Checks that the two lists of file paths match. This assertion allows for wildcard
    paths.
    c                 s       | ]}t |V  qd S Nr)   .0pathr   r   r   	<genexpr>       z'assertEqualPathsList.<locals>.<genexpr>Nc                 s   r3   r4   r)   r5   r   r   r   r8      r9   c                 3   s    | ]	}t   |V  qd S r4   fnmatch)r6   spath)fpathr   r   r8          c                 3   s    | ]	}t  | V  qd S r4   r:   )r6   r=   )r<   r   r   r8      r>   )anyr   r   )r=   r<   r   assertEqualPathsList   s   r@   )__doc__r;   typingr   r   r   r   r   certbot_apache._internalr   #certbot_apache._internal.interfacesr   r	   r
   certbot_apache._internal.objr   r!   r   r   r   r   r    r   r#   r$   r(   r*   r2   strr@   r   r   r   r   <module>   s8    


"