
    Rǻi,                    \   d dl mZ d dlmZ d dlmZmZmZm	Z	 ddl
mZ  ej                  d      Zej                  r G d dej                         Zg d	Z G d
 d ee            Z G d dee      Z G d de      Z G d de      Z G d de      Z G d dee      Z G d dee      Zy)    )annotations)suppress)AddressFamilyAF_INETAF_INET6getservbyname   )_typing_Tc                      e Zd ZddZy)_WithPeerNamec                     y N selfs    O/opt/lhia/marcimex/agent/venv/lib/python3.12/site-packages/neo4j/_addressing.pygetpeernamez_WithPeerName.getpeername$   s        N)returntuple)__name__
__module____qualname__r   r   r   r   r   r   #   s    +r   r   )AddressIPv4AddressIPv6AddressResolvedAddressResolvedIPv4AddressResolvedIPv6Addressc                  D     e Zd Z fdZd Zed        Zed        Z xZS )_AddressMetac                @    t        |   |i | d | _        d | _        y r   )super__init__	_ipv4_cls	_ipv6_cls)clsargskwargs	__class__s      r   r%   z_AddressMeta.__init__2   s#    $)&)r   c                    | j                         D cg c]-  }|j                  | j                  k(  rt        |dd       |k(  r|/ }}t        |      dk7  rt	        d|  d| d|       |d   S c c}w )Nfamilyr	   zClass z= needs exactly one direct subclass with attribute `family == z` within this module. Found: r   )__subclasses__r   getattrlen
ValueError)r(   r-   sc
subclassess       r   _subclass_by_familyz _AddressMeta._subclass_by_family7   s     ((*
/B$/69	 

 
 z?a ((.x 0$' 
 !}
s   2A.c                f    | j                   | j                  t              | _         | j                   S r   )r&   r4   r   r(   s    r   ipv4_clsz_AddressMeta.ipv4_clsH   s(    == 33G<CM}}r   c                f    | j                   | j                  t              | _         | j                   S r   )r'   r4   r   r6   s    r   ipv6_clsz_AddressMeta.ipv6_clsN   s(    == 33H=CM}}r   )	r   r   r   r%   r4   propertyr7   r9   __classcell__r+   s   @r   r"   r"   1   s5    
"  
  r   r"   c                      e Zd ZU dZdZded<   ddZedd       Ze	 	 d	 	 	 	 	 	 	 dd       Z	eddd	 	 	 	 	 	 	 dd	       Z
d
 Zedd       Zedd       Zedd       Zedd       Zedd       Zd Zy)r   aj  
    Base class to represent server addresses within the driver.

    A tuple of two (IPv4) or four (IPv6) elements, representing the address
    parts. See also python's :mod:`socket` module for more information.

        >>> Address(("example.com", 7687))
        IPv4Address(('example.com', 7687))
        >>> Address(("127.0.0.1", 7687))
        IPv4Address(('127.0.0.1', 7687))
        >>> Address(("::1", 7687, 0, 0))
        IPv6Address(('::1', 7687, 0, 0))

    :param iterable: A collection of two or four elements creating an
        :class:`.IPv4Address` or :class:`.IPv6Address` instance respectively.
    NzAddressFamily | Noner-   c                    t        ||       r|S t        |      }t        j                  | |      }|dk(  r| j                  |_        |S |dk(  r| j                  |_        |S t        d      )N      zFAddresses must consist of either two parts (IPv4) or four parts (IPv6))
isinstancer0   r   __new__r7   r+   r9   r1   )r(   iterablen_partsinsts       r   rB   zAddress.__new__j   sr    h$Oh-}}S(+a< \\DN  \ \\DN 	 8 r   c                2    |j                         } | |      S )z
        Create an address from a socket object.

        Uses the socket's ``getpeername`` method to retrieve the remote
        address the socket is connected to.
        )r   )r(   socketaddresss      r   from_socketzAddress.from_socketz   s     $$&7|r   c                "   t        |t              st        d      |j                  d      rq|dd j	                  d      \  }}}|j                  d      }t        t        t              5  t        |      }ddd       |xs |xs d}|xs |xs d} | ||ddf      S |j                  d      \  }}}t        t        t              5  t        |      }ddd       |xs |xs d}|xs |xs d} | ||f      S # 1 sw Y   xY w# 1 sw Y   3xY w)	a  
        Parse a string into an address.

        The string must be in the format ``host:port`` (IPv4) or
        ``[host]:port`` (IPv6).
        If no port is specified, or is empty, ``default_port`` will be used.
        If no host is specified, or is empty, ``default_host`` will be used.

            >>> Address.parse("localhost:7687")
            IPv4Address(('localhost', 7687))
            >>> Address.parse("[::1]:7687")
            IPv6Address(('::1', 7687, 0, 0))
            >>> Address.parse("localhost")
            IPv4Address(('localhost', 0))
            >>> Address.parse("localhost", default_port=1234)
            IPv4Address(('localhost', 1234))

        :param s: The string to parse.
        :param default_host: The default host to use if none is specified.
            :data:`None` indicates to use ``"localhost"`` as default.
        :param default_port: The default port to use if none is specified.
            :data:`None` indicates to use ``0`` as default.

        :returns: The parsed address.
        z(Address.parse requires a string argument[r	   N]:	localhostr   )
rA   str	TypeError
startswith
rpartitionlstrip	_suppressr1   int	partition)r(   sdefault_hostdefault_porthost_ports          r   parsezAddress.parse   s   @ !S!FGG<< abE,,S1MD!T;;s#D9j1 !4y!6<6;D,<,1DdAq)** KK,MD!T9j1 !4y!6<6;D,<,1Dd|$$! !! !s   *C9D9DD)rX   rY   c                   t        d |D              st        d      dj                  |      j                         D cg c]  }| j	                  |||       c}S c c}w )ao  
        Parse multiple addresses into a list.

        See :meth:`.parse` for details on the string format.

        Either a whitespace-separated list of strings or multiple strings
        can be used.

            >>> Address.parse_list("localhost:7687", "[::1]:7687")
            [IPv4Address(('localhost', 7687)), IPv6Address(('::1', 7687, 0, 0))]
            >>> Address.parse_list("localhost:7687 [::1]:7687")
            [IPv4Address(('localhost', 7687)), IPv6Address(('::1', 7687, 0, 0))]

        :param s: The string(s) to parse.
        :param default_host: The default host to use if none is specified.
            :data:`None` indicates to use ``"localhost"`` as default.
        :param default_port: The default port to use if none is specified.
            :data:`None` indicates to use ``0`` as default.

        :returns: The list of parsed addresses.
        c              3  <   K   | ]  }t        |t                y wr   )rA   rO   ).0s0s     r   	<genexpr>z%Address.parse_list.<locals>.<genexpr>   s     32:b#&3s   z-Address.parse_list requires a string argument )allrP   joinsplitr]   )r(   rX   rY   rW   as        r   
parse_listzAddress.parse_list   s^    8 333KLL XXa[&&(
 IIa|4
 	
 
s   Ac                L    | j                   j                   dt        |       dS )N())r+   r   r   r   s    r   __repr__zAddress.__repr__   s$    ..))*!E$K?!<<r   c                    | d   S )Nr   r   r   s    r   
_host_namezAddress._host_name   s    Awr   c                    | d   S )z
        The host part of the address.

        This is the first part of the address tuple.

            >>> Address(("localhost", 7687)).host
            'localhost'
        r   r   r   s    r   rZ   zAddress.host   s     Awr   c                    | d   S )a  
        The port part of the address.

        This is the second part of the address tuple.

            >>> Address(("localhost", 7687)).port
            7687
            >>> Address(("localhost", 7687, 0, 0)).port
            7687
            >>> Address(("localhost", "7687")).port
            '7687'
            >>> Address(("localhost", "http")).port
            'http'
        r	   r   r   s    r   r\   zAddress.port   s      Awr   c                    | S r   r   r   s    r   _unresolvedzAddress._unresolved  s    r   c                    t         }	 t        | d         S # t        $ r	 t        }Y nt         $ r Y nw xY w	 t	        | d         S # t        $ r	 t        }Y nt         $ r Y nw xY w |d| d         )a  
        The port part of the address as an integer.

        First try to resolve the port as an integer, using
        :func:`socket.getservbyname`. If that fails, fall back to parsing the
        port as an integer.

            >>> Address(("localhost", 7687)).port_number
            7687
            >>> Address(("localhost", "http")).port_number
            80
            >>> Address(("localhost", "7687")).port_number
            7687
            >>> Address(("localhost", [])).port_number
            Traceback (most recent call last):
                ...
            TypeError: Unknown port value []
            >>> Address(("localhost", "banana-protocol")).port_number
            Traceback (most recent call last):
                ...
            ValueError: Unknown port value 'banana-protocol'

        :returns: The resolved port number.

        :raise ValueError: If the port cannot be resolved.
        :raise TypeError: If the port cannot be resolved.
        r	   zUnknown port value )rP   r   OSErrorr1   rU   )r   	error_clss     r   port_numberzAddress.port_number  s    : $		 a)) 	#"I 			tAw< 	#"I 		-d1g[9::s'    222A A A A c                &    t         t        |       ffS r   )r   r   r   s    r   
__reduce__zAddress.__reduce__5  s    t&&r   )rC   zt.Collectionr   r   )rG   r   r   r   )NN)rW   rO   rX   
str | NonerY   
int | Noner   r   )rW   rO   rX   ry   rY   rz   r   zlist[Address])r   zt.Anyr   r   )r   rU   )r   r   r   __doc__r-   __annotations__rB   classmethodrI   r]   rh   rl   r:   rn   rZ   r\   rr   rv   rx   r   r   r   r   r   U   s"   $ $(F '     $(#'	2%2% !2% !	2%
 
2% 2%h  $(#'	 
 
 ! 
 !	 

 
 
  
D=   	 	  "   ,; ,;\'r   r   )	metaclassc                      e Zd ZdZeZddZy)r   ae  
    An IPv4 address (family ``AF_INET``).

    This class is also used for addresses that specify a host name instead of
    an IP address. E.g.,

        >>> Address(("example.com", 7687))
        IPv4Address(('example.com', 7687))

    This class should not be instantiated directly. Instead, use
    :class:`.Address` or one of its factory methods.
    c                      dj                   |  S )Nz{}:{}formatr   s    r   __str__zIPv4Address.__str__I  s    w~~t$$r   Nr   rO   )r   r   r   r|   r   r-   r   r   r   r   r   r   9  s     F%r   r   c                      e Zd ZdZeZddZy)r   z
    An IPv6 address (family ``AF_INET6``).

    This class should not be instantiated directly. Instead, use
    :class:`.Address` or one of its factory methods.
    c                      dj                   |  S )Nz[{}]:{}r   r   s    r   r   zIPv6Address.__str__W  s    y&&r   Nr   )r   r   r   r|   r   r-   r   r   r   r   r   r   M  s     F'r   r   c                  Z     e Zd ZU ded<   edd       Zed fd       Zd	 fdZd Z xZ	S )
r   rO   _unresolved_host_namec                    | j                   S r   )r   r   s    r   rn   zResolvedAddress._host_name^  s    )))r   c                N    t         |   t        | j                  g| dd        S )Nr	   )r$   rB   r   rn   )r   r+   s    r   rr   zResolvedAddress._unresolvedb  s&    ww(D48(DEEr   c                j    t         |   | |      }t        j                  t        |      }||_        |S r   )r$   rB   tcastr   r   )r(   rC   	host_namenewr+   s       r   rB   zResolvedAddress.__new__f  s0    goc8,ff_c*$-!
r   c                <    t         t        |       | j                  ffS r   )r   r   r   r   s    r   rx   zResolvedAddress.__reduce__l  s    td.H.H IIIr   r   r{   )r   rO   r   r   )
r   r   r   r}   r:   rn   rr   rB   rx   r;   r<   s   @r   r   r   [  s<    * * F FJr   r   c                      e Zd Zy)r   Nr   r   r   r   r   r   r   r   p      r   r   c                      e Zd Zy)r    Nr   r   r   r   r    r    t  r   r   r    N)
__future__r   
contextlibr   rT   rG   r   r   r   r    r
   r   TypeVarr   TYPE_CHECKINGProtocolr   __all__typer   r"   r   r   r   r   r   r    r   r   r   <module>r      s   " # ,   QYYt_ ??,

 ,!4; !Ha'e| a'H%' %('' 'Jg J*	+ 		+ 	r   