³ò
Jé¬Fc        ,   @   s­  d  d k  l Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k	 l
 Z
 l Z d  d k Z e i i Z e i d d i e ƒ ƒ Z d e i f d „  ƒ  YZ d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d e d g d e d d g d e d g d e d g d e d g d e d g d e d g d e d g d e d g d e d g d e d d g d e d d g d  e d! d g d" e d! d g d# e d$ h  d% d& <d' g d# e d( g g Z d e d g d) e d d* g d e d d g d+ e d d' g d, e d- d. d/ g d- e d0 d g d- e d- d. d g d1 e d2 g d1 e d g d3 e d2 g d3 e d g d4 e d2 g d4 e d g d5 e d$ h  d6 d& <d' g d7 e d$ h  d6 d& <d8 g d9 e d$ h  d6 d& <d: g d e d g d e d$ h  d; d& <d' g d< e d= d g d> e d2 g d> e d g d e d d g d? e d! d/ g d" e d! d g d  e d! d g d@ e d0 d/ g dA e d g dB e d g dC e d g dD e d2 g dE e d2 g dF e d2 g g  Z x8 e D]0 Z e i dG e d. e dH d= g e dI ƒ qÔWdJ „  Z dK „  Z  dL „  Z! d h  dM „ Z# e$ dN j oj e i% i& d. e i% i' e i% d. ƒ d. ƒ x= e i( dH D]* Z) d  dO k* l* Z* e* e! dP e) ƒ ƒ qwWn d S(Q   iÿÿÿÿ(   t   escapeN(   t   configt
   feedparsers   <((%s)[^>]*)></\2>t   |t	   stripHtmlc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s   remove all tags from the datac         C   sy   t  i i |  ƒ d |  _ t | t ƒ o5 y |  i | i d ƒ ƒ Wqk |  i | ƒ qk Xn |  i | ƒ |  i ƒ  d  S(   Nt    s   utf-8(	   t   sgmllibt
   SGMLParsert   __init__t   resultt
   isinstancet   strt   feedt   decodet   close(   t   selft   data(    (    s.   /home/sgala/newcode/venus/planet/shell/tmpl.pyR      s    	c         C   s.   t  |  i t ƒ o |  i i d ƒ Sn |  i S(   Ns   utf-8(   R
   R	   t   unicodet   encode(   R   (    (    s.   /home/sgala/newcode/venus/planet/shell/tmpl.pyt   __str__   s    c         C   sÁ   d d  k  } | | i j oŽ | i | } t | ƒ d j o |  i t t | ƒ ƒ 7_ q½ | i d ƒ o( | i d ƒ o |  i | d d !ƒ q½ |  i d | 7_ n |  i d | 7_ d  S(   Niÿÿÿÿi   s   &#t   ;i   s   &%s;(	   t   htmlentitydefst
   entitydefst   lenR	   t   unichrt   ordt
   startswitht   endswitht   handle_charref(   R   t   refR   (    (    s.   /home/sgala/newcode/venus/planet/shell/tmpl.pyt   handle_entityref   s     c      
   C   sv   yU | i  d ƒ o& |  i t t | d d ƒ ƒ 7_ n |  i t t | ƒ ƒ 7_ Wn |  i d | 7_ n Xd  S(   Nt   xi   i   s   &#%s;(   R   R	   R   t   int(   R   R   (    (    s.   /home/sgala/newcode/venus/planet/shell/tmpl.pyR   &   s    &c         C   s   | o |  i  | 7_  n d  S(   N(   R	   (   R   R   (    (    s.   /home/sgala/newcode/venus/planet/shell/tmpl.pyt   handle_data.   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   R!   (    (    (    s.   /home/sgala/newcode/venus/planet/shell/tmpl.pyR   	   s   				c         C   s%   t  |  t ƒ o |  i d ƒ Sn |  S(   Ns   utf-8(   R
   R   R   (   t   value(    (    s.   /home/sgala/newcode/venus/planet/shell/tmpl.pyt   String3   s    !c         C   s   t  t |  ƒ ƒ S(   N(   R   R   (   R%   (    (    s.   /home/sgala/newcode/venus/planet/shell/tmpl.pyt   Plain7   s    c         C   s   t  i t i ƒ  |  ƒ S(   N(   t   timet   strftimeR   t   date_format(   R%   (    (    s.   /home/sgala/newcode/venus/planet/shell/tmpl.pyt
   PlanetDate:   s    c         C   s   t  i t i ƒ  |  ƒ S(   N(   R(   R)   R   t   new_date_format(   R%   (    (    s.   /home/sgala/newcode/venus/planet/shell/tmpl.pyt   NewDate=   s    c         C   s   t  i d |  ƒ S(   Ns   %a, %d %b %Y %H:%M:%S +0000(   R(   R)   (   R%   (    (    s.   /home/sgala/newcode/venus/planet/shell/tmpl.pyt   Rfc822@   s    c         C   s   t  i d |  ƒ S(   Ns   %Y-%m-%dT%H:%M:%S+00:00(   R(   R)   (   R%   (    (    s.   /home/sgala/newcode/venus/planet/shell/tmpl.pyt   Rfc3399C   s    t   authort   author_namet   author_detailt   namet	   generatort   idt   icont   last_updated_822t   updated_parsedt   last_updated_isot   last_updatedt   linkt   logot   rightst   rights_detailR%   t   subtitlet   subtitle_detailt   titlet   title_detailt   title_plaint   urlt   linksR   t   relt   hreft   planet_http_locationt   author_emailt   emailt
   author_urit   content_languaget   contenti    t   languaget   summary_detailt   datet   published_parsedt   date_822t   date_isot   enclosure_hreft	   enclosuret   enclosure_lengtht   lengtht   enclosure_typet   typet	   alternatet   new_channelt   sourcet   new_datet   title_languaget   summary_languaget   updatedt   updated_822t   updated_isot	   publishedt   published_822t   published_isot   channel_i   i   c   
   
   C   s0  h  } x| D]y} |  } xj| d D];} t  | t ƒ ož | | j o‘ | d j ov | i d d ƒ d j o" t | d ƒ | d <d | d <qÊ | i d d ƒ d j o t i d | d ƒ | d <qÊ n | | } q$ t  | t ƒ o | | } q$ t  | t ƒ oX xV | D]H } x? | i ƒ  D]* \ } } | i | d ƒ | j o Pq q W| } PqWPq$ Pq$ W| o | d	 | ƒ | | d
 <q q WxB |  i ƒ  D]4 \ }	 } |	 i
 d ƒ o t | ƒ | |	 d <q—q—Wd |  j oP xM |  i i ƒ  D]8 \ }	 } |	 i
 d ƒ o t | ƒ | d |	 d <qìqìWn | S(   sE   Apply specified rules to the source, and return a template dictionaryi   R%   RY   R   s
   text/plains	   text/htmls   application/xhtml+xmls   <\1 />i   i    t   planet_i   R\   Rf   N(   R
   R   t   getR    t   emptyt   subR    t   dictt   itemst   NoneR   R&   R\   (
   R\   t   rulest   outputt   rulet   nodet   patht   testt   keyR%   R3   (    (    s.   /home/sgala/newcode/venus/planet/shell/tmpl.pyt   tmpl_mapper   sJ      "  "'  $c         C   sR   |  i  ƒ  |  i ƒ  } | i d ƒ p g  | d <n | i i | i ƒ | d =d  S(   Nt   sourcesR\   (   t   _end_sourcet   _getContextt   has_keyRv   t   appendR\   (   R   t   context(    (    s.   /home/sgala/newcode/venus/planet/shell/tmpl.pyt   _end_planet_source­   s
    
c         C   sò  t  i } | i | _ t i t d | ƒ | _ t  i |  ƒ } | ` | ` h  g  d <g  d <} | i	 t
 | i t ƒ ƒ g  } | i i d g  ƒ D] }  | |  i d d ƒ |  f q“ ~ } | i ƒ  x. | D]& \ } } | d i t
 | t ƒ ƒ qÌ Wx+ | i D]  } | d i t
 | t ƒ ƒ q WxI | d D]= }	 |	 i d ƒ |	 i d ƒ j o d |	 d <q/d	 |	 d <q/Wt i ƒ  | d
 <t i ƒ  | d <t i ƒ  | d <t i ƒ  | d <t i ƒ  | d <t i ƒ  oA t i ƒ  | d <t i ƒ  i d ƒ d j o d p d | d <n t i ƒ  }
 t |
 ƒ | d <t |
 ƒ | d <t |
 ƒ | d <d }
 } x— | d D]‹ }	 |	 i d ƒ o* |	 d |
 j o |	 d =qŸ|	 d }
 n |	 i d ƒ o; |	 d | j o |	 i d ƒ o |	 d =qê|	 d } q_q_W| S(   s3    get template information from a feedparser output t   Channelst   ItemsRv   t   planet_nameR5   R;   t   truet   guid_isPermaLinkt   falseR4   R3   t
   owner_namet   owner_emailR   t   rssi    t   atomt   feedtypeRP   RS   RR   R]   R[   N(   R   t   _FeedParserMixint   _start_sourcet   _start_planet_sourcet   newt   instancemethodR|   Rm   t   parset   updateRu   R   t   BaseRh   t   sortRz   t   entriesR~   R   t   generator_uriR3   R;   Rƒ   R„   t   findR(   t   gmtimeR+   R/   R.   Ry   (   R\   t   mixinR   Ro   t   _[1]Rv   R3   R   t   entryt   itemRP   t   channel(    (    s.   /home/sgala/newcode/venus/planet/shell/tmpl.pyt   template_info´   s\    	;
 
  1
 "c         C   sï   t  i ƒ  } | i |  ƒ } t  i d d ƒ } x0 t | ƒ i ƒ  D] \ } } | i | | ƒ q@ W| ow t i i	 t i i
 | ƒ ƒ d }	 | i d t i t i ƒ  |	 ƒ ƒ t | d ƒ }
 |
 i | i | ƒ ƒ |
 i ƒ  n | i | ƒ Sd S(   s    process an HTMLTMPL file t   html_escapei    RD   t   wN(   t   htmltmplt   TemplateManagert   preparet   TemplateProcessorRš   Rl   t   sett   osRr   t   splitextt   basenamet   urlparset   urljoinR   R;   t   opent   writet   processR   (   t   scriptt   doct   output_filet   optionst   managert   templatet   tpRt   R%   t   reluriRo   (    (    s.   /home/sgala/newcode/venus/planet/shell/tmpl.pyt   runó   s     ""t   __main__(   t   pprints-   /home/rubys/bzr/venus/tests/data/filter/tmpl/(+   t   xml.sax.saxutilsR    R   R(   R¢   t   sysR‹   R¥   t   ret   planetR   R   R   t   _BaseHTMLProcessort   elements_no_end_tagt   voidst   compilet   joinRi   R   R   R&   R'   R+   R-   R.   R/   R   R~   Rp   Rz   Ru   R|   Rš   Rm   R²   R"   Rr   t   insertt   splitt   argvRs   R´   (    (    (    s.   /home/sgala/newcode/venus/planet/shell/tmpl.pys   <module>   s’   T*						 .	,		?* 
