a
    f	gj                     @   sZ   d Z ddlmZmZmZmZmZ dadadddZ	dd Z
ddd	Zdd
dZdd ZdS )z>Implementation of the ipaddres-based network types adaptation
    )new_typenew_array_typeregister_typeregister_adapterQuotedStringNc                 C   sR   ddl a tdu rt atD ]}t||  qt jt jt jt jfD ]}t|t	 q>dS )a  
    Register conversion support between `ipaddress` objects and `network types`__.

    :param conn_or_curs: the scope where to register the type casters.
        If `!None` register them globally.

    After the function is called, PostgreSQL :sql:`inet` values will be
    converted into `~ipaddress.IPv4Interface` or `~ipaddress.IPv6Interface`
    objects, :sql:`cidr` values into into `~ipaddress.IPv4Network` or
    `~ipaddress.IPv6Network`.

    .. __: https://www.postgresql.org/docs/current/static/datatype-net-types.html
    r   N)
	ipaddress_casters_make_castersr   IPv4InterfaceIPv6InterfaceIPv4NetworkIPv6Networkr   adapt_ipaddress)Zconn_or_cursct r   V/var/www/html/llm_bihealth/app/venv/lib/python3.9/site-packages/psycopg2/_ipaddress.pyregister_ipaddress%   s    r   c                  C   s<   t ddt} tdd| }t ddt}tdd|}| |||gS )	N)ie  ZINET)i  zINET[])i  ZCIDR)i  zCIDR[])r   cast_interfacer   cast_network)ZinetZainetZcidrZacidrr   r   r   r	   B   s
    r	   c                 C   s   | d u rd S t t| S N)r   ip_interfacestrscurr   r   r   r   L   s    r   c                 C   s   | d u rd S t t| S r   )r   
ip_networkr   r   r   r   r   r   S   s    r   c                 C   s   t t| S r   )r   r   )objr   r   r   r   Y   s    r   )N)N)N)__doc__Zpsycopg2.extensionsr   r   r   r   r   r   r   r   r	   r   r   r   r   r   r   r   <module>   s   



