o
    Tie$                     @   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/html/evchargy.com/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().
    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 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   SiteZ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   ).0r.   _r   r   r   
<listcomp>f   s    z&Sitemap._languages.<locals>.<listcomp>)	languagesr   Z	LANGUAGESr)   r   r   r   r0   c   s   
zSitemap._languagesc                    s(    j r fdd  D }|S   S )Nc                    s$   g | ]}  |D ]}||fq	qS r   )r2   )r3   r+   r.   r7   r   r   r5   l   s    z"Sitemap._items.<locals>.<listcomp>)r(   items)r)   r8   r   r7   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
   overrider/   )r)   r+   Zforce_lang_codeobjr.   r   r   r   	_locationt   s   
 zSitemap._locationc                 C   s   t |  | jS r$   )r   Z	Paginatorr9   limitr7   r   r   r   r   |   s   zSitemap.paginatorc                 C   s   g S r$   r   r7   r   r   r   r8      s   zSitemap.itemsc                 C   s   |  S r$   )Zget_absolute_urlr1   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)   rB   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   ZDoesNotExistr   r    )r)   siter!   r   r   r   
get_domain   s   

zSitemap.get_domain   c                 C   s"   |  |}| |}| |||S r$   )rE   rG   _urls)r)   pagerF   rB   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   )rL   )r3   r+   r7   r   r   r5      s    z.Sitemap.get_latest_lastmod.<locals>.<listcomp>)r,   )hasattrr'   rL   maxr8   	TypeErrorr7   r   r7   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://priorityrL   
changefreq )r+   r:   rL   rR   rQ   
alternatesr   rT   )r:   r.   /rH   z	x-default)r   rJ   Zobject_listr=   r/   strr(   rT   r2   append	x_defaultr   ZLANGUAGE_CODEreplacelatest_lastmod)r)   rJ   rB   r    urlsrZ   Zall_items_lastmodZpaginator_pager+   locrQ   rL   Zurl_infoZitem_languagesr.   r   r   r   rI      sT   

	zSitemap._urlsr$   )rH   NN)r   r   r   r>   rB   r(   r6   rT   rX   r/   r2   r0   r9   r=   propertyr   r8   r:   rE   rG   rK   rP   rI   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)r_   getr`   rQ   rR   rB   )r)   Z	info_dictrQ   rR   rB   r   r   r   __init__   s
   
zGenericSitemap.__init__c                 C   s
   | j  S r$   )r_   filterr7   r   r   r   r8      s   
zGenericSitemap.itemsc                 C   s   | j d urt|| j S d S r$   )r`   r%   r1   r   r   r   rL      s   
zGenericSitemap.lastmodc                 C   s0   | j d ur| jd| j  j| j dd S d S )N-T)Zflat)r`   r_   Zorder_byZvalues_listfirstr7   r   r   r   rP      s   
z!GenericSitemap.get_latest_lastmod)NNN)	r   r   r   rQ   rR   rb   r8   rL   rP   r   r   r   r   r^      s    
r^   )T)rC   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django.utils.deprecationr   ZPING_URL	Exceptionr   r   r   r#   r^   r   r   r   r   <module>   s"    
 0