o
    h'"                     @   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   sF   |rdnd}| drd||f }|S | 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   h/var/www/html/magazine_api/magazine_env/lib/python3.10/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y   tdw | ||}t|jd}t| ds0t| dr=tt|	 
 |j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headers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 r1   )r2   r3   r   r   r   item_description6   s   zFeed.item_descriptionc                 C   s*   z|  W S  ty   td|jj w )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   r3   r   r   r   	item_link9   s   
zFeed.item_linkc                 C   sF   |  d|}|r!t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	Enclosurer2   )r*   r4   Zenc_urlencr   r   r   item_enclosuresB   s   zFeed.item_enclosuresc                 C   sp   zt | |}W n ty   | Y S w t|r6z|j}W n ty)   |jj}Y nw |jdkr3||S | S |S )N   )getattrr7   callable__code__r0   co_argcount)r*   Zattnamer.   defaultattrcoder   r   r   r;   M   s   

zFeed._get_dynamic_attrc                 C      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`      zFeed.feed_extra_kwargsc                 C   rF   )z
        Return an extra keyword arguments dictionary that is used with
        the `add_item` call of the feed generator.
        r   r3   r   r   r   item_extra_kwargsg   rH   zFeed.item_extra_kwargsc                 O   s   d S r1   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.
        r4   site)r.   rJ   )get)r*   r-   r   r   r   get_context_dataq   s   zFeed.get_context_datac                 C   s  t |}| d|}t|j|| }| jd | d|| d||| d|| jp+t t|j| d|p6|j| | d|| d|| d|| d	|| d
|| d|| d|d| 	|}d}| j
durzt| j
}W n	 ty~   Y nw d}| jdurzt| j}W n	 ty   Y nw | d|D ]}| j||||d}	|dur||	|}
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|}|r"t|r"t||}|jd |
||| d||| 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)rN   rO   rM   rP   languagerQ   rR   rS   rT   rU   rV   rW   rX   Nitems)r4   rJ   r.   r+   r5   r6   r9   r=   Zitem_author_nameZitem_author_emailZitem_author_linkr"   r#   Z	item_guidZitem_guid_is_permalinkZitem_commentsZitem_categoriesitem_copyright)rN   rM   rP   	unique_idZunique_id_is_permalink
enclosurespubdateupdateddaterR   rT   rS   commentsrU   r[   r   )r   r;   r   r   Z	is_secure	feed_typerY   r   pathrG   title_templater	   Zget_templater   description_templaterL   renderr   r   r   Zadd_itemrI   )r*   r.   r+   Zcurrent_siterM   feedZ	title_tmpZdescription_tmpr4   contextrN   rP   r]   rR   rT   rS   tzr^   r_   r   r   r   r%   {   s   


















zFeed.get_feedr1   )r   r   r   r
   ZDefaultFeedra   rc   rd   rY   r0   r5   r6   r9   r=   r;   rG   rI   r$   rL   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    

