3
.ßL]*  ã               @   s~   d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 dddg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-2019 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
é    )Ú	Formatter)ÚOptionErrorÚ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ÚtextÚnullz*.txtc             C   s<   | j }x0|D ](\}}|r*|j|j|ƒƒ q|j|ƒ qW d S )N)ÚencodingÚwriteÚencode)ÚselfÚtokensourceÚoutfileÚencÚttypeÚvalue© r   ú?/tmp/pip-install-5sebvq2j/pygments/pygments/formatters/other.pyÚformat   s
    zNullFormatter.formatN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚnameÚaliasesÚ	filenamesr   r   r   r   r   r      s
   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|Ž d| _t|dddddgdƒ| _|jdd ƒ| _| jdkrJd	| _| jd k	rˆyt| jdƒ W n" tk
r†   t	d
| j ƒ‚Y nX d S )NÚasciiÚcompressÚ ÚnoneÚgzÚbz2Úerror_colorTZredzInvalid color %r specified)
r   Ú__init__r   r   r"   Úgetr'   r   ÚKeyErrorÚ
ValueError)r   Úoptionsr   r   r   r(   ?   s    

zRawTokenFormatter.__init__c       
         s$  yˆj dƒ W n tk
r*   tdƒ‚Y nX | jdkrbdd l}|jdddˆƒ‰‡fdd	„}ˆj}nL| jd
krœdd l}|jdƒ‰ ‡ ‡fdd	„}‡ ‡fdd„}n‡fdd	„}ˆj}| jrøxd|D ]8\}}d||f }	|t	j
krê|t| j|	ƒƒ qº||	ƒ qºW n"x |D ]\}}|d||f ƒ qþW |ƒ  d S )Nó    z3The raw tokens formatter needs a binary output filer%   r   r#   Úwbé	   c                s   ˆ j | jƒ ƒ d S )N)r   r   )r
   )r   r   r   r   Z   s    z'RawTokenFormatter.format.<locals>.writer&   c                s   ˆj ˆ j| jƒ ƒƒ d S )N)r   r"   r   )r
   )Ú
compressorr   r   r   r   `   s    c                  s   ˆj ˆ jƒ ƒ ˆjƒ  d S )N)r   Úflushr   )r0   r   r   r   r1   b   s    z'RawTokenFormatter.format.<locals>.flushc                s   ˆ j | jƒ ƒ d S )N)r   r   )r
   )r   r   r   r   f   s    z%s	%r
)r   Ú	TypeErrorr"   ÚgzipÚGzipFiler1   r&   ÚBZ2Compressorr'   r   ÚErrorr   )
r   r   r   r3   r   r1   r&   r   r   Úliner   )r0   r   r   r   Q   s2    



zRawTokenFormatter.formatN)
r   r   r   r   r   r   r   Zunicodeoutputr(   r   r   r   r   r   r   %   s   zF    def testNeedsName(self):
        fragment = %r
        tokens = [
zR        ]
        self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
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   s.   t j| f|Ž | jd k	r*| jdkr*tdƒ‚d S )Nzutf-8z*Only None and utf-8 are allowed encodings.)r   r(   r   r+   )r   r,   r   r   r   r(   Š   s    zTestcaseFormatter.__init__c             C   s´   d}g }g }x.|D ]&\}}|j |ƒ |j d|||f ƒ qW tdj|ƒf }dj|ƒ}	t}
| jd krx|j||	 |
 ƒ n0|j|jdƒƒ |j|	jdƒƒ |j|
jdƒƒ |jƒ  d S )Nú é   z%s(%s, %r),
r#   zutf-8z            )ÚappendÚTESTCASE_BEFOREÚjoinÚTESTCASE_AFTERr   r   r   r1   )r   r   r   ÚindentationZrawbufZoutbufr   r   ZbeforeZduringÚafterr   r   r   r   �   s    


zTestcaseFormatter.formatN)r   r   r   r   r   r   r(   r   r   r   r   r   r	   �   s
   N)r   Zpygments.formatterr   Zpygments.utilr   r   Zpygments.tokenr   Zpygments.consoler   Ú__all__r   r   r;   r=   r	   r   r   r   r   Ú<module>
   s   
U