o
    üÞhÕ'  ã                   @   sH  d Z g d¢ZddlZddlmZmZ zddlmZmZm	Z	m
Z
mZmZmZ eefZW n eyE   ddlmZmZm	Z	m
Z
mZmZ eZY nw ddd„Zdd	d
„Zddd„Zdd„ Ze dej¡jZG dd„ dƒZdd„ Zdd„ ZzddlmZ W n ey‡   ddlmZ Y nw e d¡jZze  W n e!y�   e"Z Y nw dd„ Z#dS )z5External interface to the BeautifulSoup HTML parser.
)Ú
fromstringÚparseÚconvert_treeé    N)ÚetreeÚhtml)ÚBeautifulSoupÚTagÚCommentÚProcessingInstructionÚNavigableStringÚDeclarationÚDoctype)r   r   r	   r
   r   r   c                 K   s   t | ||fi |¤ŽS )a¤  Parse a string of HTML data into an Element tree using the
    BeautifulSoup parser.

    Returns the root ``<html>`` Element of the tree.

    You can pass a different BeautifulSoup parser through the
    `beautifulsoup` keyword, and a diffent Element factory function
    through the `makeelement` keyword.  By default, the standard
    ``BeautifulSoup`` class and the default factory of `lxml.html` are
    used.
    )Ú_parse)ÚdataÚbeautifulsoupÚmakeelementÚbsargs© r   úT/var/www/html/premium_crap/venv/lib/python3.10/site-packages/lxml/html/soupparser.pyr      s   r   c                 K   s0   t | dƒs	t| ƒ} t| ||fi |¤Ž}t |¡S )aY  Parse a file into an ElemenTree using the BeautifulSoup parser.

    You can pass a different BeautifulSoup parser through the
    `beautifulsoup` keyword, and a diffent Element factory function
    through the `makeelement` keyword.  By default, the standard
    ``BeautifulSoup`` class and the default factory of `lxml.html` are
    used.
    Úread)ÚhasattrÚopenr   r   ÚElementTree)Úfiler   r   r   Úrootr   r   r   r   $   s   
	
r   c                 C   s*   t | |ƒ}| ¡ }|D ]}| |¡ q|S )a  Convert a BeautifulSoup tree to a list of Element trees.

    Returns a list instead of a single root Element to support
    HTML-like soup with more than one root element.

    You can pass a different Element factory through the `makeelement`
    keyword.
    )Ú_convert_treeÚgetchildrenÚremove)Úbeautiful_soup_treer   r   ÚchildrenÚchildr   r   r   r   3   s
   
	r   c                 K   s†   |d u rt }t|dƒrd|vrd|d< t|dƒr d|vr d|d< || fi |¤Ž}t||ƒ}t|ƒdkr>|d jdkr>|d S d|_|S )	NÚHTML_ENTITIESÚconvertEntitiesr   ÚDEFAULT_BUILDER_FEATURESÚfeatureszhtml.parseré   r   )r   r   r   ÚlenÚtag)Úsourcer   r   r   Útreer   r   r   r   r   E   s   


r   z`(?:\s|[<!])*DOCTYPE\s*HTML(?:\s+PUBLIC)?(?:\s+(\'[^\']*\'|"[^"]*"))?(?:\s+(\'[^\']*\'|"[^"]*"))?c                   @   s   e Zd Zdd„ Zdd„ ZdS )Ú
_PseudoTagc                 C   s   d| _ g | _|| _d S )Nr   )ÚnameÚattrsÚcontents)Úselfr-   r   r   r   Ú__init__`   s   
z_PseudoTag.__init__c                 C   s
   | j  ¡ S ©N)r-   Ú__iter__)r.   r   r   r   r1   e   s   
z_PseudoTag.__iter__N)Ú__name__Ú
__module__Ú__qualname__r/   r1   r   r   r   r   r*   ^   s    r*   c                 C   sø  |d u rt jj}d  }}d  }}t| ƒD ]-\}}t|tƒr6|d u r#|}|}|d u r5|jr5|j ¡ dkr5|}q|d u rAt|tƒrA|}q|d u rNg  }}	| j	}
n| j	d |… }| j	||d … }
| j	|d d … }	|d urƒ|
 
|¡}|
d |… |j	 |
|d d …  |_	nt|
ƒ}t|ƒ}||ƒ}|}t|ƒD ]}||ƒ}|d ur¦| |¡ |}q•|}|	D ]}||ƒ}|d ur¼| |¡ |}q«|d urúz| ¡ }W n tyÓ   |j}Y nw t|ƒ}|sÝ	 |S | ¡ \}}| ¡ j}|oï|dd… |_|oø|dd… |_|S )Nr   r%   éÿÿÿÿ)r   Úhtml_parserr   Ú	enumerateÚ
isinstancer   r+   ÚlowerÚ_DECLARATION_OR_DOCTYPEr-   Úindexr*   Ú_init_node_convertersÚreversedÚaddpreviousÚaddnextÚoutput_readyÚAttributeErrorÚstringÚ_parse_doctype_declarationÚgroupsÚgetroottreeÚdocinfoÚ	public_idÚ
system_url)r   r   Úfirst_element_idxÚlast_element_idxÚ	html_rootÚdeclarationÚiÚeÚpre_rootÚ	post_rootÚrootsÚconvert_nodeÚres_rootÚprevÚ	convertedÚdoctype_stringÚmatchÚexternal_idÚsys_urirF   r   r   r   r   i   sp   
€€
&
€
€
ÿú
r   c                    s˜   i ‰g ‰‡‡fdd„}‡‡fdd„‰d‡‡fdd„	‰dd„ ‰d	d
„ ‰ |t tƒ‡‡‡‡fdd„ƒ}|tƒdd„ ƒ}|tƒdd„ ƒ}|tƒ‡ fdd„ƒ}ˆS )Nc                     s   ‡‡‡ fdd„}|S )Nc                    s    ˆD ]}| ˆ |< ˆ  |¡ q| S r0   )Úappend)ÚhandlerÚt)Ú
convertersÚordered_node_typesÚtypesr   r   ÚaddÃ   s   z5_init_node_converters.<locals>.converter.<locals>.addr   )r_   r`   ©r]   r^   )r_   r   Ú	converterÂ   s   z(_init_node_converters.<locals>.converterc                    s$   ˆD ]}t | |ƒrˆ |   S qd S r0   )r8   )Únoder\   ra   r   r   Úfind_best_converterÊ   s
   
ÿz2_init_node_converters.<locals>.find_best_converterc                    sN   zˆ t | ƒ }W n ty   ˆ| ƒ }ˆ t | ƒ< Y nw |d u r"d S || |ƒS r0   )ÚtypeÚKeyError)Úbs_nodeÚparentr[   )r]   rd   r   r   rR   Ð   s   ÿ
z+_init_node_converters.<locals>.convert_nodec                 S   sV   t | tƒr"i }|  ¡ D ]\}}t |tƒrd |¡}t|ƒ||< q|S dd„ | D ƒ}|S )Nú c                 S   s   i | ]	\}}|t |ƒ“qS r   ©Úunescape)Ú.0ÚkÚvr   r   r   Ú
<dictcomp>â   s    z<_init_node_converters.<locals>.map_attrs.<locals>.<dictcomp>)r8   ÚdictÚitemsÚlistÚjoinrk   )Úbs_attrsÚattribsrm   rn   r   r   r   Ú	map_attrsÚ   s   


ÿz(_init_node_converters.<locals>.map_attrsc                 S   s<   t | ƒdkr| jp
d| | _d S | d jpd| | d _d S )Nr   Ú r5   )r&   ÚtextÚtail)rh   rx   r   r   r   Úappend_textå   s   z*_init_node_converters.<locals>.append_textc              	      s    | j }|d ur|rˆ|ƒnd }tj|| j|d�}n|rˆ|ƒni }ˆ| j|d�}| D ]#}zˆt|ƒ }W n	 ty=   Y nw |d urG|||ƒ q*ˆ ||ƒ q*|S )N)Úattrib)r,   r   Ú
SubElementr+   re   rf   )rg   rh   r,   ru   Úresr    r[   )rR   r]   r   rv   r   r   Úconvert_tagí   s"   ÿ
z*_init_node_converters.<locals>.convert_tagc                 S   s    t  | ¡}|d ur| |¡ |S r0   )r   ÚHtmlCommentrZ   ©rg   rh   r}   r   r   r   Úconvert_comment  s   

z._init_node_converters.<locals>.convert_commentc                 S   s>   |   d¡r| d d… } tj|  dd¡Ž }|d ur| |¡ |S )Nú?r5   ri   r%   )Úendswithr   r
   ÚsplitrZ   r€   r   r   r   Ú
convert_pi  s   

z)_init_node_converters.<locals>.convert_pic                    s   |d urˆ |t | ƒƒ d S r0   rj   )rg   rh   )rz   r   r   Úconvert_text  s   z+_init_node_converters.<locals>.convert_textr0   )r   r*   r	   r
   r   )r   rb   r~   r�   r…   r†   r   )rz   rR   r]   rd   r   rv   r^   r   r<   ¾   s    



r<   )Úname2codepointz&(\w+);c                 C   s   | sdS dd„ }t || ƒS )Nrw   c                 S   s2   z
t t|  d¡ ƒW S  ty   |  d¡ Y S w )Nr%   r   )Úunichrr‡   Úgrouprf   )Úmr   r   r   Úunescape_entity5  s
   ÿz!unescape.<locals>.unescape_entity)Úhandle_entities)rB   r‹   r   r   r   rk   1  s   
rk   )NNr0   )$Ú__doc__Ú__all__ÚreÚlxmlr   r   Úbs4r   r   r	   r
   r   r   r   r:   ÚImportErrorr   r   r   r   ÚcompileÚ
IGNORECASErW   rC   r*   r   r<   Úhtml.entitiesr‡   ÚhtmlentitydefsÚsubrŒ   rˆ   Ú	NameErrorÚchrrk   r   r   r   r   Ú<module>   sH    $ ü


üüUcÿþ