
    Evg=                        d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 d Zd Zd	 Z G d
 d          Z G d d          Z G d de          Z G d de          Z G d de          Z G d de          ZeZdS )a  
Syndication feed generation library -- used for generating RSS, etc.

Sample usage:

>>> from django.utils import feedgenerator
>>> feed = feedgenerator.Rss201rev2Feed(
...     title="Poynter E-Media Tidbits",
...     link="http://www.poynter.org/column.asp?id=31",
...     description="A group blog by the sharpest minds in online journalism.",
...     language="en",
... )
>>> feed.add_item(
...     title="Hello",
...     link="http://www.holovaty.com/test/",
...     description="Testing."
... )
>>> with open('test.rss', 'w') as fp:
...     feed.write(fp, 'utf-8')

For definitions of the different versions of RSS, see:
https://web.archive.org/web/20110718035220/http://diveintomark.org/archives/2004/02/04/incompatible-rss
    N)StringIO)urlparse)
iri_to_uri)SimplerXMLGeneratorc                     t          | t          j                  s1t          j                            | t          j                              } t          j                            |           S N)
isinstancedatetimecombinetimeemailutilsformat_datetimedates    W/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/utils/feedgenerator.pyrfc2822_dater   "   sL    dH-.. @ ((x}??;&&t,,,    c                     t          | t          j                  s1t          j                            | t          j                              } |                                 |                                 dndz   S )NZ )r	   r
   r   r   	isoformat	utcoffsetr   s    r   rfc3339_dater   (   s^    dH-.. @ ((x}??>>dnn&6&6&>ssBGGr   c                     t          |           }d}|d|                    d          z  }d|j        |d|j        d|j        S )z
    Create a TagURI.

    See
    https://web.archive.org/web/20110514113830/http://diveintomark.org/archives/2004/05/28/howto-atom-id
    r   Nz,%sz%Y-%m-%dztag::/)r   strftimehostnamepathfragment)urlr   bitsds       r   get_tag_urir%   .   sR     C==D
ADMM*---#}}aaaDMMJJr   c                   ~    e Zd ZdZ	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 	 	 ddZd Zd Zd Zd	 Z	d
 Z
d Zd Zd ZdS )SyndicationFeedzGBase class for all syndication feeds. Subclasses should provide write()Nc                 J   d }|	od |	D             }	 ||          t          |           ||           ||           ||           ||          t          |           ||          |	pdt          |
           ||          |p| ||          d|| _        g | _        d S )Nc                 (    | t          |           n| S r   strss    r   to_strz(SyndicationFeed.__init__.<locals>.to_strP       ]3q6661r   c                 ,    g | ]}t          |          S  r*   ).0cs     r   
<listcomp>z,SyndicationFeed.__init__.<locals>.<listcomp>S   s    $@$@$@SVV$@$@$@r   r1   )titlelinkdescriptionlanguageauthor_emailauthor_nameauthor_linksubtitle
categoriesfeed_urlfeed_copyrightidttl)r   feeditems)selfr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   	feed_guidrA   kwargsr.   s                   r   __init__zSyndicationFeed.__init__?   s    "	2 	2 	2  @$@$@Z$@$@$@
VE]]t$$!6+..x(("F<00!6+..%k22x(($*"8,,$f^44#t6#;;
 
 
	  


r   r1   c                 R   d |ofd|D             }| j                              |          t          |           |           |           |          t          |          || |           |	          |
|pd|pd |           |          d|           dS )z
        Add an item to the feed. All args are expected to be strings except
        pubdate and updateddate, which are datetime.datetime objects, and
        enclosures, which is an iterable of instances of the Enclosure class.
        c                 (    | t          |           n| S r   r*   r,   s    r   r.   z(SyndicationFeed.add_item.<locals>.to_str   r/   r   c                 &    g | ]} |          S r1   r1   )r2   r3   r.   s     r   r4   z,SyndicationFeed.add_item.<locals>.<listcomp>   s!    $C$C$C1VVAYY$C$C$Cr   r1   )r5   r6   r7   r9   r:   r;   pubdateupdateddatecomments	unique_idunique_id_is_permalink
enclosuresr=   item_copyrightrA   N)rC   appendr   )rD   r5   r6   r7   r9   r:   r;   rK   rM   rN   rO   r=   rQ   rA   rL   rP   rF   r.   s                    @r   add_itemzSyndicationFeed.add_itemf   s    2	2 	2 	2  C$C$C$C$C
$C$C$C

"4((%vk22 &| 4 4%vk22)+66"*"F8,,#VI..*@(.B(.B"(&"8"8vc{{   !	
 	
 	
 	
 	
r   c                 *    t          | j                  S r   )lenrC   rD   s    r   	num_itemszSyndicationFeed.num_items   s    4:r   c                     i S )zx
        Return extra attributes to place on the root (i.e. feed/channel) element.
        Called from write().
        r1   rV   s    r   root_attributeszSyndicationFeed.root_attributes   s	    
 	r   c                     dS )zd
        Add elements in the root (i.e. feed/channel) element. Called
        from write().
        Nr1   rD   handlers     r   add_root_elementsz!SyndicationFeed.add_root_elements   s	    
 	r   c                     i S )zZ
        Return extra attributes to place on each item (i.e. item/entry) element.
        r1   )rD   items     r   item_attributeszSyndicationFeed.item_attributes   s	     	r   c                     dS )zF
        Add elements on each item (i.e. item/entry) element.
        Nr1   rD   r\   r_   s      r   add_item_elementsz!SyndicationFeed.add_item_elements   s	     	r   c                      t          d          )z
        Output the feed in the given encoding to outfile, which is a file-like
        object. Subclasses should override this.
        z;subclasses of SyndicationFeed must provide a write() method)NotImplementedError)rD   outfileencodings      r   writezSyndicationFeed.write   s    
 "I
 
 	
r   c                 r    t                      }|                     ||           |                                S )zD
        Return the feed in the given encoding as a string.
        )r   rh   getvalue)rD   rg   r-   s      r   writeStringzSyndicationFeed.writeString   s/     JJ

1hzz||r   c                     d}d}| j         D ](}|D ]#}|                    |          }|r
|||k    r|}$)|p.t          j                            t          j        j                  S )z
        Return the latest item's pubdate or updateddate. If no items
        have either of these attributes this return the current UTC date/time.
        N)rL   rK   )tz)rC   getr
   nowtimezoneutc)rD   latest_date	date_keysr_   date_key	item_dates         r   latest_post_datez SyndicationFeed.latest_post_date   s    
 .	J 	0 	0D% 0 0 HHX..	 0"*i+.E.E&/	0 Mh/33x7H7L3MMMr   )
NNNNNNNNNN)NNNNNNNr1   NNNN)__name__
__module____qualname____doc__rG   rS   rW   rY   r]   r`   rc   rh   rk   rv   r1   r   r   r'   r'   <   s       MM % % % %X #!0
 0
 0
 0
d          
 
 
  N N N N Nr   r'   c                       e Zd ZdZd ZdS )	EnclosurezAn RSS enclosurec                 L    ||c| _         | _        t          |          | _        dS )z#All args are expected to be stringsN)length	mime_typer   r"   )rD   r"   r~   r   s       r   rG   zEnclosure.__init__   s#    &,i#T^c??r   N)rw   rx   ry   rz   rG   r1   r   r   r|   r|      s)        # # # # #r   r|   c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )RssFeedz"application/rss+xml; charset=utf-8c                    t          ||d          }|                                 |                    d|                                            |                    d|                                            |                     |           |                     |           |                     |           |                    d           d S )NTshort_empty_elementsrsschannel)	r   startDocumentstartElementrss_attributesrY   r]   write_itemsendChannelElement
endElementrD   rf   rg   r\   s       r   rh   zRssFeed.write   s    %gxdSSSUD$7$7$9$9:::Y(<(<(>(>???w'''!!!w'''5!!!!!r   c                     | j         ddS )Nhttp://www.w3.org/2005/Atom)versionz
xmlns:atom)_versionrV   s    r   r   zRssFeed.rss_attributes   s    }7
 
 	
r   c                     | j         D ]V}|                    d|                     |                     |                     ||           |                    d           Wd S )Nr_   rC   r   r`   rc   r   rb   s      r   r   zRssFeed.write_items   sn    J 	' 	'D  )=)=d)C)CDDD""7D111v&&&&	' 	'r   c                    |                     d| j        d                    |                     d| j        d                    |                     d| j        d                    | j        d         %|                     dd d| j        d         d           | j        d         !|                     d| j        d                    | j        d	         D ]}|                     d
|           | j        d         !|                     d| j        d                    |                     dt          |                                                      | j        d         #|                     d| j        d                    d S d S )Nr5   r6   r7   r>   z	atom:linkrD   relhrefr8   r=   categoryr?   	copyrightlastBuildDaterA   )addQuickElementrB   r   rv   rD   r\   cats      r   r]   zRssFeed.add_root_elements   s}   7);<<<	&(9:::ty/GHHH9Z ,##T649Z;P#Q#Q   9Z ,##J	*0EFFF9\* 	5 	5C##J44449%&2##K;K1LMMMd>S>S>U>U1V1VWWW9U'##E49U+;<<<<< ('r   c                 0    |                     d           d S )Nr   )r   r[   s     r   r   zRssFeed.endChannelElement  s    9%%%%%r   N)	rw   rx   ry   content_typerh   r   r   r]   r   r1   r   r   r   r      sd        7L" " "
 
 
' ' '= = =$& & & & &r   r   c                       e Zd ZdZd ZdS )RssUserland091Feedz0.91c                     |                     d|d                    |                     d|d                    |d         |                     d|d                    d S d S )Nr5   r6   r7   )r   rb   s      r   rc   z$RssUserland091Feed.add_item_elements  sj    g777V555*##M43FGGGGG +*r   Nrw   rx   ry   r   rc   r1   r   r   r   r     s-        HH H H H Hr   r   c                       e Zd ZdZd ZdS )Rss201rev2Feedz2.0c                    |                     d|d                    |                     d|d                    |d         |                     d|d                    |d         r1|d         r)|                     d|d         d|d         d           nL|d         r|                     d|d                    n'|d         r|                     d	|d         d
di           |d         )|                     dt          |d                              |d         |                     d|d                    |d         qi }t          |                    d          t                    r*t          |d                                                   |d<   |                     d|d         |           |d         |                     d|d                    |d         rit          |d                   }t          |          dk    rt          d          |d         }|                     dd|j
        |j        |j        d           |d         D ]}|                     d|           d S )Nr5   r6   r7   r:   r9   authorz ()z
dc:creatorzxmlns:dcz http://purl.org/dc/elements/1.1/rK   pubDaterM   rN   rO   isPermaLinkguidrA   rP      zrRSS feed items may only have one enclosure, see http://www.rssboard.org/rss-profile#element-channel-item-enclosurer   	enclosurer   )r"   r~   typer=   r   )r   r   r	   rn   boolr+   lowerlistrU   
ValueErrorr"   r~   r   )rD   r\   r_   
guid_attrsrP   r   r   s          r   rc   z Rss201rev2Feed.add_item_elements  s   g777V555*##M43FGGG  	4#7 	##tN';';';T-=P=P=PQ    .! 	##Hd>.BCCCC-  	##]#?@   	?&##I|DO/L/LMMM
'##JZ0@AAA(J$((#;<<dCC X,/5M0N,O,O,U,U,W,W
=)##FD,=zJJJ;"##E4;777  	d<011J:"" Y   #1I##$='.%/    % 	5 	5C##J4444	5 	5r   Nr   r1   r   r   r   r     s(        H55 55 55 55 55r   r   c                   4    e Zd ZdZdZd Zd Zd Zd Zd Z	dS )		Atom1Feedz#application/atom+xml; charset=utf-8r   c                     t          ||d          }|                                 |                    d|                                            |                     |           |                     |           |                    d           d S )NTr   rB   )r   r   r   rY   r]   r   r   r   s       r   rh   zAtom1Feed.write[  s    %gxdSSSVT%9%9%;%;<<<w'''!!!6"""""r   c                 X    | j         d         | j        | j         d         dS d| j        iS )Nr8   )xmlnszxml:langr   )rB   nsrV   s    r   rY   zAtom1Feed.root_attributesc  s3    9Z ,!W$)J2GHHHTW%%r   c                    |                     d| j        d                    |                     ddd| j        d         d           | j        d         %|                     ddd| j        d         d           |                     d| j        d                    |                     d	t          |                                                      | j        d
         |                    di            |                     d| j        d
                    | j        d         !|                     d| j        d                    | j        d         !|                     d| j        d                    |                    d           | j        d         !|                     d| j        d                    | j        d         D ]}|                     ddd|i           | j        d         #|                     d| j        d                    d S d S )Nr5   r6   r   	alternater   r>   rD   r@   updatedr:   r   namer9   r   r;   urir<   r=   r   termr?   rights)r   rB   r   rv   r   r   r   s      r   r]   zAtom1Feed.add_root_elementsi  s   7);<<<BTYv5FGG	
 	
 	
 9Z ,##FDIj4IJJ   	dio666	<8M8M8O8O+P+PQQQ9]#/  2...##FDIm,DEEEy(4''>1JKKKy'3''ty/GHHHx(((9Z ,##J	*0EFFF9\* 	C 	CC##JVSMBBBB9%&2##Hdi8H.IJJJJJ 32r   c                     | j         D ]V}|                    d|                     |                     |                     ||           |                    d           Wd S )Nentryr   rb   s      r   r   zAtom1Feed.write_items  sn    J 	( 	(D  $*>*>t*D*DEEE""7D111w''''	( 	(r   c           
      D   |                     d|d                    |                     dd|d         dd           |d         )|                     dt          |d                              |d         )|                     d	t          |d                              |d
         |                    di            |                     d|d
                    |d         |                     d|d                    |d         |                     d|d                    |                    d           |d         	|d         }nt	          |d         |d                   }|                     d|           |d         |                     d|d         ddi           |d         D ]-}|                     ddd|j        |j        |j        d           .|d         D ]}|                     ddd|i           |d         |                     d|d                    d S d S )Nr5   r6   r   r   )r   r   rK   	publishedrL   r   r:   r   r   r9   r   r;   r   rN   r@   r7   summaryr   htmlrP   r   )r   r   r~   r   r=   r   r   rQ   r   )r   r   r   r   r%   r"   r~   r   )rD   r\   r_   rN   r   r   s         r   rc   zAtom1Feed.add_item_elements  ss   g777T&\+,V,VWWW	?&##Kd9o1N1NOOO*##I|D<O/P/PQQQ *  2...##FD,?@@@N#/''n1EFFFM".''tM/BCCCx((( ([)II#DL$y/BBIi000 *##ItM/BVVDTUUU l+ 
	 
	I##&%M'.%/	 	 	 	 	 % 	C 	CC##JVSMBBBB  !-##Hd3C.DEEEEE .-r   N)
rw   rx   ry   r   r   rh   rY   r]   r   rc   r1   r   r   r   r   V  sq        8L	&B# # #& & &K K K4( ( (2F 2F 2F 2F 2Fr   r   )rz   r
   r   ior   urllib.parser   django.utils.encodingr   django.utils.xmlutilsr   r   r   r%   r'   r|   r   r   r   r   DefaultFeedr1   r   r   <module>r      s   0         ! ! ! ! ! ! , , , , , , 5 5 5 5 5 5- - -H H HK K KYN YN YN YN YN YN YN YNx# # # # # # # #,& ,& ,& ,& ,&o ,& ,& ,&^H H H H H H H H95 95 95 95 95W 95 95 95xeF eF eF eF eF eF eF eFT r   