
    <|h(2                     F   d dl mZ d dl m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
 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 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 d dlmZ  G d de	      Z G d dee      Z G d de      Z G d de      Zy)    )absolute_import)print_functionN)BytesIO)DEFAULT_BUFFER_SIZE)FileIO)	RawIOBase)UnsupportedOperation)reraise)cancel_wait_ex)FileObjectBase)OpenDescriptor)WriteIsWriteallMixin)wait_on_watcher)get_hub)_read)_write)ignored_errors)make_nonblockingc                       e Zd ZdZdZdZdZdZddZd Z	d Z
d Zd Zd Zed	        Zd
 Zd Zed        Zd Zd Zd Zd ZddZd Zy)GreenFileDescriptorIONFc                    t        j                  |        || _        || _        || _        |j
                  | _        t        |       |j                  }|j                  }t               | _        | j                  j                  j                  }	 |r ||d      | _        |r ||d      | _        y y #  | j!                           xY w)N      )r   __init___closefd_filenonamefileio_modemoder   can_read	can_writer   hubloopio_read_watcher_write_watcherclose)selffilenoopen_descriptorclosefdreadablewritable
io_watchers          V/var/www/html/test/engine/venv/lib/python3.12/site-packages/gevent/_fileobjectposix.pyr   zGreenFileDescriptorIO.__init__)   s    4 	#//	 "++",,9XX]]%%
	%/%:"&0&;# 	 JJLs    B1 1Cc                     t        | j                  dd      }	 |j                         |j                          S # |j                          w xY w)NrF)r   r   isattyr'   )r(   fs     r/   r2   zGreenFileDescriptorIO.isattyM   s5    4<<e,	88:GGIAGGIs	   9 Ac                     | j                   d uS N)r%   r(   s    r/   r,   zGreenFileDescriptorIO.readableU   s    !!--    c                     | j                   d uS r5   )r&   r6   s    r/   r-   zGreenFileDescriptorIO.writableX   s    ""$..r7   c                     | j                   C	 t        j                  | j                  dt        j                         d| _         | j                   S | j                   S # t
        $ r d| _         Y | j                   S w xY w)Nr   TF)	_seekableoslseekr   SEEK_CUROSErrorr6   s    r/   seekablezGreenFileDescriptorIO.seekable[   si    >>!&q"++6 "&~~t~~	  '!& ~~	's   /A A:9A:c                     | j                   S r5   )r   r6   s    r/   r)   zGreenFileDescriptorIO.filenoe   s    ||r7   c                     | j                   S r5   )_closedr6   s    r/   closedzGreenFileDescriptorIO.closedh   s    ||r7   c                     | j                   }| j                  }| j                  }d x| _        x| _         | _        |j                  ||ft        | j
                  | j                  | j                  | j                         y r5   )	r%   r&   r"   cancel_waits_close_and_thenr   $_GreenFileDescriptorIO__finish_closer   r   _keep_alive)r(   
read_eventwrite_eventr"   s       r/   __destroy_eventsz&GreenFileDescriptorIO.__destroy_eventsl   sq    ''
))hh>BBB4%(;''%MMLL	
r7   c                     | j                   ry | j                          d| _         	 | j                          d x| _        | _        y # d x| _        | _        w xY w)NT)rB   flush&_GreenFileDescriptorIO__destroy_eventsr   rG   r6   s    r/   r'   zGreenFileDescriptorIO.close{   sN    <<

 	3!!#.22DL4+d2DL4+s   A Ac                     	 | rt        j                  |       t        |d      r|j                          y y # t        |d      r|j                          w w xY w)Nr'   )r;   r'   hasattr)r+   r)   
keep_alives      r/   __finish_closez$GreenFileDescriptorIO.__finish_close   sM    	# z7+  " ,wz7+  " ,s	   7 Ac                     | j                   t        d      	 	 t        | j                  |      S # t        $ r }|j
                  d   t        vr Y d }~nd }~ww xY wt        | j                   d d | j                         f)Nreadr   )	r%   r	   r   r   r>   argsr   r   r"   )r(   nexs      r/   __readzGreenFileDescriptorIO.__read   sy    %&v..T\\1-- 771:^3 4 D..dDHHE    0 	AAAc                     t               }	 	 | j                  t              }|s	 |j                         S |j	                  |       ;# t        $ r d }Y 2w xY wr5   )r   _GreenFileDescriptorIO__readr   r   writegetvalue)r(   retdatas      r/   readallzGreenFileDescriptorIO.readall   s^    i{{#67 ||~ IIdO  "  	s   A AAc                     | j                  t        |            }t        |      }	 ||d | |S # t        $ r<}dd l}t	        ||j                        s||j                  d|      |d | Y d }~|S d }~ww xY w)Nr      b)rZ   len	TypeErrorarray
isinstance)r(   br^   rU   errrd   s         r/   readintozGreenFileDescriptorIO.readinto   sw    {{3q6"I	,AbqE   	,a-	KKd+AbqE	,s   . 	A31A..A3c                     | j                   t        d      	 	 t        | j                  |      S # t        $ r }|j
                  d   t        vr Y d }~nd }~ww xY wt        | j                   d d | j                         f)Nr[   r   )	r&   r	   r   r   r>   rT   r   r   r"   )r(   rf   rV   s      r/   r[   zGreenFileDescriptorIO.write   sy    &&w//dllA.. 771:^3 4 D//tTXXF rX   c                     	 t        j                  | j                  ||      S # t        $ r  t        $ r@}t        t        t        |j                   t        j                         d          Y d }~y d }~ww xY w)Nr   )	r;   r<   r   IOErrorr>   r
   rT   sysexc_info)r(   offsetwhencerV   s       r/   seekzGreenFileDescriptorIO.seek   sa    		C88DLL&&99 	 	C
 GWbgg.q0ABB	Cs    # A56A00A5c                 t    dt        |       j                  t        |       | j                  | j                  fz  S )Nz<%s at 0x%x fileno=%s mode=%r>)type__name__idr   r   r6   s    r/   __repr__zGreenFileDescriptorIO.__repr__   s3    /JD4<<3
 
 	
r7   )T)r   )rs   
__module____qualname__r%   r&   rB   r:   rG   r   r2   r,   r-   r?   r)   propertyrC   rM   r'   staticmethodrF   rZ   r_   rh   r[   rp   ru    r7   r/   r   r      s     MNGIK"H./  

3 # #	F
	G
C
r7   r   c                       e Zd Zy)GreenFileDescriptorIOWriteallN)rs   rv   rw   rz   r7   r/   r|   r|      s    r7   r|   c                       e Zd Zd Zd Zy)GreenOpenDescriptorc                 .   | j                         r$t        | j                  | | j                        }|S d}t	        j
                  |       }|j                         }t        || |      }||_        	 |j                  |_        |S # t        $ r |`Y |S w xY w)N)r+   F)
is_fdr   _fobjr+   r   _do_open_rawr)   rG   r   AttributeError)r(   fileior+   rawr)   s        r/   r   z GreenOpenDescriptor._do_open_raw   s    ::<*4::tT\\RF"  G --d3CZZ\F*64IF!$F !hh  "  K s   2B BBc                     ||us| j                  |      sJ |j                  t        u rt        |_        |S t	        j
                  | ||      }|S r5   )_raw_object_is_new	__class__r   r|   r   _make_atomic_write)r(   resultr   s      r/   r   z&GreenOpenDescriptor._make_atomic_write   sX     S D$;$;C$@@@44<F  $66tVSIFr7   N)rs   rv   rw   r   r   rz   r7   r/   r~   r~      s    *	r7   r~   c                        e Zd ZdZeZd Zd Zy)FileObjectPosixa  
    FileObjectPosix()

    A file-like object that operates on non-blocking files but
    provides a synchronous, cooperative interface.

    .. caution::
         This object is only effective wrapping files that can be used meaningfully
         with :func:`select.select` such as sockets and pipes.

         In general, on most platforms, operations on regular files
         (e.g., ``open('a_file.txt')``) are considered non-blocking
         already, even though they can take some time to complete as
         data is copied to the kernel and flushed to disk: this time
         is relatively bounded compared to sockets or pipes, though.
         A :func:`~os.read` or :func:`~os.write` call on such a file
         will still effectively block for some small period of time.
         Therefore, wrapping this class around a regular file is
         unlikely to make IO gevent-friendly: reading or writing large
         amounts of data could still block the event loop.

         If you'll be working with regular files and doing IO in large
         chunks, you may consider using
         :class:`~gevent.fileobject.FileObjectThread` or
         :func:`~gevent.os.tp_read` and :func:`~gevent.os.tp_write` to bypass this
         concern.

    .. tip::
         Although this object provides a :meth:`fileno` method and so
         can itself be passed to :func:`fcntl.fcntl`, setting the
         :data:`os.O_NONBLOCK` flag will have no effect (reads will
         still block the greenlet, although other greenlets can run).
         However, removing that flag *will cause this object to no
         longer be cooperative* (other greenlets will no longer run).

         You can use the internal ``fileio`` attribute of this object
         (a :class:`io.RawIOBase`) to perform non-blocking byte reads.
         Note, however, that once you begin directly using this
         attribute, the results from using methods of *this* object
         are undefined, especially in text mode. (See :issue:`222`.)

    .. versionchanged:: 1.1
       Now uses the :mod:`io` package internally. Under Python 2, previously
       used the undocumented class :class:`socket._fileobject`. This provides
       better file-like semantics (and portability to Python 3).
    .. versionchanged:: 1.2a1
       Document the ``fileio`` attribute for non-blocking reads.
    .. versionchanged:: 1.2a1

        A bufsize of 0 in write mode is no longer forced to be 1.
        Instead, the underlying buffer is flushed after every write
        operation to simulate a bufsize of 0. In gevent 1.0, a
        bufsize of 0 was flushed when a newline was written, while
        in gevent 1.1 it was flushed when more than one byte was
        written. Note that this may have performance impacts.
    .. versionchanged:: 1.3a1
        On Python 2, enabling universal newlines no longer forces unicode
        IO.
    .. versionchanged:: 1.5
       The default value for *mode* was changed from ``rb`` to ``r``. This is consistent
       with :func:`open`, :func:`io.open`, and :class:`~.FileObjectThread`, which is the
       default ``FileObject`` on some platforms.
    .. versionchanged:: 1.5
       Stop forcing buffering. Previously, given a ``buffering=0`` argument,
       *buffering* would be set to 1, and ``buffering=1`` would be forced to
       the default buffer size. This was a workaround for a long-standing concurrency
       issue. Now the *buffering* argument is interpreted as intended.
    c                 p    t        |i |}t        j                  | |       |j                         | _        y r5   )r~   r   r   
opened_rawr   )r(   rT   kwargs
descriptors       r/   r   zFileObjectPosix.__init__J  s1    ($9&9
j1 ++-r7   c                     	 |j                          | j                  j                          d | _        y # d | _        w xY wr5   )r'   r   )r(   fobjr+   s      r/   	_do_closezFileObjectPosix._do_closeP  s1    	JJL KKDK$DKs   *4 	=N)rs   rv   rw   __doc__r   default_bufsizer   r   rz   r7   r/   r   r     s    CJ *O.r7   r   )
__future__r   r   r;   rl   r$   r   r   r   r   r	   gevent._compatr
   gevent._fileobjectcommonr   r   r   r   gevent._hub_primitivesr   
gevent.hubr   	gevent.osr   r   r   r   r   r|   r~   r   rz   r7   r/   <module>r      s}    & % 	 
  "   # " 3 3 3 9 2    $ &}
I }
@	$8$9	
 .  FUn Ur7   