
v^!                 @   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 Gd d   d e  Z Gd 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   s`   | r d n d } | j  d  r4 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-8lau8j11/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               @   s   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  | | |  } Wn t k
 r9 t d   Yn X|  j | |  } t d | j  } t |  d  s| t |  d  r t 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   s=   y | j    SWn( t k
 r8 t d | j j   Yn Xd  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   sk   |  j  d |  } | rg t j d t |  d t |  j  d |   d t |  j  d |    } | g Sg  S)NZitem_enclosure_urlr   lengthZitem_enclosure_lengthZ	mime_typeZitem_enclosure_mime_type)_get_dynamic_attrr
   Z	Enclosurer3   )r,   r4   Zenc_urlencr   r   r   item_enclosuresB   s    	zFeed.item_enclosuresc             C   s   y t  |  |  } Wn t k
 r+ | SYn Xt |  r y | j } Wn t k
 re | j j } Yn X| j d k r | |  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"   d | j  d  d | j  d  i 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.
        r0   r4   site)get)r,   r/   r   r   r   get_context_dataq   s    zFeed.get_context_datac          .   C   s  t  |  } |  j d |  } t | j | | j    } |  j d |  j d |  d |  j d |  d | d |  j d |  d |  j p t   d t | j |  j d |  p | j | j    d |  j d |  d |  j d |  d	 |  j d	 |  d
 |  j d
 |  d |  j d |  d |  j d |  d |  j d |  |  j	 |   } d } |  j
 d k	 ry t j |  j
  } Wn t k
 rYn Xd } |  j d k	 ry t j |  j  } Wn t k
 rYn Xx2|  j d |  D]} |  j d | d | d | 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 |  } | r4t |  r4t | |  } |  j d |  } | rgt |  rgt | |  } | j d |
 d | d | d |  j d | |  d |  j d  |  d! | d" | d# | d | d	 | d | d
 |  j d$ |  d% |  j d% |  |  j |   qW| S)&z
        Return a feedgenerator.DefaultFeed object, fully populated, for
        this feed. Raise FeedDoesNotExist for invalid parameters.
        linktitleZsubtitledescriptionlanguageZfeed_urlauthor_nameauthor_linkauthor_email
categoriesZfeed_copyrightZ	feed_guidZttlNitemsr4   rH   r0   r-   r5   r6   r9   r=   Zitem_author_nameZitem_author_emailZitem_author_linkr%   r&   Z	unique_idZ	item_guidZunique_id_is_permalinkZitem_guid_is_permalink
enclosurespubdateupdateddateZitem_categoriesZitem_copyright)r   r;   r   r   Z	is_secure	feed_typerN   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   rM   rT   rO   rQ   rP   tzrU   rV   r   r   r   r(   {   s    	
		zFeed.get_feed)r    r!   r"   r
   ZDefaultFeedrW   rY   rZ   rN   r2   r5   r6   r9   r=   r;   rF   rG   r'   rJ   r(   r   r   r   r   r#      s   		
r#   N)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   
