o
    0׾gU                     @   sp  d 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ZddlmZ eee ejdd	 ejZejZejZejZejZejZG d
d deZG dd dejZG dd dejZeZdddZeejdrxdd Zed eedrdedfddZ ndZ!dZ"e#edfddZ ee e Z$dZ%e%D ]Z&eee&re'ee&e( e&< e&e$vre$e& q[&dS )z
Python 3 socket module.
    )absolute_importN)_socketcommon)copy_globals)PYPY)dup )names_to_ignoredunder_names_to_keepc                   @   sd   e Zd ZdZdd Zdd Zdd ZeZdd	 Ze Z	 Z
 Z Z ZZeZd
d ZeZdd ZdS )_closedsocketfamilytypeprotoorig_filenodescriptionc                 C   s"   || _ || _|| _|| _|| _d S Nr   )selfr   r   r   r   r   r   r   Y/var/www/html/backend_erp/backend_erp_env/lib/python3.10/site-packages/gevent/_socket3.py__init__'   s
   
z_closedsocket.__init__c                 C      dS )Nr   r   r   r   r   fileno.      z_closedsocket.filenoc                 C   r   )zNo-opNr   r   r   r   r   close1   s    z_closedsocket.closec                  O   s
   t td)NzBad file descriptor)OSErrorEBADF)argskwargsr   r   r   _dummy6   s   
z_closedsocket._dummyc                 C   r   )NFr   r   r   r   r   __bool__<   r   z_closedsocket.__bool__c                 C   s   dt | | j| jf S )Nz/<socket object [closed proxy at 0x%x fd=%s %s]>)idr   r   r   r   r   r   __repr__A   s
   z_closedsocket.__repr__N)__name__
__module____qualname__	__slots__r   r   r   detachr   sendrecv	recv_intosendtorecvfromrecvfrom_intogetsocknamer    __getattr__r"   r   r   r   r   r
   $   s    r
   c                   @   s*   e Zd ZdZeredd dd ZdS dS )_wrefsocket)__weakref__c                 C   s   |   S r   )
gettimeout)sr   r   r   <lambda>U   s    z_wrefsocket.<lambda>c                 C   s
   |  |S r   )
settimeout)r3   nvr   r   r   r4   V   s   
 N)r#   r$   r%   r&   r   propertytimeoutr   r   r   r   r0   H   s    r0   c                       sz  e Zd ZdZeZdZdJ fdd	Zdd Zd	d
 Z	e
edr$edd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdKddddddZd d! Zd"d# Zd$d% Zejfd&d'Zd(d) Zed*d+ Zd,d- Ze
ejd.rud/d0 Ze
ejd1rd2d3 Ze
ejd4rdLd7d8Z dMd9d:Z!dMd;d<Z"d=d> Z#dMd?d@Z$e%j&dAkrdBdC Z'dDdE Z(ndFdC Z'dGdE Z(dHe'_dIe(_  Z)S )Nsocketa{  
    gevent `socket.socket <https://docs.python.org/3/library/socket.html#socket-objects>`_
    for Python 3.

    This object should have the same API as the standard library socket linked to above. Not all
    methods are specifically documented here; when they are they may point out a difference
    to be aware of or may document a method the standard library does not.
    )_io_refs_closedr   Nc                    s   t    d| _|d u r|dkrtj}|dkrt}|dkrd}| ||||| _d | _d| _	t
j| jd t
j| j}t | _| jjj}||d| _||d| _t
 | _d S )NFr   r         )superr   r;   AddressFamilyAF_INETSOCK_STREAM_gevent_sock_class_sockr8   r:   _socketr9   setblockingr   get_hubhubloopio_read_event_write_eventgetdefaulttimeout)r   r   r   r   r   io_class	__class__r   r   r   s   s&   

zsocket.__init__c                 C   s   t | j|S r   )getattrrC   )r   namer   r   r   r/      s   zsocket.__getattr__c                 C   s
   | j  S r   )rC   _acceptr   r   r   r   rR      s   
zsocket._acceptSOCK_NONBLOCKc                 C   s"   | j dkr| jjtj @ S | jjS )N        )r8   rC   r   rD   rS   r   r   r   r   r      s   
zsocket.typec                 C   s   | S r   r   r   r   r   r   	__enter__   r   zsocket.__enter__c                 G   s   | j s	|   d S d S r   )r;   r   )r   r   r   r   r   __exit__   s   zsocket.__exit__c              
   C   s   zt | j}W n ty } z
d| }W Y d}~nd}~ww |drAd| jj| jjt| ddr2dp3dt| | 	 |d	d f }|S )
z.Wrap __repr__() to reveal the real class name.z<socket [%r]>Nz<socket objectz<%s.%s%s at 0x%x%s%sr;   Fz	 [closed]    )
reprrC   	Exception
startswithrO   r$   r#   rP   r!   _extra_repr)r   r3   exr   r   r   r"      s    

zsocket.__repr__c                 C   r   )NrW   r   r   r   r   r   r\      r   zsocket._extra_reprc                 C   s   t d)NzCannot serialize socket object)	TypeErrorr   r   r   r   __getstate__   s   zsocket.__getstate__c                 C   s6   t |  }| j| j| j| j|d}||   |S )zjdup() -> socket object

        Return a new socket object connected to the same system resource.
        r   )r   r   rO   r   r   r   r5   r2   )r   fdsockr   r   r   r      s   z
socket.dupc                 C   sz   	 z|   \}}W n ty   | jdkr Y nw | | j qt| j| j| j|d}t	 du r9| 
 r9|d ||fS )zaccept() -> (socket object, address info)

        Wait for an incoming connection.  Return a new socket
        representing the connection, and the address of the client.
        For IP sockets, the address info is a pair (hostaddr, port).
        TrT   r`   N)rR   BlockingIOErrorr8   _waitrJ   r9   r   r   r   rL   r2   rE   )r   ra   addrrb   r   r   r   accept   s   

zsocket.acceptr)encodingerrorsnewlinec                C   s
  |D ]
}|dvrt dqd|v }d|v p| }|s|sJ d|v }	d}
|r*|
d7 }
|r0|
d7 }
t| |
}|  jd7  _|du rBd	}|d
k rItj}|d
krU|	sSt d|S |ra|rat|||}n|rjt||}n
|snJ t||}|	rx|S t||||}||_	|S )zReturn an I/O stream connected to the socket

        The arguments are as for io.open() after the filename,
        except the only mode characters supported are 'r', 'w' and 'b'.
        The semantics are similar too.
        >   brg   wz&invalid mode %r (only r, w, b allowed)rl   rg   rk   rW   r<   Nr   r   z!unbuffered streams must be binary)

ValueErrorSocketIOr:   rI   DEFAULT_BUFFER_SIZEBufferedRWPairBufferedReaderBufferedWriterTextIOWrappermode)r   rt   	bufferingrh   ri   rj   cwritingreadingbinaryrawmoderawbuffertextr   r   r   makefile   sD   
zsocket.makefilec                 C   s.   | j dkr|  j d8  _ | jr|   d S d S )Nr   r<   )r:   r;   r   r   r   r   r   _decref_socketios  s
   
zsocket._decref_socketiosc                 C   s6   | j j| }|r| j j|j d S |  d S r   )rG   rH   
closing_fdr   run_callbackr   )r   rb   scheduled_newr   r   r   _drop_ref_on_close  s   zsocket._drop_ref_on_closec                 C   sx   | j sd S | j }d}d}d}d }z|j}|j}|j}| }W n	 ty(   Y nw | j|dkd t|||||| _ d S )Nr   closed)closefd)rC   r   r   r   r   r   _drop_events_and_closer
   )r   reasonrb   r   r   r   r   r   r   r   _detach_socket!  s"   zsocket._detach_socketc                 C   s   | j sd S | d d S )Nr   )rC   r   )r   _ssr   r   r   _real_close?  s   zsocket._real_closec                 C   s    d| _ | jdkr|   d S d S )NTr   )r;   r:   r   r   r   r   r   r   G  s   
zsocket.closec                 C   s   | j S r   )r;   r   r   r   r   r   M  s   zsocket.closedc                 C   s   d| _ | j}| d | S )a  
        detach() -> file descriptor

        Close the socket object without closing the underlying file
        descriptor. The object cannot be used after this call; when the
        real file descriptor is closed, the number that was previously
        used here may be reused. The fileno() method, after this call,
        will return an invalid socket id.

        The previous descriptor is returned.

        .. versionchanged:: 1.5

           Also immediately drop any native event loop resources.
        Tdetached)r;   rC   r   r'   )r   rb   r   r   r   r'   Q  s   
zsocket.detachrecvmsgc              
   G   s^   	 z| j j| W S  ty' } z|jd tks| jdkr W Y d }~nd }~ww | | j qNTr   rT   )rC   r   errorr   EWOULDBLOCKr8   rd   rJ   )r   r   r]   r   r   r   r   j  s   zsocket.recvmsgrecvmsg_intoc              
   G   sx   	 z|r| j j|g|R  W S | j |W S  ty4 } z|jd tks)| jdkr* W Y d }~nd }~ww | | j qr   )rC   r   r   r   r   r8   rd   rJ   )r   buffersr   r]   r   r   r   r   u  s   zsocket.recvmsg_intosendmsgr   r   c                 C   s   z
| j ||||W S  tyc } zM|ttdd@ r |jd tks'| jdkr( | | j	 z| j ||||W W  Y d }~S  ty^ } z|jd tkrYW Y d }~W Y d }~dS  d }~ww d }~ww )NMSG_DONTWAITr   rT   )
rC   r   r   rP   rD   r   r   r8   rd   rK   )r   r   ancdataflagsaddressr]   ex2r   r   r   r     s$    zsocket.sendmsgc                 C   s   t  r   )
__socket___GiveupOnSendfiler   fileoffsetcountr   r   r   _sendfile_use_sendfile  s   zsocket._sendfile_use_sendfilec           
   
   C   s  |  ||| |  dkrtd|r|| |rt|dnd}d}|j}| j}zR	 |r9t|| |}|dkr9n.t||}|sBn%	 z||}	W n	 tyR   Y qBw ||	7 }|	t	|k rd||	d  }nnqCq+|W |dkrzt
|dr{|||  S S S |dkrt
|dr|||  w w w )Nr   z&non-blocking sockets are not supportedi    Tseek)_check_sendfile_paramsr2   rm   r   minreadr(   
memoryviewrc   lenhasattr)
r   r   r   r   	blocksize
total_sent	file_read	sock_senddatasentr   r   r   _sendfile_use_send  sH   
zsocket._sendfile_use_sendc                 C   sh   dt |ddvrtd| jt@ std|d ur0t|ts%td||dkr2td|d S d S )Nrk   rt   z$file should be opened in binary modez+only SOCK_STREAM type sockets are supportedz+count must be a positive integer (got {!r})r   )rP   rm   r   rA   
isinstanceintr^   formatr   r   r   r   r     s   

zsocket._check_sendfile_paramsc                 C   s   |  |||S )a  sendfile(file[, offset[, count]]) -> sent

        Send a file until EOF is reached by using high-performance
        os.sendfile() and return the total number of bytes which
        were sent.
        *file* must be a regular file object opened in binary mode.
        If os.sendfile() is not available (e.g. Windows) or file is
        not a regular file socket.send() will be used instead.
        *offset* tells from where to start reading the file.
        If specified, *count* is the total number of bytes to transmit
        as opposed to sending the file until EOF is reached.
        File position is updated on return or also in case of error in
        which case file.tell() can be used to figure out the number of
        bytes which were sent.
        The socket must be of SOCK_STREAM type.
        Non-blocking sockets are not supported.

        .. versionadded:: 1.1rc4
           Added in Python 3.5, but available under all Python 3 versions in
           gevent.
        )r   r   r   r   r   sendfile  s   zsocket.sendfilentc                 C      t |  S r   )osget_handle_inheritabler   r   r   r   r   get_inheritable     zsocket.get_inheritablec                 C      t |  | d S r   )r   set_handle_inheritabler   r   inheritabler   r   r   set_inheritable     zsocket.set_inheritablec                 C   r   r   )r   r   r   r   r   r   r   r     r   c                 C   r   r   )r   r   r   r   r   r   r   r     r   z&Get the inheritable flag of the socketz&Set the inheritable flag of the socket)r   r   r   N)rg   N)r   r   N)r   N)*r#   r$   r%   __doc__r0   rB   r&   r   r/   rR   r   rD   r7   r   rU   rV   r"   r\   r_   r   rf   r~   r   r   r   r9   r   r   r   r'   r   r   r   r   r   r   r   r   rQ   r   r   __classcell__r   r   rN   r   r9   Y   sZ    


.
	


$


r9   c                 C   s   t | }t||||S )z fromfd(fd, family, type[, proto]) -> socket object

    Create a socket object from a duplicate of the given file
    descriptor.  The remaining arguments are the same as for socket().
    )r   r9   )ra   r   r   r   nfdr   r   r   fromfd  s   r   sharec                 C   s   t ddd| S )z fromshare(info) -> socket object

        Create a socket object from a the bytes object returned by
        socket.share(pid).
        r   )r9   )infor   r   r   	fromshare	  s   r   
socketpairc                 C   sf   | du rzt } W n ty   t} Y nw t| ||\}}t| ||| }t| ||| }||fS )a  socketpair([family[, type[, proto]]]) -> (socket object, socket object)

        Create a pair of socket objects from the sockets returned by the platform
        socketpair() function.
        The arguments are the same as for socket() except the default family is
        AF_UNIX if defined on the platform; otherwise, the default is AF_INET.

        .. versionchanged:: 1.2
           All Python 3 versions on Windows supply this function (natively
           supplied by Python 3.5 and above).
        N)AF_UNIX	NameErrorr@   rD   r   r9   r'   )r   r   r   ark   r   r   r   r     s   z	127.0.0.1z::1c           
   	   C   s  | t krt}n| tkrt}ntd|tkrtd|dkr"tdt| ||}zT||df |  |	 d d \}}t| ||}z'|
d z	|||f W n ttfy^   Y nw |
d | \}}	W n   |   W |  ||fS |  w )Nz?Only AF_INET and AF_INET6 socket address families are supportedz)Only SOCK_STREAM socket type is supportedr   zOnly protocol zero is supportedr=   FT)r@   
_LOCALHOSTAF_INET6_LOCALHOST_V6rm   rA   r9   bindlistenr.   rE   connectrc   InterruptedErrorrf   r   )
r   r   r   hostlsockre   portcsockssock_r   r   r   r   5  s>   


)r   TCP_KEEPALIVETCP_KEEPCNT)r   ))r   
__future__r   rI   r   geventr   gevent._utilr   gevent._compatr   rD   r   globals__extensions__r   _implements__implements____imports____dns__rn   objectr
   r9   r0   SocketMixin
SocketTyper   r   r   appendrA   r   r   r   r@   __all____version_specific___xrP   varsr   r   r   r   <module>   sX   $   %



&

