o
    iiD3                     @  s  U d dl m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"eB eB Z#de$d< e%e"e&f Z'de$d< e'e"B Z(de$d< e%e)e'f Z*de$d< e%e)e"f Z+de$d< edZ,ej-fdddd8d$d%Z.G d&d' d'eZ/G d(d) d)eZ0G d*d+ d+ee0Z1G d,d- d-e1Z2G d.d/ d/ee1 e0Z3G d0d1 d1ee* e0Z4G d2d3 d3ee) e0Z5G d4d5 d5ee+ e0Z6G d6d7 d7ee) e0Z7dS )9    )annotationsN)abstractmethod)Callable
CollectionMapping)AsyncExitStack)IOBase)IPv4AddressIPv6Address)AddressFamily)Any	TypeAliasTypeVar   )get_async_backend)TypedAttributeProviderTypedAttributeSettyped_attribute   )
ByteStreamListenerUnreliableObjectStream)	TaskGroupr   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 rB   Z/var/www/scraper.webshop2u.hu/html/venv/lib/python3.10/site-packages/anyio/abc/_sockets.py_validate_socket   sv   







rD   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   r6   r   local_addressr,   
local_portr)   
raw_socketremote_addressremote_portN)__name__
__module__r4   __doc__r   r6   __annotations__rF   rG   rH   rI   rJ   rB   rB   rB   rC   rE   c   s   
  rE   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_socketr6   rB   selfrB   rC   <lambda>   s    z2_SocketProvider.extra_attributes.<locals>.<lambda>c                     s    j  S rR   rS   r9   rB   )convertrU   rB   rC   rV      s    c                     s    j S rR   )rS   rB   rT   rB   rC   rV          c                         S rR   rB   rB   )peernamerB   rC   rV          c                     s    j  d S )Nr   rW   rB   rT   rB   rC   rV      s   r   c                     rZ   rR   rB   rB   )rJ   rB   rC   rV      r\   )_core._socketsrQ   rE   r6   rF   rH   rS   r5   r.   rI   r   r7   r8   rG   rJ   )rU   
attributesrB   )rX   r[   rJ   rU   rC   extra_attributes   s$   z _SocketProvider.extra_attributesr)   c                 C  s   d S rR   rB   rT   rB   rB   rC   rS      s   z_SocketProvider._raw_socketN)r(   rP   )r(   r)   )rK   rL   r4   propertyr_   r   rS   rB   rB   rB   rC   rO      s    rO   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)rD   r-   SOCK_STREAMr   wrap_stream_socketclsr!   r?   rB   rB   rC   from_socket      zSocketStream.from_socketN)r!   r"   r(   rb   rK   rL   r4   rM   classmethodri   rB   rB   rB   rC   rb          rb   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

        Trd   N)rD   r-   re   AF_UNIXr   wrap_unix_stream_socketrg   rB   rB   rC   ri      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)
        NrB   )rU   rr   rt   rB   rB   rC   send_fds   rY   zUNIXSocketStream.send_fdsmsglenr,   maxfdstuple[bytes, list[int]]c                   rw   )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)
        NrB   )rU   ry   rz   rB   rB   rC   receive_fds   rY   zUNIXSocketStream.receive_fdsN)r!   r"   r(   rn   )rr   rs   rt   ru   r(   rv   )ry   r,   rz   r,   r(   r{   )rK   rL   r4   rl   ri   r   rx   r|   rB   rB   rB   rC   rn      s    	rn   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                   rc   )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)rD   r-   re   r   wrap_listener_socketrg   rB   rB   rC   ri      s   zSocketListener.from_socketrb   c                   rw   )zAccept an incoming connection.NrB   rT   rB   rB   rC   accept  rY   zSocketListener.acceptNhandlerCallable[[SocketStream], Any]
task_groupTaskGroup | Nonerv   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)rU   r   r   r   stackstreamrB   rB   rC   serve  s   zSocketListener.serve)r!   r"   r(   r}   )r(   rb   rR   )r   r   r   r   r(   rv   )	rK   rL   r4   rM   rl   ri   r   r   r   rB   rB   rB   rC   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                   rc   )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)rD   r-   
SOCK_DGRAMr   wrap_udp_socketrg   rB   rB   rC   ri   #  rj   zUDPSocket.from_socketdatars   hoststrportr,   rv   c                   s   |  |||ffI dH S )z^
        Alias for :meth:`~.UnreliableObjectSendStream.send` ((data, (host, port))).

        Nsend)rU   r   r   r   rB   rB   rC   sendto2  s   zUDPSocket.sendtoN)r!   r"   r(   r   )r   rs   r   r   r   r,   r(   rv   rK   rL   r4   rM   rl   ri   r   rB   rB   rB   rC   r     s
    r   c                   @  ra   )	ConnectedUDPSocketzy
    Represents an connected UDP socket.

    Supports all relevant extra attributes from :class:`~SocketAttribute`.
    r!   r"   r(   c                   rc   )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

        Trd   N)rD   r-   r   r   wrap_connected_udp_socketrg   rB   rB   rC   ri   A  s   zConnectedUDPSocket.from_socketN)r!   r"   r(   r   rk   rB   rB   rB   rC   r   :  rm   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)rD   r-   r   rp   r   wrap_unix_datagram_socketrg   rB   rB   rC   ri   ^  s   zUNIXDatagramSocket.from_socketr   rs   pathr   rv   c                   s   |  ||fI dH S )zCAlias for :meth:`~.UnreliableObjectSendStream.send` ((data, path)).Nr   )rU   r   r   rB   rB   rC   r   p  s   zUNIXDatagramSocket.sendtoN)r!   r"   r(   r   )r   rs   r   r   r(   rv   r   rB   rB   rB   rC   r   U  s
    r   c                   @  ra   )	ConnectedUNIXDatagramSocketz
    Represents a connected Unix datagram socket.

    Supports all relevant extra attributes from :class:`~SocketAttribute`.
    r!   r"   r(   c                   ro   )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

        Trd   N)rD   r-   r   rp   r   #wrap_connected_unix_datagram_socketrg   rB   rB   rC   ri   |  s
   z'ConnectedUNIXDatagramSocket.from_socketN)r!   r"   r(   r   rk   rB   rB   rB   rC   r   u  rm   r   )r!   r"   r#   r$   r%   r&   r   r'   r    r'   r(   r)   )8
__future__r   r/   r-   abcr   collections.abcr   r   r   
contextlibr   ior   	ipaddressr	   r
   r   typingr   r   r   _core._eventloopr   _core._typedattrr   r   r   _streamsr   r   r   _tasksr   r   r   rN   tupler,   r   r   rs   r   r   r   r:   rD   rE   rO   rb   rn   r}   r   r   r   r   rB   rB   rB   rC   <module>   sH    E)&',
 