o
    Mf'"                     @   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   b/var/www/html/analyze/labelStudio/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   latest_post_dateutctimetuple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_title2   s   zFeed.item_titlec                 C   s   t |S r3   )r4   r5   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.)get_absolute_urlAttributeErrorr   	__class__r   r5   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 )Nitem_enclosure_urlitem_enclosure_lengthitem_enclosure_mime_type)r   length	mime_type)_get_dynamic_attrr
   	Enclosurer4   )r+   r6   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   )getattrr:   callable__code__r2   co_argcount)r+   attnamer/   defaultattrcoder   r   r   rB   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   rP   )z
        Return an extra keyword arguments dictionary that is used with
        the `add_item` call of the feed generator.
        r   r5   r   r   r   item_extra_kwargsg   rR   zFeed.item_extra_kwargsc                 O   s   d S r3   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.
        r6   site)r/   rT   )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)rX   rY   rW   rZ   languager[   r\   r]   r^   r_   r`   ra   rb   Nitems)r6   rT   r/   r,   r7   r8   r<   rF   item_author_nameitem_author_emailitem_author_linkr"   r#   	item_guiditem_guid_is_permalinkitem_commentsitem_categoriesitem_copyright)rX   rW   rZ   	unique_idunique_id_is_permalink
enclosurespubdateupdateddater\   r^   r]   commentsr_   rl   r   )r   rB   r   r   	is_secure	feed_typerc   r   pathrQ   title_templater	   get_templater   description_templaterV   renderr   r   r   add_itemrS   )r+   r/   r,   current_siterW   feed	title_tmpdescription_tmpr6   contextrX   rZ   ro   r\   r^   r]   tzrp   rq   r   r   r   r%   {   s   


















zFeed.get_feedr3   )r   r   r   r
   DefaultFeedrt   rv   rx   rc   r2   r7   r8   r<   rF   rB   rQ   rS   r$   rV   r%   r   r   r   r   r       s     	

r    N)F)calendarr   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    

