
    <|h'_                        d Z ddlmZmZmZ 	 ddlmZ ddlZddl	Z	ddl
Z
ddlZddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZ  G d de      Z G d de      Z G d dej2                        Z G d dej6                        Z G d de      Z G d dej>                        Z G d de      Z  G d de ej>                        Z! G d de      Z" G d de      Z# G d d e      Z$ G d! d"e$      Z% G d# d$e$      Z&y# e$ r dZY w xY w)%z
gevent internals.
    )absolute_importprint_functiondivision)EBADF	   N)_get_hub_noargs)integer_types)reraise)fspath)	SemaphoreDummySemaphorec                       e Zd Zd Zy)cancel_wait_exc                 :    t         j                  | t        d       y )Nz.File descriptor was closed in another greenletIOError__init__r   selfs    W/var/www/html/test/engine/venv/lib/python3.12/site-packages/gevent/_fileobjectcommon.pyr   zcancel_wait_ex.__init__   s    C	E    N__name__
__module____qualname__r    r   r   r   r      s    Er   r   c                       e Zd Zd Zy)FileObjectClosedc                 :    t         j                  | t        d       y )Nz+Bad file descriptor (FileObject was closed)r   r   s    r   r   zFileObjectClosed.__init__   s    @	Br   Nr   r   r   r   r   r      s    Br   r   c                   8    e Zd ZdZdZd Zd ZddZd Zd Z	e	Z
y)	UniversalNewlineBytesWrapperz
    Uses TextWrapper to decode universal newlines, but returns the
    results as bytes.

    This is for Python 2 where the 'rU' mode did that.
    Nc                 L    t         j                  j                  | |dd |       y )Nlatin-1)encodingnewlineline_buffering)ioTextIOWrapperr   )r   fobjr&   s      r   r   z%UniversalNewlineBytesWrapper.__init__,   s(    
!!$y*.1? 	" 	Ar   c                 j    t        j                  j                  | g|i |}|j                  d      S Nr#   )r'   r(   readencode)r   argskwargsresults       r   r,   z!UniversalNewlineBytesWrapper.read2   s1    !!&&t=d=f=}}Y''r   c                 d    t         j                  j                  | |      }|j                  d      S r+   )r'   r(   readliner-   )r   limitr0   s      r   r2   z%UniversalNewlineBytesWrapper.readline6   s)    !!**47}}Y''r   c                     | S Nr   r   s    r   __iter__z%UniversalNewlineBytesWrapper.__iter__:   s	     r   c                 6    | j                         }|st        |S r5   r2   StopIterationr   lines     r   __next__z%UniversalNewlineBytesWrapper.__next__@       }}r   ))r   r   r   __doc__moder   r,   r2   r6   r<   nextr   r   r   r!   r!   $   s/     DA(( Dr   r!   c                       e Zd Zd Zy)FlushingBufferedWriterc                 f    t         j                  j                  | |      }| j                          |S r5   )r'   BufferedWriterwriteflush)r   brets      r   rF   zFlushingBufferedWriter.writeK   s(    %%dA.


r   Nr   r   r   rF   r   r   r   rC   rC   I   s    r   rC   c                        e Zd Z fdZ xZS )WriteallMixinc                     t         t        | 
  }t        |      }|r#t        |      } ||      }||k(  r	 |S ||d }|r#|S )z
        Similar to :meth:`socket.socket.sendall`, ensures that all the contents of
        *value* have been written (though not necessarily flushed) before returning.

        Returns the length of *value*.

        .. versionadded:: 20.12.0
        N)superrL   rF   len)r   valuerF   totallw	__class__s         r   writeallzWriteallMixin.writeallS   sW     mT0E
E
AeAAv !"IE  r   )r   r   r   rU   __classcell__)rT   s   @r   rL   rL   Q   s     r   rL   c                       e Zd ZdZdZy)FileIOz8A subclass that we can dynamically assign __class__ for.r   N)r   r   r   r?   	__slots__r   r   r   rX   rX   j   s
    BIr   rX   c                       e Zd Zd Zy)WriteIsWriteallMixinc                 $    | j                  |      S r5   )rU   )r   rP   s     r   rF   zWriteIsWriteallMixin.writeq   s    }}U##r   NrJ   r   r   r   r[   r[   o   s    $r   r[   c                       e Zd Zy)WriteallFileION)r   r   r   r   r   r   r^   r^   u   s    r   r^   c                       e Zd ZdZed        Z	 	 	 	 ddZej                  Z	dZ
dZd Zd Zd Zd Zd	 Zed
        Zed        Zd Zd Zd Zy)OpenDescriptora_  
    Interprets the arguments to `open`. Internal use only.

    Originally based on code in the stdlib's _pyio.py (Python implementation of
    the :mod:`io` module), but modified for gevent:

    - Native strings are returned on Python 2 when neither
      'b' nor 't' are in the mode string and no encoding is specified.
    - Universal newlines work in that mode.
    - Allows externally unbuffered text IO.

    :keyword bool atomic_write: If true, then if the opened, wrapped, stream
        is unbuffered (meaning that ``write`` can produce short writes and the return
        value needs to be checked), then the implementation will be adjusted so that
        ``write`` behaves like Python 2 on a built-in file object and writes the
        entire value. Only set this on Python 2; the only intended user is
        :class:`gevent.subprocess.Popen`.
    c           
      P    ||t        d| d|d|d|      |||S ||S |S )NzCannot specify both =z and )	TypeError)	pref_namepreferred_valold_nameold_valdefaults        r   _collapse_argzOpenDescriptor._collapse_arg   sL    
 $)<='    W_N - 9}FwFr   Nc                 6   | j                  d|	d|d      }	~| j                  d|d|d      }~t        |d      s^t        |t              st	        |      }t        |t
        t        ft        z         st        d|z        t        |t
        t        f      rd}	t        |t
              st        d	|z        t        |t              st        d
|z        |t        |t
              st        d|z        |t        |t
              st        d|z        t        |      }|t        d      z
  st        |      t        |      kD  rt        d	|z        d|v }d|v }d|v }d|v }d|v }d|v }d|v }d|v }|xs
 |xs |xs |}|r|rt        d      d}|r|rt        d      ||z   |z   |z   dkD  rt        d      |s|s|s|st        d      |r|t        d      |r|t        d      |r|t        d      |r |dk(  rdd l}|j                  dt        d        || _        |xr dxs d!|xr dxs d!z   |xr dxs d!z   |xr dxs d!z   |xr dxs d!z   | _        | j                  |rdnd!z   |rdnd!z   | _        || _        || _        || _        || _        || _        || _        || _        || _        |xs || _        | j,                   xr | j.                   xr | xr | | _        || _        || _        || _        || _        || _        |	| _         |
| _!        y )"NclosefdcloseT	bufferingbufsizer>   filenozinvalid file: %rzinvalid mode: %rzinvalid buffering: %rzinvalid encoding: %rzinvalid errors: %rzaxrwb+tUxrrS   a+trH   Uz4mode U cannot be combined with 'x', 'w', 'a', or '+'z'can't have text and binary mode at once   z)can't have read/write/append mode at oncez/must have exactly one of read/write/append modez-binary mode doesn't take an encoding argumentz+binary mode doesn't take an errors argumentz+binary mode doesn't take a newline argumentr   zaline buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used    )"ri   hasattr
isinstancer	   r   strbytesrc   setrO   
ValueErrorwarningswarnRuntimeWarning_fobjfileio_moder@   creatingreadingwriting	appendingupdatingtextbinary	can_writecan_readnative	universalrm   r$   errorsr%   rk   atomic_write)r   r)   r@   rn   rl   r$   r   r%   rm   rk   r   modesr   r   r   r   r   r   r   r   r   r   s                         r   r   zOpenDescriptor.__init__   s    $$Y%N&&{Iy'SUV	tX&dM2d|dS%L=$@A 2T 9::$e-$$.566)]33i?@@
8S(A2X=>>j&=069::D	3z?"c$i#e*&</$677%<,,5L	%<e|5L	@@9@	 !WXX GFFGGg')3a7HIIGw)NOOh*LMMf(JKKg)JKKi1nMM G(!- 
##3$"&3$"&  S&B( C%2	' 	 $$t<vSUV	 " 	"+8		M ,$++o ,,%+ 	 #" (r   c                 6    t        | j                  t              S r5   )rz   r   r	   r   s    r   is_fdzOpenDescriptor.is_fd  s    $**m44r   c                     | j                   3| j                         }	 | j                  |      | _         | j                   S | j                   S #  |j                           xY w)z9
        Return the :meth:`wrapped` file object.
        )_opened
opened_raw_OpenDescriptor__wrappedrl   r   raws     r   openedzOpenDescriptor.opened  sY     <<//#C#~~c2 ||t|| 		s   A Ac                     | j                   |uS r5   r   r   s     r   _raw_object_is_newz!OpenDescriptor._raw_object_is_new  s    zz$$r   c                 \    | j                   | j                         | _         | j                   S r5   )_opened_raw_do_open_rawr   s    r   r   zOpenDescriptor.opened_raw  s+    ##002Dr   c                     t        | j                  d      r| j                  S t        | j                  | j                  | j                        S )Nro   )ry   r   rX   r   rk   r   s    r   r   zOpenDescriptor._do_open_raw"  s9    4::x(::
 djj$"2"2DLLAAr   c                     t        | t        j                  t        j                  f      xs t	        | d      xr | j
                  d uS )Nbuffer)rz   r'   BufferedIOBase
TextIOBasery   r   )streams    r   is_bufferedzOpenDescriptor.is_buffered+  s@     v 1 12==AB I)Gfmm4.G	
r   c                     | j                   }	 t        j                  |j                               j                  }|dkD  r|}|S # t
        t        f$ r Y |S w xY w)Nrv   )default_buffer_sizeosfstatro   
st_blksizeOSErrorAttributeError)clsr   r0   bss       r   buffer_size_for_streamz%OpenDescriptor.buffer_size_for_stream3  s_    ((	&--/*55B Av ( 	 	s   -A AAc                 L   | j                   rt        j                  }nj| j                  s| j                  s| j
                  rt        j                  }n5| j                  rt        j                  }nt        d| j                  z        	  |||      }|S # t        $ r |}Y |S w xY w)Nzunknown mode: %r)r   r'   BufferedRandomr   r   r   rE   r   BufferedReaderr~   r@   r   )r   r   rm   Bufferr0   s        r   
__bufferedzOpenDescriptor.__buffered?  s    ==&&F]]dlldnn&&F\\&&F/$));<<	FI.F   	 F	s   		B B#"B#c                     ||us| j                  |      r-|j                  t        u rt        |_        |S t	        d|z        |S )Nz[Don't know how to make %s have atomic write. Please open a gevent issue with your use-case.)r   rT   rX   r^   NotImplementedError)r   r0   r   s      r   _make_atomic_writez!OpenDescriptor._make_atomic_writeR  sZ      7 7 <6)#1   *E  r   c                    | j                   r%t        |t        j                        rt	        d      |}| j
                  }d}|dk(  s|dk  r|j                         rd}d}|dk  r| j                  |      }|dk  rt	        d      |dk7  r#| j                  |      s| j                  ||      }| j                   sQt        |t        j                        s7t        j                  || j                  | j                  | j                  |      }||us| j                  |      r	 | j                  |_        | j$                  r3| j                  |      s"t        |t&              s| j)                  ||      }|S # t         t"        f$ r Y Rw xY w)z
        Wraps the raw IO object (`RawIOBase` or `io.TextIOBase`) in
        buffers, text decoding, and newline handling.
        z4Unable to perform binary IO on top of text IO streamFrv   r   r>   Tzinvalid buffering size)r   rz   r'   r   r~   rm   isattyr   r   _OpenDescriptor__bufferedr(   r$   r   r%   r   r@   r   rc   r   r[   r   )r   r   r0   rm   r&   s        r   	__wrappedzOpenDescriptor.__wrappedl  sg   
 ;;:c2==9 STTNN	>Y]szz|I!Nq=33F;Iq=566>$"2"26": __VY7F{{ c2==1 ))&$--dll*8:  7 7 <"ii !!((0"6+?@ ,,VS9F #I.  s   !E3 3FF)	rq   NNNNNNNF)r   r   r   r?   staticmethodri   r   r'   DEFAULT_BUFFER_SIZEr   r   r   r   r   r   r   r   r   classmethodr   r   r   r   r   r   r   r`   r`   y   s    & G G <@59)-#f)P 00GK5% 
B 
 
 	 	&49r   r`   c                   &    e Zd ZdZd Zd Zd ZeZy)	_ClosedIO)namec                 F    	 |j                   | _         y # t        $ r Y y w xY wr5   )r   r   )r   io_objs     r   r   z_ClosedIO.__init__  s$    	DI 		s    	  c                 $    |dk(  rt         t        )Nr   )r   r   r   r   s     r   __getattr__z_ClosedIO.__getattr__  s    6>  r   c                      y)NFr   r   s    r   __bool__z_ClosedIO.__bool__  s    r   N)r   r   r   rY   r   r   r   __nonzero__r   r   r   r   r     s    
 IKr   r   c                       e Zd ZdZdZdZd Z ed d       Zd Z	d Z
ed	        Zd
 Zd Zd Zd Zd Zd Zd Zd Zd ZeZd ZeZy)FileObjectBasez
    Internal base class to ensure a level of consistency
    between :class:`~.FileObjectPosix`, :class:`~.FileObjectThread`
    and :class:`~.FileObjectBlock`.
    )rG   ro   writablereadableseekseekabletellr,   r2   	readlinesread1readintorF   rU   
writelinestruncateNc                 p    |j                         | _        |j                  | _        | j	                          y r5   )r   _iork   _close_do_delegate_methods)r   
descriptors     r   r   zFileObjectBase.__init__  s-    $$& !((!!#r   c                     | j                   S r5   )r   )ss    r   <lambda>zFileObjectBase.<lambda>  s
    AEE r   c                 @    t        | d|      xs | j                         S )Nr   )setattrr   )r   nvs     r   r   zFileObjectBase.<lambda>  s    5" 5 Q9O9O9Q r   c                     | j                   D ]k  }t        | j                  |d       }t        t	        |       |      }|r|st        | || j                  |             Pt        | |      s]|r`t        | |       m y r5   )_delegate_methodsgetattrr   ry   typer   _wrap_methoddelattr)r   	meth_namemethimplemented_by_classs       r   r   z#FileObjectBase._do_delegate_methods  sn    // 	)I488Y5D#*4:y#A 0i):):4)@Ay)2Fi(	)r   c                     |S )z
        Wrap a method we're copying into our dictionary from the underlying
        io object to do something special or different, if necessary.
        r   )r   methods     r   r   zFileObjectBase._wrap_method  s	    
 r   c                 6    t        | j                  t              S )zTrue if the file is closed)rz   r   r   r   s    r   closedzFileObjectBase.closed  s     $((I..r   c                    t        | j                  t              ry | j                  }t        | j                        | _        	 | j                  || j                         d }| j
                  }| j                  D ]  }|j                  |d         y # d }| j
                  }| j                  D ]  }|j                  |d         w xY wr5   )rz   r   r   	_do_closer   __dict__r   pop)r   r)   dr   s       r   rl   zFileObjectBase.close  s    dhh	*xxTXX&	'NN4-D A!33 '	i&'	 D A!33 '	i&'s   B 3Cc                     t               r5   )r   r   r)   rk   s      r   r   zFileObjectBase._do_close  s    !##r   c                 .    t        | j                  |      S r5   )r   r   r   s     r   r   zFileObjectBase.__getattr__   s    txx&&r   c                     d| j                   j                  t        |       | j                  rdnd| j                  | j                         fz  S )Nz<%s at 0x%x %s_fobj=%r%s>r   rx   )rT   r   idr   r'   _extra_reprr   s    r   __repr__zFileObjectBase.__repr__#  sF    *NN##tHHGG.
 
 	
r   c                      y)Nrx   r   r   s    r   r   zFileObjectBase._extra_repr,  s    r   c                     | S r5   r   r   s    r   	__enter__zFileObjectBase.__enter__/      r   c                 $    | j                          y r5   rl   )r   r.   s     r   __exit__zFileObjectBase.__exit__2      

r   c                     | S r5   r   r   s    r   r6   zFileObjectBase.__iter__5  r   r   c                 6    | j                         }|st        |S r5   r8   r:   s     r   r<   zFileObjectBase.__next__8  r=   r   c                      y)NTr   r   s    r   r   zFileObjectBase.__bool__@  s    r   )r   r   r   r?   r   r   r   propertyr'   r   r   r   rl   r   r   r   r   r   r  r6   r<   rA   r   r   r   r   r   r   r     s    8 C$ 
/ R
SB) / /' $'
 D Kr   r   c                       e Zd ZdZd Zd Zy)FileObjectBlockz
    FileObjectBlock()

    A simple synchronous wrapper around a file object.

    Adds no concurrency or gevent compatibility.
    c                 N    t        |g|i |}t        j                  | |       y r5   )r`   r   r   )r   r)   r.   r/   r   s        r   r   zFileObjectBlock.__init__O  s&    #D:4:6:
j1r   c                 $    |j                          y r5   r  r   s      r   r   zFileObjectBlock._do_closeS  r  r   N)r   r   r   r?   r   r   r   r   r   r	  r	  F  s    2r   r	  c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)FileObjectThreada  
    FileObjectThread()

    A file-like object wrapping another file-like object, performing all blocking
    operations on that object in a background thread.

    .. caution::
        Attempting to change the threadpool or lock of an existing FileObjectThread
        has undefined consequences.

    .. versionchanged:: 1.1b1
       The file object is closed using the threadpool. Note that whether or
       not this action is synchronous or asynchronous is not documented.
    c                    |j                  dd      }|j                  dd      }t        |i |}|xs t               j                  | _        || _        | j                  du rt               | _        n| j                  st               | _        t        | j                  d      s!t        dt        | j                        z        |j                         g| _        t        j                  | |       y)a  
        :keyword bool lock: If True (the default) then all operations will
           be performed one-by-one. Note that this does not guarantee that, if using
           this file object from multiple threads/greenlets, operations will be performed
           in any particular order, only that no two operations will be attempted at the
           same time. You can also pass your own :class:`gevent.lock.Semaphore` to synchronize
           file operations with an external resource.
        :keyword bool closefd: If True (the default) then when this object is closed,
           the underlying object is closed as well. If *fobj* is a path, then
           *closefd* must be True.
        lockT
threadpoolNr   z'Expected a Semaphore or boolean, got %r)r   r`   get_hubr  r  r   r   ry   rc   r   r   _FileObjectThread__io_holderr   r   )r   r.   r/   r  r  r   s         r   r   zFileObjectThread.__init__g  s     zz&$'ZZd3
#T4V4
$<	(<(<	99!DI&(DItyy+.ETYYWXX&--/0j1r   c                 z   d | j                   d<   	 | j                  5  | j                  j                  |j                         d d d        |r.|fd}~| j                  j                  |      }~|r	t        |  y y y # 1 sw Y   :xY w# |r.|fd}~| j                  j                  |      }~|r	t        |  w w w xY w)Nr   c                 r    	 | j                          d } y #  t        j                         cY d } S xY w# d } w xY wr5   )rl   sysexc_infor   s    r   rl   z)FileObjectThread._do_close.<locals>.close  s4    %
 !%	."||~- $s    /2 2 6)r  r  r  applyrG   r
   )r   r)   rk   rl   r  s        r   r   zFileObjectThread._do_close  s    "	' 2%%djj12  !% % ??007X& + 2 2  !% % ??007X& + s"   B &A<B <BB 2B:c                 `    t         j                  |        | j                  | j                  d<   y Nr   )r   r   r   r  r   s    r   r   z%FileObjectThread._do_delegate_methods  s$    ++D1"hhr   c                      d| j                   S )Nz threadpool=)r  r   s    r   r   zFileObjectThread._extra_repr  s    #'??44r   c                     | j                   | j                  | j                  t        j                        fd       }|S )Nc                  p    d   t         5  j                  | |      cd d d        S # 1 sw Y   y xY wr  )r   r  )r.   r/   	io_holderr  r   r  s     r   thread_methodz4FileObjectThread._wrap_method.<locals>.thread_method  s?    |# '& >!''f=> > >s   ,5)r  r  r  	functoolswraps)r   r   r  r  r  r  s    ` @@@r   r   zFileObjectThread._wrap_method  sE     $$	yy__
		 	> 
!	> r   N)	r   r   r   r?   r   r   r   r   r   r   r   r   r  r  W  s     28'<'5r   r  )'r?   
__future__r   r   r   errnor   ImportErrorr'   r  r  r   
gevent.hubr   r  gevent._compatr	   r
   r   gevent.lockr   r   r   r   r   r(   r!   rE   rC   objectrL   rX   r[   r^   r`   r   r   r	  r  r   r   r   <module>r(     s   A @ 
  
 	 1 ( " ! 1EW EBw B"2#3#3 "JR.. F 2RYY 
$= $	)299 	lV l^	 0CV CLn "b~ b_  Es   C= =DD