o
    ÖŸŽi¨  ã                   @   sÚ   d dl Z d dl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 dlmZ d d	lmZ d d
lmZ d dlmZ eG dd„ dƒƒZdd„ Zdd„ Ze			ddd„ƒZe			ddd„ƒZdS )é    N)Ú	dataclass©Úwraps)Úget_current_site)Ú	EmptyPageÚPageNotAnInteger)ÚHttp404)ÚTemplateResponse)Úreverse)Útimezone)ÚRemovedInDjango50Warning)Ú	http_datec                   @   s*   e Zd ZU eed< dZeed< dd„ ZdS )ÚSitemapIndexItemÚlocationNÚlast_modc                 C   s   d}t j|tdd� | jS )NzZCalling `__str__` on SitemapIndexItem is deprecated, use the `location` attribute instead.é   )Ú
stacklevel)ÚwarningsÚwarnr   r   )ÚselfÚmsg© r   úgC:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\site-packages\django/contrib/sitemaps/views.pyÚ__str__   s   ÿzSitemapIndexItem.__str__)Ú__name__Ú
__module__Ú__qualname__ÚstrÚ__annotations__r   Úboolr   r   r   r   r   r      s   
 r   c                    s   t ˆ ƒ‡ fdd„ƒ}|S )Nc                    s$   ˆ | g|¢R i |¤Ž}d|j d< |S )Nznoindex, noodp, noarchivezX-Robots-Tag)Úheaders)ÚrequestÚargsÚkwargsÚresponse©Úfuncr   r   Úinner    s   
zx_robots_tag.<locals>.innerr   )r&   r'   r   r%   r   Úx_robots_tag   s   r(   c                 C   sN   t |tjƒstj |tjj¡}t |¡rt |tjj¡}| du r"|S t	| |ƒS )z^
    Returns the latest `lastmod` where `lastmod` can be either a date or a
    datetime.
    N)
Ú
isinstanceÚdatetimeÚcombineÚtimeÚminr   Zis_naiveZ
make_awareÚutcÚmax)Zcurrent_lastmodZnew_lastmodr   r   r   Ú_get_latest_lastmod)   s
   
r0   úsitemap_index.xmlúapplication/xmlú%django.contrib.sitemaps.views.sitemapc                 C   s  | j }t| ƒ}g }d}d }	| ¡ D ]W\}
}t|ƒr|ƒ }|jd u r#|n|j}t|d|
id�}d||j|f }| ¡ }|rH|d urFt|	|ƒ}	nd}| 	t
||ƒ¡ td|jjd ƒD ]}| 	t
d||f |ƒ¡ qYq|rv|	rvd	t|	 ¡ ƒi}nd }t| |d
|i||d�S )NTÚsection)r#   z	%s://%s%sFr   é   z%s?p=%súLast-ModifiedÚsitemaps©Úcontent_typer    )Úschemer   ÚitemsÚcallableÚprotocolr
   ÚdomainZget_latest_lastmodr0   Úappendr   ÚrangeZ	paginatorZ	num_pagesr   Ú	timestampr	   )r!   r7   Útemplate_namer9   Zsitemap_url_nameÚreq_protocolÚreq_siteÚsitesZall_indexes_lastmodÚlatest_lastmodr4   Úsiter=   Zsitemap_urlZabsolute_urlÚsite_lastmodÚpager    r   r   r   Úindex5   s@   ÿÿûrJ   úsitemap.xmlc              	   C   s  | j }t| ƒ}|d ur||vrtd| ƒ‚|| g}n| ¡ }| j dd¡}d }	d}
g }|D ]C}z(t|ƒr8|ƒ }| |j|||d�¡ |
rWt	|dd ƒ}|d urUt
|	|ƒ}	nd}
W q. tye   td| ƒ‚ tyq   td	| ƒ‚w |
r�|	r~d
t|	 ¡ ƒind }nd }t| |d|i||d�S )Nz$No sitemap available for section: %rÚpr5   T)rI   rG   r=   rF   FzPage %s emptyzNo page '%s'r6   Zurlsetr8   )r:   r   r   ÚvaluesÚGETÚgetr<   ÚextendZget_urlsÚgetattrr0   r   r   r   rA   r	   )r!   r7   r4   rB   r9   rC   rD   ÚmapsrI   ZlastmodZall_sites_lastmodÚurlsrG   rH   r    r   r   r   Úsitemapf   sJ   €ÿûrT   )r1   r2   r3   )NrK   r2   )r*   r   Údataclassesr   Ú	functoolsr   Zdjango.contrib.sites.shortcutsr   Zdjango.core.paginatorr   r   Zdjango.httpr   Zdjango.template.responser	   Zdjango.urlsr
   Zdjango.utilsr   Zdjango.utils.deprecationr   Zdjango.utils.httpr   r   r(   r0   rJ   rT   r   r   r   r   Ú<module>   s4    
û0û