
    h=                         S r SSKrSSKrSSKJr  SSKJr  SSKJr  SSK	J
r
  S rS rS	 r " S
 S5      r " S S5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r\rg)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                     [        U [        R                  5      (       d3  [        R                  R                  U [        R                  " 5       5      n [        R
                  R                  U 5      $ N)
isinstancedatetimecombinetimeemailutilsformat_datetimedates    L/var/www/html/env/lib/python3.13/site-packages/django/utils/feedgenerator.pyrfc2822_dater   "   sH    dH--..  ((x}}?;;&&t,,    c                     [        U [        R                  5      (       d3  [        R                  R                  U [        R                  " 5       5      n U R	                  5       U R                  5       c  S-   $ S-   $ )NZ )r	   r
   r   r   	isoformat	utcoffsetr   s    r   rfc3339_dater   (   sY    dH--..  ((x}}?>>dnn&6&>sGGBGGr   c                     [        U 5      nSnUb  SUR                  S5      -  nSUR                  < U< SUR                  < SUR                  < 3$ )z|
Create a TagURI.

See
https://web.archive.org/web/20110514113830/http://diveintomark.org/archives/2004/05/28/howto-atom-id
r   z,%sz%Y-%m-%dztag::/)r   strftimehostnamepathfragment)urlr   bitsds       r   get_tag_urir%   .   sG     C=D
ADMM*--#}}aDMMJJr   c                       \ rS rSrSr          SS jr            SS jrS rS rS r	S	 r
S
 rS rS rS rSrg)SyndicationFeed<   zGBase class for all syndication feeds. Subclasses should provide write()Nc                 T   S nU	=(       a    U	 Vs/ s H  n[        U5      PM     snn	U" U5      [        U5      U" U5      U" U5      U" U5      U" U5      [        U5      U" U5      U	=(       d    S[        U
5      U" U5      U=(       d    UU" U5      S.UEU l        / U l        g s  snf )Nc                 "    U b  [        U 5      $ U $ r   strss    r   to_str(SyndicationFeed.__init__.<locals>.to_strP       ]3q611r    )titlelinkdescriptionlanguageauthor_emailauthor_nameauthor_linksubtitle
categoriesfeed_urlfeed_copyrightidttl)r,   r   feeditems)selfr3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   	feed_guidr?   kwargsr/   cs                    r   __init__SyndicationFeed.__init__?   s    "	2  @Z$@ZSVZ$@
E]t$!+.x("<0!+.%k2x($*"8,$^4#t#;
 
	  
# %As   B%c                 Z   S nU=(       a    U Vs/ s H  nU" U5      PM     snnU R                   R                  U" U5      [        U5      U" U5      U" U5      U" U5      [        U5      UUU" U5      U" U	5      U
U=(       d    SU=(       d    SU" U5      U" U5      S.UE5        gs  snf )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                 "    U b  [        U 5      $ U $ r   r+   r-   s    r   r/   (SyndicationFeed.add_item.<locals>.to_str   r1   r   r2   )r3   r4   r5   r7   r8   r9   pubdateupdateddatecomments	unique_idunique_id_is_permalink
enclosuresr;   item_copyrightr?   N)rA   appendr   )rB   r3   r4   r5   r7   r8   r9   rK   rM   rN   rO   r;   rQ   r?   rL   rP   rD   r/   rE   s                      r   add_itemSyndicationFeed.add_itemf   s    2	2  C
$C
1VAY
$C


"4(%k2 &| 4%k2)+6"*"8,#I.*@(.B(.B"("8c{  !	
 %Ds   B(c                 ,    [        U R                  5      $ r   )lenrA   rB   s    r   	num_itemsSyndicationFeed.num_items   s    4::r   c                     0 $ )z`
Return extra attributes to place on the root (i.e. feed/channel) element.
Called from write().
r2   rW   s    r   root_attributesSyndicationFeed.root_attributes   s	    
 	r   c                     g)zL
Add elements in the root (i.e. feed/channel) element. Called
from write().
Nr2   rB   handlers     r   add_root_elements!SyndicationFeed.add_root_elements   s    
 	r   c                     0 $ )zJ
Return extra attributes to place on each item (i.e. item/entry) element.
r2   )rB   items     r   item_attributesSyndicationFeed.item_attributes   s	     	r   c                     g)z6
Add elements on each item (i.e. item/entry) element.
Nr2   rB   r_   rc   s      r   add_item_elements!SyndicationFeed.add_item_elements   s     	r   c                     [        S5      e)zq
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)rB   outfileencodings      r   writeSyndicationFeed.write   s    
 "I
 	
r   c                 X    [        5       nU R                  X!5        UR                  5       $ )z4
Return the feed in the given encoding as a string.
)r   rn   getvalue)rB   rm   r.   s      r   writeStringSyndicationFeed.writeString   s#     J

1zz|r   c                 
   SnSnU R                    H2  nU H)  nUR                  U5      nU(       d  M  Ub  XQ:  d  M'  UnM+     M4     U=(       d5    [        R                  R                  [        R                  R
                  S9$ )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)rA   getr
   nowtimezoneutc)rB   latest_date	date_keysrc   date_key	item_dates         r   latest_post_date SyndicationFeed.latest_post_date   sv    
 .	JJD% HHX.	9"*i.E&/	 &  Mh//33x7H7H7L7L3MMr   )r@   rA   )
NNNNNNNNNN)NNNNNNNr2   NNNN)__name__
__module____qualname____firstlineno____doc__rF   rS   rX   r[   r`   rd   rh   rn   rr   r~   __static_attributes__r2   r   r   r'   r'   <   s    M %X #!0
d
Nr   r'   c                       \ rS rSrSrS rSrg)	Enclosure   zAn RSS enclosurec                 @    X#sU l         U l        [        U5      U l        g)z#All args are expected to be stringsN)length	mime_typer   r"   )rB   r"   r   r   s       r   rF   Enclosure.__init__   s    &,#T^c?r   )r   r   r"   N)r   r   r   r   r   rF   r   r2   r   r   r   r      s
    #r   r   c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
RssFeed   z"application/rss+xml; charset=utf-8c                 @   [        XSS9nUR                  5         UR                  SU R                  5       5        UR                  SU R	                  5       5        U R                  U5        U R                  U5        U R                  U5        UR                  S5        g )NTshort_empty_elementsrsschannel)	r   startDocumentstartElementrss_attributesr[   r`   write_itemsendChannelElement
endElementrB   rl   rm   r_   s       r   rn   RssFeed.write   s    %gdSUD$7$7$9:Y(<(<(>?w'!w'5!r   c                      U R                   SS.$ )Nhttp://www.w3.org/2005/Atom)versionz
xmlns:atom)_versionrW   s    r   r   RssFeed.rss_attributes   s    }}7
 	
r   c                     U R                    HF  nUR                  SU R                  U5      5        U R                  X5        UR	                  S5        MH     g )Nrc   rA   r   rd   rh   r   rg   s      r   r   RssFeed.write_items   sG    JJD  )=)=d)CD""71v& r   c                    UR                  SU R                  S   5        UR                  SU R                  S   5        UR                  SU R                  S   5        U R                  S   b#  UR                  SS SU R                  S   S.5        U R                  S   b  UR                  SU R                  S   5        U R                  S	    H  nUR                  S
U5        M     U R                  S   b  UR                  SU R                  S   5        UR                  S[        U R                  5       5      5        U R                  S   b   UR                  SU R                  S   5        g g )Nr3   r4   r5   r<   z	atom:linkrB   relhrefr6   r;   categoryr=   	copyrightlastBuildDater?   )addQuickElementr@   r   r~   rB   r_   cats      r   r`   RssFeed.add_root_elements   sA   7);<		&(9:tyy/GH99Z ,##T6499Z;P#Q 99Z ,##J		*0EF99\*C##J4 +99%&2##K;K1LMd>S>S>U1VW99U'##E499U+;< (r   c                 &    UR                  S5        g )Nr   )r   r^   s     r   r   RssFeed.endChannelElement  s    9%r   r2   N)r   r   r   r   content_typern   r   r   r`   r   r   r2   r   r   r   r      s     7L"
'=$&r   r   c                       \ rS rSrSrS rSrg)RssUserland091Feedi  z0.91c                     UR                  SUS   5        UR                  SUS   5        US   b  UR                  SUS   5        g g )Nr3   r4   r5   )r   rg   s      r   rh   $RssUserland091Feed.add_item_elements  sO    g7V5*##M43FG +r   r2   Nr   r   r   r   r   rh   r   r2   r   r   r   r     s    HHr   r   c                       \ rS rSrSrS rSrg)Rss201rev2Feedi  z2.0c                    UR                  SUS   5        UR                  SUS   5        US   b  UR                  SUS   5        US   (       a+  US   (       a!  UR                  SUS   < SUS   < S35        OBUS   (       a  UR                  SUS   5        O"US   (       a  UR                  S	US   S
S05        US   b  UR                  S[        US   5      5        US   b  UR                  SUS   5        US   b[  0 n[        UR                  S5      [        5      (       a  [        US   5      R                  5       US'   UR                  SUS   U5        US   b  UR                  SUS   5        US   (       ab  [        US   5      n[        U5      S:  a  [        S5      eUS   nUR                  SSUR                  UR                  UR                  S.5        US    H  nUR                  SU5        M     g )Nr3   r4   r5   r8   r7   authorz ()z
dc:creatorzxmlns:dcz http://purl.org/dc/elements/1.1/rK   pubDaterM   rN   rO   isPermaLinkguidr?   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	   rv   boolr,   lowerlistrV   
ValueErrorr"   r   r   )rB   r_   rc   
guid_attrsrP   r   r   s          r   rh    Rss201rev2Feed.add_item_elements  s   g7V5*##M43FG 4#7##tN';T-=PQ .!##Hd>.BC- ##]#?@ 	?&##I|DO/LM
'##JZ0@A(J$((#;<dCC,/5M0N,O,U,U,W
=)##FD,=zJ;"##E4;7 d<01J:" Y  #1I##$=='..%// %C##J4 &r   r2   Nr   r2   r   r   r   r     s    H55r   r   c                   :    \ rS rSrSrSrS rS rS rS r	S r
S	rg
)	Atom1FeediV  z#application/atom+xml; charset=utf-8r   c                     [        XSS9nUR                  5         UR                  SU R                  5       5        U R	                  U5        U R                  U5        UR                  S5        g )NTr   r@   )r   r   r   r[   r`   r   r   r   s       r   rn   Atom1Feed.write[  s]    %gdSVT%9%9%;<w'!6"r   c                 v    U R                   S   b  U R                  U R                   S   S.$ SU R                  0$ )Nr6   )xmlnszxml:langr   )r@   nsrW   s    r   r[   Atom1Feed.root_attributesc  s8    99Z ,!WW$))J2GHHTWW%%r   c                    UR                  SU R                  S   5        UR                  SSSU R                  S   S.5        U R                  S   b#  UR                  SSSU R                  S   S.5        UR                  SU R                  S   5        UR                  S	[        U R                  5       5      5        U R                  S
   b  UR	                  S0 5        UR                  SU R                  S
   5        U R                  S   b  UR                  SU R                  S   5        U R                  S   b  UR                  SU R                  S   5        UR                  S5        U R                  S   b  UR                  SU R                  S   5        U R                  S    H  nUR                  SSSU05        M     U R                  S   b   UR                  SU R                  S   5        g g )Nr3   r4   r   	alternater   r<   rB   r>   updatedr8   r   namer7   r   r9   urir:   r;   r   termr=   rights)r   r@   r   r~   r   r   r   s      r   r`   Atom1Feed.add_root_elementsi  s   7);<BTYYv5FG	
 99Z ,##FDIIj4IJ 	diio6	<8M8M8O+PQ99]#/  2.##FDIIm,DEyy(4''>1JKyy'3''tyy/GHx(99Z ,##J		*0EF99\*C##JVSMB +99%&2##Hdii8H.IJ 3r   c                     U R                    HF  nUR                  SU R                  U5      5        U R                  X5        UR	                  S5        MH     g )Nentryr   rg   s      r   r   Atom1Feed.write_items  sG    JJD  $*>*>t*DE""71w' r   c           
      r   UR                  SUS   5        UR                  SSUS   SS.5        US   b  UR                  S[        US   5      5        US   b  UR                  S	[        US   5      5        US
   bn  UR                  S0 5        UR                  SUS
   5        US   b  UR                  SUS   5        US   b  UR                  SUS   5        UR                  S5        US   b  US   nO[	        US   US   5      nUR                  SU5        US   b  UR                  SUS   SS05        US    H9  nUR                  SSSUR
                  UR                  UR                  S.5        M;     US    H  nUR                  SSSU05        M     US   b  UR                  SUS   5        g g )Nr3   r4   r   r   )r   r   rK   	publishedrL   r   r8   r   r   r7   r   r9   r   rN   r>   r5   summaryr   htmlrP   r   )r   r   r   r   r;   r   r   rQ   r   )r   r   r   r   r%   r"   r   r   )rB   r_   rc   rN   r   r   s         r   rh   Atom1Feed.add_item_elements  s   g7T&\+,VW	?&##Kd9o1NO*##I|D<O/PQ *  2.##FD,?@N#/''n1EFM".''tM/BCx( ([)I#DL$y/BIi0 *##ItM/BVVDTU l+I##&%MM'..%//		 , %C##JVSMB &  !-##Hd3C.DE .r   r2   N)r   r   r   r   r   r   rn   r[   r`   r   rh   r   r2   r   r   r   r   V  s'    8L	&B#&K4(2Fr   r   )r   r
   r   ior   urllib.parser   django.utils.encodingr   django.utils.xmlutilsr   r   r   r%   r'   r   r   r   r   r   DefaultFeedr2   r   r   <module>r      s   0    ! , 5-HKYN YNx# #,&o ,&^H H95W 95xeF eFT r   