o
    þÞhÏ   ã                   @   sn  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 zddlZddlZddlZddlZW n eyG   d	ZY nw d
Zdd„ Zdd„ Zd0dd„ZddddddœZe dej¡Zdd„ Zdd„ Z	d1dd„Zer�ejj j! "de¡ e #¡ D ]	\Z$Z%ee$e%ƒ qƒedƒZ&ed ƒZ'ed!ƒZ(d"d#„ Z)d$d%„ Z*d&d'„ Z+d(d)„ Z,d*d+„ Z-d,d-„ Z.d.d/„ Z/dS )2zBMisc. utility functions/classes for admin documentation generator.é    N)ÚHeaderParseError)ÚHeaderParser)Úcleandoc)Úreverse)Ú_lazy_re_compile)Ú	mark_safeFTc                 C   sD   t | dƒr| j}|j› d|j› �S | j}t| d| jjƒ}|d | S )NÚ
view_classÚ.Ú__qualname__)Úhasattrr   Ú
__module__r
   ÚgetattrÚ	__class__Ú__name__)Ú	view_funcÚklassÚmod_nameÚ	view_name© r   ú^/var/www/html/premium_crap/venv/lib/python3.10/site-packages/django/contrib/admindocs/utils.pyÚget_view_name   s   
r   c                 C   sÂ   | sddi fS t | ƒ} t d| ¡}|d }t|ƒdkr d}i }n<tƒ }z	| |d ¡}W n ty@   i }d |dd… ¡}Y nw t| 	¡ ƒ}|rSd |dd… ¡}n	d |dd… ¡}|||fS )zN
    Parse out the parts of a docstring.  Return (title, body, metadata).
    Ú z\n{2,}r   é   éÿÿÿÿz

N)
r   ÚreÚsplitÚlenr   Úparsestrr   ÚjoinÚdictÚitems)Ú	docstringÚpartsÚtitleÚbodyÚmetadataÚparserr   r   r   Úparse_docstring    s(   
þ
r'   c                 C   s`   dd|t dƒ d¡dddœ}|od| }d}tj d	¡ƒ }tjj||  |d
||d�}t|d ƒS )z<
    Convert the string from reST to an XHTML fragment.
    Té   zdjango-admindocs-docrootú/F)Údoctitle_xformÚinitial_header_levelÚdefault_reference_contextÚ	link_baseÚraw_enabledÚfile_insertion_enabledz<%s>z7
.. default-role:: cmsreference

%s

.. default-role::
ÚhtmlN)Úsource_pathÚdestination_pathÚwriterÚsettings_overridesÚfragment)r   ÚrstripÚdocutilsÚwritersÚget_writer_classÚcoreÚpublish_partsr   )Útextr,   Úthing_being_parsedÚ	overridesÚsourceÚwriter_instancer"   r   r   r   Ú	parse_rst<   s$   ú	ûrA   z%s/models/%s/z%s/views/%s/z%s/templates/%s/z%s/filters/#%sz%s/tags/#%s)ÚmodelÚviewÚtemplateÚfilterÚtagz^(.+?)\s*(?<!\x00)<([^<]*?)>$c                 C   s.   t  | ¡}|rd| d¡| d¡fS d| | fS )zÂ
    Split role content into title and target, if given.

    From sphinx.util.nodes.split_explicit_title
    See https://github.com/sphinx-doc/sphinx/blob/230ccf2/sphinx/util/nodes.py#L389
    Tr   é   F)Úexplicit_title_reÚmatchÚgroup)r<   rI   r   r   r   Úsplit_explicit_titlem   s   

rK   c                    s.   | dv ‰ d‡ ‡fdd„	}t jjj | |¡ d S )N)rD   rC   c                    sX   |d u ri }t |ƒ\}}}	tjj||fdˆ|jjjˆ r|	n|	 ¡ f i|¤Ž}
|
gg fS ©NÚrefuri)rK   r7   ÚnodesÚ	referenceÚdocumentÚsettingsr-   Úlower)ÚnameÚrawtextr<   ÚlinenoÚinlinerÚoptionsÚcontentÚ_r#   ÚtargetÚnode©Úis_case_sensitiveÚurlbaser   r   Ú_role~   s    þþÿü
ö
z$create_reference_role.<locals>._role©NN)r7   ÚparsersÚrstÚrolesÚregister_canonical_role)Úrolenamer^   r_   r   r\   r   Úcreate_reference_rolez   s   rf   c           	      C   sP   |d u ri }|j jj}tjj||fdt| |j jj| ¡ f i|¤Ž}|gg fS rL   )	rP   rQ   r,   r7   rN   rO   ÚROLESr-   rR   )	rS   rT   r<   rU   rV   rW   rX   Úcontextr[   r   r   r   Údefault_reference_role“   s    
þþÿü
ö
ri   Úcmsreferencez\(\?P(<\w+>)z\(z\(\?\:c                 C   s   t  ddd„ | ¡S )z1Remove unescaped metacharacters from the pattern.z/((?:^|(?<!\\))(?:\\\\)*)(\\?)([?*+^$]|\\[bBAZ])c                 S   s    | d r| d | d  S | d S )NrG   r   r(   r   )Úmr   r   r   Ú<lambda>º   s     z(replace_metacharacters.<locals>.<lambda>)r   Úsub©Úpatternr   r   r   Úreplace_metacharacters¶   s
   ýrp   c                 C   sx   d\}}t ||d … ƒD ]-\}}|dkr|dkr|d7 }n|dkr)|dkr)|d8 }|}|dkr9| || d f  S qd S )N)r   Nú(ú\r   ú)r   )Ú	enumerate)ÚstartÚendro   Úunmatched_open_bracketsÚ	prev_charÚidxÚvalr   r   r   Ú_get_group_start_end¿   s   
ÿör{   c                 c   s^   � d }|  | ¡D ]$}t| d¡| d¡| ƒ }r,|\}}|r"||ks$|s*|||fV  |}qd S )Nr   )Úfinditerr{   ru   rv   )ro   Úgroup_matcherÚprev_endrI   Úindicesru   rv   r   r   r   Ú_find_groupsÐ   s   €€ûr€   c                    s6   ‡ fdd„t ˆ tƒD ƒ}|D ]
\}}ˆ  ||¡‰ qˆ S )a  
    Find named groups in `pattern` and replace them with the group name. E.g.,
    1. ^(?P<a>\w+)/b/(\w+)$ ==> ^<a>/b/(\w+)$
    2. ^(?P<a>\w+)/b/(?P<c>\w+)/$ ==> ^<a>/b/<c>/$
    3. ^(?P<a>\w+)/b/(\w+) ==> ^<a>/b/(\w+)
    4. ^(?P<a>\w+)/b/(?P<c>\w+) ==> ^<a>/b/<c>
    c                    s&   g | ]\}}}ˆ ||… |d  f‘qS )r   r   )Ú.0ru   rv   rI   rn   r   r   Ú
<listcomp>â   s    ÿÿz(replace_named_groups.<locals>.<listcomp>)r€   Únamed_group_matcherÚreplace)ro   Úgroup_pattern_and_nameÚgroup_patternÚ
group_namer   rn   r   Úreplace_named_groupsÚ   s   
þrˆ   c                 C   sZ   d\}}t | tƒD ]\}}}|r|| ||… 7 }|| d|… d 7 }|}q	|| |d…  S )a)  
    Find unnamed groups in `pattern` and replace them with '<var>'. E.g.,
    1. ^(?P<a>\w+)/b/(\w+)$ ==> ^(?P<a>\w+)/b/<var>$
    2. ^(?P<a>\w+)/b/((x|y)\w+)$ ==> ^(?P<a>\w+)/b/<var>$
    3. ^(?P<a>\w+)/b/(\w+) ==> ^(?P<a>\w+)/b/<var>
    4. ^(?P<a>\w+)/b/((x|y)\w+) ==> ^(?P<a>\w+)/b/<var>
    ©r   NNz<var>)r€   Úunnamed_group_matcher)ro   Úfinal_patternr~   ru   rv   rY   r   r   r   Úreplace_unnamed_groupsë   s   rŒ   c                 C   sF   t | tƒ}d\}}|D ]\}}}|| ||… 7 }|}q|| |d…  S )zÇ
    Find non-capturing groups in the given `pattern` and remove them, e.g.
    1. (?P<a>\w+)/b/(?:\w+)c(?:\w+) => (?P<a>\\w+)/b/c
    2. ^(?:\w+(?:\w+))a => ^a
    3. ^a(?:\w+)/b(?:\w+) => ^a/b
    r‰   N)r€   Únon_capturing_group_matcher)ro   Úgroup_start_end_indicesr‹   r~   ru   rv   rY   r   r   r   Úremove_non_capturing_groupsü   s   
r�   c                 C   s   t |  dd¡ dd¡ƒS )Nz<p>r   z</p>)r   r„   )Úvaluer   r   r   Ústrip_p_tags  s   r‘   )Nr`   )0Ú__doc__r   Úemail.errorsr   Úemail.parserr   Úinspectr   Údjango.urlsr   Údjango.utils.regex_helperr   Údjango.utils.safestringr   Údocutils.corer7   Údocutils.nodesÚdocutils.parsers.rst.rolesÚdocutils.writersÚImportErrorÚdocutils_is_availabler   r'   rA   rg   ÚcompileÚDOTALLrH   rK   rf   ri   ra   rb   rc   rd   r    rS   r^   rƒ   rŠ   r�   rp   r{   r€   rˆ   rŒ   r�   r‘   r   r   r   r   Ú<module>   s^    ÿ	
'û
ÿ
ÿ	
