
    Sf                         d Z ddlZddlmZ ddlmZmZ ddlmZ	m
Z
 ddlmZ ddlmZ dd	lmZmZ d
 Zd Z G d de          ZdS )zO
When defining hostconfs you need to use the ``patterns`` and ``host`` helpers
    N)settings)ImproperlyConfiguredViewDoesNotExist)get_callableget_mod_func)	smart_str)cached_property   )normalize_schemenormalize_portc                     	 t          |           S # t          $ r3}t          |j        d                             dd                    d}~ww xY w)z
    Convert a string version of a function name to the callable object.

    If the lookup_view is not an import path, it is assumed to be a URL pattern
    label and the original string is returned.
    r   ViewCallableN)actual_get_callabler   r   argsreplace)lookup_viewexcs     G/var/www/html/env/lib/python3.11/site-packages/django_hosts/defaults.pyr   r      s]    L";/// L L L"38A;#6#6vz#J#JKKKLs    
A.A		Ac                    g }|D ]|}t          |t          t          f          rt          |d| i}n|                    |            |j        }|d |D             v rt          d|z            |                    |           }|S )a  
    The function to define the list of hosts (aka hostconfs), e.g.::

        from django_hosts import patterns

        host_patterns = patterns('path.to',
            (r'www', 'urls.default', 'default'),
            (r'api', 'urls.api', 'api'),
        )

    :param prefix: the URLconf prefix to pass to the host object
    :type prefix: str
    :param \*args: a list of :class:`~django_hosts.defaults.hosts` instances
                   or an iterable thereof
    prefixc                     g | ]	}|j         
S  )name).0hs     r   
<listcomp>zpatterns.<locals>.<listcomp>4   s    ***qAF***    zDuplicate host name: %s)
isinstancelisttuplehost
add_prefixr   r   append)r   r   hostsargr   s        r   patternsr'      s      E  cD%=)) 	#s+f++CCNN6"""x**E*****&'@4'GHHHSLr   c                   n    e Zd ZdZ	 	 d
dZd Zed             Zed             Ze	d             Z
dd	ZdS )r"   a  
    The host object used in host conf together with the
    :func:`django_hosts.defaults.patterns` function, e.g.::

        from django_hosts import patterns, host

        host_patterns = patterns('path.to',
            host(r'www', 'urls.default', name='default'),
            host(r'api', 'urls.api', name='api'),
            host(r'admin', 'urls.admin', name='admin', scheme='https://'),
        )

    :param regex: a regular expression to be used to match the request's
                  host.
    :type regex: str
    :param urlconf: the dotted path of a URLconf module of the host
    :type urlconf: str
    :param callback: a callable or the dotted path of a callable to be used
                     when matching has happened
    :type callback: callable or str
    :param prefix: the prefix to apply to the ``urlconf`` parameter
    :type prefix: str
    :param scheme: the scheme to prepend host names with during reversing,
                   e.g. when using the host_url() template tag. Defaults to
                   :attr:`~django.conf.settings.HOST_SCHEME`.
    :param port: the port to append to host names during reversing,
                 e.g. when using the host_url() template tag. Defaults to
                 :attr:`~django.conf.settings.HOST_PORT`.
    :type scheme: str
    N c                 b   || _         t          t          dd                              d          }|rd|z   nd}	t	          j        ||	d          | _        || _        || _        || _	        || _
        t          |          r|| _        nd|c| _        | _        |                     |           dS )z
        Compile hosts. We add a literal fullstop to the end of every
        pattern to avoid rather unwieldy escaping in every definition.
        The pattern is also suffixed by the PARENT_HOST setting if it exists.
        PARENT_HOSTr)   .z\.z(\.|:|$)N)regexgetattrr   lstriprecompilecompiled_regexurlconfr   _scheme_portcallable	_callback_callback_strr#   )
selfr-   r3   r   callbackr   schemeportparent_hostsuffixs
             r   __init__zhost.__init__Y   s     
hr::AA#FF(3;$$ jEE666)JKK	
H 	@%DNN15x.DND.r   c                     t          d| j        j        d| j        d| j        d| j        d| j        d| j        d          S )N< z: regex=z	 urlconf=z scheme=z port=>)r   	__class____name__r   r-   r3   r;   r<   r9   s    r   __repr__zhost.__repr__n   sV    y.1114999djjj,,,TYYY@ A A 	Ar   c                 n    | j         t          t          dd          | _         t          | j                   S )NHOST_SCHEMEz//)r4   r.   r   r   rF   s    r   r;   zhost.schemes   s-    <"8]DAADL---r   c                 n    | j         t          t          dd          | _         t          | j                   S )N	HOST_PORTr)   )r5   r.   r   r   rF   s    r   r<   z	host.porty   s-    : ;;;DJdj)))r   c                    | j         | j         S | j        d S 	 t          | j                  | _         n# t          $ r>}t	          | j                  \  }}t          d|dt          |                    d }~wt          $ rA}t	          | j                  \  }}t          d|d|dt          |                    d }~ww xY w| j         S )Nc                      d S )Nr   )r   kwargss     r   <lambda>zhost.callback.<locals>.<lambda>   s    4 r   zCould not import 'z'. Error was: zTried importing 'z' from module 'z' but failed. Error was: )r7   r8   r   ImportErrorr   r   strAttributeError)r9   r   mod_name_	func_names        r   r:   zhost.callback   s   >%>!'///	H)$*<==DNN 	= 	= 	=&t'9::KHa&&(0#c((((< = = =  	H 	H 	H".t/A"B"BHi&&(1		888SXXX(G H H H	H
 ~s    4 
C9A77C<C  Cc                 X    |r'|                     d          dz   | j        z   | _        dS dS )zC
        Adds the prefix string to a string-based urlconf.
        r,   N)rstripr3   )r9   r   s     r   r#   zhost.add_prefix   s<      	C!==--3dlBDLLL	C 	Cr   )Nr)   NN)r)   )rE   
__module____qualname____doc__r?   rG   r	   r;   r<   propertyr:   r#   r   r   r   r"   r"   :   s         < DF#'       *A A A
 . . _.
 * * _*
   X&C C C C C Cr   r"   )rZ   r0   django.confr   django.core.exceptionsr   r   django.urlsr   r   r   django.utils.encodingr   django.utils.functionalr	   utilsr   r   r'   objectr"   r   r   r   <module>rc      s    
			             I I I I I I I I        , + + + + + 3 3 3 3 3 3 3 3 3 3 3 3 3 3
L 
L 
L  :^C ^C ^C ^C ^C6 ^C ^C ^C ^C ^Cr   