a
    5Xhe$                     @   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   e/var/www/viveiro_mudafortebrasil/venv/lib/python3.9/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 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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 0 t|rD| 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       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.   r8   r   r   r5   l   s   z"Sitemap._items.<locals>.<listcomp>)r(   items)r)   r9   r   r8   r   _itemsh   s    
zSitemap._itemsc                 C   sT   | j rH|\}}t|p| | d|W  d    S 1 s>0    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	Paginatorr:   limitr8   r   r   r   r   |   s    zSitemap.paginatorc                 C   s   g S r$   r   r8   r   r   r   r9      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)   rC   r   r   r   get_protocol   s    	zSitemap.get_protocolc                 C   sV   |d u rPt dr@t d}z|j }W n |jy>   Y n0 |d u rPt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$   )rF   rH   _urls)r)   pagerG   rC   r    r   r   r   get_urls   s    

zSitemap.get_urlsc                    sZ   t  dsd S t jrPz t fdd  D d dW S  tyL   Y d S 0 n jS d S )Nlastmodc                    s   g | ]}  |qS r   )rM   )r3   r+   r8   r   r   r5      r6   z.Sitemap.get_latest_lastmod.<locals>.<listcomp>)r,   )hasattrr'   rM   maxr9   	TypeErrorr8   r   r8   r   get_latest_lastmod   s    

 
zSitemap.get_latest_lastmodc              	   C   sx  g }d }d}| j |}|jD ]@}| d| | | }	| d|}
| d|}|rx|d u}|rx|d u st||krx|}||	|| d|t|
d ur|
ndg d}| jrV| jrV| |d }|D ]2}| d| | || }	|d	 	|	|d
 q| j
rVtj|v rVtj}| d| | || }	|	d| ddd}	|d	 	|	dd
 |	| q|rt|rt|| _|S )NTz://priorityrM   
changefreq )r+   r;   rM   rS   rR   
alternatesr   rU   )r;   r.   /rI   z	x-default)r   rK   Zobject_listr>   r/   strr(   rU   r2   append	x_defaultr   ZLANGUAGE_CODEreplacelatest_lastmod)r)   rK   rC   r    urlsr[   Zall_items_lastmodZpaginator_pager+   locrR   rM   Zurl_infoZitem_languagesr.   r   r   r   rJ      sZ    
	zSitemap._urls)N)N)N)N)rI   NN)r   r   r   r?   rC   r(   r7   rU   rY   r/   r2   r0   r:   r>   propertyr   r9   r;   rF   rH   rL   rQ   rJ   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p6|| _d S )Nqueryset
date_field)r`   getra   rR   rS   rC   )r)   Z	info_dictrR   rS   rC   r   r   r   __init__   s
    
zGenericSitemap.__init__c                 C   s
   | j  S r$   )r`   filterr8   r   r   r   r9      s    zGenericSitemap.itemsc                 C   s   | j d urt|| j S d S r$   )ra   r%   r1   r   r   r   rM      s    
zGenericSitemap.lastmodc                 C   s0   | j d ur,| jd| j  j| j dd S d S )N-T)Zflat)ra   r`   Zorder_byZvalues_listfirstr8   r   r   r   rQ      s    
z!GenericSitemap.get_latest_lastmod)NNN)	r   r   r   rR   rS   rc   r9   rM   rQ   r   r   r   r   r_      s   
r_   )T)rD   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