yu p d dl Z d dlZd dlmZ d dlmZ G d de j Zd Zd Z dd Z
dd
ZdS )
N)error)univc ~ e Zd ZdZd Zd Zd Zdej fdZ ddZ
ed Zej
d Zd
ZdS )
CachingStreamWrappera 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 || _ t j | _ d| _ d S Nr )_rawioBytesIO_cache_markedPosition)selfraws v/builddir/build/BUILD/imunify360-venv-2.6.2/opt/imunify360/venv/lib/python3.11/site-packages/pyasn1/codec/streaming.py__init__zCachingStreamWrapper.__init__ s$ jll c | | }| j t | t j |S N)readr seeklenosSEEK_CUR)r nresults r peekzCachingStreamWrapper.peek s8 1#f++r{333
r c dS )NT r s r seekablezCachingStreamWrapper.seekable! s tr c 8 | j || S r )r r )r r whences r r zCachingStreamWrapper.seek$ s {6***r c | j | }|dk r|t | z }|s|S | j | }| j | ||z S )Nr! )r r r r write)r r read_from_cache
read_from_raws r r zCachingStreamWrapper.read( st +**1--77
_%%%A
'&& q))
-(((..r c | j S )a Position 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 markedPositionz#CachingStreamWrapper.markedPosition5 s
##r c || _ | j t j k r9t j | j | _ d| _ d S d S r )r
r tellr
DEFAULT_BUFFER_SIZEr r )r values r r) z#CachingStreamWrapper.markedPosition? s_
%
; 666*T[%5%5%7%788DK#$D 76r c 4 | j S r )r r+ r s r r+ zCachingStreamWrapper.tellM s {!!!r Nr! )__name__
__module____qualname____doc__r r r r SEEK_SETr r propertyr) setterr+ r r r r r
s ! ! !
+ + + +/ / / / $ $ X$ % % %" " " " "r r c t | t j r| S t | t rt j | S t | t j r&t j | S | r| S t | S # t $ r% t j d| j j
z dz w xY w)ai 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.
zCannot convert z to a seekable bit stream.)
isinstancer
r bytesr OctetStringasOctetsr r AttributeErrorr UnsupportedSubstrateError __class__r0 ) substrates r asSeekableStreamr@ Q s )RZ(( 0 Iu % % 0z)$$$ It/ 0 0 0z),,../// * 3' 222 * * *- 3 <<(
)* * **s B, B, ,/Cc # K t | t j rr| }| dt
j | |k }| |t
j |V dS | d }|dV |r | dt
j | V dS )a Check 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! )
r8 r
r r+ r r SEEK_ENDr4 r r )r? cpr receiveds r
isEndOfStreamrF v s )RZ((
^^
q"+&&&!!R'r2;''' >>!$$EEE ,NN2r{+++lr r! c # x K t | d rK| | }|dV t | |k rdV t | |k |V dS | } t | | D ]}|V | | dS # | | w xY w)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 r+ readFromStreamr )r? sizerE current_positionchunks r peekIntoStreamrM s y&!! ->>$''EEE(mmd""EEE (mmd"" %>>++ -' 488
NN+,,,,,INN+,,,,s 3B" "B9c # b K | | }|t j | V nw|s|dk rt j | t | |k rF| t | t j t j | V nn|V dS )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
TN)contextr )r r SubstrateUnderrunErrorEndOfStreamErrorr r r r )r? rJ rO rE s r rI rI s :>>$''.w???????
daii(9999
]]T
!
!NNCMM>2;777 .w???????
!$ NNNNNr r/ )r! N)r
r pyasn1r pyasn1.typer IOBaser r@ rF rM rI r r r