Ñò
ŬT~Kc           @   s  d  d k  l Z l Z l Z d  d k l Z d  d k l Z d  d k l	 Z	 d  d k
 l
 Z
 d  d k l Z d  d k Z d d  Z d	 e e f d
     YZ h e d  e d  6e d  e d  6e d  e d  6e d  e d  6e d  e d  6e d  e d  6e d  e d  6e d  e d  6e d  e d  6e d  e d  6e d  e d   6e d!  e d"  6e d#  e d$  6e d%  e d&  6e d'  e d(  6e d)  e d*  6e d+  e d,  6e d-  e d.  6e d/  e d0  6e d1  e d2  6e d3  e d4  6e d5  e d6  6e d7  e d8  6e d9  e d:  6e d;  e d<  6e d=  e d>  6e d?  e d@  6Z e dA j oc d  d k Z d  d k Z e
   Z x+ e i dB D] Z e e i e  e  qàWe i e i  n d S(C   i˙˙˙˙(   t   ContentHandlert   make_parsert   SAXParseException(   t   InputSource(   t
   SGMLParser(   t   StringIO(   t   ConfigParser(   t
   entitydefsNc         C   sŞ   t  |  d  o |  i   }  n | p t   } n t |  } yC t   } | i t |    t   } | i |  | i	 |  Wn  t
 j
 o | i |   n X| S(   Nt   read(   t   hasattrR   R   t
   OpmlParserR   t   setByteStreamR   R   t   setContentHandlert   parseR   t   feed(   t   opmlt   configt
   opmlParsert   sourcet   parser(    (    s   /net/bzr/venus/planet/opml.pyt   opml2config
   s    		R
   c           B   s;   e  Z e i d   Z d   Z d   Z d   Z d   Z RS(   s	   &(#?\w+);c         C   s'   t  i |   t i |   | |  _ d  S(   N(   R    t   __init__R   R   (   t   selfR   (    (    s   /net/bzr/venus/planet/opml.pyR   %   s    c         C   sÖ  | d j o d  S| i  d  ob | d d j o1 | i  d  o  t | i    } d | d <n | d i   d j o d  Sn | i  d  p | d i   oh xe | i   D]O } | i   d j o6 | | i   o% t | i    } | | | d <Pq´ q´ Wd  Sn | i  d	  p | d	 i   oL | i  d
  p | d
 i   o d  St | i    } | d
 | d	 <n | d } |  i i |  p7 |  i i |  |  i i	 | d |  i
 | d	   n d  S(   Nt   outlinet   typet   linkt   urlt   rsst   atomt   xmlUrlt   xmlurlt   textt   titlet   name(   s   rsss   atom(   t   has_keyt   dictt   itemst   lowert   stript   keysR   t   has_sectiont   add_sectiont   sett   unescape(   R   R!   t   attrst	   attributeR   (    (    s   /net/bzr/venus/planet/opml.pyt   startElement*   s2     " 	# $	## 
c         C   s)  |  i  i |  } xŝ t d t |  d  D]ä } | | t i   j oÇ t | | } |  i  i |  } | o | i d  | | <n t t	 |   | | <| | i
 d  o[ | | i
 d  o% t t | | d d   | | <qt t | | d   | | <qq+ q+ Wd i |  i d  S(   Ni   i   t   #s   #xi   u    s   utf-8(   t   entitiest   splitt   ranget   lenR   R'   t   matcht   groupt   unichrt   ordt
   startswitht   intt   joint   encode(   R   R   t   parsedt   it	   codepointR4   (    (    s   /net/bzr/venus/planet/opml.pyR+   T   s     %*c         C   sµ   t  |  } x | D] } y | | i d  | | <Wq | | i d  } d i g  } | D]% } | | t j o t | p | q^ ~  } | | | <q Xq W|  i | |  d  S(   Ns   utf-8s
   iso-8859-1u    (   R#   t   decodeR:   t   cp1252R.   (   R   R!   R,   R-   t   workt   _[1]t   c(    (    s   /net/bzr/venus/planet/opml.pyt   unknown_starttagk   s     B(	   t   __name__t
   __module__t   ret   compileR0   R   R.   R+   RD   (    (    (    s   /net/bzr/venus/planet/opml.pyR
   "   s
   		*	iĴ   i   i   i   i  i   i   i   i&   i   i    i   i!   i   iĈ  i   i0   i   i`  i   i9   i   iR  i   i}  i   i   i   i   i   i   i   i   i   i"   i   i   i   i   i   iÜ  i   i"!  i   ia  i   i:   i   iS  i   i~  i   ix  i   t   __main__i   (   t   xml.saxR    R   R   t   xml.sax.xmlreaderR   t   sgmllibR   t	   cStringIOR   R   t   htmlentitydefsR   RG   t   NoneR   R
   R6   R@   RE   t   syst   urllibR   t   argvR   t   urlopent   writet   stdout(    (    (    s   /net/bzr/venus/planet/opml.pyt   <module>   sV   U	 
