ó
xiù\c           @   sT  d  Z  d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l	 m
 Z
 d d l m Z m Z d d d	 d
 g e e ƒ Z i  Z i  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d e j f d „  ƒ  YZ e j e Z e e ƒ Z e j j  e j ƒ e e j e <e ` e ` e ` e ` d S(   s¿   
    pygments.formatters
    ~~~~~~~~~~~~~~~~~~~

    Pygments formatters.

    :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
iÿÿÿÿN(   t   basename(   t
   FORMATTERS(   t   find_plugin_formatters(   t   ClassNotFoundt
   itervaluest   get_formatter_by_namet   get_formatter_for_filenamet   get_all_formatterst   load_formatter_from_filec         C   sJ   | t  k r9 t j t j | ƒ ƒ } t  | <| j |  ƒ St  | j |  ƒ S(   sB   Return whether the supplied file name fn matches pattern filename.(   t   _pattern_cachet   ret   compilet   fnmatcht	   translatet   match(   t   fnt   globt   pattern(    (    s;   lib/python2.7/site-packages/pygments/formatters/__init__.pyt   _fn_matches   s     c         C   sL   t  |  d d d g ƒ } x- | j D]" } t | | ƒ } | t | j <q" Wd S(   s4   Load a formatter (and all others in the module too).t   __all__N(   t
   __import__t   NoneR   t   getattrt   _formatter_cachet   name(   t   module_namet   modt   formatter_namet   cls(    (    s;   lib/python2.7/site-packages/pygments/formatters/__init__.pyt   _load_formatters%   s    c          c   sh   xB t  t ƒ D]4 }  |  d t k r4 t |  d ƒ n  t |  d Vq Wx t ƒ  D] \ } } | VqO Wd S(   s-   Return a generator for all formatter classes.i   i    N(   R   R   R   R   R   (   t   infot   _t	   formatter(    (    s;   lib/python2.7/site-packages/pygments/formatters/__init__.pyR   -   s    c         C   s„   xP t  t ƒ D]B \ } } } } } |  | k r | t k rG t | ƒ n  t | Sq Wx* t ƒ  D] \ } } |  | j k r] | Sq] Wd S(   sA   Lookup a formatter by alias.

    Returns None if not found.
    N(   R   R   R   R   R   t   aliases(   t   aliasR   R   R!   R   R   (    (    s;   lib/python2.7/site-packages/pygments/formatters/__init__.pyt   find_formatter_class8   s    "c         K   s5   t  |  ƒ } | d k r+ t d |  ƒ ‚ n  | |   S(   sY   Lookup and instantiate a formatter by alias.

    Raises ClassNotFound if not found.
    s   no formatter found for name %rN(   R#   R   R   (   t   _aliast   optionsR   (    (    s;   lib/python2.7/site-packages/pygments/formatters/__init__.pyR   G   s    t   CustomFormatterc         J   sÊ   yi i  } e  |  d ƒ  } | j ƒ  | UWd QX| | k rT e d | |  f ƒ ‚ n  | | } | |   SWnZ e k
 rŽ } e d |  ƒ ‚ n8 e k
 r£ } ‚  n# e k
 rÅ } e d | ƒ ‚ n Xd S(   s!  Load a formatter from a file.

    This method expects a file located relative to the current working
    directory, which contains a class named CustomFormatter. By default,
    it expects the Formatter to be named CustomFormatter; you can specify
    your own class name as the second argument to this function.

    Users should be very careful with the input, because this method
    is equivalent to running eval on the input file.

    Raises ClassNotFound if there are any problems importing the Formatter.

    .. versionadded:: 2.2
    t   rbNs   no valid %s class found in %ss   cannot read %ss'   error when loading custom formatter: %s(   t   opent   readR   t   IOErrort	   Exception(   t   filenamet   formatternameR%   t   custom_namespacet   ft   formatter_classt   err(    (    s;   lib/python2.7/site-packages/pygments/formatters/__init__.pyR   R   s    
c         K   sÎ   t  |  ƒ }  xj t t ƒ D]\ \ } } } } } xD | D]< } t |  | ƒ r5 | t k rc t | ƒ n  t | |   Sq5 Wq Wx> t ƒ  D]3 } x* | j D] } t |  | ƒ r“ | |   Sq“ Wqƒ Wt d |  ƒ ‚ d S(   sd   Lookup and instantiate a formatter by filename pattern.

    Raises ClassNotFound if not found.
    s#   no formatter found for file name %rN(	   R    R   R   R   R   R   R   t	   filenamesR   (   R   R%   t   modnameR   R   R2   R,   R   (    (    s;   lib/python2.7/site-packages/pygments/formatters/__init__.pyR   v   s    "t   _automodulec           B   s   e  Z d  Z d „  Z RS(   s    Automatically import formatters.c         C   sU   t  j | ƒ } | rE t | d ƒ t | d } t |  | | ƒ | St | ƒ ‚ d  S(   Ni    i   (   R   t   getR   R   t   setattrt   AttributeError(   t   selfR   R   R   (    (    s;   lib/python2.7/site-packages/pygments/formatters/__init__.pyt   __getattr__Œ   s    (   t   __name__t
   __module__t   __doc__R9   (    (    (    s;   lib/python2.7/site-packages/pygments/formatters/__init__.pyR4   ‰   s   (!   R<   R
   t   syst   typesR   t   os.pathR    t   pygments.formatters._mappingR   t   pygments.pluginR   t   pygments.utilR   R   t   listR   R   R	   R   R   R   R#   R   R   R   t
   ModuleTypeR4   t   modulesR:   t   oldmodt   newmodt   __dict__t   update(    (    (    s;   lib/python2.7/site-packages/pygments/formatters/__init__.pyt   <module>
   s2   					$	