
    Ƒi8                        S r SSKJr  SSKrSSKJr  SSKJr  SSKJ	r	  SSK
JrJr  SSKJrJr  SS	KJrJr  SS
KJrJr  SSKJr  \" SSSS9r " S S5      rg)u3   UniversalDetector — streaming encoding detection.    )annotationsN)MappingProxyType)ClassVar)_utils)DEFAULT_MAX_BYTES_validate_max_bytes)EncodingEraLanguageFilter)PREFERRED_SUPERSETapply_legacy_rename)DetectionDictDetectionResult)run_pipelineg        )encoding
confidencelanguagec                      \ rS rSr% Sr\R                  r\" \5      r	S\
S'   \R                  S\R                  \4         SS jjrSS jrSS jrSS	 jr\SS
 j5       r\SS j5       rSrg)UniversalDetector   a  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_MAPTc                    U[         R                  :w  a  [        R                  " S[        SS9  X l        [        U5        X0l        X@l        [        5       U l
        SU l        SU l        SU l        g)a  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: If ``True`` (the default), remap legacy
    encoding names to their modern equivalents.
: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.
zMlang_filter is not implemented in this version of chardet and will be ignored   )
stacklevelFN)r
   ALLwarningswarnDeprecationWarning_rename_legacyr   _encoding_era
_max_bytes	bytearray_buffer_done_closed_result)selflang_filtershould_rename_legacyencoding_era	max_bytess        P/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/chardet/detector.py__init__UniversalDetector.__init__*   sb    $ .,,,MM&"	 3I&)# {
/3    c                F   U R                   (       a  Sn[        U5      eU R                  (       a  gU R                  [	        U R
                  5      -
  nUS:  a  U R
                  R                  USU 5        [	        U R
                  5      U R                  :  a  SU l        gg)aY  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#   r    lenr"   extend)r&   byte_strmsg	remainings       r+   feedUniversalDetector.feedL   s|     <<?CS/!::OOc$,,&77	q=LL) 45t||/DJ 0r.   c                    U R                   (       dK  SU l         [        U R                  5      n[        XR                  U R
                  S9nUS   U l        SU l        U R                  $ )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$   bytesr"   r   r   r    r%   r#   result)r&   dataresultss      r+   closeUniversalDetector.closeb   sR     ||DL&D"4););tWG"1:DLDJ{{r.   c                L    [        5       U l        SU l        SU l        SU l        g)z2Reset the detector to its initial state for reuse.FN)r!   r"   r#   r$   r%   r&   s    r+   resetUniversalDetector.resetr   s      {
r.   c                    U R                   $ )z9Whether detection is complete and no more data is needed.)r#   r@   s    r+   doneUniversalDetector.doney   s     zzr.   c                    U R                   b8  U R                   R                  5       nU R                  (       a  [        U5        U$ [        R                  5       $ )z"The current best detection result.)r%   to_dictr   r   _NONE_RESULT)r&   ds     r+   r:   UniversalDetector.result~   sE     <<#$$&A""#A&H##%%r.   )r"   r$   r#   r   r    r   r%   N)
r'   r
   r(   boolr)   r	   r*   intreturnNone)r3   zbytes | bytearrayrM   rN   )rM   r   )rM   rN   )rM   rK   )__name__
__module____qualname____firstlineno____doc__r   MINIMUM_THRESHOLDr   r   r   __annotations__r
   r   r	   r   r,   r6   r=   rA   propertyrD   r:   __static_attributes__ r.   r+   r   r      s     00 8H8J4  '5&8&8%)$/OO* 4# 4 # 4 "	 4
  4 
 4D,    & &r.   r   )rS   
__future__r   r   typesr   typingr   chardetr   chardet._utilsr   r   chardet.enumsr	   r
   chardet.equivalencesr   r   chardet.pipeliner   r   chardet.pipeline.orchestratorr   rH   r   rX   r.   r+   <module>rb      s@    9 "  "   A 5 H ; 6tLs& s&r.   