B
    `a[*                 @   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-2017 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textZnullz*.txtc             C   s<   | j }x0|D ](\}}|r*||| q|| qW d S )N)encodingwriteencode)selftokensourceoutfileencttypevalue r   8lib/python3.7/site-packages/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| _|dd | _| jdkrJd	| _| jd k	ryt| jd W n" tk
r   t	d
| j Y nX d S )Nasciicompress Z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 d W n tk
r*   tdY nX | jdkrbdd l}|dddfdd	}j}nL| jd
krdd l}|d  fdd	} fdd}nfdd	}j}| jrxd|D ]8\}}d||f }	|t	j
kr|t| j|	 q||	 qW n"x |D ]\}}|d||f  qW |  d S )N    z3The raw tokens formatter needs a binary output filer#   r   r"   wb	   c                s     |   d S )N)r   r   )r
   )r   r   r   r   Z   s    z'RawTokenFormatter.format.<locals>.writer$   c                s     |   d S )N)r   r!   r   )r
   )
compressorr   r   r   r   `   s    c                  s         d S )N)r   flushr   )r.   r   r   r   r/   b   s    z'RawTokenFormatter.format.<locals>.flushc                s     |   d S )N)r   r   )r
   )r   r   r   r   f   s    z%s	%r
)r   	TypeErrorr!   gzipZGzipFiler/   r$   ZBZ2Compressorr%   r   Errorr   )
r   r   r   r1   r   r/   r$   r   r   liner   )r.   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 ]&\}}| | | d|||f  qW td|f }d|}	t}
| jd krx|||	 |
  n0||d ||	d ||
d |  d S )Nz            z%s(%s, %r),
r"   zutf-8)appendTESTCASE_BEFOREjoinTESTCASE_AFTERr   r   r   r/   )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
   N)r   Zpygments.formatterr   Zpygments.utilr   r   Zpygments.tokenr   Zpygments.consoler   __all__r   r   r5   r7   r	   r   r   r   r   <module>
   s   
U