a
    xd                     @   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   X/var/www/html/Ranjet/env/lib/python3.9/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().
    Zsitemapz%s?%sN)_get_sitemap_full_urlr   r   )sitemap_urlZping_urlsitemap_uses_httpsZsitemap_full_urlparamsr   r   r   ping_google   s    
r   c                 C   s   t dstd| d u rZztd} W n2 tyX   ztd} W n tyR   Y n0 Y n0 | d u rjtdt d}|j }|rd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   SiteZ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 0 t|r6||S |S N)getattrAttributeErrorcallable)selfnameobjdefaultattrr   r   r   Z__get?   s    
zSitemap.__getc                 C   s   g S r$   r   r(   r   r   r   itemsH   s    zSitemap.itemsc                 C   s   |  S r$   )Zget_absolute_url)r(   r*   r   r   r   locationK   s    zSitemap.locationc                 C   s   t |  | jS r$   )r   Z	Paginatorr.   limitr-   r   r   r   r   N   s    zSitemap.paginator   c           
      C   s   | j d ur| j }|d u rd}|d u rltdr\td}z|j }W n |jyZ   Y n0 |d u rltd|j}t	| ddrg }t
 }tjD ]$\}}	t
| || |||7 }qt
| n| |||}|S )Nr   r   r   zbTo use sitemaps, either enable the sites framework or pass a Site/RequestSite object in your view.Zi18nF)protocolr   r   r   r   r   ZDoesNotExistr   r    r%   r
   Zget_languager   Z	LANGUAGESactivate_urls)
r(   pagesiter2   r!   r    urlsZcurrent_lang_codeZ	lang_codeZ	lang_namer   r   r   get_urlsR   s2    



zSitemap.get_urlsc                 C   s   g }d }d}| j |jD ]}d||| d|f }| d|}	| d|}
|rp|
d u}|rp|d u sl|
|krp|
}|||
| d|t|	d ur|	ndd}|| q|r|r|| _|S )	NTr   r/   prioritylastmod
changefreq )itemr/   r:   r;   r9   )r   r5   Zobject_list_Sitemap__getstrappendlatest_lastmod)r(   r5   r2   r    r7   rA   Zall_items_lastmodr=   locr9   r:   Zurl_infor   r   r   r4   t   s2    
zSitemap._urls)N)r1   NN)r   r   r   r0   r2   r>   r.   r/   propertyr   r8   r4   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)rE   getrF   r9   r;   r2   )r(   Z	info_dictr9   r;   r2   r   r   r   __init__   s
    
zGenericSitemap.__init__c                 C   s
   | j  S r$   )rE   filterr-   r   r   r   r.      s    zGenericSitemap.itemsc                 C   s   | j d urt|| j S d S r$   )rF   r%   )r(   r=   r   r   r   r:      s    
zGenericSitemap.lastmod)NNN)r   r   r   r9   r;   rH   r.   r:   r   r   r   r   rD      s
   
rD   z+django.contrib.sitemaps.apps.SiteMapsConfig)T)urllib.parser   urllib.requestr   Zdjango.appsr   r   Zdjango.confr   Zdjango.corer   Zdjango.core.exceptionsr   Zdjango.urlsr   r	   Zdjango.utilsr
   ZPING_URL	Exceptionr   r   r   r#   rD   Zdefault_app_configr   r   r   r   <module>   s   
X