o
    ge$                     @   s   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 d dlmZmZ d d	l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 )    N)	urlencode)urlopen)apps)settings)	paginator)ImproperlyConfigured)NoReverseMatchreverse)translation)RemovedInDjango50Warningz,https://www.google.com/webmasters/tools/pingc                   @   s   e Zd ZdS )SitemapNotFoundN)__name__
__module____qualname__ r   r   ]/var/www/rescue_company/venv/lib/python3.10/site-packages/django/contrib/sitemaps/__init__.pyr      s    r   Tc                 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 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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   _getR   s   zSitemap._getc                 C   s   |   S )z+Languages for which this item is displayed.)
_languagesr-   r/   r   r   r   get_languages_for_item_   s   zSitemap.get_languages_for_itemc                 C   s    | j d ur| j S dd tjD S )Nc                 S   s   g | ]\}}|qS r   r   ).0r2   _r   r   r   
<listcomp>f   s    z&Sitemap._languages.<locals>.<listcomp>)	languagesr   	LANGUAGESr-   r   r   r   r4   c   s   
zSitemap._languagesc                    s(    j r fdd  D }|S   S )Nc                    s$   g | ]}  |D ]}||fq	qS r   )r6   )r7   r/   r2   r<   r   r   r9   l   s    z"Sitemap._items.<locals>.<listcomp>)r,   items)r-   r=   r   r<   r   _itemsh   s   
zSitemap._itemsc                 C   sT   | j r$|\}}t|p| | d|W  d    S 1 sw   Y  | d|S )Nlocation)r,   r
   overrider3   )r-   r/   force_lang_codeobjr2   r   r   r   	_locationt   s   
 zSitemap._locationc                 C   s   t |  | jS r(   )r   	Paginatorr>   limitr<   r   r   r   r   |   s   zSitemap.paginatorc                 C   s   g S r(   r   r<   r   r   r   r=      s   zSitemap.itemsc                 C   s   |  S r(   )get_absolute_urlr5   r   r   r   r?      s   zSitemap.locationc                 C   s0   | j d u r|d u rtjdtdd | j p|pdS )NzThe default sitemap protocol will be changed from 'http' to 'https' in Django 5.0. Set Sitemap.protocol to silence this warning.   )category
stacklevelr   )protocolwarningswarnr   )r-   rJ   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(   )rM   rP   _urls)r-   pagerO   rJ   r#   r   r   r   get_urls   s   

zSitemap.get_urlsc                    sT   t  dsd S t jr'zt fdd  D d dW S  ty&   Y d S w  jS )Nlastmodc                    s   g | ]}  |qS r   )rU   )r7   r/   r<   r   r   r9      s    z.Sitemap.get_latest_lastmod.<locals>.<listcomp>)r0   )hasattrr+   rU   maxr=   	TypeErrorr<   r   r<   r   get_latest_lastmod   s   

 zSitemap.get_latest_lastmodc              	   C   sj  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	 	|	|d
 q_| j
rtj|v rtj}| d| | || }	|	d| ddd}	|d	 	|	dd
 |	| q|r|r|| _|S )NTz://priorityrU   
changefreq )r/   r?   rU   r[   rZ   
alternatesr   r]   )r?   r2   /rQ   z	x-default)r   rS   object_listrC   r3   strr,   r]   r6   append	x_defaultr   LANGUAGE_CODEreplacelatest_lastmod)r-   rS   rJ   r#   urlsre   all_items_lastmodpaginator_pager/   locrZ   rU   url_infoitem_languagesr2   r   r   r   rR      sT   

	zSitemap._urlsr(   )rQ   NN)r   r   r   rE   rJ   r,   r:   r]   rb   r3   r6   r4   r>   rC   propertyr   r=   r?   rM   rP   rT   rY   rR   r   r   r   r   r'   =   s*    





r'   c                   @   s6   e Zd ZdZdZd
ddZ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)rn   getro   rZ   r[   rJ   )r-   	info_dictrZ   r[   rJ   r   r   r   __init__   s
   
zGenericSitemap.__init__c                 C   s
   | j  S r(   )rn   filterr<   r   r   r   r=      s   
zGenericSitemap.itemsc                 C   s   | j d urt|| j S d S r(   )ro   r)   r5   r   r   r   rU      s   
zGenericSitemap.lastmodc                 C   s0   | j d ur| jd| j  j| j dd S d S )N-T)flat)ro   rn   order_byvalues_listfirstr<   r   r   r   rY      s   
z!GenericSitemap.get_latest_lastmod)NNN)	r   r   r   rZ   r[   rr   r=   rU   rY   r   r   r   r   rm      s    
rm   )T)rK   urllib.parser   urllib.requestr   django.appsr   r   django.confr   django.corer   django.core.exceptionsr   django.urlsr   r	   django.utilsr
   django.utils.deprecationr   PING_URL	Exceptionr   r   r   r'   rm   r   r   r   r   <module>   s"    
 0