
    i                    *   d Z ddlmZ ddlZddlmZ dZddZi Z e	dd      D  cg c]  } d	|  	 c} d
D  cg c]  } d|  	 c} z    e	dd      D  cg c]  } d|  	 c} z   dgz   Z
e
D ]  Z edez         Z ee      ee<    yc c} w c c} w c c} w )u,  
`ftfy.bad_codecs.sloppy` provides character-map encodings that fill their "holes"
in a messy but common way: by outputting the Unicode codepoints with the same
numbers.

This is incredibly ugly, and it's also in the HTML5 standard.

A single-byte encoding maps each byte to a Unicode character, except that some
bytes are left unmapped. In the commonly-used Windows-1252 encoding, for
example, bytes 0x81 and 0x8D, among others, have no meaning.

Python, wanting to preserve some sense of decorum, will handle these bytes
as errors. But Windows knows that 0x81 and 0x8D are possible bytes and they're
different from each other. It just hasn't defined what they are in terms of
Unicode.

Software that has to interoperate with Windows-1252 and Unicode -- such as all
the common Web browsers -- will pick some Unicode characters for them to map
to, and the characters they pick are the Unicode characters with the same
numbers: U+0081 and U+008D. This is the same as what Latin-1 does, and the
resulting characters tend to fall into a range of Unicode that's set aside for
obsolete Latin-1 control characters anyway.

These sloppy codecs let Python do the same thing, thus interoperating with
other software that works this way. It defines a sloppy version of many
single-byte encodings with holes. (There is no need for a sloppy version of
an encoding without holes: for example, there is no such thing as
sloppy-iso-8859-2 or sloppy-macroman.)

The following encodings will become defined:

- sloppy-windows-1250 (Central European, sort of based on ISO-8859-2)
- sloppy-windows-1251 (Cyrillic)
- sloppy-windows-1252 (Western European, based on Latin-1)
- sloppy-windows-1253 (Greek, sort of based on ISO-8859-7)
- sloppy-windows-1254 (Turkish, based on ISO-8859-9)
- sloppy-windows-1255 (Hebrew, based on ISO-8859-8)
- sloppy-windows-1256 (Arabic)
- sloppy-windows-1257 (Baltic, based on ISO-8859-13)
- sloppy-windows-1258 (Vietnamese)
- sloppy-cp874 (Thai, based on ISO-8859-11)
- sloppy-iso-8859-3 (Maltese and Esperanto, I guess)
- sloppy-iso-8859-6 (different Arabic)
- sloppy-iso-8859-7 (Greek)
- sloppy-iso-8859-8 (Hebrew)
- sloppy-iso-8859-11 (Thai)

Aliases such as "sloppy-cp1252" for "sloppy-windows-1252" will also be
defined.

Five of these encodings (`sloppy-windows-1250` through `sloppy-windows-1254`)
are used within ftfy.

Here are some examples, using :func:`ftfy.explain_unicode` to illustrate how
sloppy-windows-1252 merges Windows-1252 with Latin-1:

    >>> from ftfy import explain_unicode
    >>> some_bytes = b'\x80\x81\x82'
    >>> explain_unicode(some_bytes.decode('latin-1'))
    U+0080  \x80    [Cc] <unknown>
    U+0081  \x81    [Cc] <unknown>
    U+0082  \x82    [Cc] <unknown>

    >>> explain_unicode(some_bytes.decode('windows-1252', 'replace'))
    U+20AC  €       [Sc] EURO SIGN
    U+FFFD  �       [So] REPLACEMENT CHARACTER
    U+201A  ‚       [Ps] SINGLE LOW-9 QUOTATION MARK

    >>> explain_unicode(some_bytes.decode('sloppy-windows-1252'))
    U+20AC  €       [Sc] EURO SIGN
    U+0081  \x81    [Cc] <unknown>
    U+201A  ‚       [Ps] SINGLE LOW-9 QUOTATION MARK
    )annotationsN)normalize_encodingu   �c           	        t        t        d            }t        |j                  d            }|j                  | d      }t	        |      D ]  \  }}|t
        k7  s|||<    t
        |d<   dj                  |      t        j                         G fddt        j                        } G fd	d
t        j                        } G fddt        j                        } G d d|t        j                        }	 G d d|t        j                        }
t        j                  d| z    |       j                   |       j                  |||
|	      S )a  
    Take a codec name, and return a 'sloppy' version of that codec that can
    encode and decode the unassigned bytes in that encoding.

    Single-byte encodings in the standard library are defined using some
    boilerplate classes surrounding the functions that do the actual work,
    `codecs.charmap_decode` and `charmap_encode`. This function, given an
    encoding name, *defines* those boilerplate classes.
       zlatin-1replace)errors    c                  *    e Zd ZddfdZdd fdZy) make_sloppy_codec.<locals>.Codecc                2    t        j                  ||      S N)codecscharmap_encode)selfinputr   encoding_tables      r/home/developers/rajanand/mypropertyqr-fmb-refixing-v2/venv/lib/python3.12/site-packages/ftfy/bad_codecs/sloppy.pyencodez'make_sloppy_codec.<locals>.Codec.encode{       ((GG    c                2    t        j                  ||      S r   )r   charmap_decode)r   r   r   decoding_tables      r   decodez'make_sloppy_codec.<locals>.Codec.decode~   r   r   N)strict)r   strr   
str | Nonereturnztuple[bytes, int])r   bytesr   r   r   ztuple[str, int])__name__
__module____qualname__r   r   )r   r   s   r   Codecr   z   s    	H	Hr   r$   c                      e Zd Zdd fdZy)-make_sloppy_codec.<locals>.IncrementalEncoderc                L    t        j                  || j                        d   S Nr   )r   r   r   )r   r   finalr   s      r   r   z4make_sloppy_codec.<locals>.IncrementalEncoder.encode   !    ((^LQOOr   NF)r   r   r)   boolr   r    )r!   r"   r#   r   )r   s   r   IncrementalEncoderr&      	    	Pr   r-   c                      e Zd Zdd fdZy)-make_sloppy_codec.<locals>.IncrementalDecoderc                L    t        j                  || j                        d   S r(   )r   r   r   )r   r   r)   r   s      r   r   z4make_sloppy_codec.<locals>.IncrementalDecoder.decode   r*   r   Nr+   )r   r    r)   r,   r   r   )r!   r"   r#   r   )r   s   r   IncrementalDecoderr0      r.   r   r2   c                      e Zd Zy)'make_sloppy_codec.<locals>.StreamWriterNr!   r"   r#    r   r   StreamWriterr4          r   r7   c                      e Zd Zy)'make_sloppy_codec.<locals>.StreamReaderNr5   r6   r   r   StreamReaderr:      r8   r   r;   sloppy-)namer   r   incrementalencoderincrementaldecoderstreamreaderstreamwriter)r    rangelistr   	enumerateREPLACEMENT_CHARjoinr   charmap_buildr$   r-   r2   r7   r;   	CodecInfor   )encoding	all_bytessloppy_charsdecoded_charsicharr$   r-   r2   r7   r;   r   r   s              @@r   make_sloppy_codecrO   S   s6    eCj!I 	((34L $$Xi$@M
 ]+ #4##"LO# *L WW\*N)).9N
H HPV66 PPV66 Puf11 uf11  !w~~w~~--!! r   i  i  zwindows-)               z	iso-8859-cpcp874r<   )rI   r   r   zcodecs.CodecInfo)__doc__
__future__r   r   	encodingsr   rE   rO   CODECSrB   INCOMPLETE_ENCODINGS	_encoding	_new_name)nums   0r   <module>r_      s   HT #  ( DR 
!&tT!23#xu3$45S3%56"4./cC5z/0 i  & 5I"9y#89I))4F95 45/s   BBB