o
    Ñ­j>'  ã                   @   s6  d Z ddlZddlmZ e d¡Ze dejejB ejB ¡Z	e dej
ejB ejB ¡Ze dej¡ZG dd	„ d	eƒZG d
d„ deƒZd2dd„Zd3dd„Zd3dd„Zd3dd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zi Zdd „ Zd!d"„ Zd4d#d$„Zd5d&d'„ZG d(d)„ d)ƒZ d*d+„ Z!d,d-„ Z"d.d/„ Z#G d0d1„ d1eƒZ$dS )6z´
    pygments.util
    ~~~~~~~~~~~~~

    Utility functions.

    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
é    N)ÚTextIOWrapperz[/\\ ]z”
    <!DOCTYPE\s+(
     [a-zA-Z_][a-zA-Z0-9]*
     (?: \s+      # optional in HTML5
     [a-zA-Z_][a-zA-Z0-9]*\s+
     "[^"]*")?
     )
     [^>]*>
z<(.+?)(\s.*?)?>.*?</.+?>z\s*<\?xml[^>]*\?>c                   @   ó   e Zd ZdZdS )ÚClassNotFoundzCRaised if one of the lookup functions didn't find a matching class.N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r
   r
   úJ/var/www/html/CropPilot/venv/lib/python3.10/site-packages/pygments/util.pyr      ó    r   c                   @   r   )ÚOptionErrorzƒ
    This exception will be raised by all option processing functions if
    the type or value of the argument is not correct.
    Nr   r
   r
   r
   r   r   "   r   r   Fc              	   C   s@   |   ||¡}|r| ¡ }||vrtd |d tt|ƒ¡¡ƒ‚|S )z}
    If the key `optname` from the dictionary is not in the sequence
    `allowed`, raise an error, otherwise return it.
    z%Value for option {} must be one of {}z, )ÚgetÚlowerr   ÚformatÚjoinÚmapÚstr)ÚoptionsÚoptnameÚallowedÚdefaultÚnormcaseÚstringr
   r
   r   Úget_choice_opt(   s   r   c                 C   s‚   |   ||¡}t|tƒr|S t|tƒrt|ƒS t|tƒs&td|›d|› d�ƒ‚| ¡ dv r.dS | ¡ dv r6dS td|›d|› d�ƒ‚)	a@  
    Intuitively, this is `options.get(optname, default)`, but restricted to
    Boolean value. The Booleans can be represented as string, in order to accept
    Boolean value from the command line arguments. If the key `optname` is
    present in the dictionary `options` and is not associated with a Boolean,
    raise an `OptionError`. If it is absent, `default` is returned instead.

    The valid string values for ``True`` are ``1``, ``yes``, ``true`` and
    ``on``, the ones for ``False`` are ``0``, ``no``, ``false`` and ``off``
    (matched case-insensitively).
    úInvalid type ú for option z%; use 1/0, yes/no, true/false, on/off)Ú1ÚyesÚtrueÚonT)Ú0ÚnoÚfalseÚoffFúInvalid value )r   Ú
isinstanceÚboolÚintr   r   r   ©r   r   r   r   r
   r
   r   Úget_bool_opt5   s   


r*   c              	   C   s^   |   ||¡}zt|ƒW S  ty   td|›d|› d�ƒ‚ ty.   td|›d|› d�ƒ‚w )z?As :func:`get_bool_opt`, but interpret the value as an integer.r   r   z ; you must give an integer valuer%   )r   r(   Ú	TypeErrorr   Ú
ValueErrorr)   r
   r
   r   Úget_int_optR   s   
ÿr-   c                 C   sJ   |   ||¡}t|tƒr| ¡ S t|ttfƒrt|ƒS td|›d|› d�ƒ‚)zµ
    If the key `optname` from the dictionary `options` is a string,
    split it at whitespace and return it. If it is already a list
    or a tuple, it is returned as a list.
    r   r   z; you must give a list value)r   r&   r   ÚsplitÚlistÚtupler   )r   r   r   Úvalr
   r
   r   Úget_list_opt^   s   
r2   c                 C   sL   | j sdS g }| j  ¡  ¡ D ]}| ¡ r| d| ¡  ¡ q d |¡ ¡ S )NÚ ú )r	   ÚstripÚ
splitlinesÚappendr   Úlstrip)ÚobjÚresÚliner
   r
   r   Údocstring_headlinen   s   r<   c                    s   ‡ fdd„}ˆ j |_ t|ƒS )zAReturn a static text analyser function that returns float values.c              	      sZ   zˆ | ƒ}W n
 t y   Y dS w |sdS ztdtdt|ƒƒƒW S  ttfy,   Y dS w )Ng        g      ð?)Ú	ExceptionÚminÚmaxÚfloatr,   r+   )ÚtextÚrv©Úfr
   r   Útext_analyse|   s   ÿÿz%make_analysator.<locals>.text_analyse)r	   Ústaticmethod)rD   rE   r
   rC   r   Úmake_analysatorz   s   rG   c                 C   s    |   d¡}|dkr| d|…  ¡ }n|  ¡ }| d¡rNzdd„ t |dd…  ¡ ¡D ƒd }W n
 ty9   Y d	S w t d
|› d�tj	¡}| 
|¡durNdS d	S )aò  Check if the given regular expression matches the last part of the
    shebang if one exists.

        >>> from pygments.util import shebang_matches
        >>> shebang_matches('#!/usr/bin/env python', r'python(2\.\d)?')
        True
        >>> shebang_matches('#!/usr/bin/python2.4', r'python(2\.\d)?')
        True
        >>> shebang_matches('#!/usr/bin/python-ruby', r'python(2\.\d)?')
        False
        >>> shebang_matches('#!/usr/bin/python/ruby', r'python(2\.\d)?')
        False
        >>> shebang_matches('#!/usr/bin/startsomethingwith python',
        ...                 r'python(2\.\d)?')
        True

    It also checks for common windows executable file extensions::

        >>> shebang_matches('#!C:\\Python2.4\\Python.exe', r'python(2\.\d)?')
        True

    Parameters (``'-f'`` or ``'--foo'`` are ignored so ``'perl'`` does
    the same as ``'perl -e'``)

    Note that this method automatically searches the whole string (eg:
    the regular expression is wrapped in ``'^$'``)
    Ú
r   Nz#!c                 S   s   g | ]}|r|  d ¡s|‘qS )ú-)Ú
startswith)Ú.0Úxr
   r
   r   Ú
<listcomp>®   s
    ÿ
ÿz#shebang_matches.<locals>.<listcomp>é   éÿÿÿÿFú^z(\.(exe|cmd|bat|bin))?$T)Úfindr   rJ   Úsplit_path_rer.   r5   Ú
IndexErrorÚreÚcompileÚ
IGNORECASEÚsearch)rA   ÚregexÚindexÚ
first_lineÚfoundr
   r
   r   Úshebang_matches‹   s    

ÿÿr\   c                 C   s<   t  | ¡}|du rdS | d¡}t |tj¡ | ¡ ¡duS )zÁCheck if the doctype matches a regular expression (if present).

    Note that this method only checks the first part of a DOCTYPE.
    eg: 'html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
    NFé   )Údoctype_lookup_rerW   ÚgrouprT   rU   ÚIÚmatchr5   )rA   rX   ÚmÚdoctyper
   r
   r   Údoctype_matches¸   s
   

rd   c                 C   s
   t | dƒS )z3Check if the file looks like it has a html doctype.Úhtml)rd   )rA   r
   r
   r   Úhtml_doctype_matchesÅ   s   
rf   c                 C   sn   t  | ¡rdS t| ƒ}zt| W S  ty6   t | ¡}|dur#Y dS t | dd… ¡du}|t|< | Y S w )z2Check if a doctype exists or if we have some tags.TNiè  )Úxml_decl_rera   ÚhashÚ_looks_like_xml_cacheÚKeyErrorr^   rW   Útag_re)rA   Úkeyrb   rB   r
   r
   r   Úlooks_like_xmlÍ   s   


úrm   c                 C   s   d| d?  d| d@  fS )zoGiven a unicode character code with length greater than 16 bits,
    return the two 16 bit surrogate pair.
    iÀ×  é
   i Ü  iÿ  r
   )Úcr
   r
   r   ÚsurrogatepairÝ   s   rp   c           	      C   s¤   g }d| d }d|d  d }|  ||  d ¡ |r*|D ]}|  || d ¡ qn|D ]}t|d ƒ}|  ||dd…  |d	  d ¡ q,|  |d
 ¡ d |¡S )z)Formats a sequence of strings for output.r4   é   r]   z = (ú,ú"NéþÿÿÿrO   ú)rH   )r7   Úreprr   )	Úvar_nameÚseqÚrawÚindent_levelÚlinesÚbase_indentÚinner_indentÚiÚrr
   r
   r   Úformat_linesæ   s   ÿ$
r€   r
   c                 C   s>   g }t ƒ }| D ]}||v s||v rq| |¡ | |¡ q|S )za
    Returns a list with duplicates removed from the iterable `it`.

    Order is preserved.
    )Úsetr7   Úadd)ÚitÚalready_seenÚlstÚseenr~   r
   r
   r   Úduplicates_removedù   s   
r‡   c                   @   s   e Zd ZdZdd„ ZdS )ÚFuturez‡Generic class to defer some work.

    Handled specially in RegexLexerMeta, to support regex string construction at
    first use.
    c                 C   s   t ‚©N)ÚNotImplementedError©Úselfr
   r
   r   r     s   z
Future.getN)r   r   r   r	   r   r
   r
   r
   r   rˆ   	  s    rˆ   c                 C   sz   z
|   d¡} | dfW S  ty<   zddl}| ¡ }|   |¡} | |fW  Y S  ttfy;   |   d¡} | df Y  Y S w w )zÃDecode *text* with guessed encoding.

    First try UTF-8; this should fail for non-UTF-8 encodings.
    Then try the preferred locale encoding.
    Fall back to latin-1, which always works.
    zutf-8r   NÚlatin1)ÚdecodeÚUnicodeDecodeErrorÚlocaleÚgetpreferredencodingÚLookupError)rA   r�   Úprefencodingr
   r
   r   Úguess_decode  s   



þúr”   c                 C   sH   t |ddƒr z|  |j¡} W n ty   Y t| ƒS w | |jfS t| ƒS )zÊDecode *text* coming from terminal *term*.

    First try the terminal encoding, if given.
    Then try UTF-8.  Then try the preferred locale encoding.
    Fall back to latin-1, which always works.
    ÚencodingN)ÚgetattrrŽ   r•   r�   r”   )rA   Útermr
   r
   r   Úguess_decode_from_terminal(  s   ü
r˜   c                 C   s"   t | ddƒr	| jS ddl}| ¡ S )z7Return our best guess of encoding for the given *term*.r•   Nr   )r–   r•   r�   r‘   )r—   r�   r
   r
   r   Úterminal_encoding9  s   r™   c                   @   s   e Zd Zdd„ ZdS )ÚUnclosingTextIOWrapperc                 C   s   |   ¡  d S r‰   )Úflushr‹   r
   r
   r   ÚcloseC  s   zUnclosingTextIOWrapper.closeN)r   r   r   rœ   r
   r
   r
   r   rš   A  s    rš   )NFr‰   )Fr   )r
   )%r	   rT   Úior   rU   rR   ÚDOTALLÚ	MULTILINEÚVERBOSEr^   rV   rk   r`   rg   r,   r   r=   r   r   r*   r-   r2   r<   rG   r\   rd   rf   ri   rm   rp   r€   r‡   rˆ   r”   r˜   r™   rš   r
   r
   r
   r   Ú<module>   s@    

ø	ÿ



-
	

