
    vKg                     v    S SK r S SKrS SKJr  S SKJr   " S S\ R                  5      rS rS r	S
S jr
SS	 jrg)    N)error)univc                       \ rS rSrSrS rS rS rS\R                  4S jr
SS jr\S	 5       r\R                  S
 5       rS rSrg)CachingStreamWrapper   a  Wrapper around non-seekable streams.

Note that the implementation is tied to the decoder,
not checking for dangerous arguments for the sake
of performance.

The read bytes are kept in an internal cache until
setting _markedPosition which may reset the cache.
c                 R    Xl         [        R                  " 5       U l        SU l        g Nr   )_rawioBytesIO_cache_markedPosition)selfraws     V/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/pyasn1/codec/streaming.py__init__CachingStreamWrapper.__init__   s    	jjl     c                     U R                  U5      nU R                  R                  [        U5      * [        R
                  5        U$ N)readr   seeklenosSEEK_CUR)r   nresults      r   peekCachingStreamWrapper.peek   s2    1#f+r{{3r   c                     g)NT r   s    r   seekableCachingStreamWrapper.seekable!   s    r   c                 8    U R                   R                  X5      $ r   )r   r   )r   r   whences      r   r   CachingStreamWrapper.seek$   s    {{**r   c                     U R                   R                  U5      nUS:w  a  U[        U5      -  nU(       d  U$ U R                  R                  U5      nU R                   R	                  U5        X#-   $ )Nr%   )r   r   r   r
   write)r   r   read_from_cacheread_from_raws       r   r   CachingStreamWrapper.read(   sb    ++**1-7_%%A&&		q)-(..r   c                     U R                   $ )zPosition where the currently processed element starts.

This is used for back-tracking in SingleItemDecoder.__call__
and (indefLen)ValueDecoder and should not be used for other purposes.
The client is not supposed to ever seek before this position.
)r   r"   s    r   markedPosition#CachingStreamWrapper.markedPosition5   s     ###r   c                     Xl         U R                  R                  5       [        R                  :  a;  [        R
                  " U R                  R                  5       5      U l        SU l         g g r	   )r   r   tellr   DEFAULT_BUFFER_SIZEr   r   )r   values     r   r/   r0   ?   sQ    
  %
 ;; 6 66**T[[%5%5%78DK#$D  7r   c                 6    U R                   R                  5       $ r   )r   r2   r"   s    r   r2   CachingStreamWrapper.tellM   s    {{!!r   )r   r   r
   Nr%   )__name__
__module____qualname____firstlineno____doc__r   r   r#   r   SEEK_SETr   r   propertyr/   setterr2   __static_attributes__r!   r   r   r   r      s^    !

  +/ $ $ % %"r   r   c                    [        U [        R                  5      (       a  U $ [        U [        5      (       a  [        R                  " U 5      $ [        U [        R
                  5      (       a$  [        R                  " U R                  5       5      $  U R                  5       (       a  U $ [        U 5      $ ! [         a1    [        R                  " SU R                  R                  -   S-   5      ef = f)a=  Convert object to seekable byte-stream.

Parameters
----------
substrate: :py:class:`bytes` or :py:class:`io.IOBase` or :py:class:`univ.OctetString`

Returns
-------
: :py:class:`io.IOBase`

Raises
------
: :py:class:`~pyasn1.error.PyAsn1Error`
    If the supplied substrate cannot be converted to a seekable stream.
zCannot convert z to a seekable bit stream.)
isinstancer   r   bytesr   OctetStringasOctetsr#   r   AttributeErrorr   UnsupportedSubstrateError	__class__r8   )	substrates    r   asSeekableStreamrJ   Q   s      )RZZ((	Iu	%	%zz)$$	It//	0	0zz),,.//	*'	22 *--	 3 3 < <<()* 	**s   B3 (
B3 3;C.c              #     #    [        U [        R                  5      (       ah  U R                  5       nU R	                  S[
        R                  5        U R                  5       U:H  nU R	                  U[
        R                  5        Uv   gU R                  S5      nUc  Sv   U(       a   U R	                  S[
        R                  5        U(       + v   g7f)zCheck whether we have reached the end of a stream.

Although it is more effective to read and catch exceptions, this
function

Parameters
----------
substrate: :py:class:`IOBase`
    Stream to check

Returns
-------
: :py:class:`bool`
r      Nr%   )
rB   r   r   r2   r   r   SEEK_ENDr=   r   r   )rI   cpr   receiveds       r   isEndOfStreamrP   v   s      )RZZ((^^q"++&!R'r2;;' >>!$NN2r{{+ls   CCc              #   L  #    [        U S5      (       aA  U R                  U5      nUc  Sv   [        U5      U:  a  Sv   [        U5      U:  a  M  Uv   gU R                  5       n [	        X5       H  nUv   M	     U R                  U5        g! U R                  U5        f = f7f)a  Peek into stream.

Parameters
----------
substrate: :py:class:`IOBase`
    Stream to read from.

size: :py:class:`int`
    How many bytes to peek (-1 = all available)

Returns
-------
: :py:class:`bytes` or :py:class:`str`
    The return type depends on Python major version
r   N)hasattrr   r   r2   readFromStreamr   )rI   sizerO   current_positionchunks        r   peekIntoStreamrW      s       y&!!>>$'(md" (md"  %>>+	-'	8 9 NN+,INN+,s$   AB$B$&B <B$B!!B$c              #   T  #     U R                  U5      nUc  [        R                  " US9v   OrU(       d  US:w  a  [        R                  " US9e[	        U5      U:  aA  U R                  [	        U5      * [        R                  5        [        R                  " US9v   OOM  Uv   g7f)a  Read from the stream.

Parameters
----------
substrate: :py:class:`IOBase`
    Stream to read from.

Keyword parameters
------------------
size: :py:class:`int`
    How many bytes to read (-1 = all available)

context: :py:class:`dict`
    Opaque caller context will be attached to exception objects created
    by this function.

Yields
------
: :py:class:`bytes` or :py:class:`str` or :py:class:`SubstrateUnderrunError`
    Read data or :py:class:`~pyasn1.error.SubstrateUnderrunError`
    object if no `size` bytes is readily available in the stream. The
    data type depends on Python major version

Raises
------
: :py:class:`~pyasn1.error.EndOfStreamError`
    Input stream is exhausted
N)contextr   )r   r   SubstrateUnderrunErrorEndOfStreamErrorr   r   r   r   )rI   rT   rY   rO   s       r   rS   rS      s     : >>$'..w??dai((99]T!NNCM>2;;7 ..w?? ! $ Ns   B&B(r7   )r%   N)r   r   pyasn1r   pyasn1.typer   IOBaser   rJ   rP   rW   rS   r!   r   r   <module>r_      s=    
 	  A"299 A"H"*JB!-H/r   