U
    gY                     @  s   d dl mZ d dlZd dlmZ d dlmZmZmZ d dl	Z	d dl
mZmZ er\d dlmZ G dd deZed	ed
Zzd dl
mZ dZW n ek
r   dZY nX ed	ddddZdddddZdS )    )annotationsN)contextmanager)TYPE_CHECKINGProtocolTypeVar)SOCK_STREAMsocket)	Generatorc                   @  s   e Zd ZddddZdS )ClosableNone)returnc                 C  s   d S N )selfr   r   D/tmp/pip-unpacked-wheel-ks04xdmi/trio/_highlevel_open_unix_stream.pyclose       zClosable.closeN)__name__
__module____qualname__r   r   r   r   r   r
      s   r
   CloseT)bound)AF_UNIXTFzGenerator[CloseT, None, None])objr   c                 c  s&   z
| V  W n   |     Y nX d S r   )r   )r   r   r   r   close_on_error   s
    
r   z3str | bytes | os.PathLike[str] | os.PathLike[bytes]ztrio.SocketStream)filenamer   c              	     sJ   t stdttt}t| |t| I dH  W 5 Q R X t	
|S )a  Opens a connection to the specified
    `Unix domain socket <https://en.wikipedia.org/wiki/Unix_domain_socket>`__.

    You must have read/write permission on the specified file to connect.

    Args:
      filename (str or bytes): The filename to open the connection to.

    Returns:
      SocketStream: a :class:`~trio.abc.Stream` connected to the given file.

    Raises:
      OSError: If the socket file could not be connected to.
      RuntimeError: If AF_UNIX sockets are not supported.
    z/Unix sockets are not supported on this platformN)has_unixRuntimeErrorr   r   r   r   connectosfspathtrioZSocketStream)r   sockr   r   r   open_unix_socket&   s    

 r#   )
__future__r   r   
contextlibr   typingr   r   r   r!   Ztrio.socketr   r   collections.abcr	   r
   r   r   r   ImportErrorr   r#   r   r   r   r   <module>   s"   
