o
    [h$                     @   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   /home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/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   Zlatest_post_date	timestamp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_title3   s   zFeed.item_titlec                 C   s   t |S r2   )r3   r4   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.)Zget_absolute_urlAttributeErrorr   	__class__r   r4   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 )NZitem_enclosure_urlZitem_enclosure_lengthZitem_enclosure_mime_type)r   lengthZ	mime_type)_get_dynamic_attrr   Z	Enclosurer3   )r+   r5   Z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.   )getattrr8   callabler   __code__r1   co_argcount
isinstancer   r   staticmethodr   )r+   Zattnamer/   defaultattrfunccoder   r   r   r<   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+   r/   r   r   r   feed_extra_kwargsl      zFeed.feed_extra_kwargsc                 C   rJ   )z
        Return an extra keyword arguments dictionary that is used with
        the `add_item` call of the feed generator.
        r   r4   r   r   r   item_extra_kwargss   rL   zFeed.item_extra_kwargsc                 O   s   d S r2   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.
        r5   site)r/   rN   )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| 	|}d}| j
durz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stylesheets)rR   rS   rQ   rT   languagerU   rV   rW   rX   rY   rZ   r[   r\   r]   Nitems)r5   rN   r/   r,   r6   r7   r:   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)rR   rQ   rT   	unique_idZunique_id_is_permalink
enclosurespubdateupdateddaterV   rX   rW   commentsrY   r`   r   )r   r<   r   r   Z	is_secure	feed_typer^   r   pathrK   title_templater
   Zget_templater	   description_templaterP   renderr   r   r   Zadd_itemrM   )r+   r/   r,   Zcurrent_siterQ   feedZ	title_tmpZdescription_tmpr5   contextrR   rT   rb   rV   rX   rW   tzrc   rd   r   r   r   r&      s   



















zFeed.get_feedr2   )r   r   r    r   ZDefaultFeedrf   rh   ri   r^   r1   r6   r7   r:   r>   r<   rK   rM   r%   rP   r&   r   r   r   r   r!      s     	

r!   N)F)inspectr   r   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    

