o
    pXZ:9                     @   sp  d Z dZdZdZed deee ZddlZddl	Z	e	j
d dkr,eZdd	lmZ nzdd	lmZ W n eyC   dd	lmZ Y nw G d
d dZi fddZdd Zdd ZG dd dZG dd dZG dd dZG dd dZG dd dZG dd dZG dd dZG d d! d!ZG d"d# d#ZG d$d% d%ZG d&d' d'ZG d(d) d)eZG d*d+ d+eZ dS ),z:PyRSS2Gen - A Python library for generating RSS 2.0 feeds.	PyRSS2Gen)   r       z(Andrew Dalke <dalke@dalkescientific.com>-.r   N   )StringIOc                   @   s    e Zd ZdddZdddZdS )WriteXmlMixin
iso-8859-1c                 C   s6   ddl m} |||}|  | | |  d S )Nr   )saxutils)xml.saxr
   XMLGeneratorstartDocumentpublishendDocument)selfoutfileencodingr
   handler r   -/home/novalis_dt/novalis.org/cgi/PyRSS2Gen.py	write_xml   s
   
zWriteXmlMixin.write_xmlc                 C   s   t  }| || | S N)r   r   getvalue)r   r   fr   r   r   to_xml%   s   zWriteXmlMixin.to_xmlN)r	   )__name__
__module____qualname__r   r   r   r   r   r   r      s    
r   c                 C   sL   t |ts	|d u r| || |d ur| | | | d S ||  d S r   )
isinstance
basestringstartElement
characters
endElementr   )r   nameobjdr   r   r   _element+   s   
r&   c                 C   s   |d u rd S t | || d S r   )r&   )r   r#   r$   r   r   r   _opt_element7   s   r'   c                 C   s:   dg d|    | jg d| jd  | j| j| j| jf S )zVconvert a datetime into an RFC 822 formatted date

    Input date must be in GMT.
    z#%s, %02d %s %04d %02d:%02d:%02d GMT)MonTueWedThuFriSatSun)JanFebMarAprMayJunJulAugSepOctNovDecr   )weekdaydaymonthyearhourminutesecond)dtr   r   r   _format_date=   s   rC   c                   @   $   e Zd ZdZi Zdd Zdd ZdS )
IntElementzimplements the 'publish' API for integers

    Takes the tag name and the integer value to publish.
    
    (Could be used for anything which uses str() to be published
    to text for XML.)
    c                 C      || _ || _d S r   )r#   val)r   r#   rG   r   r   r   __init__]      
zIntElement.__init__c                 C   s0   | | j| j |t| j || j d S r   )r    r#   element_attrsr!   strrG   r"   r   r   r   r   r   r   `   s   zIntElement.publishNr   r   r   __doc__rJ   rH   r   r   r   r   r   rE   T   s
    rE   c                   @       e Zd ZdZdd Zdd ZdS )DateElementzimplements the 'publish' API for a datetime.datetime

    Takes the tag name and the datetime to publish.

    Converts the datetime to RFC 2822 timestamp (4-digit year).
    c                 C   rF   r   )r#   rB   )r   r#   rB   r   r   r   rH   l   rI   zDateElement.__init__c                 C   s   t || jt| j d S r   )r&   r#   rC   rB   rL   r   r   r   r   o   s   zDateElement.publishNr   r   r   rN   rH   r   r   r   r   r   rP   e   s    rP   c                   @   s"   e Zd ZdZdddZdd ZdS )CategoryzPublish a category elementNc                 C   rF   r   )categorydomain)r   rS   rT   r   r   r   rH   u   rI   zCategory.__init__c                 C   s,   i }| j d ur| j |d< t|d| j| d S )NrT   rS   )rT   r&   rS   r   r   r%   r   r   r   r   x   s   

zCategory.publishr   rQ   r   r   r   r   rR   s   s    
rR   c                   @   rO   )CloudzPublish a cloudc                 C   s"   || _ || _|| _|| _|| _d S r   rT   portpathregisterProcedureprotocol)r   rT   rX   rY   rZ   r[   r   r   r   rH      s
   
zCloud.__init__c              
   C   s,   t |dd | jt| j| j| j| jd d S )NcloudrW   )r&   rT   rK   rX   rY   rZ   r[   rL   r   r   r   r      s   zCloud.publishNrQ   r   r   r   r   rV   ~   s    rV   c                   @   s(   e Zd ZdZi Z	dddZdd ZdS )ImagezPublish a channel ImageNc                 C   s(   || _ || _|| _|| _|| _|| _d S r   )urltitlelinkwidthheightdescription)r   r^   r_   r`   ra   rb   rc   r   r   r   rH      s   
zImage.__init__c                 C   s   | d| j t|d| j t|d| j t|d| j | j}t|tr)t	d|}t
|d| | j}t|tr<t	d|}t
|d| t
|d| j |d d S )Nimager^   r_   r`   ra   rb   rc   )r    rJ   r&   r^   r_   r`   ra   r   intrE   r'   rb   rc   r"   )r   r   ra   rb   r   r   r   r      s   



zImage.publish)NNNrM   r   r   r   r   r]      s    
	r]   c                   @   s"   e Zd ZdZdddZdd ZdS )	GuidzPublish a guid

    Defaults to being a permalink, which is the assumption if it's
    omitted.  Hence strings are always permalinks.
    r   c                 C   rF   r   )guidisPermaLink)r   rg   rh   r   r   r   rH      rI   zGuid.__init__c                 C   s0   i }| j r
d|d< nd|d< t|d| j| d S )Ntruerh   falserg   )rh   r&   rg   rU   r   r   r   r      s
   
zGuid.publishN)r   rQ   r   r   r   r   rf      s    
rf   c                   @   rD   )	TextInputz=Publish a textInput

    Apparently this is rarely used.
    c                 C   s   || _ || _|| _|| _d S r   )r_   rc   r#   r`   )r   r_   rc   r#   r`   r   r   r   rH      s   
zTextInput.__init__c                 C   sT   | d| j t|d| j t|d| j t|d| j t|d| j |d d S )N	textInputr_   rc   r#   r`   )r    rJ   r&   r_   rc   r#   r`   r"   rL   r   r   r   r      s   zTextInput.publishNrM   r   r   r   r   rk      s
    rk   c                   @   rO   )	EnclosurezPublish an enclosurec                 C   s   || _ || _|| _d S r   r^   lengthtype)r   r^   ro   rp   r   r   r   rH      s   
zEnclosure.__init__c                 C   s$   t |dd | jt| j| jd d S )N	enclosurern   )r&   r^   rK   ro   rp   rL   r   r   r   r      s   zEnclosure.publishNrQ   r   r   r   r   rm      s    rm   c                   @   rO   )Sourcez7Publish the item's original source, used by aggregatorsc                 C   rF   r   )r#   r^   )r   r#   r^   r   r   r   rH      rI   zSource.__init__c                 C   s   t |d| jd| ji d S )Nsourcer^   )r&   r#   r^   rL   r   r   r   r      s   zSource.publishNrQ   r   r   r   r   rr      s    rr   c                   @   rD   )	SkipHourszHPublish the skipHours

    This takes a list of hours, as integers.
    c                 C   
   || _ d S r   )hours)r   rv   r   r   r   rH         
zSkipHours.__init__c                 C   sB   | j r|d| j | j D ]
}t|dt| q|d d S d S )N	skipHoursr?   )rv   r    rJ   r&   rK   r"   )r   r   r?   r   r   r   r      s   
zSkipHours.publishNrM   r   r   r   r   rt      
    rt   c                   @   rD   )SkipDayszDPublish the skipDays

    This takes a list of days as strings.
    c                 C   ru   r   )days)r   r{   r   r   r   rH      rw   zSkipDays.__init__c                 C   s>   | j r|d| j | j D ]}t|d| q|d d S d S )NskipDaysr<   )r{   r    rJ   r&   r"   )r   r   r<   r   r   r   r     s   
zSkipDays.publishNrM   r   r   r   r   rz      ry   rz   c                   @   sX   e Zd ZdZddiZi ZdddddddedddddddddfddZdd	 Zd
d Z	dS )RSS2zThe main RSS class.

    Stores the channel attributes, with the "category" elements under
    ".categories" and the RSS items under ".items".
    versionz2.0Nz%http://blogs.law.harvard.edu/tech/rssc                 C   s   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
d u r!g }
|
| _	|| _
|| _|| _|| _|| _|| _|| _|| _|| _|d u rEg }|| _d S r   )r_   r`   rc   language	copyrightmanagingEditor	webMasterpubDatelastBuildDate
categories	generatordocsr\   ttlrd   ratingrl   rx   r|   items)r   r_   r`   rc   r   r   r   r   r   r   r   r   r   r\   r   rd   r   rl   rx   r|   r   r   r   r   rH     s0   
zRSS2.__init__c                 C   s  | d| j | d| j t|d| j t|d| j t|d| j | | t|d| j	 t|d| j
 t|d| j t|d	| j | j}t|tjrRtd
|}t|d
| | j}t|tjrftd|}t|d| | jD ]}t|trzt|}|| qot|d| j t|d| j | jd ur| j| | j}t| jtrtd|}t|d| | jd ur| j| t|d| j | jd ur| j| | jd ur| j| | j d ur| j | | j!D ]}|| q|"d |"d d S )Nrsschannelr_   r`   rc   r   r   r   r   r   r   r   r   r   r   )#r    	rss_attrsrJ   r&   r_   r`   rc   publish_extensionsr'   r   r   r   r   r   r   datetimerP   r   r   r   rR   r   r   r   r\   r   re   rE   rd   r   rl   rx   r|   r   r"   )r   r   r   r   rS   r   itemr   r   r   r   H  sV   












zRSS2.publishc                 C      d S r   r   rL   r   r   r   r        zRSS2.publish_extensions)
r   r   r   rN   r   rJ   _generator_namerH   r   r   r   r   r   r   r}   	  s0    
69r}   c                   @   sB   e Zd ZdZi Z										d	ddZdd Zdd ZdS )
RSSItemzPublish an RSS ItemNc                 C   sd   |d u r|d u rt d|| _|| _|| _|| _|d u rg }|| _|| _|| _|| _|	| _	|
| _
d S )Nz4must define at least one of 'title' or 'description')	TypeErrorr_   r`   rc   authorr   commentsrq   rg   r   rs   )r   r_   r`   rc   r   r   r   rq   rg   r   rs   r   r   r   rH     s    
zRSSItem.__init__c                 C   s   | d| j t|d| j t|d| j | | t|d| j t|d| j | jD ]}t	|t
r6t|}|| q+t|d| j | jd urN| j| t|d| j | j}t	|tjrctd|}t|d| | jd urt| j| |d d S )	Nr   r_   r`   rc   r   r   rg   r   )r    rJ   r'   r_   r`   r   rc   r   r   r   r   rR   r   r   rq   rg   r   r   rP   rs   r"   )r   r   rS   r   r   r   r   r     s*   





zRSSItem.publishc                 C   r   r   r   rL   r   r   r   r     r   zRSSItem.publish_extensions)
NNNNNNNNNN)r   r   r   rN   rJ   rH   r   r   r   r   r   r   r     s     
r   )!rN   r   __version__
__author__joinmaprK   r   r   sysversion_infor   ior   	cStringIOImportErrorr   r&   r'   rC   rE   rP   rR   rV   r]   rf   rk   rm   rr   rt   rz   r}   r   r   r   r   r   <module>   s@    !