o
    ì6Wj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w W n ey/   dZdZY nw 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dedejeef fdd„Zdd„ ZdS )é    Nc                 C   s   t  | ¡d pdS )NÚencodingÚ )ÚchardetÚdetect)Údata© r   úc/home/esfera/Documents/content_generation/venv/lib/python3.10/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 ]}| d¡\}}}| ¡  ¡ dkr0| ¡  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   ÚchunksÚ	mime_typeÚ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r(d}|dd… }n||dd… t jkrB|dd… tkrBd}|dd… }nb|dd… t jkr\|dd… tkr\d}|dd… }nH|dd	… t jkrnd
}|d	d… }n6|dd… tkryd}n+|dd… tkr„d}n |dd… t	kr�d}n|dd… t
kršd}n
|dd… tkr¤d}|}z|r±| |¡ d
¡}W n ttfy¿   d}Y nw 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
}n8||v �s| d¡�r!| d¡�r!d}	|�pd}n| d¡�r-|�p+d}n| �r;d| v�r;|�p9d}n|�p?d
}| ¡ dk�rId}| ¡ dk�rRd}d}| �rl|	�sld| v �rfd| d  }nd}t|ƒ}d}g }|||td
ddfD ]M}t|ƒ�r„||ƒ}|�s‰�qy||v �r��qy| |¡ z| |¡}W n ttf�y©   Y �qyw d}d}t |¡�r»t ||¡}n|d | }| d
¡} |�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-4Úcsucs4Ú	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   TÚbozoÚ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   )Úhttp_headersr   ÚresultÚbom_encodingÚxml_encodingÚtempdataÚxml_encoding_matchÚhttp_content_typeÚhttp_encodingÚacceptable_content_typeÚapplication_content_typesÚtext_content_typesÚrfc3023_encodingÚerrorÚmsgÚknown_encodingÚtried_encodingsÚproposed_encodingÚnew_declarationr   r   r   Úconvert_to_utf8_   sî   /	""€ü
þý
þý

ÿ


ÿ
ÿÿÿ
ÿÿr]   )r0   ÚreÚtypingÚtÚcchardetr   ÚImportErrorr	   Ú
exceptionsr   r   r   r7   r8   r9   r:   r;   r4   ÚcompilerH   r@   ÚstrÚTupler   r]   r   r   r   r   Ú<module>   s4   ÿ€þ	

