o
    7a                     @   s   d dl mZ G dd deZG dd deZG dd deZeejdejd	< eejd
ddejd< eejdejd< ed
dejd
< eejdejd	< eejdejd< eeejd
dejd
< d
S )    )EntitySubstitutionc                   @   sb   e Zd ZdZi Zi ZdZdZee	ddgdZ
dd Z					dddZdd Zdd Zdd Zd	S )	Formattera   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, as
                 well as some optimizations in the way tags are rendered.
     * '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.
    htmlZxmlZscriptZstyle)cdata_containing_tagsc                 C   s&   |d ur|S || j krt S | j| S N)XMLsetHTML_DEFAULTS)selflanguagevaluekwarg r   //usr/lib/python3/dist-packages/bs4/formatter.py_default*   s
   

zFormatter._defaultN/Fc                 C   s,   || _ || _|| _| ||d| _|| _dS )a3  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.
        :param blank_attributes_are_booleans: Render attributes whose value
            is the empty string as HTML-style boolean attributes.
            (Attributes whose value is None are always rendered this way.)
        r   N)r   entity_substitutionvoid_element_close_prefixr   r   empty_attributes_are_booleans)r
   r   r   r   r   r   r   r   r   __init__1   s   
zFormatter.__init__c                 C   sF   | j s|S ddlm} t||r|jdur|jj| jv r|S |  |S )a  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.
           )NavigableStringN)r   elementr   
isinstanceparentnamer   )r
   nsr   r   r   r   
substituteQ   s   	

zFormatter.substitutec                 C   s
   |  |S )zProcess the value of an attribute.

        :param ns: A string.
        :return: A string with certain characters replaced by named
           or numeric entities.
        )r   )r
   r   r   r   r   attribute_valuee   s   
zFormatter.attribute_valuec                    s.   |j du rg S t fddt|j  D S )a  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.

        If `empty_boolean_attributes` is True, then attributes whose
        values are set to the empty string will be treated as boolean
        attributes.
        Nc                 3   s.    | ]\}}| j r|d krdn|fV  qdS ) N)r   ).0kvr
   r   r   	<genexpr>{   s
    
z'Formatter.attributes.<locals>.<genexpr>)Zattrssortedlistitems)r
   tagr   r#   r   
attributesn   s
   
zFormatter.attributes)NNr   NF)__name__
__module____qualname____doc__ZXML_FORMATTERSZHTML_FORMATTERSHTMLr   dictr   r	   r   r   r   r   r)   r   r   r   r   r      s"    

 	r   c                       $   e Zd ZdZi Z fddZ  ZS )HTMLFormatterzA generic Formatter for HTML.c                        t t| j| jg|R i |S r   )superr1   r   r.   r
   argskwargs	__class__r   r   r          zHTMLFormatter.__init__r*   r+   r,   r-   REGISTRYr   __classcell__r   r   r7   r   r1          r1   c                       r0   )XMLFormatterzA generic Formatter for XML.c                    r2   r   )r3   r>   r   r   r4   r7   r   r   r      r9   zXMLFormatter.__init__r:   r   r   r7   r   r>      r=   r>   )r   r   NT)r   r   r   Zhtml5Zminimal)	Z
bs4.dammitr   r   r1   r>   Zsubstitute_htmlr;   Zsubstitute_xmlr   r   r   r   r   <module>   s6    }