o
    0׾gWf                     @   s  d dl mZ g dZg dZee7 Zg dZg dZd dlZd dlmZ	 d dl
mZ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 ereeddg erd 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+ e"Z,n*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+ zd d lm.Z. W n e/y   d!Z.Y nw zd d"lm0Z0 W n e/y   d#Z0Y nw zd d$lm1Z1 W n e/y   d#Z1Y nw e"fZ2erd d%lm3Z3 e2e3f7 Z2d dl4Z4e4j5Z6d dl5Z7zd dl8Z9W n
 e/y    Y nw e7j:Z;d Z<Z=ee7e> ed&d'Ze7j?D ]Z<e@e7e<Z=eAe=eefrMe=e> e<< eBe< q4[<[=eCZDd d(lEmFZF eFGeD eFjHZIeFjJZJeFjKZKeFjLZLG d)d* d*e:ZMeMfd+d,ZNd-d. ZOd/d0 ZPdDd1d2ZQd3d4 ZRd5d6 ZSd7d8 ZTdEd:d;ZUeDfd<d=ZVe7jWe7jXfd>d?ZYe7jZfZ[e7j\re[e7j]f7 Z[d@dA Z^e_ Z`G dBdC dCe_Zaeab  ea`bdS )F    )absolute_import)create_connectionsocket
SocketTypefromfd
socketpair)getaddrinfogethostbynamegethostbyname_exgethostbyaddrgetnameinfogetfqdn)cancel_wait	wait_read
wait_writewait_readwrite)errorgaierrorherrorhtonlhtonsntohlntohs	inet_aton	inet_ntoa	inet_pton	inet_ntoptimeoutgethostnamegetprotobynamegetservbynamegetservbyportgetdefaulttimeoutsetdefaulttimeouterrorTabAddressFamily
SocketKindCMSG_LEN
CMSG_SPACEdupif_indextonameif_nameindexif_nametoindexsethostnamecreate_serverhas_dualstack_ipv6N)get_hub_noargs)string_typesinteger_types)PY39)WIN)OSX)	exc_clear)copy_globals)
get_memory)wait_on_socket)Timeoutrecv_fdssend_fds)	WSAEINVAL)WSAEWOULDBLOCK)WSAEINPROGRESS)WSAEALREADY)
WSAEISCONN)formatError)EINVAL)EWOULDBLOCK)EINPROGRESS)EALREADY)EAGAIN)EISCONN)strerror)EBADF	   )EHOSTUNREACH)ECONNREFUSED)
EPROTOTYPET)
only_namesignore_missing_names)_hub_primitivesc                       s   e Zd Z fddZ  ZS )cancel_wait_exc                    s   t t| td d S )Nz.File descriptor was closed in another greenlet)superrS   __init__rJ   self	__class__ ^/var/www/html/backend_erp/backend_erp_env/lib/python3.10/site-packages/gevent/_socketcommon.pyrU      s   
zcancel_wait_ex.__init__)__name__
__module____qualname__rU   __classcell__rZ   rZ   rX   r[   rS      s    rS   c                 C   s   t  | | dS )z&See :meth:`gevent.hub.Hub.cancel_wait`N)get_hubr   )watcherr   rZ   rZ   r[   r         r   c                 C      t  j| S )z
    gethostbyname(host) -> address

    Return the IP address (a string of the form '255.255.255.255') for a host.

    .. seealso:: :doc:`/dns`
    )r`   resolverr	   hostnamerZ   rZ   r[   r	      s   r	   c                 C   rc   )a<  
    gethostbyname_ex(host) -> (name, aliaslist, addresslist)

    Return the true host name, a list of aliases, and a list of IP addresses,
    for a host.  The host argument is a string giving a host name or IP number.
    Resolve host and port into list of address info entries.

    .. seealso:: :doc:`/dns`
    )r`   rd   r
   re   rZ   rZ   r[   r
      s   
r
   c                 C   s*   t  j| |||||}dd |D }|S )a  
    Resolve host and port into list of address info entries.

    Translate the host/port argument into a sequence of 5-tuples that contain
    all the necessary arguments for creating a socket connected to that service.
    host is a domain name, a string representation of an IPv4/v6 address or
    None. port is a string service name such as 'http', a numeric port number or
    None. By passing None as the value of host and port, you can pass NULL to
    the underlying C API.

    The family, type and proto arguments can be optionally specified in order to
    narrow the list of addresses returned. Passing zero as a value for each of
    these arguments selects the full range of results.

    .. seealso:: :doc:`/dns`
    c                 S   s0   g | ]\}}}}}t |tt |t|||fqS rZ   )_intenum_converterr%   r&   ).0afsocktypeproto	canonnamesarZ   rZ   r[   
<listcomp>   s    zgetaddrinfo.<locals>.<listcomp>)r`   rd   r   )hostportfamilytyperk   flagsaddrlistresultrZ   rZ   r[   r      s
   r   c                 C   s"   z|| W S  t y   |  Y S w N)
ValueError)value
enum_klassrZ   rZ   r[   rg      s
   
rg   c                 C   rc   )a  
    gethostbyaddr(ip_address) -> (name, aliaslist, addresslist)

    Return the true host name, a list of aliases, and a list of IP addresses,
    for a host.  The host argument is a string giving a host name or IP number.

    .. seealso:: :doc:`/dns`
    )r`   rd   r   )
ip_addressrZ   rZ   r[   r      s   	r   c                 C   s   t  j| |S )z{
    getnameinfo(sockaddr, flags) -> (host, port)

    Get host and port for a sockaddr.

    .. seealso:: :doc:`/dns`
    )r`   rd   r   )sockaddrrs   rZ   rZ   r[   r      s   r    c                 C   s   |   } | r
| dv rt } z	t| \}}}W n
 ty    Y | S w |d| |D ]} t| tr8d| v r7 | S q)d| v r? | S q)|} | S )a  Get fully qualified domain name from name.

    An empty argument is interpreted as meaning the local host.

    First the hostname returned by gethostbyaddr() is checked, then
    possibly existing aliases. In case no FQDN is available, hostname
    from gethostname() is returned.

    .. versionchanged:: 23.7.0
       The IPv6 generic address '::' now returns the result of
       ``gethostname``, like the IPv4 address '0.0.0.0'.
    )z0.0.0.0z::r      ..)stripr   r   r   insert
isinstancebytes)namerf   aliases_rZ   rZ   r[   r   
  s,   
r   c           
      C   s   d}t |}d}||k r?||d }	|du r|| |	|7 }n|r)|dkr)|dd}|| j|	||d7 }|t  }||k s|S )a  
    Send the complete contents of ``data_memory`` before returning.
    This is the core loop around :meth:`send`.

    :param timeleft: Either ``None`` if there is no timeout involved,
       or a float indicating the timeout to use.
    :param end: Either ``None`` if there is no timeout involved, or
       a float giving the absolute end time.
    :return: An updated value for ``timeleft`` (or None)
    :raises timeout: If ``timeleft`` was given and elapsed while
       sending this chunk.
    r   N	timed out   r   )lensendtime)
r   data_memoryrs   timeleftendr   	data_sentlen_data_memorystarted_timerchunkrZ   rZ   r[   __send_chunk-  s   r   c                 C   s   t |}|sdS t| ||d}d}d}d}	| jdur%| j}	t |	 }||k rJt|| |}
|||
 }t| |||	|}	|t |7 }||k s)dS dS )zw
    Send the *data_memory* (which should be a memoryview)
    using the gevent *socket*, performing well on PyPy.
    r   i   N)r   max
getsockoptr   r   minr   )r   r   rs   
SOL_SOCKET	SO_SNDBUFr   
chunk_sizer   r   r   	chunk_endr   rZ   rZ   r[   _sendallP  s    #
r   c                 C   s   | j tvs
t|ts|S zt| j |d r|W S W n ty#   Y n	 ty+   Y nw |d d \}}t|d | j }|d d }t	|dkrO|d |f}|S |d ||d |d f}|S )Nr      rM      )
rq   _RESOLVABLE_FAMILIESr   tuple
__socket__r   AttributeError_SocketErrorr   r   )sockaddressro   rp   rrZ   rZ   r[   _resolve_addr  s&   
r   c                   @   s\  e Zd ZdZdd ZdefddZdd Zd	d
 Zdd Z	e
ee	ZeZdd Zdd Zdd Zdd Ze
dd Ze
dd Z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eejd'rld(d) Zeejd*rvd+d, Z d-d. Z!d/d0 Z"d1d2 Z#d3d4 Z$d5d6 Z%d7d8 Z&d9d: Z'd;d< Z(dGd>d?Z)d@dA Z*d=e+fdBdCZ,e-dDdE Z.dFS )HSocketMixin)hubr   _read_event_write_event_sock__weakref__c                 C   s"   d | _ d | _d | _d | _d | _d S rv   )r   r   r   r   r   rV   rZ   rZ   r[   rU     s
   
zSocketMixin.__init__Tc                 C   sB   | j }| j}| j}d  | _| _|||f||r| jnt| j d S rv   )r   r   r   cancel_waits_close_and_then_drop_ref_on_closeidr   )rW   closefd_cancel_wait_exr   
read_eventwrite_eventrZ   rZ   r[   _drop_events_and_close  s   z"SocketMixin._drop_events_and_closec                 C   s   t rv   )NotImplementedError)rW   r   rZ   rZ   r[   r     s   zSocketMixin._drop_ref_on_closec                 C   s   | j jp| jjS rv   r   refr   rV   rZ   rZ   r[   _get_ref  s   zSocketMixin._get_refc                 C   s   || j _|| j_d S rv   r   )rW   rx   rZ   rZ   r[   _set_ref  s   zSocketMixin._set_refc                 C   sZ   |d ur$z|j }W n ty   td|t|w | }|dk r$tdtj| | d S )Nza float is required        zTimeout value out of range)	__float__r   	TypeErrorrr   rw   r   r   __set__)rW   howlongfrZ   rZ   r[   
settimeout  s   
zSocketMixin.settimeoutc                 C   s   t j| t| S rv   )r   r   __get__rr   rV   rZ   rZ   r[   
gettimeout  rb   zSocketMixin.gettimeoutc                 C   s   |rd | _ d S d| _ d S )Nr   r   )rW   flagrZ   rZ   r[   setblocking  s   

zSocketMixin.setblockingc                 C   sd   |dkr| j | jt n|dkr| j | jt n| j | jt | j | jt | j| d S )Nr   r   )r   r   r   rS   r   r   shutdown)rW   howrZ   rZ   r[   r   	  s   zSocketMixin.shutdownc                 C      t | jjtS rv   )rg   r   rq   r%   rV   rZ   rZ   r[   <lambda>      zSocketMixin.<lambda>c                 C   r   rv   )rg   r   rr   r&   rV   rZ   rZ   r[   r     r   c                 C   s   | j jS rv   )r   rk   rV   rZ   rZ   r[   r     s    c                 C   
   | j  S rv   )r   filenorV   rZ   rZ   r[   r        
zSocketMixin.filenoc                 C   r   rv   )r   getsocknamerV   rZ   rZ   r[   r     r   zSocketMixin.getsocknamec                 C   r   rv   )r   getpeernamerV   rZ   rZ   r[   r     r   zSocketMixin.getpeernamec                 C   s   | j |S rv   )r   bindrW   r   rZ   rZ   r[   r   "     zSocketMixin.bindc                 G      | j j| S rv   )r   listenrW   argsrZ   rZ   r[   r   %  r   zSocketMixin.listenc                 G   r   rv   )r   r   r   rZ   rZ   r[   r   (  r   zSocketMixin.getsockoptc                 G   r   rv   )r   
setsockoptr   rZ   rZ   r[   r   +  r   zSocketMixin.setsockoptioctlc                 G   r   rv   )r   r   r   rZ   rZ   r[   r   /  r   zSocketMixin.ioctl
sleeptaskwc                 G   r   rv   )r   r   r   rZ   rZ   r[   r   2  r   zSocketMixin.sleeptaskwc                 C   s
   | j dkS )z
        Returns whether the socket will approximate blocking
        behaviour.

        .. versionadded:: 1.3a2
            Added in Python 3.7.
        r   r   rV   rZ   rZ   r[   getblocking5  s   
zSocketMixin.getblockingc                 C   s   |  | dS )a  
        Connect to *address*.

        .. versionchanged:: 20.6.0
            If the host part of the address includes an IPv6 scope ID,
            it will be used instead of ignored, if the platform supplies
            :func:`socket.inet_pton`.
        N)_internal_connectr   rZ   rZ   r[   connect?  s   zSocketMixin.connectc                 C   s   z|  |pdW S  tjy   t Y S  tjy     tyF } zz|j}W n ty6   |jd }Y nw |rA|W  Y d}~S  d}~ww )a0  
        Connect to *address*, returning a result code.

        .. versionchanged:: 23.7.0
           No longer uses an overridden ``connect`` method on
           this object. Instead, like the standard library, this method always
           uses a non-replacable internal connection function.
        r   N)	r   r   r   rG   r   r   errnor   r   )rW   r   exerrrZ   rZ   r[   
connect_exP  s"   	
zSocketMixin.connect_exc                 C   s   | j dkr| j|S t| j|}t| j t dU 	 | tjtj	}|r.t
|t|| j|}|r:|tkr;n-|tttfv sH|tkrOtrO| | j nt|tr`|d dkr`|tkr`t}t
|t|qW d    d S 1 ssw   Y  d S )Nr   r   r   r   zfe80::1)r   r   r   r   r:   _start_new_or_dummyr   r   r   SO_ERRORr   rI   r   rH   rD   rE   rF   rC   
is_windows_waitr   r   r   rL   rN   )rW   r   r   ru   rZ   rZ   r[   r   p  s*   


"zSocketMixin._internal_connectc              
   G   d   	 z| j j| W S  ty* } z|jd tks| jdkr t  W Y d }~nd }~ww | | j qNr   r   r   )	r   recvr   r   rD   r   r6   r   r   rW   r   r   rZ   rZ   r[   r     s   zSocketMixin.recvc              
   G   r   r   )	r   recvfromr   r   rD   r   r6   r   r   r   rZ   rZ   r[   r        zSocketMixin.recvfromc              
   G   r   r   )	r   recvfrom_intor   r   rD   r   r6   r   r   r   rZ   rZ   r[   r     r   zSocketMixin.recvfrom_intoc              
   G   r   r   )	r   	recv_intor   r   rD   r   r6   r   r   r   rZ   rZ   r[   r     r   zSocketMixin.recv_intor   c                 C   s   t |}t| ||S rv   )_get_memoryr   )rW   datars   r   rZ   rZ   r[   sendall  s   zSocketMixin.sendallc                 G   s   z| j j| W S  tyZ } zG|jd tks| jdkr t  | | j z| j j| W W  Y d }~S  tyU } z|jd tkrPt  W Y d }~W Y d }~dS  d }~ww d }~ww Nr   r   )	r   sendtor   r   rD   r   r6   r   r   )rW   r   r   ex2rZ   rZ   r[   r     s$   zSocketMixin.sendtoc                 C   s   |t u r| j}z| j||W S  tyb } zG|jd tvs"|dkr# t  | | j	 z| j||W W  Y d }~S  ty] } z|jd t
krXt  W Y d }~W Y d }~dS  d }~ww d }~ww r   )timeout_defaultr   r   r   r   r   
GSENDAGAINr6   r   r   rD   )rW   r   rs   r   r   r   rZ   rZ   r[   r     s(   zSocketMixin.sendc              
   C   st   t |  D ]1\}}|drqt|dr|jrqttj|d }|r%|js&qz|j|_W q tt	fy7   Y qw d S )Nr   __doc__)
varsitems
startswithhasattrr   getattrr   r   r   r   )clskvsmethrZ   rZ   r[   _fixup_docstrings  s   

zSocketMixin._fixup_docstringsN)r   )/r\   r]   r^   	__slots__rU   rS   r   r   r   r   propertyr   _wait_on_socketr   r   r   r   r   rq   rr   rk   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   classmethodr   rZ   rZ   rZ   r[   r     sP    	

 !



r   )r   r   r   r   )r|   )c
__future__r   _implements__dns____extensions____imports__r   gevent._hub_localr0   r`   gevent._compatr1   r2   r3   r4   r   r5   is_macosr6   gevent._utilr7   gevent._greenlet_primitivesr8   r   gevent._hub_primitivesr9   r  gevent.timeoutr:   extendr   r=   rC   r>   rD   r?   rE   r@   rF   rA   rH   gevent.win32utilrB   rI   rG   osrJ   ImportErrorrL   rN   r   rO   _socketr   _realsocketr   backports.socketpair	backportsr   r   _name_valueglobals__all__r   r   appendr   _timeout_errorgeventrR   set_default_timeout_errorwait_on_watcherwaitr   r   r   rS   r   r	   r
   r   rg   r   r   r   r   r   r   r   AF_INETr   has_ipv6AF_INET6r   objectr   r   r   rZ   rZ   rZ   r[   <module>   s   	$	







#$
;$  B