ó
*;^c           @   s  d  d l  m Z d e f d     YZ d e f d     YZ d e f d     YZ e d e j  e j d	 <e d e j d
 d  e j d <e d e j  e j d <e d d  e j d <e d e j  e j d	 <e d e j  e j d <e e e j	 d d  e j d <d S(   i˙˙˙˙(   t   EntitySubstitutiont	   Formatterc           B   sz   e  Z d  Z i  Z i  Z d Z d Z e d e d d g   Z	 d   Z
 d d d d d  Z d	   Z d
   Z d   Z RS(   sł  Describes a strategy to use when outputting a parse tree to a string.

    Some parts of this strategy come from the distinction between
    HTML4, HTML5, and XML. Others are configurable by the user.

    Formatters are passed in as the `formatter` argument to methods
    like `PageElement.encode`. Most people won't need to think about
    formatters, and most people who need to think about them can pass
    in one of these predefined strings as `formatter` rather than
    making a new Formatter object:

    For HTML documents:
     * 'html' - HTML entity substitution for generic HTML documents. (default)
     * 'html5' - HTML entity substitution for HTML5 documents.
     * 'minimal' - Only make the substitutions necessary to guarantee
                   valid HTML.
     * None - Do not perform any substitution. This will be faster
              but may result in invalid markup.

    For XML documents:
     * 'html' - Entity substitution for XHTML documents.
     * 'minimal' - Only make the substitutions necessary to guarantee
                   valid XML. (default)
     * None - Do not perform any substitution. This will be faster
              but may result in invalid markup.
    t   htmlt   xmlt   cdata_containing_tagst   scriptt   stylec         C   s1   | d  k	 r | S| |  j k r& t   S|  j | S(   N(   t   Nonet   XMLt   sett   HTML_DEFAULTS(   t   selft   languaget   valuet   kwarg(    (    s/   /tmp/pip-unpacked-wheel-q6Hrcs/bs4/formatter.pyt   _default)   s
    t   /c         C   s7   | |  _  | |  _ | |  _ |  j | | d  |  _ d S(   sZ  Constructor.

        :param language: This should be Formatter.XML if you are formatting
           XML markup and Formatter.HTML if you are formatting HTML markup.

        :param entity_substitution: A function to call to replace special
           characters with XML/HTML entities. For examples, see 
           bs4.dammit.EntitySubstitution.substitute_html and substitute_xml.
        :param void_element_close_prefix: By default, void elements
           are represented as <tag/> (XML rules) rather than <tag>
           (HTML rules). To get <tag>, pass in the empty string.
        :param cdata_containing_tags: The list of tags that are defined
           as containing CDATA in this dialect. For example, in HTML,
           <script> and <style> tags are defined as containing CDATA,
           and their contents should not be formatted.
        R   N(   R   t   entity_substitutiont   void_element_close_prefixR   R   (   R   R   R   R   R   (    (    s/   /tmp/pip-unpacked-wheel-q6Hrcs/bs4/formatter.pyt   __init__0   s
    			c         C   sa   |  j  s | Sd d l m } t | |  rT | j d k	 rT | j j |  j k rT | S|  j  |  S(   s  Process a string that needs to undergo entity substitution.
        This may be a string encountered in an attribute value or as
        text.

        :param ns: A string.
        :return: A string with certain characters replaced by named
           or numeric entities.
        i˙˙˙˙(   t   NavigableStringN(   R   t   elementR   t
   isinstancet   parentR   t   nameR   (   R   t   nsR   (    (    s/   /tmp/pip-unpacked-wheel-q6Hrcs/bs4/formatter.pyt
   substituteK   s    		c         C   s   |  j  |  S(   s­   Process the value of an attribute.

        :param ns: A string.
        :return: A string with certain characters replaced by named
           or numeric entities.
        (   R   (   R   R   (    (    s/   /tmp/pip-unpacked-wheel-q6Hrcs/bs4/formatter.pyt   attribute_value_   s    c         C   s   t  | j j    S(   s  Reorder a tag's attributes however you want.
        
        By default, attributes are sorted alphabetically. This makes
        behavior consistent between Python 2 and Python 3, and preserves
        backwards compatibility with older versions of Beautiful Soup.
        (   t   sortedt   attrst   items(   R   t   tag(    (    s/   /tmp/pip-unpacked-wheel-q6Hrcs/bs4/formatter.pyt
   attributesh   s    N(   t   __name__t
   __module__t   __doc__t   XML_FORMATTERSt   HTML_FORMATTERSt   HTMLR   t   dictR	   R
   R   R   R   R   R   R    (    (    (    s/   /tmp/pip-unpacked-wheel-q6Hrcs/bs4/formatter.pyR      s   				t   HTMLFormatterc           B   s   e  Z d  Z i  Z d   Z RS(   s   A generic Formatter for HTML.c         O   s   t  t |   j |  j | |  S(   N(   t   superR(   R   R&   (   R   t   argst   kwargs(    (    s/   /tmp/pip-unpacked-wheel-q6Hrcs/bs4/formatter.pyR   u   s    (   R!   R"   R#   t   REGISTRYR   (    (    (    s/   /tmp/pip-unpacked-wheel-q6Hrcs/bs4/formatter.pyR(   r   s   t   XMLFormatterc           B   s   e  Z d  Z i  Z d   Z RS(   s   A generic Formatter for XML.c         O   s   t  t |   j |  j | |  S(   N(   R)   R-   R   R   (   R   R*   R+   (    (    s/   /tmp/pip-unpacked-wheel-q6Hrcs/bs4/formatter.pyR   |   s    (   R!   R"   R#   R,   R   (    (    (    s/   /tmp/pip-unpacked-wheel-q6Hrcs/bs4/formatter.pyR-   y   s   R   R   R   t   html5t   minimalN(
   t
   bs4.dammitR    R   R(   R-   t   substitute_htmlR,   R   t   substitute_xmlR   (    (    (    s/   /tmp/pip-unpacked-wheel-q6Hrcs/bs4/formatter.pyt   <module>   s$   o	