
    *pj}                        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  SSKJrJrJr  SS	KJrJr  SS
KJrJrJr  SSKJrJrJr  SSKJr  SSKJrJr   " S S5      r g)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                     \ rS rSr% Sr\R                  r\" \5      r	S\
S'   \R                  S\R                  \4SSSSSS	S
.                     SS j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_MAPFTNcp1252zutf-8)prefer_supersetcompat_namesinclude_encodingsexclude_encodingsno_match_encodingempty_input_encodingc                  U[         R                  :w  a  [        R                  " S[        SS9  [        X%5      nXPl        X`l        [        U5        X0l	        X@l
        [        US5      U l        [        US5      U l        [        U	S5      U l        [        U
S5      U l        [#        5       U l        SU l        SU l        SU l        S	U l        g	)
ab  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 subset encodings in the
    result to their decode-safe Windows/CP superset equivalents
    (e.g., ISO-8859-1 -> Windows-1252).  If ``False`` (default),
    skip the renaming --- not a promise of the smallest matching
    encoding.  The default will change to ``True`` in chardet 8.0.
    See :func:`chardet.detect` for details.
: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_input_truncated_done_closed_result)selflang_filtershould_rename_legacyencoding_era	max_bytesr   r   r   r   r   r    s              L/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/chardet/detector.py__init__UniversalDetector.__init__2   s    R .,,,MM&"	 3 
 !0)I&)#"52#
 #62#
 #52#
 &8 "8&
" !{ %
/3    c                   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5      [        US5      :  a  SU l        [	        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)	r4   
ValueErrorr3   r+   lenr1   extendmaxr2   )r6   byte_strmsg	remainings       r;   feedUniversalDetector.feed|   s     <<?CS/!::OOc$,,&77	q=LL) 45x=3y!,, %)D!t||/DJ 0r>   c                B   U R                   (       d  SU l         [        U R                  5      n[        UU R                  U R
                  U R                  U R                  U R                  U 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:   input_truncatedr   r   r   r    r   )r4   bytesr1   r   r*   r+   r2   r,   r-   r.   r/   r5   r3   result)r6   dataresultss      r;   closeUniversalDetector.close   s     ||DL&D"""// $ 5 5"&"9"9"&"9"9"&"9"9%)%?%?	G #1:DLDJ{{r>   c                Z    [        5       U l        SU l        SU l        SU l        SU l        g)z2Reset the detector to its initial state for reuse.FN)r0   r1   r2   r3   r4   r5   r6   s    r;   resetUniversalDetector.reset   s(     { %
r>   c                    U R                   $ )z9Whether detection is complete and no more data is needed.)r3   rR   s    r;   doneUniversalDetector.done   s     zzr>   c                    U R                   bT  U R                   R                  5       nU R                  (       a  [        U5        U R                  (       a  [        U5        U$ [        R                  " 5       $ )z"The current best detection result.)r5   to_dictr(   r   r)   r   r   )r6   ds     r;   rL   UniversalDetector.result   sV     <<#$$&A$$(+!!"1%H##%%r>   )r1   r4   r)   r3   r/   r*   r-   r,   r2   r+   r.   r(   r5   )r7   r   r8   boolr9   r   r:   intr   r\   r   r\   r   Iterable[str] | Noner   r^   r   strr    r_   returnNone)rD   zbytes | bytearrayr`   ra   )r`   r   )r`   ra   )r`   r\   )__name__
__module____qualname____firstlineno____doc__r   MINIMUM_THRESHOLDr   r   r   __annotations__r   r$   r   r   r<   rG   rO   rS   propertyrV   rL   __static_attributes__ r>   r;   r   r      s    00 8H8J4  '5&8&8%*$/OO*H4 !&!2626!)$+H4#H4 #H4 "	H4
 H4 H4 H4 0H4 0H4 H4 "H4 
H4T62   	& 	&r>   r   )!rf   
__future__r   r%   collections.abcr   typesr   typingr   chardetr   chardet._utilsr   r	   r
   chardet.enumsr   r   chardet.output_namesr   r   r   chardet.pipeliner   r   r   chardet.pipeline.orchestratorr   chardet.registryr   r   r   rk   r>   r;   <module>rw      sN    9 "  $ "   
 6 
 J I 6 Dl& l&r>   