HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/bs4/builder/__pycache__/_lxml.cpython-38.pyc
U

t�^�/�
@s�dZddgZzddlmZWn.ek
rJZzddlmZW5dZ[XYnXddlmZddlm	Z	ddl
mZdd	lm
Z
mZmZmZmZdd
lmZmZmZmZmZmZmZddlmZdZd
d�ZGdd�de�ZGdd�dee�ZdS)ZMIT�LXMLTreeBuilderForXML�LXMLTreeBuilder�)�CallableN)�BytesIO)�StringIO)�etree)�Comment�Doctype�NamespacedAttribute�ProcessingInstruction�XMLProcessingInstruction)�FAST�HTML�HTMLTreeBuilder�
PERMISSIVE�ParserRejectedMarkup�TreeBuilder�XML)�EncodingDetector�lxmlcCstdd�t|���D��S)zInvert a dictionary.css|]\}}||fVqdS�N�)�.0�k�vrr�3/usr/lib/python3/dist-packages/bs4/builder/_lxml.py�	<genexpr>&sz_invert.<locals>.<genexpr>)�dict�list�items)�drrr�_invert$sr!cs�eZdZejZdZeZdZ	dgZ
e	eee
egZdZedd�Zee�Z�fdd�Zd	d
�Zdd�Zd
d�Zd*�fdd�	Zdd�Zd+dd�Zdd�Zdd�Zifdd�Zdd�Zdd�Z d d!�Z!d"d#�Z"d$d%�Z#d&d'�Z$d(d)�Z%�Z&S),rTzlxml-xml�xmliz$http://www.w3.org/XML/1998/namespace)r"cs tt|��|�|�|j�dS)z�Let the BeautifulSoup object know about the standard namespace
        mapping.

        :param soup: A `BeautifulSoup`.
        N)�superr�initialize_soup�_register_namespaces�DEFAULT_NSMAPS)�self�soup��	__class__rrr$Csz%LXMLTreeBuilderForXML.initialize_soupcCs6t|���D]$\}}|r||jjkr||jj|<qdS)z�Let the BeautifulSoup object know about namespaces encountered
        while parsing the document.

        This might be useful later on when creating CSS selectors.

        :param mapping: A dictionary mapping namespace prefixes to URIs.
        N)rrr(Z_namespaces)r'�mapping�key�valuerrrr%Lsz*LXMLTreeBuilderForXML._register_namespacescCs"|jdk	r|jStj|dd|d�S)z�Find the default parser for the given encoding.

        :param encoding: A string.
        :return: Either a parser object or a class, which
          will be instantiated with default arguments.
        NFT��targetZstrip_cdataZrecover�encoding)�_default_parserr�	XMLParser�r'r0rrr�default_parser[s
�z$LXMLTreeBuilderForXML.default_parsercCs(|�|�}t|t�r$||dd|d�}|S)z�Instantiate an appropriate parser for the given encoding.

        :param encoding: A string.
        :return: A parser object such as an `etree.XMLParser`.
        FTr.)r4�
isinstancer)r'r0�parserrrr�
parser_forgs

�z LXMLTreeBuilderForXML.parser_forNcs>||_|dk	rt|�|_d|_|jg|_tt|�jf|�dSr)	r1�set�empty_element_tagsr(�DEFAULT_NSMAPS_INVERTED�nsmapsr#r�__init__)r'r6r9�kwargsr)rrr<ws

zLXMLTreeBuilderForXML.__init__cCs0|ddkr$t|dd��dd��Sd|fSdS)Nr�{��})�tuple�split)r'�tagrrr�	_getNsTag�szLXMLTreeBuilderForXML._getNsTagc	cs�|j}|rt|_nt|_t|t�r2|d|dfVt|t�rP|�d�d|dfV||g}t||||�}|jD]}|j	||dfVqldS)aARun any preliminary steps necessary to make incoming markup
        acceptable to the parser.

        lxml really wants to get a bytestring and convert it to
        Unicode itself. So instead of using UnicodeDammit to convert
        the bytestring to Unicode using different encodings, this
        implementation uses EncodingDetector to iterate over the
        encodings, and tell lxml to try to parse the document as each
        one in turn.

        :param markup: Some markup -- hopefully a bytestring.
        :param user_specified_encoding: The user asked to try this encoding.
        :param document_declared_encoding: The markup itself claims to be
            in this encoding.
        :param exclude_encodings: The user asked _not_ to try any of
            these encodings.

        :yield: A series of 4-tuples:
         (markup, encoding, declared encoding,
          has undergone character replacement)

         Each 4-tuple represents a strategy for converting the
         document to Unicode and parsing it. Each strategy will be tried 
         in turn.
        NF�utf8)
�is_xmlr�processing_instruction_classrr5�str�encoderZ	encodings�markup)	r'rJZuser_specified_encodingZexclude_encodingsZdocument_declared_encodingZis_htmlZ
try_encodingsZdetectorr0rrr�prepare_markup�s(


��
z$LXMLTreeBuilderForXML.prepare_markupc
Cs�t|t�rt|�}nt|t�r&t|�}|�|j�}z\|�|jj	�|_
|j
�|�t|�dkr�|�|j�}t|�dkrP|j
�|�qP|j
�
�Wn2tttjfk
r�}zt|��W5d}~XYnXdS)Nr)r5�bytesrrHr�read�
CHUNK_SIZEr7r(�original_encodingr6�feed�len�close�UnicodeDecodeError�LookupErrorr�ParserErrorr)r'rJ�data�errrrP�s


zLXMLTreeBuilderForXML.feedcCs|jg|_dSr)r:r;)r'rrrrR�szLXMLTreeBuilderForXML.closecCst|�}d}t|�dkr4t|j�dkr4|j�d�nXt|�dkr�|�|�|j�t|��|��}t|���D]\}}t	d|d�}|||<qni}t|���D]F\}	}
|�
|	�\}}	|dkr�|
||	<q�|�|�}t	||	|�}	|
||	<q�|}|�
|�\}}|�|�}|j�
||||�dS)Nrr?Zxmlnszhttp://www.w3.org/2000/xmlns/)rrQr;�appendr%r!�copyrrr
rD�_prefix_for_namespacer(Zhandle_starttag)r'�nameZattrsZnsmap�nsprefix�prefix�	namespaceZ	attributeZ	new_attrs�attrr-rrr�start�s6
�




zLXMLTreeBuilderForXML.startcCs<|dkrdSt|j�D] }|dk	r||kr||SqdS)z9Find the currently active prefix for the given namespace.N)�reversedr;)r'r^�inverted_nsmaprrrrZsz+LXMLTreeBuilderForXML._prefix_for_namespacecCs�|j��|jjd}|�|�\}}d}|dk	r\t|j�D] }|dk	r:||kr:||}q\q:|j�||�t|j�dkr�|j��dS)N���r?)	r(�endDataZtagStackrDrar;Z
handle_endtagrQ�pop)r'r[Z
completed_tagr^r\rbrrr�ends
zLXMLTreeBuilderForXML.endcCs0|j��|j�|d|�|j�|j�dS)N� )r(rd�handle_datarG)r'r/rVrrr�pis
zLXMLTreeBuilderForXML.picCs|j�|�dSr)r(rh�r'ZcontentrrrrV!szLXMLTreeBuilderForXML.datacCs(|j��t�|||�}|j�|�dSr)r(rdr	Zfor_name_and_idsZobject_was_parsed)r'r[Zpubid�system�doctyperrrrl$s
zLXMLTreeBuilderForXML.doctypecCs&|j��|j�|�|j�t�dS)z#Handle comments as Comment objects.N)r(rdrhrrjrrr�comment)s
zLXMLTreeBuilderForXML.commentcCsd|S)�See `TreeBuilder`.z)<?xml version="1.0" encoding="utf-8"?>
%sr�r'Zfragmentrrr�test_fragment_to_document/sz/LXMLTreeBuilderForXML.test_fragment_to_document)NN)NNN)'�__name__�
__module__�__qualname__rr2ZDEFAULT_PARSER_CLASSrFrrG�NAME�ALTERNATE_NAMES�LXMLrr
r�featuresrNrr&r!r:r$r%r4r7r<rDrKrPrRr`rZrfrirVrlrmrp�
__classcell__rrr)rr(s:
		�
3.	c@sFeZdZeZdgZeeeeegZ	dZ
eZdd�Z
dd�Zdd�Zd	S)
rz	lxml-htmlFcCstjSr)rZ
HTMLParserr3rrrr4=szLXMLTreeBuilder.default_parserc
Csf|jj}z&|�|�|_|j�|�|j��Wn2tttj	fk
r`}zt
|��W5d}~XYnXdSr)r(rOr7r6rPrRrSrTrrUr)r'rJr0rWrrrrP@szLXMLTreeBuilder.feedcCsd|S)rnz<html><body>%s</body></html>rrorrrrpJsz)LXMLTreeBuilder.test_fragment_to_documentN)rqrrrsrvrtrurr
rrwrFrrGr4rPrprrrrr4s
) Z__license__�__all__Zcollections.abcr�ImportErrorrW�collections�iorrrrZbs4.elementrr	r
rrZbs4.builderr
rrrrrrZ
bs4.dammitrrvr!rrrrrr�<module>s&�$