/ lib / pygments / util.pyc
util.pyc
  1  o

  2   ��c�#�@s6dZddlZddlmZe�d�Ze�dejejBejB�Z	e�dej
  3  ejBejB�Ze�dej�Z
Gdd	�d	e�ZGd
  4  d�de�Zd2d
d�Zd3dd�Zd3dd�Zd3dd�Zdd�Zdd�Zdd�Zdd�Zdd�ZiZdd �Zd!d"�Zd4d#d$�Zd5d&d'�ZGd(d)�d)�Z d*d+�Z!d,d-�Z"d.d/�Z#Gd0d1�d1e�Z$dS)6z�
  5      pygments.util
  6      ~~~~~~~~~~~~~
  7  
  8      Utility functions.
  9  
 10      :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
 11      :license: BSD, see LICENSE for details.
 12  �N)�
TextIOWrapperz[/\\ ]z�
 13      <!DOCTYPE\s+(
 14       [a-zA-Z_][a-zA-Z0-9]*
 15       (?: \s+      # optional in HTML5
 16       [a-zA-Z_][a-zA-Z0-9]*\s+
 17       "[^"]*")?
 18       )
 19       [^>]*>
 20  z<(.+?)(\s.*?)?>.*?</.+?>z\s*<\?xml[^>]*\?>c@seZdZdZdS)�
ClassNotFoundzCRaised if one of the lookup functions didn't find a matching class.N)�__name__�
 21  __module__�__qualname__�__doc__�rr��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pygments\util.pyrsrc@seZdZdS)�OptionErrorN)rrrrrrr	r
 22  "sr
 23  FcCs@|�||�}|r|��}||vrtd|d�tt|��f��|S)Nz%Value for option %s must be one of %sz, )�get�lowerr
 24  �join�map�str)�options�optname�allowed�default�normcase�stringrrr	�get_choice_opt&s�rcCsv|�||�}t|t�r
|St|t�rt|�St|t�s#td||f��|��dvr+dS|��dvr3dStd||f��)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�
 25  isinstance�bool�intrr
 26  r�rrrrrrr	�get_bool_opt0s$
 27  
 28  
 29  ����r#cCsR|�||�}zt|�WStytd||f��ty(td||f��w)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)rr!�	TypeErrorr
 30 31  ValueErrorr"rrr	�get_int_optDs
 32  �����r&cCsD|�||�}t|t�r|��St|ttf�rt|�Std||f��)Nz9Invalid type %r for option %s; you must give a list value)rrr�split�list�tupler
 33  )rrr�valrrr	�get_list_optRs
 34  ��r+cCsL|jsdSg}|j����D]}|��r|�d|���qd�|���S)N�� )r�strip�
 35  splitlines�appendr
�lstrip)�obj�res�linerrr	�docstring_headline^sr5cs�fdd�}�j|_t|�S)zAReturn a static text analyser function that returns float values.c	sZz�|�}Wn
 36  tyYdSw|sdSztdtdt|���WSttfy,YdSw)Ngg�?)�	Exception�min�max�floatr%r$)�text�rv��frr	�text_analysels��z%make_analysator.<locals>.text_analyse)r�staticmethod)r=r>rr<r	�make_analysatorjsr@cCs�|�d�}|dkr|d|���}n|��}|�d�rLzdd�t�|dd����D�d}Wn
 37  ty9Yd	Swt�d
 38  |tj	�}|�
 39  |�durLdSd	S)a�Check if the given regular expression matches the last part of the
 40      shebang if one exists.
 41  
 42          >>> from pygments.util import shebang_matches
 43          >>> shebang_matches('#!/usr/bin/env python', r'python(2\.\d)?')
 44          True
 45          >>> shebang_matches('#!/usr/bin/python2.4', r'python(2\.\d)?')
 46          True
 47          >>> shebang_matches('#!/usr/bin/python-ruby', r'python(2\.\d)?')
 48          False
 49          >>> shebang_matches('#!/usr/bin/python/ruby', r'python(2\.\d)?')
 50          False
 51          >>> shebang_matches('#!/usr/bin/startsomethingwith python',
 52          ...                 r'python(2\.\d)?')
 53          True
 54  
 55      It also checks for common windows executable file extensions::
 56  
 57          >>> shebang_matches('#!C:\\Python2.4\\Python.exe', r'python(2\.\d)?')
 58          True
 59  
 60      Parameters (``'-f'`` or ``'--foo'`` are ignored so ``'perl'`` does
 61      the same as ``'perl -e'``)
 62  
 63      Note that this method automatically searches the whole string (eg:
 64      the regular expression is wrapped in ``'^$'``)
 65      �
 66  rNz#!cSsg|]}|r|�d�s|�qS)�-)�
 67  startswith)�.0�xrrr	�
 68  <listcomp>�s
 69  �
 70  �z#shebang_matches.<locals>.<listcomp>������Fz^%s(\.(exe|cmd|bat|bin))?$T)�findrrC�
split_path_rer'r.�
 71  IndexError�re�compile�
 72  IGNORECASE�search)r:�regex�index�
 73  first_line�foundrrr	�shebang_matches{s 
 74  
 75  ��rTcCs<t�|�}|durdS|�d�}t�|tj��|���duS)z�Check if the doctype matches a regular expression (if present).
 76  
 77      Note that this method only checks the first part of a DOCTYPE.
 78      eg: 'html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
 79      NF�)�doctype_lookup_rerO�grouprLrM�I�matchr.)r:rP�m�doctyperrr	�doctype_matches�s
 80  
 81  
 82  r\cCs
 83  t|d�S)z3Check if the file looks like it has a html doctype.�html)r\)r:rrr	�html_doctype_matches�s
 84  r^cCsnt�|�rdSt|�}zt|WSty6t�|�}|dur#YdSt�|dd��du}|t|<|YSw)z2Check if a doctype exists or if we have some tags.TNi�)�xml_decl_rerY�hash�_looks_like_xml_cache�KeyErrorrVrO�tag_re)r:�keyrZr;rrr	�looks_like_xml�s
 85  
 86  
 87  �recCsd|d?d|d@fS)zoGiven a unicode character code with length greater than 16 bits,
 88      return the two 16 bit surrogate pair.
 89      i���
 90  i�i�r)�crrr	�
surrogatepair�srhc	Cs�g}d|d}d|dd}|�||d�|r*|D]}|�||d�qn|D]}t|d�}|�||dd�|d	d�q,|�|d
 91  �d�|�S)z)Formats a sequence of strings for output.r-�rUz = (�,�"N�����rH�)rA)r0�reprr
)	�var_name�seq�raw�indent_level�linesZbase_indentZinner_indent�i�rrrr	�format_lines�s�$
 92  rvrcCs>g}t�}|D]}||vs||vrq|�|�|�|�q|S)za
 93      Returns a list with duplicates removed from the iterable `it`.
 94  
 95      Order is preserved.
 96      )�setr0�add)�itZalready_seen�lst�seenrtrrr	�duplicates_removed�s
 97  r|c@seZdZdZdd�ZdS)�Futurez�Generic class to defer some work.
 98  
 99      Handled specially in RegexLexerMeta, to support regex string construction at
100      first use.
101      cCst��N)�NotImplementedError��selfrrr	r�sz
102  Future.getN)rrrrrrrrr	r}�sr}cCsxz
103  |�d�}|dfWSty;zddl}|��}|��}||fWYSttfy:|�d�}|dfYYSww)z�Decode *text* with guessed encoding.
104  
105      First try UTF-8; this should fail for non-UTF-8 encodings.
106      Then try the preferred locale encoding.
107      Fall back to latin-1, which always works.
108      zutf-8rN�latin1)�decode�UnicodeDecodeError�locale�getpreferredencoding�LookupError)r:r�Zprefencodingrrr	�guess_decodes
109  
110  
111  ��r�cCsHt|dd�r z|�|j�}WntyYt|�Sw||jfSt|�S)z�Decode *text* coming from terminal *term*.
112  
113      First try the terminal encoding, if given.
114      Then try UTF-8.  Then try the preferred locale encoding.
115      Fall back to latin-1, which always works.
116      �encodingN)�getattrr�r�r�r�)r:�termrrr	�guess_decode_from_terminals�
117  r�cCs"t|dd�r	|jSddl}|��S)z7Return our best guess of encoding for the given *term*.r�Nr)r�r�r�r�)r�r�rrr	�terminal_encoding)sr�c@seZdZdd�ZdS)�UnclosingTextIOWrappercCs|��dSr~)�flushr�rrr	�close3szUnclosingTextIOWrapper.closeN)rrrr�rrrr	r�1sr�)NFr~)Fr)r)%rrL�iorrMrJ�DOTALL�	MULTILINE�VERBOSErVrNrcrXr_r%rr6r
118  rr#r&r+r5r@rTr\r^rarerhrvr|r}r�r�r�r�rrrr	�<module>s@
119  
120  �	�
121  
122  
123  
124  
125  -

126  	
127  
128