
    f j                        d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZmZmZ dd	lmZmZ dd
lmZmZmZ ddlmZmZmZ ddlmZ ddlmZmZ  G d d          Z dS )u3   UniversalDetector — streaming encoding detection.    )annotationsN)Iterable)MappingProxyType)ClassVar)_utils)DEFAULT_MAX_BYTES_resolve_prefer_superset_validate_max_bytes)EncodingEraLanguageFilter)PREFERRED_SUPERSETapply_compat_namesapply_preferred_superset)_NONE_RESULTDetectionDictDetectionResult)run_pipeline)_validate_encodingnormalize_encodingsc                      e Zd ZU dZej        Z ee          Zde	d<   e
j        dej        efddddddd	d%dZd&dZd'd!Zd(d"Zed)d#            Zed'd$            ZdS )*UniversalDetectora  Streaming character encoding detector.

    Implements a feed/close pattern for incremental detection of character
    encoding from byte streams.  Compatible with the chardet 6.x API.

    All detection is performed by the same pipeline used by
    :func:`chardet.detect` and :func:`chardet.detect_all`, ensuring
    consistent results regardless of which API is used.

    .. note::

        This class is **not** thread-safe.  Each thread should create its own
        :class:`UniversalDetector` instance.
    z$ClassVar[MappingProxyType[str, str]]
LEGACY_MAPFTNcp1252zutf-8)prefer_supersetcompat_namesinclude_encodingsexclude_encodingsno_match_encodingempty_input_encodinglang_filterr   should_rename_legacyboolencoding_erar   	max_bytesintr   r   r   Iterable[str] | Noner   r   strr   returnNonec                  |t           j        k    rt          j        dt          d           t          ||          }|| _        || _        t          |           || _	        || _
        t          |d          | _        t          |d          | _        t          |	d          | _        t          |
d          | _        t#                      | _        d| _        d| _        d	| _        d	S )
a3  Initialize the detector.

        :param lang_filter: Deprecated -- accepted for backward compatibility
            but has no effect.  A warning is emitted when set to anything
            other than :attr:`LanguageFilter.ALL`.
        :param should_rename_legacy: Deprecated alias for *prefer_superset*.
        :param encoding_era: Restrict candidate encodings to the given era.
        :param max_bytes: Maximum number of bytes to buffer from
            :meth:`feed` calls before stopping accumulation.
        :param prefer_superset: If ``True``, remap ISO subset encodings to
            their Windows/CP superset equivalents (e.g., ISO-8859-1 ->
            Windows-1252).
        :param compat_names: If ``True`` (default), return encoding names
            compatible with chardet 5.x/6.x.  If ``False``, return raw Python
            codec names.
        :param include_encodings: If given, restrict detection to only these
            encodings (names or aliases).
        :param exclude_encodings: If given, remove these encodings from the
            candidate set.
        :param no_match_encoding: Encoding to return when no candidate
            survives the pipeline.  Defaults to ``"cp1252"``.
        :param empty_input_encoding: Encoding to return for empty input.
            Defaults to ``"utf-8"``.
        zMlang_filter is not implemented in this version of chardet and will be ignored   )
stacklevelr   r   r   r   FN)r   ALLwarningswarnDeprecationWarningr	   _prefer_superset_compat_namesr
   _encoding_era
_max_bytesr   _include_encodings_exclude_encodingsr   _no_match_encoding_empty_input_encoding	bytearray_buffer_done_closed_result)selfr    r!   r#   r$   r   r   r   r   r   r   s              dC:\Users\Terasoftware\OneDrive\Desktop\faahhh\fyndo\fyndo\venv\Lib\site-packages\chardet/detector.py__init__zUniversalDetector.__init__2   s
   L .,, 	M&"	    3 /
 
 !0)I&&&)#"52#
 #
 #62#
 #
 #52#
 #
 &8 "8&
 &
" !{{
/3    byte_strbytes | bytearrayc                   | j         rd}t          |          | j        rdS | j        t	          | j                  z
  }|dk    r"| j                            |d|                    t	          | j                  | j        k    r	d| _        dS dS )a  Feed a chunk of bytes to the detector.

        Data is accumulated in an internal buffer.  Once *max_bytes* have
        been buffered, :attr:`done` is set to ``True`` and further data is
        ignored until :meth:`reset` is called.

        :param byte_str: The next chunk of bytes to examine.
        :raises ValueError: If called after :meth:`close` without a
            :meth:`reset`.
        z+feed() called after close() without reset()Nr   T)r<   
ValueErrorr;   r4   lenr:   extend)r>   rB   msg	remainings       r?   feedzUniversalDetector.feedx   s     < 	"?CS//!: 	FOc$,&7&77	q= 	6L) 4555t|/ 	DJJJ	 	rA   r   c           	         | j         scd| _         t          | j                  }t          || j        | j        | j        | j        | j        | j	                  }|d         | _
        d| _        | j        S )zFinalize detection and return the best result.

        Runs the full detection pipeline on the buffered data.

        :returns: A dictionary with keys ``"encoding"``, ``"confidence"``,
            and ``"language"``.
        T)r$   r   r   r   r   r   )r<   bytesr:   r   r3   r4   r5   r6   r7   r8   r=   r;   result)r>   dataresultss      r?   closezUniversalDetector.close   sz     | 	DL&&D""/"&"9"&"9"&"9%)%?  G #1:DLDJ{rA   c                V    t                      | _        d| _        d| _        d| _        dS )z2Reset the detector to its initial state for reuse.FN)r9   r:   r;   r<   r=   r>   s    r?   resetzUniversalDetector.reset   s&     {{
rA   c                    | j         S )z9Whether detection is complete and no more data is needed.)r;   rR   s    r?   donezUniversalDetector.done   s     zrA   c                    | j         G| j                                         }| j        rt          |           | j        rt          |           |S t          j                    S )z"The current best detection result.)r=   to_dictr1   r   r2   r   r   )r>   ds     r?   rM   zUniversalDetector.result   sg     < 	$$&&A$ ,(+++! &"1%%%H#%%%rA   )r    r   r!   r"   r#   r   r$   r%   r   r"   r   r"   r   r&   r   r&   r   r'   r   r'   r(   r)   )rB   rC   r(   r)   )r(   r   )r(   r)   )r(   r"   )__name__
__module____qualname____doc__r   MINIMUM_THRESHOLDr   r   r   __annotations__r   r-   r   r   r@   rJ   rP   rS   propertyrU   rM    rA   r?   r   r      s%          0 8H7G8 8J     '5&8%*$/O*D4 !&!2626!)$+D4 D4 D4 D4 D4 D4L   ,   0       X 	& 	& 	& X	& 	& 	&rA   r   )!r\   
__future__r   r.   collections.abcr   typesr   typingr   chardetr   chardet._utilsr   r	   r
   chardet.enumsr   r   chardet.equivalencesr   r   r   chardet.pipeliner   r   r   chardet.pipeline.orchestratorr   chardet.registryr   r   r   r`   rA   r?   <module>rl      ss   9 9 " " " " " "  $ $ $ $ $ $ " " " " " "                     
 6 5 5 5 5 5 5 5         
 J I I I I I I I I I 6 6 6 6 6 6 D D D D D D D Da& a& a& a& a& a& a& a& a& a&rA   