
    Bh%	                     N    d dl Z d dlmZ d dlmZ d dlmZ d Zd Z	d Z
d Zd	 Zy)
    N)ImproperlyConfigured)gettext)get_cms_settingc                  R   t        d      j                  dd      \  } }	 t        j                  |       }t	        ||      }|S # t
        $ r)}t        t        d      j                  |             |d}~wt        $ r*}t        t        d      j                  ||             |d}~ww xY w)z
    This is the recommended method for obtaining the specified
    CMS_REQUEST_IP_RESOLVER as it also does some basic import validation.

    Returns the resolver or raises an ImproperlyConfigured exception.
    REQUEST_IP_RESOLVER.   zCUnable to find the specified CMS_REQUEST_IP_RESOLVER module: "{0}".NzUUnable to find the specified CMS_REQUEST_IP_RESOLVER function: "{0}" in module "{1}".)
r   rsplit	importlibimport_modulegetattrImportErrorr   _formatAttributeError)module	attributeip_resolver_moduleip_resolvererrs        N/home/dcms/DCMS/lib/python3.12/site-packages/cms/utils/request_ip_resolvers.pyget_request_ip_resolverr   	   s     ((=>EEc1MFI
L&44V<0)<   1"  v(-0	1  L" ' ((.y&(ACHK	LLs#   !A 	B&$A00B&<%B!!B&c                 L    t        |       xs t        |       xs t        |       S )z
    This is a hybrid request IP resolver that attempts should address most
    cases. Order is important here. A 'REAL_IP' header supersedes an
    'X_FORWARDED_FOR' header which supersedes a 'REMOTE_ADDR' header.
    )real_ipx_forwarded_ipremote_addr_iprequests    r   default_request_ip_resolverr      s%     	NN73N~g7N    c                 8    | j                   j                  d      S )z
    Returns the IP Address contained in the HTTP_X_REAL_IP headers, if
    present. Otherwise, `None`.

    Should handle Nginx and some other WSGI servers.
    z	X-Real-Ip)headersgetr   s    r   r   r   *   s     ??{++r    c                 8    | j                   j                  d      S )z
    Returns the IP Address contained in the 'REMOTE_ADDR' header, if
    present. Otherwise, `None`.

    Should be suitable for local-development servers and some HTTP servers.
    REMOTE_ADDR)METAr#   r   s    r   r   r   4   s     <<M**r    c                 j    | j                   j                  d      }|r|j                  d      }|d   S y)z
    Returns the IP Address contained in the 'HTTP_X_FORWARDED_FOR' header, if
    present. Otherwise, `None`.

    Should handle properly configured proxy servers.
    zX-Forwarded-For,r   N)r"   r#   split)r   ip_address_lists     r   r   r   >   s<     oo))*;<O)//4q!! r    )r   django.core.exceptionsr   django.utils.translationr   r   cms.utils.confr   r   r   r   r   r    r    r   <module>r/      s*     7 1 *,,+
"r    