3
.ßL]|.  ã               @   sÐ  d Z ddlZddlZejdƒZejdejejB ejB ƒZejdej	ej
B ejB ejB ƒZejdejƒZG dd„ deƒZG d	d
„ d
eƒZd8dd„Zd9dd„Zd:dd„Zd;d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d"d#„ Zd<d$d%„Zf fd&d'„Z G d(d)„ d)e!ƒZ"d*d+„ Z#d,d-„ Z$d.d/„ Z%ej&d=k �r~e'Z'e(Z(e)e*fZ+e*Z,d1Z-e.j/Z/e.j0Z0ddl1Z1ddl2Z2e1j1Z1e2j1Z3nFe4Z'e5Z(e)fZ+e)Z,d2Z-e.j6Z/e.j7Z0dd3l8m1Z1m3Z3m9Z9 G d4d5„ d5e9ƒZ:d6d7„ Z;dS )>z±
    pygments.util
    ~~~~~~~~~~~~~

    Utility functions.

    :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
é    Nz[/\\ ]z¨
    (<\?.*?\?>)?\s*
    <!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               @   s   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   ú3/tmp/pip-install-5sebvq2j/pygments/pygments/util.pyr       s   r   c               @   s   e Zd ZdS )ÚOptionErrorN)r   r   r   r   r   r   r   r	   $   s   r	   Fc             C   s@   | j ||ƒ}|r|jƒ }||kr<td|djtt|ƒƒf ƒ‚|S )Nz%Value for option %s must be one of %sz, )ÚgetÚlowerr	   ÚjoinÚmapÚstr)ÚoptionsÚoptnameÚallowedÚdefaultÚnormcaseÚstringr   r   r   Úget_choice_opt(   s    r   c             C   s|   | j ||ƒ}t|tƒr|S t|tƒr,t|ƒS t|tƒsHtd||f ƒ‚n0|jƒ dkrXdS |jƒ dkrhdS td||f ƒ‚d S )NzBInvalid type %r for option %s; use 1/0, yes/no, true/false, on/offÚ1ÚyesÚtrueÚonTÚ0ÚnoÚfalseÚoffFzCInvalid value %r for option %s; use 1/0, yes/no, true/false, on/off)r   r   r   r   )r   r   r   r   )r
   Ú
isinstanceÚboolÚintÚstring_typesr	   r   )r   r   r   r   r   r   r   Úget_bool_opt2   s    


r"   c             C   s`   | j ||ƒ}yt|ƒS  tk
r8   td||f ƒ‚Y n$ tk
rZ   td||f ƒ‚Y nX d S )Nz=Invalid type %r for option %s; you must give an integer valuez>Invalid value %r for option %s; you must give an integer value)r
   r    Ú	TypeErrorr	   Ú
ValueError)r   r   r   r   r   r   r   Úget_int_optF   s    r%   c             C   sH   | j ||ƒ}t|tƒr|jƒ S t|ttfƒr4t|ƒS td||f ƒ‚d S )Nz9Invalid type %r for option %s; you must give a list value)r
   r   r!   ÚsplitÚlistÚtupler	   )r   r   r   Úvalr   r   r   Úget_list_optT   s    
r*   c             C   sR   | j s
dS g }x4| j jƒ jƒ D ]"}|jƒ r>|jd|jƒ  ƒ qP qW dj|ƒjƒ S )NÚ ú )r   ÚstripÚ
splitlinesÚappendr   Úlstrip)ÚobjÚresÚliner   r   r   Údocstring_headline`   s    r4   c                s   ‡ fdd„}ˆ j |_ t|ƒS )zAReturn a static text analyser function that returns float values.c                s\   yˆ | ƒ}W n t k
r    dS X |s*dS ytdtdt|ƒƒƒS  ttfk
rV   dS X d S )Ng        g      ð?)Ú	ExceptionÚminÚmaxÚfloatr$   r#   )ÚtextÚrv)Úfr   r   Útext_analysen   s    z%make_analysator.<locals>.text_analyse)r   Ústaticmethod)r;   r<   r   )r;   r   Úmake_analysatorl   s    r>   c             C   sœ   | j dƒ}|dkr$| d|… jƒ }n| jƒ }|jdƒr˜y(dd„ tj|dd… jƒ ƒD ƒd }W n tk
rr   d	S X tjd
| tj	ƒ}|j
|ƒdk	r˜d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|j d ƒ r|‘qS )ú-)Ú
startswith)Ú.0Úxr   r   r   ú
<listcomp>    s    z#shebang_matches.<locals>.<listcomp>é   é   Fz^%s(\.(exe|cmd|bat|bin))?$Téÿÿÿÿ)Úfindr   rA   Úsplit_path_rer&   r-   Ú
IndexErrorÚreÚcompileÚ
IGNORECASEÚsearch)r9   ÚregexÚindexÚ
first_lineÚfoundr   r   r   Úshebang_matches}   s    


rS   c             C   s<   t j| ƒ}|dkrdS |jdƒ}tj|tjƒj|jƒ ƒdk	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"'
    NFrE   )Údoctype_lookup_reÚmatchÚgrouprK   rL   ÚIr-   )r9   rO   ÚmÚdoctyper   r   r   Údoctype_matchesª   s
    

rZ   c             C   s
   t | dƒS )z3Check if the file looks like it has a html doctype.Úhtml)rZ   )r9   r   r   r   Úhtml_doctype_matches·   s    r\   c             C   sl   t j| ƒrdS t| ƒ}yt| S  tk
rf   tj| ƒ}|dk	rDdS tj| dd… ƒdk	}|t|< |S X dS )z2Check if a doctype exists or if we have some tags.TNiè  )Úxml_decl_rerU   ÚhashÚ_looks_like_xml_cacheÚKeyErrorrT   Útag_rerN   )r9   ÚkeyrX   r:   r   r   r   Úlooks_like_xml¿   s    

rc   c             C   s   d| d?  d| d@  fS )NiÀ×  é
   i Ü  iÿ  r   )Úcr   r   r   Ú_surrogatepairÑ   s    rf   c             C   s,  || k rt dƒ‚| dk s |dk r(t dƒ‚tjdkrFdt| ƒt|ƒf S t| ƒ\}}t|ƒ\}}||kr€dt|ƒt|ƒt|ƒf S g }|jdt|ƒt|ƒ||kr¦t|ƒp¬tdƒf ƒ || d	krì|jd
t|d	 ƒ t|d	 ƒtdƒtdƒƒ ||k�r|jdt|ƒtdƒt|ƒf ƒ ddj|ƒ d S dS )zEReturns a regular expression string to match the given non-BMP range.zBad character rangei   z+unirange is only defined for non-BMP rangesiÿÿ  z[%s-%s]z(?:%s[%s-%s])z	%s[%s-%s]iÿß  rF   z[%s-%s][%s-%s]i Ü  z(?:ú|ú)N)r$   ÚsysÚ
maxunicodeÚunichrrf   r/   r   )ÚaÚbZahÚalZbhÚblÚbufr   r   r   ÚunirangeÚ   s*    
&
rq   c       	      C   s¬   g }d| d }d|d  d }|j ||  d ƒ |rXx\|D ]}|j || d ƒ q<W n<x:|D ]2}t|d ƒ}|j ||dd…  |d  d ƒ q^W |j |d	 ƒ d
j|ƒS )z)Formats a sequence of strings for output.r,   é   rF   z = (ú,ú"NrE   rh   r?   éþÿÿÿrG   )r/   Úreprr   )	Úvar_nameÚseqÚrawÚindent_levelÚlinesZbase_indentZinner_indentÚiÚrr   r   r   Úformat_lines  s    

&r~   c             C   sB   g }t ƒ }x2| D ]*}||ks||kr&q|j|ƒ |j|ƒ qW |S )za
    Returns a list with duplicates removed from the iterable `it`.

    Order is preserved.
    )Úsetr/   Úadd)ÚitZ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 ‚d S )N)ÚNotImplementedError)Úselfr   r   r   r
   *  s    z
Future.getN)r   r   r   r   r
   r   r   r   r   r…   $  s   r…   c             C   st   y| j dƒ} | dfS  tk
rn   y ddl}|jƒ }| j ƒ } | |fS  ttfk
rh   | j dƒ} | dfS X Y nX dS )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)r9   r‹   Zprefencodingr   r   r   Úguess_decode.  s    

rŽ   c             C   sD   t |ddƒr<y| j|jƒ} W n tk
r0   Y nX | |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Ž   )r9   Útermr   r   r   Úguess_decode_from_terminalC  s    
r’   c             C   s"   t | ddƒr| jS ddl}|jƒ S )z7Return our best guess of encoding for the given *term*.r�   Nr   )r�   r�   r‹   rŒ   )r‘   r‹   r   r   r   Úterminal_encodingT  s    r“   é   Úur+   )ÚStringIOÚBytesIOÚTextIOWrapperc               @   s   e Zd Zdd„ ZdS )ÚUnclosingTextIOWrapperc             C   s   | j ƒ  d S )N)Úflush)r‡   r   r   r   Úclosew  s    zUnclosingTextIOWrapper.closeN)r   r   r   r›   r   r   r   r   r™   u  s   r™   c                s   ‡ fdd„}|S )z6Class decorator for creating a class with a metaclass.c                sR   | j jƒ }|jdd ƒ |jdd ƒ x|jdf ƒD ]}|j|ƒ q0W ˆ | j| j|ƒS )NÚ__dict__Ú__weakref__Ú	__slots__)rœ   ÚcopyÚpopr
   r   Ú	__bases__)ÚclsÚ	orig_varsÚ	slots_var)Ú	metaclassr   r   Úwrapper}  s    
zadd_metaclass.<locals>.wrapperr   )r¥   r¦   r   )r¥   r   Úadd_metaclass{  s    r§   )NF)N)N)N)Fr   )r”   r   )<r   rK   ri   rL   rI   ÚDOTALLÚ	MULTILINEÚVERBOSErT   ÚUNICODErM   ra   rW   r]   r$   r   r5   r	   r   r"   r%   r*   r4   r>   rS   rZ   r\   r_   rc   rf   rq   r~   r„   Úobjectr…   rŽ   r’   r“   Úversion_infork   Úxranger   Úunicoder!   Ú	text_typeZu_prefixÚdictÚ	iteritemsÚ
itervaluesr–   Ú	cStringIOr—   ÚchrÚrangeÚitemsÚvaluesÚior˜   r™   r§   r   r   r   r   Ú<module>
   sf   
	




-	'


