a
    (ñ»jî(  ã                   @  sH  U d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
 d dlmZ d dlmZ e	r^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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dd�ejd< eegef Zded< e
eef ZdS )é    )Úannotations)ÚCallableÚDictÚIterableÚOptionalÚSetÚTupleÚTYPE_CHECKINGÚUnion)Ú	TypeAlias)ÚEntitySubstitution)Ú_AttributeValuec                   @  sÒ   e Zd ZU dZdZded< dZded< eeddgƒd	�Z	d
ed< ded< ded< ded< ded< ded< ded< dddddœdd„Z
d-dddddddœd d!„Zddd"œd#d$„Zddd%œd&d'„Zd(d)d*œ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 `bs4.element.Tag.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.
     * 'html5-4.12.0' - The version of the 'html5' formatter used prior to
                        Beautiful Soup 4.13.0.
     * '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.

    ÚhtmlÚstrÚHTMLÚxmlÚXMLÚscriptÚstyle)Úcdata_containing_tagszDict[str, Set[str]]ÚHTML_DEFAULTSzOptional[str]Úlanguageú%Optional[_EntitySubstitutionFunction]Úentity_substitutionÚvoid_element_close_prefixzSet[str]r   ÚindentÚboolÚempty_attributes_are_booleansúOptional[Set[str]])r   ÚvalueÚkwargÚreturnc                 C  s&   |d ur|S || j krtƒ S | j| S )N)r   Úsetr   )Úselfr   r    r!   © r%   ú3E:\soccer\ml_env\Lib\site-packages\bs4/formatter.pyÚ_defaultB   s
    
zFormatter._defaultNú/Fé   úUnion[int, str])r   r   r   r   r   r   c                 C  sz   |p| j | _|| _|| _|  | j|d¡| _|| _|du r<d}t|tƒr\|dk rRd}d| }nt|t	ƒrl|}nd}|| _
dS )a»  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 set 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 empty_attributes_are_booleans: If this is set to true,
          then attributes whose values are sent to the empty string
          will be treated as `HTML boolean
          attributes<https://dev.w3.org/html5/spec-LC/common-microsyntaxes.html#boolean-attributes>`_. (Attributes
          whose value is None are always rendered this way.)
        :param indent: If indent is a non-negative integer or string,
            then the contents of elements will be indented
            appropriately when pretty-printing. An indent level of 0,
            negative, or "" will only insert newlines. Using a
            positive integer indent indents that many spaces per
            level. If indent is a string (such as "\t"), that string
            is used to indent each level. The default behavior is to
            indent one space per level.

        r   Nr   ú )r   r   r   r   r'   r   r   Ú
isinstanceÚintr   r   )r$   r   r   r   r   r   r   Z
indent_strr%   r%   r&   Ú__init__O   s"    'ÿ


zFormatter.__init__)Únsr"   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: The same string but with certain characters replaced by named
           or numeric entities.
        r)   )ÚNavigableStringN)r   Úelementr0   r,   ÚparentÚnamer   )r$   r/   r0   r%   r%   r&   Ú
substituteŠ   s    	ÿþýzFormatter.substitute)r    r"   c                 C  s
   |   |¡S )z­Process the value of an attribute.

        :param ns: A string.
        :return: A string with certain characters replaced by named
           or numeric entities.
        )r4   )r$   r    r%   r%   r&   Úattribute_value¡   s    zFormatter.attribute_valuezbs4.element.Tagz/Iterable[Tuple[str, Optional[_AttributeValue]]])Útagr"   c                   s2   |j du rg S t|j  ¡ ƒ}t‡ fdd„|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_attributes_are_booleans` 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>)ÚattrsÚlistÚitemsÚsorted)r$   r6   r?   r%   r;   r&   Ú
attributesª   s    
þzFormatter.attributes)NNr(   NFr)   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   Údictr#   r   r'   r.   r4   r5   rA   r%   r%   r%   r&   r   
   s.   
 
ÿ      ù;	r   c                      s>   e Zd ZU dZi Zded< ddd	d
dddœ‡ fdd„Z‡  ZS )ÚHTMLFormatterzA generic Formatter for HTML.z"Dict[Optional[str], HTMLFormatter]ÚREGISTRYNr(   Fr)   r   r   r   r   r*   ©r   r   r   r   r   c                   s"   t t| ƒj| j|||||d� d S ©N)r   )ÚsuperrH   r.   r   ©r$   r   r   r   r   r   ©Ú	__class__r%   r&   r.   Æ   s    
úzHTMLFormatter.__init__)Nr(   NFr)   ©rB   rC   rD   rE   rI   rF   r.   Ú__classcell__r%   r%   rN   r&   rH   Á   s   
     úrH   c                      s>   e Zd ZU dZi Zded< ddd	d
dddœ‡ fdd„Z‡  ZS )ÚXMLFormatterzA generic Formatter for XML.z!Dict[Optional[str], XMLFormatter]rI   Nr(   Fr)   r   r   r   r   r*   rJ   c                   s"   t t| ƒj| j|||||d� d S rK   )rL   rR   r.   r   rM   rN   r%   r&   r.   Ý   s    
úzXMLFormatter.__init__)Nr(   NFr)   rP   r%   r%   rN   r&   rR   Ø   s   
     úrR   )r   r   r7   T)r   r   r   Úhtml5z
html5-4.12ZminimalNr   Ú_EntitySubstitutionFunction)Ú
__future__r   Útypingr   r   r   r   r   r   r	   r
   Ztyping_extensionsr   Z
bs4.dammitr   Zbs4._typingr   r   rH   rR   Zsubstitute_htmlrI   Zsubstitute_html5Zsubstitute_xmlr   rT   rF   Z_FormatterOrNamer%   r%   r%   r&   Ú<module>   sF   ( 8ÿýýÿÿÿ