o
    "h3                     @  s,  U d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZmZ d dlmZ d d	lmZmZmZ d
dlmZ d
dlmZmZmZ ddlmZmZm Z  ddl!m"Z" ej#dkrsd dlm$Z$ nd dl%m$Z$ ee&eef Z'de(d< e)e&e*f Z+de(d< ee+e&f Z,de(d< e)e-e+f Z.de(d< e)e-e&f Z/de(d< edZ0ej1fdddd:d&d'Z2G d(d) d)eZ3G d*d+ d+eZ4G d,d- d-ee4Z5G d.d/ d/e5Z6G d0d1 d1ee5 e4Z7G d2d3 d3e e. e4Z8G d4d5 d5e e- e4Z9G d6d7 d7e e/ e4Z:G d8d9 d9e e- e4Z;dS );    )annotationsN)abstractmethod)Callable
CollectionMapping)AsyncExitStack)IOBase)IPv4AddressIPv6Address)AddressFamily)AnyTypeVarUnion   )get_async_backend)TypedAttributeProviderTypedAttributeSettyped_attribute   )
ByteStreamListenerUnreliableObjectStream)	TaskGroup)   
   )	TypeAliasr   IPAddressTypeIPSockAddrTypeSockAddrTypeUDPPacketTypeUNIXDatagramPacketTypeT_RetvalF)require_connectedrequire_bound
sock_or_fdsocket.socket | int	sock_typesocket.SocketKindaddr_familysocket.AddressFamilyr"   boolr#   returnsocket.socketc             
   C  s  t | tr4ztj| d}W n: ty3 } z|jtjkr td||r'td||r.td| d }~ww t | tjr=| }ntdt| j	 dzo|rcz|
  W n tyb } ztd|d }~ww |rz|jtjtjfv rv| d }n| }W n ty   d }Y nw |std|tjkr|j|krtd|j d	|jj |j|krtd
|j d	|jj W n ty   t | tr|   w |d |S )N)filenoz.the file descriptor does not refer to a socketzthe socket must be connectedz+the socket must be bound to a local addresszexpected an int or socket, got z insteadr   z"address family mismatch: expected z, got zsocket type mismatch: expected F)
isinstanceintsocketOSErrorerrnoENOTSOCK
ValueError	TypeErrortype__qualname__getpeernamefamilyAF_INETAF_INET6getsockname	AF_UNSPECnameBaseExceptiondetachsetblocking)r$   r&   r(   r"   r#   sockexc
bound_addr rE   E/var/www/html/venv/lib/python3.10/site-packages/anyio/abc/_sockets.py_validate_socket$   sv   







rG   c                   @  sf   e Zd ZU dZe Zded< e Zded< e Zded< e Z	ded	< e Z
ded
< e Zded< dS )SocketAttributea  
    .. attribute:: family
        :type: socket.AddressFamily

        the address family of the underlying socket

    .. attribute:: local_address
        :type: tuple[str, int] | str

        the local address the underlying socket is connected to

    .. attribute:: local_port
        :type: int

        for IP based sockets, the local port the underlying socket is bound to

    .. attribute:: raw_socket
        :type: socket.socket

        the underlying stdlib socket object

    .. attribute:: remote_address
        :type: tuple[str, int] | str

        the remote address the underlying socket is connected to

    .. attribute:: remote_port
        :type: int

        for IP based sockets, the remote port the underlying socket is connected to
    r   r9   r   local_addressr/   
local_portr,   
raw_socketremote_addressremote_portN)__name__
__module__r7   __doc__r   r9   __annotations__rI   rJ   rK   rL   rM   rE   rE   rE   rF   rH   i   s   
  rH   c                   @  s,   e Zd Zed	ddZeed
ddZdS )_SocketProviderr+   Mapping[Any, Callable[[], Any]]c                   s   ddl m  tjfddtj fddtjfddi}z	 j W n ty2   d Y nw d ur@fdd|tj	< jjt
jt
jfv rdfdd|tj< d urdd	 fd
d|tj< |S )Nr   )convert_ipv6_sockaddrc                     s    j jS N)_raw_socketr9   rE   selfrE   rF   <lambda>   s    z2_SocketProvider.extra_attributes.<locals>.<lambda>c                     s    j  S rU   rV   r<   rE   )convertrX   rE   rF   rY      s    c                     s    j S rU   )rV   rE   rW   rE   rF   rY          c                         S rU   rE   rE   )peernamerE   rF   rY          c                     s    j  d S )Nr   rZ   rE   rW   rE   rF   rY      s    r   c                     r]   rU   rE   rE   )rM   rE   rF   rY      r_   )_core._socketsrT   rH   r9   rI   rK   rV   r8   r1   rL   r   r:   r;   rJ   rM   )rX   
attributesrE   )r[   r^   rM   rX   rF   extra_attributes   s&   
z _SocketProvider.extra_attributesr,   c                 C  s   d S rU   rE   rW   rE   rE   rF   rV      s   z_SocketProvider._raw_socketN)r+   rS   )r+   r,   )rN   rO   r7   propertyrb   r   rV   rE   rE   rE   rF   rR      s    rR   c                   @     e Zd ZdZedddZdS )	SocketStreamzu
    Transports bytes over a socket.

    Supports all relevant extra attributes from :class:`~SocketAttribute`.
    r$   r%   r+   c                   $   t |tjdd}t |I dH S )aH  
        Wrap an existing socket object or file descriptor as a socket stream.

        The newly created socket wrapper takes ownership of the socket being passed in.
        The existing socket must already be connected.

        :param sock_or_fd: a socket object or file descriptor
        :return: a socket stream

        Tr"   N)rG   r0   SOCK_STREAMr   wrap_stream_socketclsr$   rB   rE   rE   rF   from_socket      zSocketStream.from_socketN)r$   r%   r+   re   rN   rO   r7   rP   classmethodrl   rE   rE   rE   rF   re          re   c                   @  s6   e Zd ZedddZedddZedddZdS )UNIXSocketStreamr$   r%   r+   c                   (   t |tjtjdd}t |I dH S )aR  
        Wrap an existing socket object or file descriptor as a UNIX socket stream.

        The newly created socket wrapper takes ownership of the socket being passed in.
        The existing socket must already be connected.

        :param sock_or_fd: a socket object or file descriptor
        :return: a UNIX socket stream

        Trg   N)rG   r0   rh   AF_UNIXr   wrap_unix_stream_socketrj   rE   rE   rF   rl      s
   zUNIXSocketStream.from_socketmessagebytesfdsCollection[int | IOBase]Nonec                      dS )z
        Send file descriptors along with a message to the peer.

        :param message: a non-empty bytestring
        :param fds: a collection of files (either numeric file descriptors or open file
            or socket objects)
        NrE   )rX   ru   rw   rE   rE   rF   send_fds   r\   zUNIXSocketStream.send_fdsmsglenr/   maxfdstuple[bytes, list[int]]c                   rz   )a  
        Receive file descriptors along with a message from the peer.

        :param msglen: length of the message to expect from the peer
        :param maxfds: maximum number of file descriptors to expect from the peer
        :return: a tuple of (message, file descriptors)
        NrE   )rX   r|   r}   rE   rE   rF   receive_fds   r\   zUNIXSocketStream.receive_fdsN)r$   r%   r+   rq   )ru   rv   rw   rx   r+   ry   )r|   r/   r}   r/   r+   r~   )rN   rO   r7   ro   rl   r   r{   r   rE   rE   rE   rF   rq      s    	rq   c                   @  s:   e Zd ZdZedddZeddd	Z	
ddddZd
S )SocketListenerz}
    Listens to incoming socket connections.

    Supports all relevant extra attributes from :class:`~SocketAttribute`.
    r$   r%   r+   c                   rf   )a  
        Wrap an existing socket object or file descriptor as a socket listener.

        The newly created listener takes ownership of the socket being passed in.

        :param sock_or_fd: a socket object or file descriptor
        :return: a socket listener

        Tr#   N)rG   r0   rh   r   wrap_listener_socketrj   rE   rE   rF   rl      s   zSocketListener.from_socketre   c                   rz   )zAccept an incoming connection.NrE   rW   rE   rE   rF   accept  r\   zSocketListener.acceptNhandlerCallable[[SocketStream], Any]
task_groupTaskGroup | Nonery   c              	     sp   ddl m} t 4 I d H }|d u r|| I d H }	 |  I d H }||| q1 I d H s1w   Y  d S )Nr   )create_task_group) r   r   enter_async_contextr   
start_soon)rX   r   r   r   stackstreamrE   rE   rF   serve  s   zSocketListener.serve)r$   r%   r+   r   )r+   re   rU   )r   r   r   r   r+   ry   )	rN   rO   r7   rP   ro   rl   r   r   r   rE   rE   rE   rF   r      s    r   c                   @  s(   e Zd ZdZedddZdddZdS )	UDPSocketz{
    Represents an unconnected UDP socket.

    Supports all relevant extra attributes from :class:`~SocketAttribute`.
    r$   r%   r+   c                   rf   )aI  
        Wrap an existing socket object or file descriptor as a UDP socket.

        The newly created socket wrapper takes ownership of the socket being passed in.
        The existing socket must be bound to a local address.

        :param sock_or_fd: a socket object or file descriptor
        :return: a UDP socket

        Tr   N)rG   r0   
SOCK_DGRAMr   wrap_udp_socketrj   rE   rE   rF   rl   )  rm   zUDPSocket.from_socketdatarv   hoststrportr/   ry   c                   s   |  |||ffI dH S )z^
        Alias for :meth:`~.UnreliableObjectSendStream.send` ((data, (host, port))).

        Nsend)rX   r   r   r   rE   rE   rF   sendto8  s   zUDPSocket.sendtoN)r$   r%   r+   r   )r   rv   r   r   r   r/   r+   ry   rN   rO   r7   rP   ro   rl   r   rE   rE   rE   rF   r   "  s
    r   c                   @  rd   )	ConnectedUDPSocketzy
    Represents an connected UDP socket.

    Supports all relevant extra attributes from :class:`~SocketAttribute`.
    r$   r%   r+   c                   rf   )aV  
        Wrap an existing socket object or file descriptor as a connected UDP socket.

        The newly created socket wrapper takes ownership of the socket being passed in.
        The existing socket must already be connected.

        :param sock_or_fd: a socket object or file descriptor
        :return: a connected UDP socket

        Trg   N)rG   r0   r   r   wrap_connected_udp_socketrj   rE   rE   rF   rl   G  s   zConnectedUDPSocket.from_socketN)r$   r%   r+   r   rn   rE   rE   rE   rF   r   @  rp   r   c                   @  s(   e Zd ZdZedddZdddZdS )UNIXDatagramSocketz
    Represents an unconnected Unix datagram socket.

    Supports all relevant extra attributes from :class:`~SocketAttribute`.
    r$   r%   r+   c                   s$   t |tjtj}t |I dH S )a'  
        Wrap an existing socket object or file descriptor as a UNIX datagram
        socket.

        The newly created socket wrapper takes ownership of the socket being passed in.

        :param sock_or_fd: a socket object or file descriptor
        :return: a UNIX datagram socket

        N)rG   r0   r   rs   r   wrap_unix_datagram_socketrj   rE   rE   rF   rl   d  s   zUNIXDatagramSocket.from_socketr   rv   pathr   ry   c                   s   |  ||fI dH S )zCAlias for :meth:`~.UnreliableObjectSendStream.send` ((data, path)).Nr   )rX   r   r   rE   rE   rF   r   v  s   zUNIXDatagramSocket.sendtoN)r$   r%   r+   r   )r   rv   r   r   r+   ry   r   rE   rE   rE   rF   r   [  s
    r   c                   @  rd   )	ConnectedUNIXDatagramSocketz
    Represents a connected Unix datagram socket.

    Supports all relevant extra attributes from :class:`~SocketAttribute`.
    r$   r%   r+   c                   rr   )ar  
        Wrap an existing socket object or file descriptor as a connected UNIX datagram
        socket.

        The newly created socket wrapper takes ownership of the socket being passed in.
        The existing socket must already be connected.

        :param sock_or_fd: a socket object or file descriptor
        :return: a connected UNIX datagram socket

        Trg   N)rG   r0   r   rs   r   #wrap_connected_unix_datagram_socketrj   rE   rE   rF   rl     s
   z'ConnectedUNIXDatagramSocket.from_socketN)r$   r%   r+   r   rn   rE   rE   rE   rF   r   {  rp   r   )r$   r%   r&   r'   r(   r)   r"   r*   r#   r*   r+   r,   )<
__future__r   r2   r0   sysabcr   collections.abcr   r   r   
contextlibr   ior   	ipaddressr	   r
   r   typingr   r   r   _core._eventloopr   _core._typedattrr   r   r   _streamsr   r   r   _tasksr   version_infor   typing_extensionsr   r   rQ   tupler/   r   r   rv   r   r    r!   r=   rG   rH   rR   re   rq   r   r   r   r   r   rE   rE   rE   rF   <module>   sP    
E)&',
 