3
W­E^×!  ã               @   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   sD   |rdnd}|j dƒr$d||f }n|j d	ƒs@td|| |f ƒ}|S )
NÚhttpsÚhttpz//z%s:%súhttp://úhttps://úmailto:z	%s://%s%s)r   r   r   )Ú
startswithr   )ÚdomainÚurlÚsecureÚprotocol© r   úB/tmp/pip-build-78s3knkw/Django/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ˆ   y| j |f|ž|Ž}W n tk
r2   tdƒ‚Y nX | j||ƒ}t|jd�}t| dƒs`t| dƒrxtt|j	ƒ j
ƒ ƒƒ|d< |j|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Ú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 )N)r3   )r,   r4   r   r   r   Úitem_description6   s    zFeed.item_descriptionc             C   s2   y|j ƒ S  tk
r,   td|jj ƒ‚Y nX d S )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    )r,   r4   r   r   r   Ú	item_link9   s    zFeed.item_linkc             C   sF   | j d|ƒ}|rBtjt|ƒt| j d|ƒƒt| j 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,   r4   Zenc_urlÚencr   r   r   Úitem_enclosuresB   s    zFeed.item_enclosuresc             C   sp   yt | |ƒ}W n tk
r"   |S X t|ƒrly
|j}W n tk
rR   |jj}Y nX |jdkrf||ƒS |ƒ S |S )Né   )Úgetattrr7   ÚcallableÚ__code__r2   Úco_argcount)r,   Zattnamer0   ÚdefaultÚattrÚcoder   r   r   r;   M   s    

zFeed._get_dynamic_attrc             C   s   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_kwargs`   s    zFeed.feed_extra_kwargsc             C   s   i S )zƒ
        Return an extra keyword arguments dictionary that is used with
        the `add_item` call of the feed generator.
        r   )r,   r4   r   r   r   Úitem_extra_kwargsg   s    zFeed.item_extra_kwargsc             O   s   d S )Nr   )r,   r-   r.   r/   r   r   r   r'   n   s    zFeed.get_objectc             K   s   |j dƒ|j 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)r0   rH   )Úget)r,   r/   r   r   r   Úget_context_dataq   s    zFeed.get_context_datac          "   C   sº  t |ƒ}| jd|ƒ}t|j||jƒ ƒ}| jf | jd|ƒ| jd|ƒ|| jd|ƒ| jpVtƒ t|j| jd|ƒpl|j|jƒ ƒ| jd|ƒ| jd|ƒ| jd|ƒ| jd	|ƒ| jd
|ƒ| jd|ƒ| jd|ƒdœ| j	|ƒ—Ž}d}| j
dk	�rytj| j
ƒ}W n tk
�r   Y nX d}| jdk	�r<ytj| jƒ}W n tk
�r:   Y nX �xv| jd|ƒD �]d}| j||||d�}	|dk	�r||j|	|ƒ}
n| jd|ƒ}
|dk	�r |j|	|ƒ}n| jd|ƒ}t|j| jd|ƒ|jƒ ƒ}| jd|ƒ}| jd|ƒ}|dk	�r| jd|ƒ}| jd|ƒ}nd }}tƒ }| jd|ƒ}|�r6t|ƒ�r6t||ƒ}| jd|ƒ}|�r\t|ƒ�r\t||ƒ}|jf |
||| jd||ƒ| jd|ƒ||||||| jd|ƒ| jd|ƒdœ| j|ƒ—Ž �qLW |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)rL   rM   rK   rN   ÚlanguagerO   rP   rQ   rR   rS   rT   rU   rV   NÚitems)r4   rH   r0   r-   r5   r6   r9   r=   Zitem_author_nameZitem_author_emailZitem_author_linkr%   r&   Z	item_guidZitem_guid_is_permalinkZitem_categoriesÚitem_copyright)rL   rK   rN   Z	unique_idZunique_id_is_permalinkÚ
enclosuresÚpubdateÚupdateddaterP   rR   rQ   rS   rY   )r   r;   r   r   Z	is_secureÚ	feed_typerW   r   ÚpathrF   Útitle_templater	   Zget_templater   Údescription_templaterJ   Úrenderr   r   r   Zadd_itemrG   )r,   r0   r-   Zcurrent_siterK   ÚfeedZ	title_tmpZdescription_tmpr4   ÚcontextrL   rN   rZ   rP   rR   rQ   Útzr[   r\   r   r   r   r(   {   s˜    


















zFeed.get_feed)N)r    r!   r"   r
   ZDefaultFeedr]   r_   r`   rW   r2   r5   r6   r9   r=   r;   rF   rG   r'   rJ   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   

