3
(h;"                 @   s   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
 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mZ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e"Z#dS )    )unicode_literals)timegm)settings)get_current_site)ImproperlyConfiguredObjectDoesNotExist)Http404HttpResponse)TemplateDoesNotExistloader)feedgeneratorsix)
force_text
iri_to_uri
smart_text)escape)	http_date)get_default_timezoneis_naive
make_awareFc             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    D/tmp/pip-install-q3hcpn_q/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               @   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   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   r   )r0   itemr    r    r!   
item_title3   s    zFeed.item_titlec             C   s   t |S )N)r   )r0   r7   r    r    r!   item_description7   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$   )r0   r7   r    r    r!   	item_link:   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	Enclosurer   )r0   r7   Zenc_urlencr    r    r!   item_enclosuresC   s    zFeed.item_enclosuresc             C   sx   yt | |}W n tk
r"   |S X t|rtytj|}W n  tk
rZ   tj|j}Y nX |jdkrn||S | S |S )N   )getattrr:   callabler   get_function_coder6   co_argcount)r0   Zattnamer4   defaultattrcoder    r    r!   r>   N   s    
zFeed._get_dynamic_attrc             C   s   i S )zz
        Returns an extra keyword arguments dictionary that is used when
        initializing the feed generator.
        r    )r0   r4   r    r    r!   feed_extra_kwargsa   s    zFeed.feed_extra_kwargsc             C   s   i S )z
        Returns an extra keyword arguments dictionary that is used with
        the `add_item` call of the feed generator.
        r    )r0   r7   r    r    r!   item_extra_kwargsh   s    zFeed.item_extra_kwargsc             O   s   d S )Nr    )r0   r1   r2   r3   r    r    r!   r+   o   s    zFeed.get_objectc             K   s   |j d|j ddS )a  
        Returns 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)r4   rK   )get)r0   r3   r    r    r!   get_context_datar   s    zFeed.get_context_datac          "   C   s  t |}| jd|}t|j||j }| jf | jd|| jd||| jd|tjt|j| jd|pf|j|j | jd|| jd|| jd|| jd	|| jd
|| jd|| jd|d| j	|}d}| j
dk	rytj| j
}W n tk
r   Y nX d}| jdk	r2ytj| j}W n tk
r0   Y nX xv| jd|D ]d}| j||||d}	|dk	rr|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|}|r,t|r,t||}| jd|}|rRt|rRt||}|jf |
||| jd||| jd|||||||| jd|| jd|d| j| qBW |S )z
        Returns a feedgenerator.DefaultFeed object, fully populated, for
        this feed. Raises FeedDoesNotExist for invalid parameters.
        linktitlesubtitledescriptionfeed_urlauthor_nameauthor_linkauthor_email
categoriesfeed_copyright	feed_guidttl)rO   rP   rN   rQ   languagerR   rS   rT   rU   rV   rW   rX   rY   Nitems)r7   rK   r4   r1   r8   r9   r<   r@   Zitem_author_nameZitem_author_emailZitem_author_linkr)   r*   Z	item_guidZitem_guid_is_permalinkZitem_categoriesitem_copyright)rO   rN   rQ   Z	unique_idZunique_id_is_permalink
enclosurespubdateupdateddaterS   rU   rT   rV   r\   )r   r>   r"   r   Z	is_secure	feed_typer   ZLANGUAGE_CODEpathrI   title_templater   Zget_templater
   description_templaterM   renderr   r   r   Zadd_itemrJ   )r0   r4   r1   Zcurrent_siterN   feedZ	title_tmpZdescription_tmpr7   contextrO   rQ   r]   rS   rU   rT   tzr^   r_   r    r    r!   r,   |   s    


















zFeed.get_feed)N)r$   r%   r&   r   ZDefaultFeedr`   rb   rc   r6   r8   r9   r<   r@   r>   rI   rJ   r+   rM   r,   r    r    r    r!   r'      s   	

r'   N)F)$
__future__r   calendarr   Zdjango.confr   Zdjango.contrib.sites.shortcutsr   Zdjango.core.exceptionsr   r   Zdjango.httpr   r	   Zdjango.templater
   r   Zdjango.utilsr   r   Zdjango.utils.encodingr   r   r   Zdjango.utils.htmlr   Zdjango.utils.httpr   Zdjango.utils.timezoner   r   r   r"   r#   objectr'   r    r    r    r!   <module>   s   

