ó
„¾^Yc           @  s0   d  Z  d d l m Z d e f d „  ƒ  YZ d S(   s8   The base class and interface for all formatting plugins.iÿÿÿÿ(   t   print_functiont   BaseFormatterc           B  sƒ   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z RS(   s"  Class defining the formatter interface.

    .. attribute:: options

        The options parsed from both configuration files and the command-line.

    .. attribute:: filename

        If specified by the user, the path to store the results of the run.

    .. attribute:: output_fd

        Initialized when the :meth:`start` is called. This will be a file
        object opened for writing.

    .. attribute:: newline

        The string to add to the end of a line. This is only used when the
        output filename has been specified.
    c         C  s5   | |  _  | j |  _ d |  _ d |  _ |  j ƒ  d S(   s]  Initialize with the options parsed from config and cli.

        This also calls a hook, :meth:`after_init`, so subclasses do not need
        to call super to call this method.

        :param optparse.Values options:
            User specified configuration parsed from both configuration files
            and the command-line interface.
        s   
N(   t   optionst   output_filet   filenamet   Nonet	   output_fdt   newlinet
   after_init(   t   selfR   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/formatting/base.pyt   __init__   s
    
			c         C  s   d S(   s!   Initialize the formatter further.N(    (   R	   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/formatting/base.pyR   +   s    c         C  s   d S(   sÀ   Notify the formatter that we're starting to process a file.

        :param str filename:
            The name of the file that Flake8 is beginning to report results
            from.
        N(    (   R	   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/formatting/base.pyt	   beginning/   s    c         C  s   d S(   sÀ   Notify the formatter that we've finished processing a file.

        :param str filename:
            The name of the file that Flake8 has finished reporting results
            from.
        N(    (   R	   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/formatting/base.pyt   finished8   s    c         C  s%   |  j  r! t |  j  d ƒ |  _ n  d S(   s}   Prepare the formatter to receive input.

        This defaults to initializing :attr:`output_fd` if :attr:`filename`
        t   aN(   R   t   openR   (   R	   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/formatting/base.pyt   startA   s    	c         C  s2   |  j  | ƒ } |  j | ƒ } |  j | | ƒ d S(   sp  Handle an error reported by Flake8.

        This defaults to calling :meth:`format`, :meth:`show_source`, and
        then :meth:`write`. To extend how errors are handled, override this
        method.

        :param error:
            This will be an instance of :class:`~flake8.style_guide.Error`.
        :type error:
            flake8.style_guide.Error
        N(   t   formatt   show_sourcet   write(   R	   t   errort   linet   source(    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/formatting/base.pyt   handleI   s    c         C  s   t  d ƒ ‚ d S(   s_  Format an error reported by Flake8.

        This method **must** be implemented by subclasses.

        :param error:
            This will be an instance of :class:`~flake8.style_guide.Error`.
        :type error:
            flake8.style_guide.Error
        :returns:
            The formatted error string.
        :rtype:
            str
        s3   Subclass of BaseFormatter did not implement format.N(   t   NotImplementedError(   R	   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/formatting/base.pyR   Y   s    c      	   C  s   xz | j  ƒ  D]l } | j | ƒ } t | ƒ } | j } | t d „  | Dƒ ƒ 7} |  j d j d | d | d | j ƒ ƒ q Wd S(   s    Format and print the statistics.c         s  s   |  ] } | j  Vq d  S(   N(   t   count(   t   .0t   stat(    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/formatting/base.pys	   <genexpr>p   s    s!   {count:<5} {error_code} {message}R   t
   error_codet   messageN(   t   error_codest   statistics_fort   nextR   t   sumt   _writeR   R   (   R	   t
   statisticsR   t   stats_for_error_codet	   statisticR   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/formatting/base.pyt   show_statisticsj   s    	c         C  sv   d j  } d j  } x] | D]U \ } } t | t ƒ rL | d | d | ƒ } n | d | d | ƒ } |  j | ƒ q Wd S(   s    Format and print the benchmarks.s   {value:<10.3} {statistic}s   {value:<10} {statistic}R$   t   valueN(   R   t
   isinstancet   intR!   (   R	   t
   benchmarkst   float_formatt
   int_formatR$   R&   t	   benchmark(    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/formatting/base.pyt   show_benchmarksw   s    		c         C  s@   |  j  j s | j d k r  d Sd | j d d } | j | S(   s/  Show the physical line generating the error.

        This also adds an indicator for the particular part of the line that
        is reported as generating the problem.

        :param error:
            This will be an instance of :class:`~flake8.style_guide.Error`.
        :type error:
            flake8.style_guide.Error
        :returns:
            The formatted error string if the user wants to show the source.
            If the user does not want to show the source, this will return
            ``None``.
        :rtype:
            str
        t    t    i   t   ^N(   R   R   t   physical_lineR   t   column_number(   R	   R   t   pointer(    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/formatting/base.pyR   Œ   s    c         C  sU   |  j  d k	 r) |  j  j | |  j ƒ n  |  j  d k sD |  j j rQ t | ƒ n  d S(   s9   Handle logic of whether to use an output file or print().N(   R   R   R   R   R   t   teet   print(   R	   t   output(    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/formatting/base.pyR!   §   s    c         C  s0   | r |  j  | ƒ n  | r, |  j  | ƒ n  d S(   sÃ  Write the line either to the output file or stdout.

        This handles deciding whether to write to a file or print to standard
        out for subclasses. Override this if you want behaviour that differs
        from the default.

        :param str line:
            The formatted string to print or write.
        :param str source:
            The source code that has been formatted and associated with the
            line of output.
        N(   R!   (   R	   R   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/formatting/base.pyR   ®   s    c         C  s,   |  j  d k	 r( |  j  j ƒ  d |  _  n  d S(   s%   Clean up after reporting is finished.N(   R   R   t   close(   R	   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/formatting/base.pyt   stopÀ   s    (   t   __name__t
   __module__t   __doc__R
   R   R   R   R   R   R   R%   R-   R   R!   R   R8   (    (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/formatting/base.pyR      s   														N(   R;   t
   __future__R    t   objectR   (    (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/formatting/base.pyt   <module>   s   