
    O&i              	       \   d Z ddlZddlmZmZ ddlmZ ddlmZ ddl	m
Z
mZmZ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ZdZn# e$ r dZY nw xY wdZdededee         fdZdedededee         fdZdededefdZdededefdZ  G d de          Z!dddeeef         fdZ"dS )zHImplements the low-level algorithms Sphinx uses for versioning doctrees.    N)productzip_longest)
itemgetter)path)TYPE_CHECKINGAnyDictIterator)uuid4)Node)SphinxTransform)SphinxTFA   doctree	conditionreturnc              #   r   K   |                      |          D ]}t                      j        |_        |V  dS )a  Add a unique id to every node in the `doctree` which matches the
    condition and yield the nodes.

    :param doctree:
        A :class:`docutils.nodes.document` instance.

    :param condition:
        A callable which returns either ``True`` or ``False`` for a given node.
    N)findallr   hexuid)r   r   nodes      ^/home/geonatureadmin/si_en_reseau/tutos/venv/lib/python3.11/site-packages/sphinx/versioning.pyadd_uidsr      sE       	**  77;



     oldnewc              #     K   |                      |          }|                     |          }g }g }i }t                      }t          ||          D ]\  }	}
|	|                    |
           t	          |	dd          st                      j        |	_        |
|                    |	           ^t          |	j	        |
j	                  }|dk    r"|	j        |
_        |
                    |
           |||	|
f<   |                    |	           |                    |
           t          ||          D ]Y\  }	}
|
|v s|	|
f|v rt          |	j	        |
j	                  }|dk    r"|	j        |
_        |
                    |
           R|||	|
f<   Zt          |                                t          d                    }|D ]V\  \  }	}
}|
|v r|
                    |
           |t          k     r|	j        |
_        :t                      j        |
_        |
V  Wt          |          |z
  D ]}
t                      j        |
_        |
V  dS )a1  Merge the `old` doctree with the `new` one while looking at nodes
    matching the `condition`.

    Each node which replaces another one or has been added to the `new` doctree
    will be yielded.

    :param condition:
        A callable which returns either ``True`` or ``False`` for a given node.
    Nr   r      )key)r   setr   appendgetattrr   r   r   	get_ratio	rawsourceaddr   sorteditemsr   VERSIONING_RATIO)r   r   r   old_iternew_iter	old_nodes	new_nodesratiosseenold_nodenew_noderatios               r   merge_doctreesr2   )   s      {{9%%H{{9%%HIIF55D)(H== ' '(X&&&x-- 	' 77;HLX&&&(,h.@AAA::#<HLHHX).F8X%&X&&&X&&&& &i;; / /(t(3v==(,h.@AAA::#<HLHHX).F8X%&& FLLNN
1666F'- 	 	#8etHHX####<HLL 77;HLNNNN 	NNT)  ww{ r   c                     t          | |g          st          S t          r(t          j        | |          t          |           dz  z  S t          | |          t          |           dz  z  S )zReturn a "similarity ratio" (in percent) representing the similarity
    between the two strings where 0 is equal and anything above less than equal.
    g      Y@)allr(   
IS_SPEEDUPLevenshteindistancelenlevenshtein_distance)r   r   s     r   r#   r#   l   sh     Sz??   C#C--SE1ABB#C--SE1ABBr   abc           	         | |k    rdS t          |           t          |          k     r|| }} | st          |          S t          t          t          |          dz                       }t          |           D ]n\  }}|dz   g}t          |          D ]Q\  }}||dz            dz   }||         dz   }	||         ||k    z   }
|                    t          ||	|
                     R|}o|d         S )zEReturn the Levenshtein edit distance between two strings *a* and *b*.r   r   )r8   listrange	enumerater!   min)r:   r;   previous_rowicolumn1current_rowjcolumn2
insertions	deletionssubstitutionss              r   r9   r9   y   s   Avvq
1vvA!1 1vvc!ffqj))**Lll # #
71ug#A,, 	J 	JJAw%a!e,q0J#A*I(Ow'/ABMs:y-HHIIII"r   c                   &    e Zd ZdZdZdeddfdZdS )UIDTransformz#Add UIDs to doctree for versioning.ip  kwargsr   Nc                    | j         }d }|j        sd S |j        rp	 t          j        |j        |j        dz             }t          |d          5 }t          j	        |          }d d d            n# 1 swxY w Y   n# t          $ r Y nw xY w|j        r|)t          t          | j        |j                             d S t          t          || j        |j                             d S )Nz.doctreerb)envversioning_conditionversioning_comparer   join
doctreedirdocnameopenpickleloadOSErrorr>   r   documentr2   )selfrM   rP   old_doctreefilenamefs         r   applyzUIDTransform.apply   s3   h' 	F! 	9S^S[:5MNN(D)) 1Q"(+a..K1 1 1 1 1 1 1 1 1 1 1 1 1 1 1    % 	W)<$-)ABBCCCCCT]C<TUUVVVVVs5   2A: A."A: .A22A: 5A26A: :
BB)__name__
__module____qualname____doc__default_priorityr   r_    r   r   rL   rL      sJ        --Wc Wd W W W W W Wr   rL   appr   c                 B    |                      t                     ddddS )NbuiltinT)versionparallel_read_safeparallel_write_safe)add_transformrL   )rf   s    r   setuprm      s0    l### "#  r   )#rc   rW   	itertoolsr   r   operatorr   osr   typingr   r   r	   r
   uuidr   docutils.nodesr   sphinx.transformsr   sphinx.applicationr   r6   r5   ImportErrorr(   r   r2   strfloatr#   intr9   rL   rm   re   r   r   <module>rz      s1   N N  * * * * * * * *             5 5 5 5 5 5 5 5 5 5 5 5             - - - - - - *))))))JJ   JJJ  d s x~    @ @4 @C @HTN @ @ @ @F
C3 
CS 
CU 
C 
C 
C 
CC C C    (W W W W W? W W W4x DcN      s   A	 	AA