o
    uvXj©!  ã                   @   sÄ   d dl mZ 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d„ZG dd„ deƒZG dd„ dƒZdS )é    )Útimegm)Úsettings)Úget_current_site)ÚImproperlyConfiguredÚObjectDoesNotExist)ÚHttp404ÚHttpResponse)ÚTemplateDoesNotExistÚloader)Úfeedgenerator)Ú
iri_to_uri)Úescape)Ú	http_date)Úget_default_timezoneÚis_naiveÚ
make_awareFc                 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   ú]/var/www/html/myproject/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                   @   st   e Zd Zej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| 	¡  
¡ ƒƒ|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Ú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_title1   s   zFeed.item_titlec                 C   s   t |ƒS r2   )r3   r4   r   r   r   Úitem_description5   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   r4   r   r   r   Ú	item_link8   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   Ú	Enclosurer3   )r*   r5   Úenc_urlÚencr   r   r   Úitem_enclosuresA   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é   )Úgetattrr9   ÚcallableÚ__code__r1   Úco_argcount)r*   Úattnamer.   ÚdefaultÚattrÚcoder   r   r   rA   L   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   rO   )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_kwargsf   rQ   zFeed.item_extra_kwargsc                 O   s   d S r2   r   )r*   r+   r,   r-   r   r   r   r$   m   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.   rS   )Úget)r*   r-   r   r   r   Úget_context_datap   s   zFeed.get_context_datac                 C   s˜  t |ƒ}|  d|¡}t|j|| ¡ ƒ}| jd|  d|¡|  d|¡||  d|¡tjt|j|  d|¡p3|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r•z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œ|  |¡¤Ž 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)rW   rX   rV   rY   ÚlanguagerZ   r[   r\   r]   r^   r_   r`   ra   NÚitems)r5   rS   r.   r+   r6   r7   r;   rE   Úitem_author_nameÚitem_author_emailÚitem_author_linkr"   r#   Ú	item_guidÚitem_guid_is_permalinkÚitem_categoriesÚitem_copyright)rW   rV   rY   Ú	unique_idÚunique_id_is_permalinkÚ
enclosuresÚpubdateÚupdateddater[   r]   r\   r^   rj   r   )r   rA   r   r   Ú	is_secureÚ	feed_typer   ÚLANGUAGE_CODEÚpathrP   Útitle_templater
   Úget_templater	   Údescription_templaterU   Úrenderr   r   r   Úadd_itemrR   )r*   r.   r+   Úcurrent_siterV   ÚfeedÚ	title_tmpÚdescription_tmpr5   ÚcontextrW   rY   rm   r[   r]   r\   Útzrn   ro   r   r   r   r%   z   s¬   


ý






ïî
ÿ
ÿÿ
ý

ÿ

òñzFeed.get_feedr2   )r   r   r   r   ÚDefaultFeedrq   rt   rv   r1   r6   r7   r;   rE   rA   rP   rR   r$   rU   r%   r   r   r   r   r       s    	

r    N)F)Úcalendarr   Údjango.confr   Ú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   r   r   r    r   r   r   r   Ú<module>   s    

