File: //lib/python2.7/site-packages/pyasn1/codec/streaming.pyc
�
��fc @ s� d d l Z d d l Z d d l Z d d l m Z d d l m Z e j d k Z d e j f d � � YZ
d � Z d � Z d d � Z
d d d
� Z d S( i����N( t error( t univi t CachingStreamWrapperc B sq e Z d Z d � Z d � Z d � Z d e j d � Z d d � Z e
d � � Z e j d � � Z d � Z
RS(
s 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 C s% | | _ t j � | _ d | _ d S( Ni ( t _rawt iot BytesIOt _cachet _markedPosition( t selft raw( ( s6 /tmp/pip-build-RDPAtx/pyasn1/pyasn1/codec/streaming.pyt __init__ s c C s0 | j | � } | j j t | � t j � | S( N( t readR t seekt lent ost SEEK_CUR( R t nt result( ( s6 /tmp/pip-build-RDPAtx/pyasn1/pyasn1/codec/streaming.pyt peek s c C s t S( N( t True( R ( ( s6 /tmp/pip-build-RDPAtx/pyasn1/pyasn1/codec/streaming.pyt seekable% s i����c C s | j j | | � S( N( R R ( R R t whence( ( s6 /tmp/pip-build-RDPAtx/pyasn1/pyasn1/codec/streaming.pyR ( s c C se | j j | � } | d k r; | t | � 8} | s; | Sn | j j | � } | j j | � | | S( Ni����( R R R
R t write( R R t read_from_cachet
read_from_raw( ( s6 /tmp/pip-build-RDPAtx/pyasn1/pyasn1/codec/streaming.pyR , s c C s | j S( s 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 ( ( s6 /tmp/pip-build-RDPAtx/pyasn1/pyasn1/codec/streaming.pyt markedPosition9 s c C sL | | _ | j j � t j k rH t j | j j � � | _ d | _ n d S( Ni ( R R t tellR t DEFAULT_BUFFER_SIZER R ( R t value( ( s6 /tmp/pip-build-RDPAtx/pyasn1/pyasn1/codec/streaming.pyR C s c C s
| j j � S( N( R R ( R ( ( s6 /tmp/pip-build-RDPAtx/pyasn1/pyasn1/codec/streaming.pyR Q s ( t __name__t
__module__t __doc__R
R R R t SEEK_SETR R t propertyR t setterR ( ( ( s6 /tmp/pip-build-RDPAtx/pyasn1/pyasn1/codec/streaming.pyR s
c C s� t | t j � r | St | t � r2 t j | � St | t j � rW t j | j � � Sy@ t r| t | t � r| t j | � S| j
� r� | St | � SWn. t k
r� t
j d | j j d � � n Xd S( si 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.
s Cannot convert s to a seekable bit stream.N( t
isinstanceR R t bytesR t OctetStringt asOctetst _PY2t filet BufferedReaderR R t AttributeErrorR t UnsupportedSubstrateErrort __class__R ( t substrate( ( s6 /tmp/pip-build-RDPAtx/pyasn1/pyasn1/codec/streaming.pyt asSeekableStreamU s
c c s� t | t j � r^ | j � } | j d t j � | j � | k } | j | t j � | VnE | j d � } | d k r� d Vn | r� | j d t j
� n | Vd S( s 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`
i i Ni����( R# R R R R R t SEEK_ENDR R t NoneR ( R- t cpR t received( ( s6 /tmp/pip-build-RDPAtx/pyasn1/pyasn1/codec/streaming.pyt
isEndOfStream� s c c s� t | d � rX | j | � } | d k r2 d Vn x t | � | k rO d Vq5 W| Vn@ | j � } z# x t | | � D] } | Vqw WWd | j | � Xd S( s? 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( t hasattrR R0 R
R t readFromStreamR ( R- t sizeR2 t current_positiont chunk( ( s6 /tmp/pip-build-RDPAtx/pyasn1/pyasn1/codec/streaming.pyt peekIntoStream� s
c c s� x� t r� | j | � } | d k r8 t j d | � Vq | r` | d k r` t j d | � � q t | � | k r� | j t | � t j � t j d | � Vq Pq W| Vd S( s 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
t contexti N(
R R R0 R t SubstrateUnderrunErrort EndOfStreamErrorR
R R R ( R- R6 R: R2 ( ( s6 /tmp/pip-build-RDPAtx/pyasn1/pyasn1/codec/streaming.pyR5 � s ( i ( R R t syst pyasn1R t pyasn1.typeR t version_infoR'