
    >Tf                     L    d dl Z d dlZd dlmZ ddlmZmZ dZd Zdd	Z	ddZ
dS )    N)escape   )HTML_ALLOWED_ATTRIBUTESHTML_ALLOWED_TAGS)
clean_htmlforeground_color	highlightc                 `    t          j        | t          t          t	          |                    S )z{
    Sanitizes HTML based on a whitelist of allowed tags and attributes.
    Also takes a list of allowed URI schemes.
    )tags
attributesurl_schemes)nh3cleanr   r   set)htmlschemess     3/var/www/html/netbox-4.1.3/netbox/utilities/html.pyr   r      s/    
 9*LL	       000000ffffffc                      d}                      d            fddD             \  }}}|dz  |dz  z   |dz  z   |k    r|S |S )z
    Return the ideal foreground color (dark or light) for a given background color in hexadecimal RGB format.

    :param dark: RBG color code for dark text
    :param light: RBG color code for light text
       #c                 F    g | ]}t          ||d z            d          S )      )int).0cbg_colors     r   
<listcomp>z$foreground_color.<locals>.<listcomp>%   s0    ===as8Aa!eG$b))===r   )r   r      gA`"?gbX9?gv/?)strip)r    darklight	THRESHOLDrgbs   `      r   r   r      se     I~~c""H====9===GAq!5y1u9q5y(944r   ...c                 (   	 t          |          t          j        u r|                    | d          \  }}}n>t          j        |          }t          j        d| d| dt          j                  \  }}}n&# t          $ r}t	          |           cY d}~S d}~ww xY w|r!t          |          |k    r||| d         z   }|r t          |          |k    r|d|         |z   }t	          |           dt	          |           dt	          |           S )	a  
    Highlight a string within a string and optionally trim the pre/post portions of the original string.

    Args:
        value: The body of text being searched against
        highlight: The string of compiled regex pattern to highlight in `value`
        trim_pre: Maximum length of pre-highlight text to include
        trim_post: Maximum length of post-highlight text to include
        trim_placeholder: String value to swap in for trimmed pre/post text
    r   )maxsplit())r,   flagsNz<mark>z</mark>)typerePatternsplitr   
IGNORECASE
ValueErrorlen)	valuer	   trim_pre	trim_posttrim_placeholderprematchpostes	            r   r	   r	   ,   s9   	??bj(((uqAAC	),,I!x(9Y(9(9(951TVTabbbC   e}}
  1CHHx''hYZZ0 3SYY**JYJ"22SkkEEEEvd||EEEs   A5A8 8
BBBB)r   r   )NNr*   )r1   r   django.utils.htmlr   	constantsr   r   __all__r   r   r	    r   r   <module>rC      s    				 



 $ $ $ $ $ $ A A A A A A A A
 
 
    F F F F F Fr   