o
    Mf                     @   s   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 d dlmZmZ d dlmZ d	ZG d
d deZdedfddZdddZG dd dZG dd deZdS )    )	urlencode)urlopen)apps)settings)	paginator)ImproperlyConfigured)NoReverseMatchreverse)translationz,https://www.google.com/webmasters/tools/pingc                   @   s   e Zd ZdS )SitemapNotFoundN)__name__
__module____qualname__ r   r   b/var/www/html/analyze/labelStudio/lib/python3.10/site-packages/django/contrib/sitemaps/__init__.pyr      s    r   NTc                 C   s*   t | |}td|i}td||f  dS )a+  
    Alert Google that the sitemap for the current site has been updated.
    If sitemap_url is provided, it should be an absolute path to the sitemap
    for this site -- e.g., '/sitemap.xml'. If sitemap_url is not provided, this
    function will attempt to deduce it by using urls.reverse().
    sitemapz%s?%sN)_get_sitemap_full_urlr   r   )sitemap_urlping_urlsitemap_uses_httpssitemap_full_urlparamsr   r   r   ping_google   s   
r   c                 C   s   t ds	td| d u r-ztd} W n ty,   ztd} W n	 ty)   Y nw Y nw | d u r5tdt d}|j }|rCdnd}d	||j	| f S )
Ndjango.contrib.siteszAping_google requires django.contrib.sites, which isn't installed.z#django.contrib.sitemaps.views.indexz%django.contrib.sitemaps.views.sitemapzPYou didn't provide a sitemap_url, and the sitemap URL couldn't be auto-detected.
sites.Sitehttpshttpz	%s://%s%s)
django_appsis_installedr   r	   r   r   	get_modelobjectsget_currentdomain)r   r   Sitecurrent_siteschemer   r   r   r      s&   


r   c                   @   s   e Zd ZdZdZdZdZdZdZdddZ	dd Z
dd	 Zdd
dZedd Zdd Zdd ZdddZdddZdddZdd ZdS )SitemapiP  NFc                 C   sH   zt | |}W n ty   | Y S w t|r"| jr|\}}||S |S N)getattrAttributeErrorcallablei18n)selfnameitemdefaultattr	lang_coder   r   r   _getK   s   zSitemap._getc                 C   s    | j d ur| j S dd tjD S )Nc                 S   s   g | ]\}}|qS r   r   ).0r1   _r   r   r   
<listcomp>[   s    z&Sitemap._languages.<locals>.<listcomp>)	languagesr   	LANGUAGESr,   r   r   r   
_languagesX   s   
zSitemap._languagesc                    s(    j r fdd  D }|S   S )Nc                    s"   g | ]}   D ]}||fqqS r   )items)r3   r1   r.   r8   r   r   r5   a   s    z"Sitemap._items.<locals>.<listcomp>)r+   r9   r:   )r,   r:   r   r8   r   _items]   s   
zSitemap._itemsc                 C   sT   | j r$|\}}t|p| | d|W  d    S 1 sw   Y  | d|S )Nlocation)r+   r
   overrider2   )r,   r.   force_lang_codeobjr1   r   r   r   	_locationi   s   
 zSitemap._locationc                 C   s   t |  | jS r'   )r   	Paginatorr;   limitr8   r   r   r   r   q   s   zSitemap.paginatorc                 C   s   g S r'   r   r8   r   r   r   r:   u   s   zSitemap.itemsc                 C   s   |  S r'   )get_absolute_urlr,   r.   r   r   r   r<   x   s   zSitemap.locationc                 C   s   | j p|pdS )Nr   )protocol)r,   rE   r   r   r   get_protocol{   s   zSitemap.get_protocolc                 C   sV   |d u r(t dr t d}z|j }W n
 |jy   Y nw |d u r(td|jS )Nr   r   zbTo use sitemaps, either enable the sites framework or pass a Site/RequestSite object in your view.)r   r   r   r    r!   DoesNotExistr   r"   )r,   siter#   r   r   r   
get_domain   s   

zSitemap.get_domain   c                 C   s"   |  |}| |}| |||S r'   )rF   rI   _urls)r,   pagerH   rE   r"   r   r   r   get_urls   s   

zSitemap.get_urlsc              	   C   sV  g }d }d}| j |}|jD ]}| d| | | }	| d|}
| d|}|r;|d u}|r;|d u s9||kr;|}||	|| d|t|
d urJ|
ndg d}| jr| jr|  D ]}| d| | || }	|d 	|	|d	 qZ| j
rtj}| d| | || }	|	d
| d
d
d}	|d 	|	dd	 |	| q|r|r|| _|S )NTz://prioritylastmod
changefreq )r.   r<   rO   rP   rN   
alternatesrR   )r<   r1   /rJ   z	x-default)r   rL   object_listr@   r2   strr+   rR   r9   append	x_defaultr   LANGUAGE_CODEreplacelatest_lastmod)r,   rL   rE   r"   urlsrZ   all_items_lastmodpaginator_pager.   locrN   rO   url_infor1   r   r   r   rK      sN   

	
zSitemap._urlsr'   )rJ   NN)r   r   r   rB   rE   r+   r6   rR   rW   r2   r9   r;   r@   propertyr   r:   r<   rF   rI   rM   rK   r   r   r   r   r&   6   s&    





r&   c                   @   s.   e Zd ZdZdZdddZdd Zdd ZdS )	GenericSitemapNc                 C   s>   |d | _ |d| _| jp|| _| jp|| _| jp|| _d S )Nqueryset
date_field)rb   getrc   rN   rP   rE   )r,   	info_dictrN   rP   rE   r   r   r   __init__   s
   
zGenericSitemap.__init__c                 C   s
   | j  S r'   )rb   filterr8   r   r   r   r:      s   
zGenericSitemap.itemsc                 C   s   | j d urt|| j S d S r'   )rc   r(   rD   r   r   r   rO      s   
zGenericSitemap.lastmod)NNN)r   r   r   rN   rP   rf   r:   rO   r   r   r   r   ra      s    
ra   )T)urllib.parser   urllib.requestr   django.appsr   r   django.confr   django.corer   django.core.exceptionsr   django.urlsr   r	   django.utilsr
   PING_URL	Exceptionr   r   r   r&   ra   r   r   r   r   <module>   s    
 