o
    <g]$                     @   s   d dl mZ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 )    )getattr_staticunwrap)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   S/var/www/html/venv/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| 	 |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   latest_post_date	timestampheaderswrite)selfrequestargskwargsobjfeedgenresponser   r   r   __call__#   s   

zFeed.__call__c                 C   s   t t|S N)r   strr,   itemr   r   r   
item_title3   s   zFeed.item_titlec                 C   s   t |S r4   )r5   r6   r   r   r   item_description7   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.)get_absolute_urlAttributeErrorr   	__class__r   r6   r   r   r   	item_link:   s   
zFeed.item_linkc                 C   sF   |  d|}|r!tjt|t|  d|t|  d|d}|gS g S )Nitem_enclosure_urlitem_enclosure_lengthitem_enclosure_mime_type)r   length	mime_type)_get_dynamic_attrr   	Enclosurer5   )r,   r7   enc_urlencr   r   r   item_enclosuresC   s   zFeed.item_enclosuresc                 C   s   zt | |}W n ty   | Y S w t|rWt|}z|j}W n ty1   t|j}|j}Y nw |jsKtt| |j	d t
sKtd|d|j	d|jdkrT||S | S |S )NzFeed method z decorated by z needs to use @functools.wraps.   )getattrr;   callabler   __code__r3   co_argcount
isinstancer   r   staticmethodr   )r,   attnamer0   defaultattrfunccoder   r   r   rC   N   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,   r0   r   r   r   feed_extra_kwargsl      zFeed.feed_extra_kwargsc                 C   rT   )z
        Return an extra keyword arguments dictionary that is used with
        the `add_item` call of the feed generator.
        r   r6   r   r   r   item_extra_kwargss   rV   zFeed.item_extra_kwargsc                 O   s   d S r4   r   )r,   r-   r.   r/   r   r   r   r%   z   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.
        r7   site)r0   rX   )get)r,   r/   r   r   r   get_context_data}   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)r\   r]   r[   r^   languager_   r`   ra   rb   rc   rd   re   rf   Nitems)r7   rX   r0   r-   r8   r9   r=   rG   item_author_nameitem_author_emailitem_author_linkr#   r$   	item_guiditem_guid_is_permalinkitem_commentsitem_categoriesitem_copyright)r\   r[   r^   	unique_idunique_id_is_permalink
enclosurespubdateupdateddater`   rb   ra   commentsrc   rp   r   )r   rC   r   r   	is_secure	feed_typerg   r   pathrU   title_templater
   get_templater	   description_templaterZ   renderr   r   r   add_itemrW   )r,   r0   r-   current_siter[   feed	title_tmpdescription_tmpr7   contextr\   r^   rs   r`   rb   ra   tzrt   ru   r   r   r   r&      s   


















zFeed.get_feedr4   )r   r   r    r   DefaultFeedrx   rz   r|   rg   r3   r8   r9   r=   rG   rC   rU   rW   r%   rZ   r&   r   r   r   r   r!      s     	

r!   N)F)inspectr   r   django.contrib.sites.shortcutsr   django.core.exceptionsr   r   django.httpr   r   django.templater	   r
   django.utilsr   django.utils.encodingr   django.utils.htmlr   django.utils.httpr   django.utils.timezoner   r   r   django.utils.translationr   r   r   r!   r   r   r   r   <module>   s    

