
    dj                        d dl Z d dl mZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZ  e j        e j        e	                   Z e j        e j        e j        e	                            Z e j        d          Ze j         G d d	                      Ze j        e j         e j        d
          de j        dede j        de j        fd                                    Ze j         e j        d
          de j        dede j        de j        fd                        Ze j        e j         e j        d
          de j        dede j        de j        fd                                    Ze j         e j        d
          de j        dede j        de j        fd                        Ze j        e j         e j        d
          de j        dede j        defd                                    Ze j        de j        dede j        defd            Ze j        de j        ej                 de j        fd            Z e j        de j        ej                 de j        fd            Z!dS )    N)NULL)libav)stash_exception)int64_tuint8_t)memcpyzOint64_t (*seek_func_t)(void *opaque, int64_t offset, int whence) noexcept nogilc                       e Zd ZddZd ZdS )PyIOFileNc           	          || _         t          }t          | j         dd           }t          | j         dd           }t          | j         dd           }t          | j         dd           | _        t          | j         dd           | _        t          | j         dd           | _        t          | j         dd           | _        t          | j         dd           | _        | j        | j        |
 |            rt          }|	| j        d u}|r#| j        | |            st          d	          n"| j        | |            st          d
          d| _
        d| _        t          j        t          j        t          j        |                    | _        t          j        | j        ||t          j        t          j        |           t(          t*          |          | _        |rt          j        | j        _        || j        _        d S )Nreadablewritableseekablereadwriteseektellclosez@File object has no write() method, or writable() returned False.z?File object has no read() method, or readable() returned False.r   T)filer   getattrfreadfwritefseekftellfclose	pyio_seek
ValueErrorpospos_is_validcythoncastp_ucharlib	av_mallocbufferavio_alloc_contextp_void	pyio_read
pyio_write	iocontextAVIO_SEEKABLE_NORMALr   max_packet_size)selfr   buffer_size	writeable	seek_funcr   r   r   s           L/home/agentuser/manim-venv/lib/python3.11/site-packages/av/container/pyio.py	__cinit__zPyIOFile.__cinit__   s   	!%	49j$7749j$7749j$77TY55
di$77TY55
TY55
di$77
 J"
&!XXZZ!%.I4/I 		{"x';HHJJ'; V   z!h&:88::&: U     k&.#-2L2LMM/KKt,,
 
  	?&)&>DN#)4&&&    c                 l   t           j        5  | j        r\t          j        t          j        | j        j                             t          j        t          j        | j                             n+t          j        t          j        | j                             d d d            d S # 1 swxY w Y   d S N)r   nogilr)   r"   av_freepaddressr$   )r,   s    r0   __dealloc__zPyIOFile.__dealloc__L   s    \ 		: 		: ~ :V^DN,ABBCCCV^DN;;<<<< V^DK88999		: 		: 		: 		: 		: 		: 		: 		: 		: 		: 		: 		: 		: 		: 		: 		: 		: 		:s   BB))B-0B-r4   )__name__
__module____qualname__r1   r8    r2   r0   r
   r
      s8        75 75 75 75r
: 
: 
: 
: 
:r2   r
   F)checkopaquebufbuf_sizereturnc                 p    t           j        5  t          | ||          cd d d            S # 1 swxY w Y   d S r4   )r   gilpyio_read_gilr>   r?   r@   s      r0   r'   r'   Y   s     
 4 4VS(334 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4   +//c           
         	 t          j        t          |           }|                    |          }t	          |t          j        t           j        t          j        t           j        |                    t          |                     |xj        t          |          z  c_        |st          j
        S t          |          S # t          $ r t                      cY S w xY wr4   )r   r    r
   r   r   r&   p_charlenr   r"   AVERROR_EOF	Exceptionr   )r>   r?   r@   r,   ress        r0   rD   rD   a   s    
!{8V,,jj""V]FKs,K,KLLcRUhh	
 	
 	
 	CHH 	#?"3xx ! ! !     !s   B1C 4C CCc                 p    t           j        5  t          | ||          cd d d            S # 1 swxY w Y   d S r4   )r   rC   pyio_write_gilrE   s      r0   r(   r(   t   s     
 5 5fc8445 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5rF   c                    	 t          j        t          |           }|d |         }|                    |          }t	          |t
                    r|n|}|xj        |z  c_        |S # t          $ r t                      cY S w xY wr4   )	r   r    r
   r   
isinstanceintr   rK   r   )r>   r?   r@   r,   bytes_to_write	ret_valuebytes_writtens          r0   rN   rN   |   s    !{8V,,YhYKK//	%/	3%?%?M		XM! ! ! !     !s   A#A& &B Boffsetwhencec                     |t           j        k    rdS t          j        5  t	          | ||          cd d d            S # 1 swxY w Y   d S )N)r"   AVSEEK_SIZEr   rC   pyio_seek_gil)r>   rU   rV   s      r0   r   r      s       r	 5 5VVV445 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5s   =AAc                 F   	 t          j        t          |           }|                    ||          }|dk    r||_        n|dk    r|xj        |z  c_        nd|_        |#|j        r|j        }n|                                }|S # t          $ r t                      cY S w xY w)Nr      F)	r   r    r
   r   r   r   r   rK   r   )r>   rU   rV   r,   rL   s        r0   rZ   rZ      s    
!{8V,,jj(( Q;;DHHq[[HHHHH %D;  #hjjll
 ! ! !     !s   BB B B pbc                 h    	 t          j        |           S # t          $ r t                      cY S w xY wr4   )r"   
avio_closerK   r   )r]   s    r0   pyio_close_gilr`      sD    !~b!!! ! ! !     !s    11c                     	 t          j        t          | j                  }t	          j        |            |j        |                                 dS # t          $ r t                       Y d S w xY w)Nr   )	r   r    r
   r>   r"   
avio_flushr   rK   r   )r]   r,   s     r0   pyio_close_custom_gilrc      sv    {8RY// 	r;"KKMMMq   s   AA A.-A.)"r   r   cython.cimportsr   r"   cython.cimports.av.errorr   cython.cimports.libc.stdintr   r   cython.cimports.libc.stringr   typedefpointerBufconstBufCseek_func_tcclassr
   cfuncr5   	exceptvalr&   rQ   r'   rD   r(   rN   r   rZ   AVIOContextr`   rc   r<   r2   r0   <module>rr      s          ( ( ( ( ( ( 4 4 4 4 4 4 8 8 8 8 8 8 8 8 . . . . . .fnV^G,--v~fnV\'%:;<<fnU 
 D: D: D: D: D: D: D: D:N 4fm 4# 4 4
 4 4 4   4
 !&- !c !VZ !FJ ! ! !  !" 5v} 54 56: 5&* 5 5 5   5
 !M! $!06
!Z! ! !  !" 5fm 5W 5fj 5W 5 5 5   5 !M!#*!4:J!! ! ! !2 !v~co6 !6: ! ! ! ! fnS_= &*      r2   