Ë
    M/ÅeŠ:  ã                   ó   — 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
 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 e
rddlmZ ddlmZ  edd¬«      Z edd¬«      Z edd¬«      Z G d„ deeef   «      Z G d„ deej2                  ej4                  f   «      Z G d„ deej8                  ej:                  f   «      Z G d„ deej>                  ej@                  f   «      Z!y )!z  Dual ParserNode implementation é    )ÚAny)ÚGeneric)ÚIterable)ÚList)ÚOptional)ÚSet)ÚTuple)ÚType)ÚTYPE_CHECKING)ÚTypeVar)Úapacheparser)Ú
assertions)Úaugeasparser)Ú
interfaces)ÚApacheParserNode)ÚAugeasParserNodeÚGenericAugeasParserNoder   )ÚboundÚGenericApacheParserNoder   ÚGenericDualNodeÚDualNodeBasec                   ó‚   — e Zd ZdZdededdfd„Zdeddfd„Zd	ede	fd
„Z
deded    fd„Zdee   dedede	dee   f
d„Zy)r   z³ Dual parser interface for in development testing. This is used as the
    base class for dual parser interface classes. This class handles runtime
    attribute value assertions.ÚprimaryÚ	secondaryÚreturnNc                 ó    — || _         || _        y )N©r   r   )Úselfr   r   s      úE/usr/lib/python3/dist-packages/certbot_apache/_internal/dualparser.pyÚ__init__zDualNodeBase.__init__    s   € àˆŒØ"ˆ�ó    Úmsgc                 óp   — | j                   j                  |«       | j                  j                  |«       y)z Call save for both parsers N)r   Úsaver   )r   r"   s     r   r$   zDualNodeBase.save%   s&   € à�‰×Ñ˜#ÔØ�‰×Ñ˜CÕ r!   Úanamec                 óÀ   — t        | j                  |«      }t        | j                  |«      }|dk(  t        |«      g}t	        |«      st        j                  ||«       |S )z Attribute value assertion Úmetadata)Úgetattrr   r   ÚcallableÚanyr   ÚassertEqualSimple)r   r%   ÚfirstvalÚ	secondvalÚ
exclusionss        r   Ú__getattr__zDualNodeBase.__getattr__*   sY   € ä˜4Ÿ<™<¨Ó/ˆÜ˜DŸN™N¨EÓ2ˆ	ð �ZÑÜ�XÓð	
ˆ
ô �:ŒÜ×(Ñ(¨°9Ô=Øˆr!   Únamec                 ó0   — | j                  t        d|«      S )zA Traverses the ancestor tree and returns ancestors matching name Úfind_ancestors©Ú_find_helperÚDualBlockNode)r   r0   s     r   r2   zDualNodeBase.find_ancestors8   s   € à× Ñ ¤Ð0@À$ÓGÐGr!   Ú	nodeclassÚfindfuncÚsearchÚkwargsc                 óT  —  t        | j                  |«      |fi |¤Ž} t        | j                  |«      |fi |¤Ž}t        j                  |«      }t        j                  |«      }g }	|r#|r!|	j                   ||d   |d   ¬«      «       |	S |r%|D ]  }
|	j                   ||d   |
¬«      «       Œ  |	S |r%|D ]  }
|	j                   ||
|d   ¬«      «       Œ  |	S t        |«      t        |«      k(  sJ ‚| j                  ||«      }|D ]  \  }}|	j                   |||¬«      «       Œ  |	S )a.  A helper for find_* functions. The function specific attributes should
        be passed as keyword arguments.

        :param interfaces.ParserNode nodeclass: The node class for results.
        :param str findfunc: Name of the find function to call
        :param str search: The search term
        r   r   )r(   r   r   r   ÚisPassNodeListÚappendÚlenÚ_create_matching_list)r   r6   r7   r8   r9   Úprimary_resÚsecondary_resÚpass_primaryÚpass_secondaryÚ	new_nodesÚcÚmatchesÚpÚss                 r   r4   zDualNodeBase._find_helper<   sl  € ð 6”g˜dŸl™l¨HÓ5°fÑGÀÑGˆØ9œ §¡°Ó9¸&ÑKÀFÑKˆô
 "×0Ñ0°Ó=ˆÜ#×2Ñ2°=ÓAˆØˆ	á™Nà×Ñ™Y¨{¸1©~Ø1>¸qÑ1AôCô Dð  Ðñ Ø"ò 9�Ø× Ñ ¡°;¸q±>Ø56ô"8õ 9ð9ð Ðñ Ø ò H�Ø× Ñ ¡°1Ø5BÀ1Ñ5Eô"Gõ HðHð Ðô �{Ó#¤s¨=Ó'9Ò9Ð9Ð9Ø×0Ñ0°¸mÓLˆGØò D‘��1Ø× Ñ ¡°1ÀÔ!BÕCðDð Ðr!   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r    Ústrr$   r   r/   r   r2   r
   r   r4   © r!   r   r   r      sš   „ ñ#ð#Ð 7ð #Ø3ð#Ø8<ó#ð
!˜ð ! ó !ð
 ð ¨ó ðH 3ð H¨4°Ñ+?ó Hð& d¨?Ñ&;ð &Àsð &ÐTWð &Ø"ð&Ø'+¨OÑ'<ô&r!   c                   ó,   ‡ — e Zd ZdZdeddfˆ fd„Zˆ xZS )ÚDualCommentNodez5 Dual parser implementation of CommentNode interface r9   r   Nc                 óˆ  •— |j                  dd«       |j                  dd«       |j                  d«      }|j                  d«      }|s|r|r|sJ ‚t        ‰| �  ||«       n6t        ‰| �  t	        j
                  di |¤Žt        j                  di |¤Ž«       t        j                  | j                  | j                  «       y)a<   This initialization implementation allows ordinary initialization
        of CommentNode objects as well as creating a DualCommentNode object
        using precreated or fetched CommentNode objects if provided as optional
        arguments primary and secondary.

        Parameters other than the following are from interfaces.CommentNode:

        :param CommentNode primary: Primary pre-created CommentNode, mainly
            used when creating new DualParser nodes using add_* methods.
        :param CommentNode secondary: Secondary pre-created CommentNode
        r   Nr   rM   )Ú
setdefaultÚpopÚsuperr    r   ÚAugeasCommentNoder   ÚApacheCommentNoder   ÚassertEqualr   r   ©r   r9   r   r   Ú	__class__s       €r   r    zDualCommentNode.__init__i   s©   ø€ ð 	×Ñ˜) TÔ*Ø×Ñ˜+ tÔ,Ø—*‘*˜YÓ'ˆØ—J‘J˜{Ó+ˆ	á‘iÙ™yÐ(Ð(Ü‰GÑ˜W iÕ0ä‰GÑœ\×;Ñ;ÑE¸fÑEÜ)×;Ñ;ÑE¸fÑEôGô 	×Ñ˜tŸ|™|¨T¯^©^Õ<r!   )rH   rI   rJ   rK   r   r    Ú__classcell__©rX   s   @r   rO   rO   e   s   ø„ á?ð= ð =¨÷ =ñ =r!   rO   c                   óN   ‡ — e Zd ZU dZeed<   deddfˆ fd„Zdee   ddfd„Z	ˆ xZ
S )ÚDualDirectiveNodez7 Dual parser implementation of DirectiveNode interface Ú
parametersr9   r   Nc                 óˆ  •— |j                  dd«       |j                  dd«       |j                  d«      }|j                  d«      }|s|r|r|sJ ‚t        ‰| �  ||«       n6t        ‰| �  t	        j
                  di |¤Žt        j                  di |¤Ž«       t        j                  | j                  | j                  «       y)aL   This initialization implementation allows ordinary initialization
        of DirectiveNode objects as well as creating a DualDirectiveNode object
        using precreated or fetched DirectiveNode objects if provided as optional
        arguments primary and secondary.

        Parameters other than the following are from interfaces.DirectiveNode:

        :param DirectiveNode primary: Primary pre-created DirectiveNode, mainly
            used when creating new DualParser nodes using add_* methods.
        :param DirectiveNode secondary: Secondary pre-created DirectiveNode
        r   Nr   rM   )rQ   rR   rS   r    r   ÚAugeasDirectiveNoder   ÚApacheDirectiveNoder   rV   r   r   rW   s       €r   r    zDualDirectiveNode.__init__‹   s©   ø€ ð 	×Ñ˜) TÔ*Ø×Ñ˜+ tÔ,Ø—*‘*˜YÓ'ˆØ—J‘J˜{Ó+ˆ	á‘iÙ™yÐ(Ð(Ü‰GÑ˜W iÕ0ä‰GÑœ\×=Ñ=ÑGÀÑGÜ)×=Ñ=ÑGÀÑGôIô 	×Ñ˜tŸ|™|¨T¯^©^Õ<r!   c                 óÄ   — | j                   j                  |«       | j                  j                  |«       t        j                  | j                   | j                  «       y)zf Sets parameters and asserts that both implementation successfully
        set the parameter sequence N)r   Úset_parametersr   r   rV   )r   r]   s     r   rb   z DualDirectiveNode.set_parameters¦   s@   € ð 	�‰×#Ñ# JÔ/Ø�‰×%Ñ% jÔ1Ü×Ñ˜tŸ|™|¨T¯^©^Õ<r!   )rH   rI   rJ   rK   rL   Ú__annotations__r   r    r   rb   rY   rZ   s   @r   r\   r\   …   s5   ø… áAàƒOð= ð =¨õ =ð6=¨°#©ð =¸4÷ =r!   r\   c            	       ó¦  ‡ — e Zd ZdZdeddfˆ fd„Z	 	 ddedeee      dee	   dd fd	„Z
	 	 ddedeee      dee	   defd
„Z	 	 ddedee	   defd„Zdeej"                     deej"                     deeej"                  ej"                  f      fd„Zddededed    fd„Zddededee   fd„Zdedee   fd„Zdd„Zdee   fd„Zdee   fd„Zˆ xZS )r5   z3 Dual parser implementation of BlockNode interface r9   r   Nc                 óˆ  •— |j                  dd«       |j                  dd«       |j                  d«      }|j                  d«      }|s|r|r|sJ ‚t        ‰| �  ||«       n6t        ‰| �  t	        j
                  di |¤Žt        j                  di |¤Ž«       t        j                  | j                  | j                  «       y)a,   This initialization implementation allows ordinary initialization
        of BlockNode objects as well as creating a DualBlockNode object
        using precreated or fetched BlockNode objects if provided as optional
        arguments primary and secondary.

        Parameters other than the following are from interfaces.BlockNode:

        :param BlockNode primary: Primary pre-created BlockNode, mainly
            used when creating new DualParser nodes using add_* methods.
        :param BlockNode secondary: Secondary pre-created BlockNode
        r   Nr   rM   )rQ   rR   rS   r    r   ÚAugeasBlockNoder   ÚApacheBlockNoder   rV   r   r   rW   s       €r   r    zDualBlockNode.__init__³   s©   ø€ ð 	×Ñ˜) TÔ*Ø×Ñ˜+ tÔ,Ø:@¿*¹*ÀYÓ:OˆØ<B¿J¹JÀ{Ó<Sˆ	á‘iÙ™yÐ(Ð(Ü‰GÑ˜W iÕ0ä‰GÑœ\×9Ñ9ÑC¸FÑCÜ)×9Ñ9ÑC¸FÑCôEô 	×Ñ˜tŸ|™|¨T¯^©^Õ<r!   r0   r]   Úpositionc                 ó¼   — | j                   j                  |||«      }| j                  j                  |||«      }t        j                  ||«       t        ||¬«      S )zÌ Creates a new child BlockNode, asserts that both implementations
        did it in a similar way, and returns a newly created DualBlockNode object
        encapsulating both of the newly created objects r   )r   Úadd_child_blockr   r   rV   r5   ©r   r0   r]   rh   Úprimary_newÚsecondary_news         r   rj   zDualBlockNode.add_child_blockÎ   sQ   € ð —l‘l×2Ñ2°4¸ÀXÓNˆØŸ™×6Ñ6°t¸ZÈÓRˆÜ×Ñ˜{¨MÔ:Ü [¸MÔJÐJr!   c                 ó¼   — | j                   j                  |||«      }| j                  j                  |||«      }t        j                  ||«       t        ||¬«      S )zÔ Creates a new child DirectiveNode, asserts that both implementations
        did it in a similar way, and returns a newly created DualDirectiveNode
        object encapsulating both of the newly created objects r   )r   Úadd_child_directiver   r   rV   r\   rk   s         r   ro   z!DualBlockNode.add_child_directiveÙ   sQ   € ð —l‘l×6Ñ6°t¸ZÈÓRˆØŸ™×:Ñ:¸4ÀÈXÓVˆÜ×Ñ˜{¨MÔ:Ü ¨ÀÔNÐNr!   Úcommentc                 ó¼   — | j                   j                  ||¬«      }| j                  j                  ||¬«      }t        j                  ||«       t        ||¬«      S )zÐ Creates a new child CommentNode, asserts that both implementations
        did it in a similar way, and returns a newly created DualCommentNode
        object encapsulating both of the newly created objects )rp   rh   )r0   rh   r   )r   Úadd_child_commentr   r   rV   rO   )r   rp   rh   rl   rm   s        r   rr   zDualBlockNode.add_child_commentä   sT   € ð —l‘l×4Ñ4¸WÈxÐ4ÓXˆØŸ™×8Ñ8¸gÐPXÐ8ÓYˆÜ×Ñ˜{¨MÔ:Ü {¸mÔLÐLr!   Úprimary_listÚsecondary_listc                 ó¼   — g }|D ]E  }d}|D ]  }	 t        j                  ||«       |} n |r|j                  ||f«       Œ<t        d«      ‚ |S # t        $ r Y ŒNw xY w)aÂ   Matches the list of primary_list to a list of secondary_list and
        returns a list of tuples. This is used to create results for find_
        methods.

        This helper function exists, because we cannot ensure that the list of
        search results returned by primary.find_* and secondary.find_* are ordered
        in a same way. The function pairs the same search results from both
        implementations to a list of tuples.
        NzCould not find a matching node.)r   rV   ÚAssertionErrorr<   )r   rs   rt   ÚmatchedrF   ÚmatchrG   s          r   r>   z#DualBlockNode._create_matching_listï   s‡   € ð ˆØò 	HˆAØˆEØ#ò �ðÜ×*Ñ*¨1¨aÔ0Ø�EÙð	ñ Ø—‘  5˜zÕ*ä$Ð%FÓGÐGð	Hð ˆøô &ò Ùðús   �AÁ	AÁAÚexcludec                 ó4   — | j                  t        d||¬«      S )a•  
        Performs a search for BlockNodes using both implementations and does simple
        checks for results. This is built upon the assumption that unimplemented
        find_* methods return a list with a single assertion passing object.
        After the assertion, it creates a list of newly created DualBlockNode
        instances that encapsulate the pairs of returned BlockNode objects.
        Úfind_blocks©ry   r3   ©r   r0   ry   s      r   r{   zDualBlockNode.find_blocks  s%   € ð × Ñ ¤°¸tØ)0ð !ó 2ð 	2r!   c                 ó4   — | j                  t        d||¬«      S )a•  
        Performs a search for DirectiveNodes using both implementations and
        checks the results. This is built upon the assumption that unimplemented
        find_* methods return a list with a single assertion passing object.
        After the assertion, it creates a list of newly created DualDirectiveNode
        instances that encapsulate the pairs of returned DirectiveNode objects.
        Úfind_directivesr|   )r4   r\   r}   s      r   r   zDualBlockNode.find_directives  s'   € ð × Ñ Ô!2Ð4EÀtØ)0ð !ó 2ð 	2r!   c                 ó0   — | j                  t        d|«      S )a�  
        Performs a search for CommentNodes using both implementations and
        checks the results. This is built upon the assumption that unimplemented
        find_* methods return a list with a single assertion passing object.
        After the assertion, it creates a list of newly created DualCommentNode
        instances that encapsulate the pairs of returned CommentNode objects.
        Úfind_comments)r4   rO   )r   rp   s     r   r�   zDualBlockNode.find_comments$  s   € ð × Ñ ¤°/À7ÓKÐKr!   c                 ó˜   — | j                   j                  |j                   «       | j                  j                  |j                  «       y)z¿Deletes a child from the ParserNode implementations. The actual
        ParserNode implementations are used here directly in order to be able
        to match a child to the list of children.N)r   Údelete_childr   )r   Úchilds     r   rƒ   zDualBlockNode.delete_child/  s0   € ð
 	�‰×!Ñ! %§-¡-Ô0Ø�‰×#Ñ# E§O¡OÕ4r!   c                 óš   — | j                   j                  «       }| j                  j                  «       }t        j                  ||«       |S )zQ Fetches the list of unsaved file paths and asserts that the lists
        match )r   Úunsaved_filesr   r   r+   )r   Úprimary_filesÚsecondary_filess      r   r†   zDualBlockNode.unsaved_files7  s>   € ð Ÿ™×2Ñ2Ó4ˆØŸ.™.×6Ñ6Ó8ˆÜ×$Ñ$ ]°OÔDàÐr!   c                 óš   — | j                   j                  «       }| j                  j                  «       }t        j                  ||«       |S )an  
        Returns a list of file paths that have currently been parsed into the parser
        tree. The returned list may include paths with wildcard characters, for
        example: ['/etc/apache2/conf.d/*.load']

        This is typically called on the root node of the ParserNode tree.

        :returns: list of file paths of files that have been parsed
        )r   Úparsed_pathsr   r   ÚassertEqualPathsList)r   Úprimary_pathsÚsecondary_pathss      r   rŠ   zDualBlockNode.parsed_paths@  s>   € ð Ÿ™×1Ñ1Ó3ˆØŸ.™.×5Ñ5Ó7ˆÜ×'Ñ'¨°ÔGØÐr!   )NN)Ú N)T)r„   r5   r   N)rH   rI   rJ   rK   r   r    rL   r   r   Úintrj   r\   ro   rO   rr   r   r   Ú
ParserNoder	   r>   Úboolr{   r   r�   rƒ   r   r†   rŠ   rY   rZ   s   @r   r5   r5   ¯   s�  ø„ á=ð= ð =¨õ =ð6 LPØ26ñ	K Cð 	K°X¸dÀ3¹iÑ5Hð 	KØ"*¨3¡-ð	KØ;Jó	Kð PTØ6:ñ	O¨ð 	O¸À$ÀsÁ)Ñ9Lð 	OØ&.¨s¡mð	OØ?Pó	Oð 02Ø48ñ	M¨ð 	MØ$,¨S¡Mð	MØ=Ló	Mð°(¸:×;PÑ;PÑ2Qð Ø.6°z×7LÑ7LÑ.Mðà#'¨¨j×.CÑ.CÀZ×EZÑEZÐ.ZÑ([Ñ#\óñ:
2 ð 
2¨dð 
2¸dÀ?Ñ>Só 
2ñ
2 Cð 
2°$ð 
2À$ÐGXÑBYó 
2ð	L Sð 	L¨T°/Ñ-Bó 	Ló5ð˜s 3™xó ð˜d 3™i÷ r!   r5   N)"rK   Útypingr   r   r   r   r   r   r	   r
   r   r   Úcertbot_apache._internalr   r   r   r   Ú%certbot_apache._internal.apacheparserr   Ú%certbot_apache._internal.augeasparserr   r   r   r   r   rT   rU   rO   r_   r`   r\   rf   rg   r5   rM   r!   r   ú<module>r–      sþ   ðÙ &Ý Ý Ý Ý Ý Ý Ý Ý Ý  Ý å 1Ý /Ý 1Ý /áÝFÝFá!Ð";ÐCUÔVÐ Ù!Ð";ÐCUÔVÐ ÙÐ+°>ÔB€ôG�7Ð2Ð4KÐKÑLô GôT=�l <×#AÑ#AØ#/×#AÑ#Að$Bñ Cô =ô@'=˜ \×%EÑ%EØ%1×%EÑ%Eð&Fñ Gô '=ôT_�L ×!=Ñ!=Ø!-×!=Ñ!=ð">ñ ?õ _r!   