o
    ‹°SÖ  ã                   @   sH   d dl mZmZmZ d dlmZ ddlmZ dZdZ	G dd„ de
ƒZd	S )
é    )Úabsolute_importÚdivisionÚprint_function©ÚStructé   )ÚUnexpectedEndOfFileErrorú>ú<c                       s|   e Zd ZdZd‡ fdd„	Zdd„ Zddd„Zdd	d
„Zddd„Zddd„Z	ddd„Z
dd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )ÚStreamReaderzÙ
    Wraps a file-like object to provide access to structured data from a
    binary file. Byte-order is configurable. *base_offset* is added to any
    base value provided to calculate actual location for reads.
    r   c                    s0   t t| ƒ ¡  || _|tkrtnt| _|| _d S ©N)Úsuperr   Ú__init__Ú_streamÚLITTLE_ENDIANÚ
BIG_ENDIANÚ_byte_orderÚ_base_offset)ÚselfÚstreamZ
byte_orderZbase_offset©Ú	__class__© úBD:\Projects\ConvertPro\env\Lib\site-packages\docx\image\helpers.pyr      s
   ÿ
zStreamReader.__init__c                 C   s   | j  |¡S )z0
        Allow pass-through read() call
        )r   Úread)r   Úcountr   r   r   r      s   zStreamReader.readc                 C   s   d}|   |||¡S )zÖ
        Return the int value of the byte at the file position defined by
        self._base_offset + *base* + *offset*. If *base* is None, the byte is
        read from the current position in the stream.
        ÚB)Ú	_read_int©r   ÚbaseÚoffsetÚfmtr   r   r   Ú	read_byte"   s   zStreamReader.read_bytec                 C   ó    | j tu rdnd}|  |||¡S )a:  
        Return the int value of the four bytes at the file position defined by
        self._base_offset + *base* + *offset*. If *base* is None, the long is
        read from the current position in the stream. The endian setting of
        this instance is used to interpret the byte layout of the long.
        z<Lz>L©r   r   r   r   r   r   r   Ú	read_long+   s   zStreamReader.read_longc                 C   r#   )z›
        Return the int value of the two bytes at the file position determined
        by *base* and *offset*, similarly to ``read_long()`` above.
        s   <Hs   >Hr$   r   r   r   r   Ú
read_short5   s   zStreamReader.read_shortc                 C   s,   dd„ }||ƒ}|   |||¡}| d¡}|S )z•
        Return a string containing the *char_count* bytes at the file
        position determined by self._base_offset + *base* + *offset*.
        c                 S   s   d|  }t |ƒS )Nz%dsr   )Ú
char_countZformat_r   r   r   Ú
str_structB   s   z)StreamReader.read_str.<locals>.str_structzUTF-8)Ú_unpack_itemÚdecode)r   r'   r   r    r(   ÚstructÚcharsZunicode_strr   r   r   Úread_str=   s
   
zStreamReader.read_strc                 C   s   | j | | }| j |¡ d S r   )r   r   Úseek)r   r   r    Úlocationr   r   r   r.   J   s   zStreamReader.seekc                 C   s
   | j  ¡ S )z0
        Allow pass-through tell() call
        )r   Útell)r   r   r   r   r0   N   s   
zStreamReader.tellc                 C   s,   |   ||¡ | j |¡}t|ƒ|k rt‚|S r   )r.   r   r   Úlenr   )r   Z
byte_countr   r    Úbytes_r   r   r   Ú_read_bytesT   s
   zStreamReader._read_bytesc                 C   s   t |ƒ}|  |||¡S r   )r   r)   )r   r!   r   r    r+   r   r   r   r   [   s   zStreamReader._read_intc                 C   s   |   |j||¡}| |¡d S )Nr   )r3   ÚsizeÚunpack)r   r+   r   r    r2   r   r   r   r)   _   s   zStreamReader._unpack_item)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r"   r%   r&   r-   r.   r0   r3   r   r)   Ú__classcell__r   r   r   r   r      s    

	



r   N)Z
__future__r   r   r   r+   r   Ú
exceptionsr   r   r   Úobjectr   r   r   r   r   Ú<module>   s   