
    !Sh                    X   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mZ dd
lmZ ddlZddlmc mZ erddlmZ ddlmZ  G d de          Z G d de
          Z G d de          Z  ed          e          Z ed           G d de                      Zd ZdS )z
This extension adds abbreviation handling to Python-Markdown.

See the [documentation](https://Python-Markdown.github.io/extensions/abbreviations)
for details.
    )annotations   )	Extension   )BlockProcessor)InlineProcessor)Treeprocessor)AtomicString
deprecated)TYPE_CHECKINGN)Markdown)BlockParserc                  <     e Zd ZdZ fdZd Zd Zd	dZd Z xZ	S )
AbbrExtensionz- Abbreviation Extension for Python-Markdown. c                n    di dgi| _         	  t                      j        di | i | _        i | _        dS )z( Initiate Extension and set up configs. glossaryz`A dictionary where the `key` is the abbreviation and the `value` is the definition.Default: `{}`N )configsuper__init__abbrsr   )selfkwargs	__class__s     ^/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/markdown/extensions/abbr.pyr   zAbbrExtension.__init__*   sR      
 	/""6"""
    c                    | j                                          | j        r!| j                             | j                   dS dS )z- Clear all previously defined abbreviations. N)r   clearr   updater   s    r   resetzAbbrExtension.reset8   sH    
M 	-Jdm,,,,,	- 	-r   c                8    | j                                          dS )z, Clear all abbreviations from the glossary. N)r   r   r    s    r   reset_glossaryzAbbrExtension.reset_glossary>   s    r   
dictionarydict[str, str]c                .    |ri || j         | _         dS dS )z\Adds `dictionary` to our glossary. Any abbreviations that already exist will be overwritten.N)r   )r   r$   s     r   load_glossaryzAbbrExtension.load_glossaryB   s+     	<;z;T];DMMM	< 	<r   c                   | j         d         d         r&|                     | j         d         d                    | j                            | j                   |                    |            |j                            t          || j                  dd           |j	        j
                            t          |j	        | j                  dd           dS )z6 Insert `AbbrTreeprocessor` and `AbbrBlockprocessor`. r   r   abbr      N)r   r'   r   r   r   registerExtensiontreeprocessorsregisterAbbrTreeprocessorparserblockprocessorsAbbrBlockprocessor)r   mds     r   extendMarkdownzAbbrExtension.extendMarkdownG   s    K
#A& 	;t{:6q9:::
$-(((
T"""
""#4R#D#DfaPPP
	!**+=bi+T+TV\^`aaaaar   )r$   r%   )
__name__
__module____qualname____doc__r   r!   r#   r'   r4   __classcell__r   s   @r   r   r   '   s        77    - - -  < < < <
b b b b b b br   r   c                  @     e Zd ZdZdd fdZddZdddZddZ xZS )r/   z3 Replace abbreviation text with `<abbr>` elements. Nr3   Markdown | Noner   dict | Nonec                n    ||ni | _         d | _        t                                          |           d S N)r   REr   r   )r   r3   r   r   s      r   r   zAbbrTreeprocessor.__init__T   s8    $)$5552
)-r   titlestrtexttailreturnetree.Elementc                j    t          j        dd|i          }t          |          |_        ||_        |S )z Create an `abbr` element. r)   rA   )etreeElementr
   rC   rD   )r   rA   rC   rD   r)   s        r   create_elementz AbbrTreeprocessor.create_elementY   s3    }Vgu%566 &&		r   elparentetree.Element | NoneNonec                   t          |          D ]}|                     ||           |j        x}rt          |t                    st          t          | j                            |                              D ]}| j        |	                    d                   r| 
                    | j        |	                    d                   |	                    d          ||                                d                   }|                    d|           |d|                                         }||_        ||j        r|j        }t          |                              |          dz   }t          |t                    st          t          | j                            |                              D ]}| 
                    | j        |	                    d                   |	                    d          ||                                d                   }|                    ||           |d|                                         }||_        dS dS dS dS )zW Recursively iterate over elements, run regex on text and wrap matches in `abbr` tags. r   Nr   )reversediter_elementrC   
isinstancer
   listr@   finditerr   grouprJ   endinsertstartrD   index)	r   rK   rL   childrC   mr)   rD   rY   s	            r   rQ   zAbbrTreeprocessor.iter_element`   s#   b\\ 	) 	)EeR((((7?4 	dL11 !$tw'7'7'='=">">?? 0 0Az!''!**- 0#224:aggajj3I177ST::W[\]\a\a\c\c\d\dWeff		!T***#JQWWYYJ/"'7DLL&&r**Q.EdL11 !$tw'7'7'='=">">?? , ,A..tz!''!**/EqwwqzzSWXYX]X]X_X_X`X`SabbDMM%...

+DD  r   rootc                :   | j         sdS t          | j                                                   }|                    t          d           t          j        dd                    d |D                        d          | _        | 	                    |           dS )z0 Step through tree to find known abbreviations. NT)keyreversez\b(?:|c              3  >   K   | ]}t          j        |          V  d S r?   )reescape).0r^   s     r   	<genexpr>z(AbbrTreeprocessor.run.<locals>.<genexpr>~   s*      /T/T3	#/T/T/T/T/T/Tr   z)\b)
r   rS   keyssortlenrb   compilejoinr@   rQ   )r   r\   	abbr_lists      r   runzAbbrTreeprocessor.runv   s    z 	F**++	3---*[sxx/T/T)/T/T/T'T'T[[[\\$r   )NN)r3   r<   r   r=   )rA   rB   rC   rB   rD   rB   rE   rF   r?   )rK   rF   rL   rM   rE   rN   )r\   rF   rE   rM   )	r5   r6   r7   r8   r   rJ   rQ   rl   r9   r:   s   @r   r/   r/   Q   s        ==      
       ,
  
  
  
  
  
  
  
 r   r/   c                  `     e Zd ZdZ ej        dej                  Zd fdZddZ	ddZ
 xZS )r2   z) Parse text for abbreviation references. z7^[*]\[(?P<abbr>[^\\]*?)\][ ]?:[ ]*\n?[ ]*(?P<title>.*)$r0   r   r   dictc                X    || _         t                                          |           d S r?   )r   r   r   )r   r0   r   r   s      r   r   zAbbrBlockprocessor.__init__   s(     
     r   rL   rF   blockrB   rE   boolc                    dS )NTr   )r   rL   rp   s      r   testzAbbrBlockprocessor.test   s    tr   blocks	list[str]c                h   |                     d          }| j                            |          }|ri|                    d                                          }|                    d                                          }|r|r|dk    s|dk    r| j                             |           n
|| j        |<   ||                                d                                         rC|                    d||                                d                             d                     |d|	                                                                         rC|                    d|d|	                                         
                    d                     dS |                    d|           d	S )
z
        Find and remove all abbreviation references from the text.
        Each reference is added to the abbreviation collection.

        r   r)   rA   z''z""N
TF)popr@   searchrU   stripr   rV   rW   lstriprX   rstrip)r   rL   rt   rp   r[   r)   rA   s          r   rl   zAbbrBlockprocessor.run   sw    

1GNN5!! 	776??((**DGGG$$**,,E  D==ETMMJNN4((((',DJt$?((** CMM!U1557788_%;%;D%A%ABBB!''))$**,, EMM!U:AGGII:%6%=%=d%C%CDDDtaur   )r0   r   r   rn   )rL   rF   rp   rB   rE   rq   )rL   rF   rt   ru   rE   rq   )r5   r6   r7   r8   rb   ri   	MULTILINEr@   r   rs   rl   r9   r:   s   @r   r2   r2      s        33	NPRP\	]	]B! ! ! ! ! !          r   r2   z4This class has been renamed to `AbbrBlockprocessor`.zJThis class will be removed in the future; use `AbbrTreeprocessor` instead.c                  ,     e Zd ZdZd fdZddZ xZS )AbbrInlineProcessorz Abbreviation inline pattern. patternrB   rA   c                X    t                                          |           || _        d S r?   )r   r   rA   )r   r   rA   r   s      r   r   zAbbrInlineProcessor.__init__   s&    !!!


r   r[   re.Match[str]datarE   tuple[etree.Element, int, int]c                   t          j        d          }t          |                    d                    |_        |                    d| j                   ||                    d          |                    d          fS )Nr)   rA   r   )	rH   rI   r
   rU   rC   setrA   rX   rV   )r   r[   r   r)   s       r   handleMatchzAbbrInlineProcessor.handleMatch   sa    }V$$ 11	$*%%%QWWQZZq))r   )r   rB   rA   rB   )r[   r   r   rB   rE   r   )r5   r6   r7   r8   r   r   r9   r:   s   @r   r   r      sW        ((     * * * * * * * *r   r   c                     t          di | S )Nr   )r   )r   s    r   makeExtensionr      s    ""6"""r   )r8   
__future__r    r   r1   r   inlinepatternsr   r-   r	   utilr
   r   typingr   rb   xml.etree.ElementTreerH   ElementTreer   blockparserr   r   r/   r2   AbbrPreprocessorr   r   r   r   r   <module>r      s     # " " " " "       , , , , , , , , , , , , * * * * * * + + + + + + + +             				 % % % % % % % % % *))))))'b 'b 'b 'b 'bI 'b 'b 'bT/  /  /  /  /  /  /  / d% % % % % % % %P V::TUUVhii  XYY* * * * */ * * ZY*# # # # #r   