o
    uvXj„  ã                   @   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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   ú]/var/www/html/myproject/venv/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Úhttpú	%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                   @   sL   e Zd ZdZdZddd„Zdd„ Zdd„ Zed	d
„ ƒZ	ddd„Z
dd„ ZdS )ÚSitemapiPÃ  Nc                 C   s:   zt | |ƒ}W n ty   | Y S w t|ƒr||ƒS |S ©N)ÚgetattrÚAttributeErrorÚcallable)ÚselfÚnameÚobjÚdefaultÚattrr   r   r   Ú__get?   s   ÿzSitemap.__getc                 C   s   g S r(   r   ©r,   r   r   r   ÚitemsH   s   zSitemap.itemsc                 C   s   |  ¡ S r(   )Úget_absolute_url)r,   r.   r   r   r   ÚlocationK   s   zSitemap.locationc                 C   s   t  |  ¡ | j¡S r(   )r   Ú	Paginatorr3   Úlimitr2   r   r   r   r   N   s   zSitemap.paginatoré   c           
      C   sÖ   | j d ur| j }|d u rd}|d u r6t d¡r.t d¡}z|j ¡ }W n
 |jy-   Y nw |d u r6tdƒ‚|j}t	| ddƒrbg }t
 ¡ }tjD ]\}}	t
 |¡ ||  |||¡7 }qHt
 |¡ |S |  |||¡}|S )Nr   r   r   zbTo use sitemaps, either enable the sites framework or pass a Site/RequestSite object in your view.Úi18nF)Úprotocolr   r   r    r!   r"   ÚDoesNotExistr   r#   r)   r
   Úget_languager   Ú	LANGUAGESÚactivateÚ_urls)
r,   ÚpageÚsiter:   r$   r#   ÚurlsÚcurrent_lang_codeÚ	lang_codeÚ	lang_namer   r   r   Úget_urlsR   s6   


ÿÿ

þzSitemap.get_urlsc                 C   s¶   g }d }d}| j  |¡jD ]D}d|||  d|¡f }|  d|¡}	|  d|¡}
|r8|
d u}|r8|d u s6|
|kr8|
}|||
|  d|¡t|	d urG|	ndƒdœ}| |¡ q|rY|rY|| _|S )	NTr   r5   ÚpriorityÚlastmodÚ
changefreqÚ )Úitemr5   rH   rI   rG   )r   r@   Úobject_listÚ_Sitemap__getÚstrÚappendÚlatest_lastmod)r,   r@   r:   r#   rB   rP   Úall_items_lastmodrK   ÚlocrG   rH   Úurl_infor   r   r   r?   t   s,   
ûzSitemap._urlsr(   )r8   NN)r   r   r   r7   r:   rM   r3   r5   Úpropertyr   rF   r?   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¡| _|| _|| _|| _d S )NÚquerysetÚ
date_field)rV   ÚgetrW   rG   rI   r:   )r,   Ú	info_dictrG   rI   r:   r   r   r   Ú__init__’   s
   

zGenericSitemap.__init__c                 C   s
   | j  ¡ S r(   )rV   Úfilterr2   r   r   r   r3   ™   s   
zGenericSitemap.itemsc                 C   s   | j d urt|| j ƒS d S r(   )rW   r)   )r,   rK   r   r   r   rH   �   s   
zGenericSitemap.lastmod)NNN)r   r   r   rG   rI   rZ   r3   rH   r   r   r   r   rU   Ž   s    
rU   z+django.contrib.sitemaps.apps.SiteMapsConfig)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'   rU   Údefault_app_configr   r   r   r   Ú<module>   s    
X