a
    ‘´íj1  ã                   @   sÎ   d dl Z d dlZd dlZz,zd dlZW n ey@   d dlZY n0 W n ey^   dZdZY n
0 dd„ Zddlm	Z	m
Z
mZ dZdZdZd	Zd
ZdZe d¡Ze d¡Zeejeef dœdd„Zdd„ ZdS )é    Nc                 C   s   t  | ¡d pdS )NÚencodingÚ )ÚchardetÚdetect)Údata© r   úS/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/feedparser/encodings.pyÚlazy_chardet_encoding*   s    r	   é   )ÚCharacterEncodingOverrideÚCharacterEncodingUnknownÚNonXMLContentTypes   Lo§”s    < ?s   < ? s      <s   <   z  z^<\?xml[^>]*?>s#   ^<\?.*encoding=[\'"](.*?)[\'"].*\?>)ÚlineÚreturnc                 C   sj   |   d¡}|sdS |d  ¡ }d}|dd… D ]2}| d¡\}}}| ¡  ¡ dkr.| ¡  d	¡}q.||fS )
a  Parse an HTTP Content-Type header.

    The return value will be a tuple of strings:
    the MIME type, and the value of the "charset" (if any).

    This is a custom replacement for Python's cgi.parse_header().
    The cgi module will be removed in Python 3.13.
    ú;)r   r   r   r   r
   Nú=Úcharsetz"')ÚsplitÚstripÚ	partitionÚlower)r   ÚchunksZ	mime_typeZcharset_valueÚchunkÚkeyÚ_Úvaluer   r   r   Úparse_content_typeG   s    

r   c              
   C   s  d}d}|dd… t jkr.d}|dd… }�n&|dd… t jkrTd}|dd… }�n |dd… t jkrˆ|dd… tkrˆd}|dd… }nÌ|dd… t jkr¼|dd… tkr¼d}|dd… }n˜|dd	… t jkràd
}|d	d… }nt|dd… tkröd}n^|dd… tk�rd}nF|dd… t	k�r&d}n.|dd… t
k�r>d}n|dd… tk�rTd}|}z|�rp| |¡ d
¡}W n ttf�yŽ   d}Y n0 t |¡}|�rÊ| ¡ d  d
¡ ¡ }|�rÊ|dv �rÊ|}|  d¡�pØd}t|ƒ\}}d}	d}
d}||
v �s| d¡�r*| d¡�r*d}	|�p&|�p&d
}np||v �sL| d¡�r\| d¡�r\d}	|�pXd}n>| d¡�rt|�ppd}n&| �r�d| v�r�|�pŒd}n
|�p˜d
}| ¡ dk�r¬d}| ¡ dk�r¾d}d}| �rò|	�sòd| v �ræd| d  }nd}t|ƒ}d}g }|||td
ddfD ] }t|ƒ�r"||ƒ}|�s,�q||v �r:�q| |¡ z| |¡}W n ttf�yj   Y n@0 d}d}t |¡�rŽt ||¡}n|d | }| d
¡} �q®�q|�sÎtdd ||f  ƒ}d}n||k�rìt d!||f ƒ}|}||d"< |�r
d#|d$< ||d%< |S )&z|Detect and convert the character encoding to UTF-8.

    http_headers is a dictionary
    data is a raw string (not Unicode)r   Né   zutf-32bezutf-32leé   zutf-16bezutf-16leé   zutf-8Úcp037r   )Úu16zutf-16Úutf16Úutf_16Úu32zutf-32Úutf32Úutf_32ziso-10646-ucs-2ziso-10646-ucs-4Zcsucs4Z	csunicodezucs-2zucs-4zcontent-type)zapplication/xmlzapplication/xml-dtdz&application/xml-external-parsed-entity)ztext/xmlztext/xml-external-parsed-entityzapplication/z+xmlr
   ztext/zus-asciiz
iso-8859-1Úgb2312Úgb18030z%s is not an XML media typezno Content-type specifiedzwindows-1252z
iso-8859-2z&<?xml version='1.0' encoding='utf-8'?>Ú
z#document encoding unknown, I tried z>%s, %s, utf-8, windows-1252, and iso-8859-2 but nothing workedz)document declared as %s, but parsed as %sr   TZbozoZbozo_exception)!ÚcodecsÚBOM_UTF32_BEÚBOM_UTF32_LEÚBOM_UTF16_BEÚ
ZERO_BYTESÚBOM_UTF16_LEÚBOM_UTF8ÚEBCDIC_MARKERÚUTF16BE_MARKERÚUTF16LE_MARKERÚUTF32BE_MARKERÚUTF32LE_MARKERÚdecodeÚencodeÚUnicodeDecodeErrorÚLookupErrorÚRE_XML_PI_ENCODINGÚmatchÚgroupsr   Úgetr   Ú
startswithÚendswithr   r	   ÚcallableÚappendÚRE_XML_DECLARATIONÚsearchÚsubr   r   )Zhttp_headersr   ÚresultZbom_encodingZxml_encodingZtempdataZxml_encoding_matchZhttp_content_typeZhttp_encodingZacceptable_content_typeZapplication_content_typesZtext_content_typesZrfc3023_encodingÚerrorÚmsgZknown_encodingÚtried_encodingsZproposed_encodingZnew_declarationr   r   r   Úconvert_to_utf8_   sì    /	""

ÿýüÿýü

ÿ




ÿÿÿ
ÿÿrI   )r*   ÚreÚtypingÚtZcchardetr   ÚImportErrorr	   Ú
exceptionsr   r   r   r1   r2   r3   r4   r5   r.   ÚcompilerB   r:   ÚstrÚTupler   rI   r   r   r   r   Ú<module>   s,   
	

