a
    œÌW_  ã                   @   sx   d Z ddlmZ ddlmZ ddlmZ ddlmZ g d¢Z	G dd„ deƒZ
G d	d
„ d
eƒZdZdZG dd„ deƒZdS )zê
    pygments.formatters.other
    ~~~~~~~~~~~~~~~~~~~~~~~~~

    Other formatters: NullFormatter, RawTokenFormatter.

    :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
é    )Ú	Formatter)Úget_choice_opt)ÚToken)Úcolorize)ÚNullFormatterÚRawTokenFormatterÚTestcaseFormatterc                   @   s*   e Zd ZdZdZddgZdgZdd„ ZdS )	r   z;
    Output the text unchanged without any formatting.
    z	Text onlyÚtextZnullz*.txtc                 C   s8   | j }|D ](\}}|r(| | |¡¡ q
| |¡ q
d S ©N)ÚencodingÚwriteÚencode)ÚselfÚtokensourceÚoutfileÚencÚttypeÚvalue© r   ú;/usr/lib/python3/dist-packages/pygments/formatters/other.pyÚformat   s
    zNullFormatter.formatN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚnameÚaliasesÚ	filenamesr   r   r   r   r   r      s
   r   c                   @   s6   e Zd ZdZdZddgZdgZdZdd„ Zd	d
„ Z	dS )r   a}  
    Format tokens as a raw representation for storing token streams.

    The format is ``tokentype<TAB>repr(tokenstring)\n``. The output can later
    be converted to a token stream with the `RawTokenLexer`, described in the
    :doc:`lexer list <lexers>`.

    Only two options are accepted:

    `compress`
        If set to ``'gz'`` or ``'bz2'``, compress the output with the given
        compression algorithm after encoding (default: ``''``).
    `error_color`
        If set to a color name, highlight error tokens using that color.  If
        set but with no value, defaults to ``'red'``.

        .. versionadded:: 0.11

    z
Raw tokensÚrawÚtokensz*.rawFc                 K   sŠ   t j| fi |¤Ž d| _t|dg d¢dƒ| _| dd ¡| _| jdu rJd| _| jd ur†zt| jdƒ W n  ty„   t	d| j ƒ‚Y n0 d S )	NÚasciiÚcompress)Ú ZnoneÚgzÚbz2r"   Úerror_colorTZredzInvalid color %r specified)
r   Ú__init__r   r   r!   Úgetr%   r   ÚKeyErrorÚ
ValueError©r   Zoptionsr   r   r   r&   ?   s    ÿ

ÿzRawTokenFormatter.__init__c           
         s  zˆ  d¡ W n ty(   tdƒ‚Y n0 | jdkr`dd l}| dddˆ¡‰‡fdd	„}ˆj}nL| jd
kršdd l}| d¡‰ ‡ ‡fdd	„}‡ ‡fdd„}n‡fdd	„}ˆj}| jrò|D ]8\}}d||f }	|t	j
u ræ|t| j|	ƒƒ q¶||	ƒ q¶n|D ]\}}|d||f ƒ qö|ƒ  d S )Nó    z3The raw tokens formatter needs a binary output filer#   r   r"   Úwbé	   c                    s   ˆ   |  ¡ ¡ d S r
   ©r   r   ©r	   ©r   r   r   r   [   s    z'RawTokenFormatter.format.<locals>.writer$   c                    s   ˆ  ˆ  |  ¡ ¡¡ d S r
   )r   r!   r   r/   ©Z
compressorr   r   r   r   b   s    c                      s   ˆ  ˆ  ¡ ¡ ˆ ¡  d S r
   )r   Úflushr   r1   r   r   r2   e   s    z'RawTokenFormatter.format.<locals>.flushc                    s   ˆ   |  ¡ ¡ d S r
   r.   r/   r0   r   r   r   i   s    z%s	%r
)r   Ú	TypeErrorr!   ÚgzipZGzipFiler2   r$   ZBZ2Compressorr%   r   ÚErrorr   )
r   r   r   r4   r   r2   r$   r   r   Úliner   r1   r   r   Q   s2    



zRawTokenFormatter.formatN)
r   r   r   r   r   r   r   Zunicodeoutputr&   r   r   r   r   r   r   %   s   r   zG    def testNeedsName(lexer):
        fragment = %r
        tokens = [
zD        ]
        assert list(lexer.get_tokens(fragment)) == tokens
c                   @   s*   e Zd ZdZdZdgZdd„ Zdd„ ZdS )	r   zU
    Format tokens as appropriate for a new testcase.

    .. versionadded:: 2.0
    ZTestcaseZtestcasec                 K   s2   t j| fi |¤Ž | jd ur.| jdkr.tdƒ‚d S )Núutf-8z*Only None and utf-8 are allowed encodings.)r   r&   r   r)   r*   r   r   r   r&   Ž   s    zTestcaseFormatter.__init__c                 C   s°   d}g }g }|D ]&\}}|  |¡ |  d|||f ¡ qtd |¡f }d |¡}	t}
| jd u rt| ||	 |
 ¡ n0| | d¡¡ | |	 d¡¡ | |
 d¡¡ | ¡  d S )Nz            z%s(%s, %r),
r"   r7   )ÚappendÚTESTCASE_BEFOREÚjoinÚTESTCASE_AFTERr   r   r   r2   )r   r   r   ZindentationZrawbufZoutbufr   r   ZbeforeZduringZafterr   r   r   r   “   s    


zTestcaseFormatter.formatN)r   r   r   r   r   r   r&   r   r   r   r   r   r   …   s
   r   N)r   Zpygments.formatterr   Zpygments.utilr   Zpygments.tokenr   Zpygments.consoler   Ú__all__r   r   r9   r;   r   r   r   r   r   Ú<module>   s   
U