a
    xd!                     @   s   d dl mZ d dlmZ d dlmZmZ d dlmZ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mZmZ d dlmZ dddZG dd deZG dd dZdS )    )timegm)get_current_site)ImproperlyConfiguredObjectDoesNotExist)Http404HttpResponse)TemplateDoesNotExistloader)feedgenerator)
iri_to_uri)escape)	http_date)get_default_timezoneis_naive
make_aware)get_languageFc                 C   sD   |rdnd}| dr$d||f }n| ds@td|| |f }|S )Nhttpshttpz//z%s:%s)zhttp://zhttps://zmailto:z	%s://%s%s)
startswithr   )domainurlsecureprotocol r   X/var/www/html/Ranjet/env/lib/python3.9/site-packages/django/contrib/syndication/views.py
add_domain   s    

r   c                   @   s   e Zd ZdS )FeedDoesNotExistN)__name__
__module____qualname__r   r   r   r   r      s   r   c                   @   sx   e Zd ZejZdZdZdZdd Z	dd Z
dd Zdd	 Zd
d ZdddZdd Zdd Zdd Zdd Zdd ZdS )FeedNc                 O   s   z| j |g|R i |}W n ty6   tdY n0 | ||}t|jd}t| dsdt| dr|tt|	 
 |d< ||d |S )NzFeed object does not exist.)content_typeitem_pubdateitem_updateddatezLast-Modifiedzutf-8)
get_objectr   r   get_feedr   r!   hasattrr   r   Zlatest_post_dateutctimetuplewrite)selfrequestargskwargsobjZfeedgenresponser   r   r   __call__#   s    zFeed.__call__c                 C   s   t t|S N)r   strr)   itemr   r   r   
item_title2   s    zFeed.item_titlec                 C   s   t |S r0   )r1   r2   r   r   r   item_description6   s    zFeed.item_descriptionc                 C   s2   z
|  W S  ty,   td|jj Y n0 d S )NzcGive your %s class a get_absolute_url() method, or define an item_link() method in your Feed class.)Zget_absolute_urlAttributeErrorr   	__class__r   r2   r   r   r   	item_link9   s    
zFeed.item_linkc                 C   sF   |  d|}|rBtjt|t|  d|t|  d|d}|gS g S )NZitem_enclosure_urlZitem_enclosure_lengthZitem_enclosure_mime_type)r   lengthZ	mime_type)_get_dynamic_attrr
   Z	Enclosurer1   )r)   r3   Zenc_urlencr   r   r   item_enclosuresB   s    zFeed.item_enclosuresc                 C   sp   zt | |}W n ty$   | Y S 0 t|rlz
|j}W n tyR   |jj}Y n0 |jdkrf||S | S |S )N   )getattrr6   callable__code__r/   co_argcount)r)   Zattnamer-   defaultattrcoder   r   r   r:   M   s    


zFeed._get_dynamic_attrc                 C   s   i S )zy
        Return an extra keyword arguments dictionary that is used when
        initializing the feed generator.
        r   )r)   r-   r   r   r   feed_extra_kwargs`   s    zFeed.feed_extra_kwargsc                 C   s   i S )z
        Return an extra keyword arguments dictionary that is used with
        the `add_item` call of the feed generator.
        r   r2   r   r   r   item_extra_kwargsg   s    zFeed.item_extra_kwargsc                 O   s   d S r0   r   )r)   r*   r+   r,   r   r   r   r$   n   s    zFeed.get_objectc                 K   s   | d| ddS )a  
        Return a dictionary to use as extra context if either
        ``self.description_template`` or ``self.item_template`` are used.

        Default implementation preserves the old behavior
        of using {'obj': item, 'site': current_site} as the context.
        r3   site)r-   rG   )get)r)   r,   r   r   r   get_context_dataq   s    zFeed.get_context_datac                 C   s  t |}| d|}t|j|| }| jf | d|| d||| d|| jpVt t|j| d|pl|j| | d|| d|| d|| d	|| d
|| d|| d|d| 	|}d}| j
durzt| j
}W n ty   Y n0 d}| jdur4zt| j}W n ty2   Y n0 | d|D ]d}| j||||d}	|durp||	|}
n| d|}
|dur||	|}n| d|}t|j| d|| }| d|}| d|}|dur| d|}| d|}nd }}t }| d|}|r*t|r*t||}| d|}|rPt|rPt||}|jf |
||| d||| d|||||||| d|| d|d| | q@|S )z
        Return a feedgenerator.DefaultFeed object, fully populated, for
        this feed. Raise FeedDoesNotExist for invalid parameters.
        linktitlesubtitledescriptionfeed_urlauthor_nameauthor_linkauthor_email
categoriesfeed_copyright	feed_guidttl)rK   rL   rJ   rM   languagerN   rO   rP   rQ   rR   rS   rT   rU   Nitems)r3   rG   r-   r*   r4   r5   r8   r<   Zitem_author_nameZitem_author_emailZitem_author_linkr"   r#   Z	item_guidZitem_guid_is_permalinkZitem_categoriesitem_copyright)rK   rJ   rM   Z	unique_idZunique_id_is_permalink
enclosurespubdateupdateddaterO   rQ   rP   rR   rX   )r   r:   r   r   Z	is_secure	feed_typerV   r   pathrE   title_templater	   Zget_templater   description_templaterI   renderr   r   r   Zadd_itemrF   )r)   r-   r*   Zcurrent_siterJ   feedZ	title_tmpZdescription_tmpr3   contextrK   rM   rY   rO   rQ   rP   tzrZ   r[   r   r   r   r%   {   s    




















zFeed.get_feed)N)r   r   r   r
   ZDefaultFeedr\   r^   r_   rV   r/   r4   r5   r8   r<   r:   rE   rF   r$   rI   r%   r   r   r   r   r       s   	

r    N)F)calendarr   Zdjango.contrib.sites.shortcutsr   Zdjango.core.exceptionsr   r   Zdjango.httpr   r   Zdjango.templater   r	   Zdjango.utilsr
   Zdjango.utils.encodingr   Zdjango.utils.htmlr   Zdjango.utils.httpr   Zdjango.utils.timezoner   r   r   Zdjango.utils.translationr   r   r   r    r   r   r   r   <module>   s   

