
    $gY&              	          d Z ddlmZ ddlmc mZ ddlmZ ddlZddl	Z	ddl
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Z e
j        d          Z e
j        d	          Z e
j        d
          Z e
j        d          Zej                            d          rdZnej        dk    rdZndZdej        k    Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z' G d d edg d                    Z( G d d e          Z)d$d"Z*d$d#Z+dS )%zW
General utilities.

MIT license.

Copyright (c) 2017 Isaac Muse <isaacmuse@gmail.com>
    )InlineProcessorN)
namedtuple)pathname2urlurl2pathname)urlparsewrapsz
^[A-Za-z]$z^[A-Za-z]:(?:\\.*)?$z!(http|ftp)s?|data|mailto|tel|newsz^///[A-Za-z]:(?:/.*)?$winwindowsdarwinosxlinux)   	   c                      t           dk    S )zIs Windows.r   	_PLATFORM     M/var/www/html/netbox-4.1.3/venv/lib/python3.11/site-packages/pymdownx/util.pyis_winr   #   s     	!!r   c                      t           dk    S )z	Is Linux.r   r   r   r   r   is_linuxr   )   s     r   c                      t           dk    S )z	Is macOS.r   r   r   r   r   is_macr   /   s     r   c                      t          |           S )zPath to URL.)r   )paths    r   url2pathr   5   s     r   c                     t          |           }t                      r1t                              |          r|                    ddd          }|S )zURL to path.z///    )r   r   RE_WIN_DEFAULT_PROTOCOLmatchreplace)urlr   s     r   path2urlr&   ;   sM     Dxx *+11$77 *||E2q))Kr   c                      t          |           S )zGet the Unicode code points.)list)ss    r   get_code_pointsr*   E   s     77Nr   c                      t          |           S )zGet Unicode ord.)ord)cs    r   get_ordr.   K   s     q66Mr   c                      t          |           S )zGet the Unicode char.)chr)values    r   get_charr2   Q   s     u::r   c                     t          j         | j                  }|D ]}||vr|                    |           || _        dS )z
    Add chars to the escape list.

    Don't just append as it modifies the global list permanently.
    Make a copy and extend **that** copy so that only this Markdown
    instance gets modified.
    N)copyESCAPED_CHARSappend)mdechrsescapedecs       r   escape_charsr;   W   sQ     i())G  WNN2Br   c                    d}d}t          t          j        |                     \  }}}}}}t                              |          rd}n:|dk    r|dk    r
|dk    rd}n$|dk    r;t
                              |          r!d||z                       dd          z   }d}d}n|dk    r3|                    d          r||z                       dd          }d}d}n|dk    rd}nt                              |          r1d	                    ||                    dd                    }d}d}d}nV|dk    r*|dk    r$|                     d          rd|z   |z   }d}d}d}n&|dk    r	|dk    rd}n|                    d	          rd}||||||||fS )
a  
    Parse the URL.

    Try to determine if the following is a file path or
    (as we will call anything else) a URL.

    We return it slightly modified and combine the path parts.

    We also assume if we see something like c:/ it is a Windows path.
    We don't bother checking if this **is** a Windows system, but
    'nix users really shouldn't be creating weird names like c: for their folder.
    FTr    file/\z/{}:{}z//)r>   r?   )
r   htmlunescapeRE_URLr#   RE_WIN_DRIVE_PATHr$   
startswithRE_WIN_DRIVE_LETTERformat)	r%   is_urlis_absoluteschemenetlocr   paramsqueryfragments	            r   	parse_urlrN   g   s    FK4<T]3=O=O4P4P1FFD&%||F $	2&B,,42::	6		066v>>	ftm,,T3777	6		f//55	&&tS11	6				"	"6	*	* vt||D#'>'>??	2&B,,3>>$+?+?,f}t#	2&B,,		%	% FD&%6;OOr   c                   $     e Zd ZdZd fd	Z xZS )
PatSeqItemzPattern sequence item item.Fc                 N    t                                          | ||||          S )zCreate object.)super__new__)clspatternbuildertagsfull_recursion	__class__s        r   rS   zPatSeqItem.__new__   s#     wwsGWdNKKKr   )F)__name__
__module____qualname____doc__rS   __classcell__)rY   s   @r   rP   rP      sM        %%L L L L L L L L L Lr   rP   )rU   rV   rW   rX   c                   :    e Zd ZdZg Zd Zd Zd Zd Zd Z	d Z
dS )	PatternSequenceProcessorzMProcessor for handling complex nested patterns such as strong and em matches.c                     t          j        |          }|                    d          }|                     ||d||           |S )zReturn single tag.   N)etreeElementgroupparse_sub_patterns)selfmtagrX   idxel1texts          r   build_singlez%PatternSequenceProcessor.build_single   sA    mC  wwqzzc4EEE
r   c                    |                     d          \  }}t          j        |          }t          j        |          }|                    d          }	|                     |	|d||           |                    |           t          |                                          dk    r.|                    d          }	|                     |	||||           |S )zReturn double tag.,rb   Nr   )splitrc   rd   re   rf   r6   lengroups
rg   rh   rW   rX   rj   tag1tag2rk   el2rl   s
             r   build_doublez%PatternSequenceProcessor.build_double   s     ZZ__
dmD!!mD!!wwqzzc4EEE

3qxxzz??a771::D##D#sNCHHH
r   c                 h   |                     d          \  }}t          j        |          }t          j        |          }|                    d          }	|                     |	|d||           |                    d          }	|                    |           |                     |	|d||           |S )zFReturn double tags (variant 2): `<strong>text <em>text</em></strong>`.ro   rb   Nr   )rp   rc   rd   re   rf   r6   rs   s
             r   build_double2z&PatternSequenceProcessor.build_double2   s     ZZ__
dmD!!mD!!wwqzzc4EEEwwqzz

3c4EEE
r   c                 h   d}d}t          |          }||k     r| j                            ||          rd}	t          | j                  D ]\  }
}|s|
|k    r|j                            ||          }|r|||                    d                   }|r|||_        n||_        | 	                    ||j
        |j        |j        |
          }|                    |           |}|                    d          x}}d}	|	s|dz  }n|dz  }||k     ||d         }|r|	||_        dS ||_        dS dS )a  
        Parses sub patterns.

        `data` (`str`):
            text to evaluate.

        `parent` (`etree.Element`):
            Parent to attach text and sub elements to.

        `last` (`etree.Element`):
            Last appended child to parent. Can also be None if parent has no children.

        `idx` (`int`):
            Current pattern index that was used to evaluate the parent.

        r   FNTr!   )rq   compiled_rer#   	enumeratePATTERNSrU   starttailrl   build_elementrV   rW   rX   r6   end)rg   dataparentlastrX   rj   offsetposlengthmatchedindexitemrh   rl   els                  r   rf   z+PatternSequenceProcessor.parse_sub_patterns   s   $ TFll%%dC00 #,T]#;#; ' 'KE4) !esll **455A '
  $F1771::$56 3#/,0		.2!//4<DL_afggb)))!'(uuQxx/"& 1HC qA FllF FGG} 	# 			"		# 	#r   c                     |dk    r|                      ||||          S |dk    r|                     ||||          S |                     ||||          S )zElement builder.double2double)ry   rw   rm   )rg   rh   rV   rW   rX   r   s         r   r   z&PatternSequenceProcessor.build_element  sh     i%%a~uEEE  $$QneDDD$$QneDDDr   c                 T   d}d}d}t          | j                  D ]\  }}|j                            ||                    d                    }|rT|                    d          }|                    d          }|                     ||j        |j        |j	        |          } n|||fS )zParse patterns.Nr   )
r|   r}   rU   r#   r~   r   r   rV   rW   rX   )	rg   rh   r   r   r~   r   r   r   m1s	            r   handleMatchz$PatternSequenceProcessor.handleMatch  s     $T]33 	 	KE4##D!''!**55B ffQii''DL$)TEXZ_``	
 5#~r   N)rZ   r[   r\   r]   r}   rm   rw   ry   rf   r   r   r   r   r   r`   r`      s}        WWH      ># ># >#@E E E    r   r`   rb   c                       fd}|S )z
    Raise a `DeprecationWarning` when wrapped function/method is called.

    Usage:

        @deprecated("This method will be removed in version X; use Y instead.")
        def some_method()"
            pass
    c                 B     t                      fd            }|S )Nc                  b    t          j        dj         d t                      | i |S )N'z' is deprecated. category
stacklevel)warningswarnrZ   DeprecationWarning)argskwargsfuncmessager   s     r   _deprecated_funcz6deprecated.<locals>._wrapper.<locals>._deprecated_func9  sN    M=DM==G==+%   
 4((((r   r   )r   r   r   r   s   ` r   _wrapperzdeprecated.<locals>._wrapper8  s?    	t	) 	) 	) 	) 	) 	) 
	)  r   r   )r   r   r   s   `` r   
deprecatedr   -  s)    	  	  	  	  	  	  Or   c                 >    t          j        | t          |           dS )zWarn deprecated.r   N)r   r   r   )r   r   s     r   warn_deprecatedr   E  s0     M#     r   )rb   ),r]   markdown.inlinepatternsr   xml.etree.ElementTreerc   ElementTreecollectionsr   sysr4   rer@   urllib.requestr   r   urllib.parser   	functoolsr	   r   compilerE   rC   rB   r"   platformrD   r   version_infoPY39r   r   r   r   r&   r*   r.   r2   r;   rN   rP   r`   r   r   r   r   r   <module>r      s    4 3 3 3 3 3 % % % % % % % % % " " " " " " 



  				  5 5 5 5 5 5 5 5 ! ! ! ! ! !        bj// BJ677 	7	8	8$"*%>?? <5!! II\XIII!!" " "                    8P 8P 8PvL L L L LL*Z*Z*Z[[ L L L       D   0     r   