Ë
    ÄÏÉi8  ã                  ó¶   — 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mZ ddlmZmZ dd	lmZmZ dd
lmZmZ ddlmZ  eddd¬«      Z G d„ d«      Zy)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                  óÌ   — 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„Zdd„Zdd„Zdd„Zedd	„«       Zedd
„«       Zy)Ú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_MAPTc                óê   — |t         j                  k7  rt        j                  dt        d¬«       || _        t        |«       || _        || _        t        «       | _
        d| _        d| _        d| _        y)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        ú`/Users/bowang/.openclaw/workspace/ChatDev/.venv/lib/python3.12/site-packages/chardet/detector.pyÚ__init__zUniversalDetector.__init__*   sh   € ð$ œ.×,Ñ,Ò,ÜM‰Mð&ä"Øõ	ð 3ˆÔÜ˜IÔ&Ø)ˆÔØ#ˆŒÜ “{ˆŒØˆŒ
ØˆŒØ/3ˆó    c                ó.  — | j                   rd}t        |«      ‚| j                  ry| j                  t	        | j
                  «      z
  }|dkD  r| j
                  j                  |d| «       t	        | j
                  «      | j                  k\  rd| _        yy)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"   r   Úlenr!   Úextend)r%   Úbyte_strÚmsgÚ	remainings       r*   ÚfeedzUniversalDetector.feedL   s|   € ð <Š<Ø?ˆCÜ˜S“/Ð!Ø:Š:ØØ—O‘O¤c¨$¯,©,Ó&7Ñ7ˆ	ØqŠ=ØL‰L×Ñ ¨¨)Ð 4Ô5Üˆt|‰|Ó §¡Ò/ØˆDJð 0r,   c                óÐ   — | j                   sOd| _         t        | j                  «      }t        || j                  | j
                  ¬«      }|d   | _        d| _        | j                  S )zãFinalize 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*   ÚclosezUniversalDetector.closeb   sT   € ð |Š|ØˆDŒLÜ˜Ÿ™Ó&ˆDÜ" 4¨×);Ñ);ÀtÇÁÔWˆGØ" 1™:ˆDŒLØˆDŒJØ{‰{Ðr,   c                óL   — t        «       | _        d| _        d| _        d| _        y)z2Reset the detector to its initial state for reuse.FN)r    r!   r"   r#   r$   ©r%   s    r*   ÚresetzUniversalDetector.resetr   s    € ä “{ˆŒØˆŒ
ØˆŒØˆr,   c                ó   — | j                   S )z9Whether detection is complete and no more data is needed.)r"   r<   s    r*   ÚdonezUniversalDetector.doney   s   € ð z‰zÐr,   c                ó¨   — | j                   3| j                   j                  «       }| j                  rt        |«       |S t        j                  «       S )z"The current best detection result.)r$   Úto_dictr   r   Ú_NONE_RESULT)r%   Úds     r*   r7   zUniversalDetector.result~   sE   € ð <‰<Ð#Ø—‘×$Ñ$Ó&ˆAØ×"Ò"Ü# AÔ&ØˆHÜ×#Ñ#Ó%Ð%r,   N)
r&   r
   r'   Úboolr(   r	   r)   ÚintÚreturnÚNone)r1   zbytes | bytearrayrF   rG   )rF   r   )rF   rG   )rF   rD   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚMINIMUM_THRESHOLDr   r   r   Ú__annotations__r
   r   r	   r   r+   r4   r:   r=   Úpropertyr?   r7   © r,   r*   r   r      s²   … ñð ×0Ñ0Ðñ 8HØó8€JÐ4ó ð '5×&8Ñ&8Ø%)Ø$/§O¡OØ*ð 4à#ð 4ð #ð 4ð "ð	 4ð
 ð 4ð 
ó 4óDó,ó ð òó ðð ò&ó ñ&r,   r   )rK   Ú
__future__r   r   Útypesr   Útypingr   Úchardetr   Úchardet._utilsr   r   Úchardet.enumsr	   r
   Úchardet.equivalencesr   r   Úchardet.pipeliner   r   Úchardet.pipeline.orchestratorr   rB   r   rO   r,   r*   Ú<module>rY      s@   ðÙ 9å "ã Ý "Ý å ß Aß 5ß Hß ;Ý 6á¨¸ÀtÔL€÷s&ò s&r,   