o
    ˷eO#                     @   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   W/var/www/ideatree/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
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    | 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>b   s    z&Sitemap._languages.<locals>.<listcomp>)	languagesr   	LANGUAGESr-   r   r   r   
_languages_   s   
zSitemap._languagesc                    s(    j r fdd  D }|S   S )Nc                    s"   g | ]}   D ]}||fqqS r   )items)r4   r2   r/   r9   r   r   r6   h   s    z"Sitemap._items.<locals>.<listcomp>)r,   r:   r;   )r-   r;   r   r9   r   _itemsd   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   	_locationp   s   
 zSitemap._locationc                 C   s   t |  | jS r(   )r   	Paginatorr<   limitr9   r   r   r   r   x   s   zSitemap.paginatorc                 C   s   g S r(   r   r9   r   r   r   r;   |   s   zSitemap.itemsc                 C   s   |  S r(   )get_absolute_urlr-   r/   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-   rI   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(   )rL   rO   _urls)r-   pagerN   rI   r#   r   r   r   get_urls   s   

zSitemap.get_urlsc                    sP   t  dsd S t jr%zt fdd  D W S  ty$   Y d S w  jS )Nlastmodc                    s   g | ]}  |qS r   )rT   )r4   r/   r9   r   r   r6      s    z.Sitemap.get_latest_lastmod.<locals>.<listcomp>)hasattrr+   rT   maxr;   	TypeErrorr9   r   r9   r   get_latest_lastmod   s   

zSitemap.get_latest_lastmodc              	   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://priorityrT   
changefreq )r/   r=   rT   rZ   rY   
alternatesr\   )r=   r2   /rP   z	x-default)r   rR   object_listrA   r3   strr,   r\   r:   append	x_defaultr   LANGUAGE_CODEreplacelatest_lastmod)r-   rR   rI   r#   urlsrd   all_items_lastmodpaginator_pager/   locrY   rT   url_infor2   r   r   r   rQ      sR   

	zSitemap._urlsr(   )rP   NN)r   r   r   rC   rI   r,   r7   r\   ra   r3   r:   r<   rA   propertyr   r;   r=   rL   rO   rS   rX   rQ   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)rl   getrm   rY   rZ   rI   )r-   	info_dictrY   rZ   rI   r   r   r   __init__   s
   
zGenericSitemap.__init__c                 C   s
   | j  S r(   )rl   filterr9   r   r   r   r;      s   
zGenericSitemap.itemsc                 C   s   | j d urt|| j S d S r(   )rm   r)   rE   r   r   r   rT      s   
zGenericSitemap.lastmodc                 C   s0   | j d ur| jd| j  j| j dd S d S )N-T)flat)rm   rl   order_byvalues_listfirstr9   r   r   r   rX      s   
z!GenericSitemap.get_latest_lastmod)NNN)	r   r   r   rY   rZ   rp   r;   rT   rX   r   r   r   r   rk      s    
rk   )T)rJ   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'   rk   r   r   r   r   <module>   s"    
 +