
    Sf                        d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZmZ  e            d             Z e            dd            Z e            dd            Z e            d             Zd Z d Z! ej"        e!           ddZ# ee#e$          Z%	 	 	 ddZ eee$          Z&dS )z
If you want to reverse the hostname or the full URL or a view including the
scheme, hostname and port you'll need to use the ``reverse`` and
``reverse_host`` helper functions (or its lazy cousins).
    N)	lru_cache)import_module)settings)ImproperlyConfigured)setting_changed)NoReverseMatchreverse)
iri_to_uri)lazy)	normalize   )host)normalize_schemenormalize_portc                  V    	 t           j        S # t          $ r t          d          w xY w)NzMissing ROOT_HOSTCONF setting)r   ROOT_HOSTCONFAttributeErrorr        H/var/www/html/env/lib/python3.11/site-packages/django_hosts/resolvers.pyget_hostconfr      s?    D%% D D D"#BCCCDs    (c                 @    | t                      } t          |           S N)r   r   )hostconfs    r   get_hostconf_moduler      s    >>"""r   c                     | +	 t           j        } n# t          $ r t          d          w xY wt	                      D ]}|j        | k    r|c S t          d| z            )NzMissing DEFAULT_HOST settingzNo host called '%s' exists)r   DEFAULT_HOSTr   r   get_host_patternsnamer   )r   r   s     r   get_hostr    %   s    |	G(DD 	G 	G 	G&'EFFF	G!##  9KKK 
5<
=
==s    +c                      t                      } t          |           }	 |j        S # t          $ r t	          d| z            w xY w)NzMissing host_patterns in '%s')r   r   host_patternsr   r   )r   modules     r   r   r   2   sZ    ~~H **FO## O O O"#BX#MNNNOs	   & Ac                      t                                            t                                           t                                           t                                           d S r   )r   cache_clearr   r    r   r   r   r   clear_host_cachesr&   <   sP    ##%%%!!#####r   c                 .    | dv rt                       d S d S )N>   r   r   )r&   )settingenterkwargss      r   setting_changed_receiverr+   C   s(    333 43r   c           	         |r|rt          d          |pd}|pi }t          | t                    st          |           } t	          | j                  D ]\  }}|rBt          |          t          |          k    r(|t          t          ||                    z  }n8t          |
                                          t          |          k    r|||z  }t          j        | j        |          rAt          t          dd                              d          }|r|r||k    r|d|}n|}|c S t!          d| j        d|d|d	          )
a  
    Given the host name and the appropriate parameters,
    reverses the host, e.g.::

        >>> from django.conf import settings
        >>> settings.ROOT_HOSTCONF = 'mysite.hosts'
        >>> settings.PARENT_HOST = 'example.com'
        >>> from django_hosts.resolvers import reverse_host
        >>> reverse_host('with_username', args=('jezdez',))
        'jezdez.example.com'

    :param name: the name of the host as specified in the hostconf
    :param args: the host arguments to use to find a matching entry in the
                 hostconf
    :param kwargs: similar to args but key value arguments
    :raises django.core.urlresolvers.NoReverseMatch: if no host matches
    :rtype: reversed hostname
    z2Don't mix *args and **kwargs in call to reverse()!r   PARENT_HOST .zReverse host for 'z' with arguments 'z' and keyword arguments 'z' not found.)
ValueError
isinstancehost_clsr    r   regexlendictzipsetkeysrematchgetattrr   lstripr   r   )r   argsr*   resultparams	candidateparent_hosts          r   reverse_hostrB   K   s   &  O OMNNN:2D\rFdH%% ~~#DJ//   	(4yyCKK''c&$&7&7!8!88II6;;==!!S[[00I8DJ	** 	!(M2>>EEcJJK , ,k!9!9+499kk BII +I	 .)))TTT6663 4 4 4r   c
                    t          |          }t          |||          }
t          | |j        |pd|pi |          }||j        }nt          |          }|	|j        }	nt          |	          }	t          ||
|	|          S )a  
    Given the host and view name and the appropriate parameters,
    reverses the fully qualified URL, e.g.::

        >>> from django.conf import settings
        >>> settings.ROOT_HOSTCONF = 'mysite.hosts'
        >>> settings.PARENT_HOST = 'example.com'
        >>> from django_hosts.resolvers import reverse
        >>> reverse('about')
        '//www.example.com/about/'
        >>> reverse('about', host='www')
        '//www.example.com/about/'
        >>> reverse('repo', args=('jezdez',), host='www', scheme='git', port=1337)
        'git://jezdez.example.com:1337/repo/'

    You can set the used port and scheme in the host object or override with
    the paramater named accordingly.

    The host name can be left empty to automatically fall back to the default
    hostname as defined in the :attr:`~django.conf.settings.DEFAULT_HOST`
    setting.

    :param viewname: the name of the view
    :param args: the arguments of the view
    :param kwargs: the keyed arguments of the view
    :param prefix: the prefix of the view urlconf
    :param current_app: the current_app argument
    :param scheme: the scheme to use
    :param port: the port to use
    :param host: the name of the host
    :param host_args: the host arguments
    :param host_kwargs: the host keyed arguments
    :raises django.core.urlresolvers.NoReverseMatch: if no host or path matches
    :rtype: the fully qualified URL with path
    )r=   r*   r   )urlconfr=   r*   current_app)	r    rB   reverse_pathrD   schemer   portr   r
   )viewnamer=   r*   prefixrE   r   	host_argshost_kwargsrG   rH   hostnamepaths               r   r	   r	      s    L D>>DD!*#.0 0 0H ZR|  D ~!&))|yd##FFHHddDDABBBr   r   )NN)	NNNNNNNNN)'__doc__r9   	functoolsr   	importlibr   django.confr   django.core.exceptionsr   django.core.signalsr   django.urlsr   r	   rF   django.utils.encodingr
   django.utils.functionalr   django.utils.regex_helperr   defaultsr   r2   utilsr   r   r   r   r    r   r&   r+   connectrB   strreverse_host_lazyreverse_lazyr   r   r   <module>r_      s   
 
			       # # # # # #             7 7 7 7 7 7 / / / / / / ? ? ? ? ? ? ? ? , , , , , , ( ( ( ( ( ( / / / / / / & & & & & & 3 3 3 3 3 3 3 3 D D D # # # # 	> 	> 	> 	> O O O$ $ $  
  0 1 1 124 24 24 24n Ds++  HL37";C ;C ;C ;C@ tGS!!r   