ó
†¾^Yc           @   s8  d  Z  d d l Z d d l Z e j d k rE d „  Z d d „ Z n d „  Z e Z d e f d	 „  ƒ  YZ d
 e	 f d „  ƒ  YZ
 e d e f i d d 6e
 d 6e d 6ƒ Z d e
 f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d d d „  ƒ  YZ e ƒ  Z d S(   s   
module for generating and serializing xml and html structures
by using simple python objects.

(c) holger krekel, holger at merlinux eu. 2009
iÿÿÿÿNi   i    c         C   s   |  S(   N(    (   t   s(    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyt   u
   s    c         C   s#   t  |  d ƒ r |  j ƒ  St |  ƒ S(   Nt   __unicode__(   t   hasattrR   t   str(   t   xt   errors(    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyt   unicode   s    
c         C   s
   t  |  ƒ S(   N(   R   (   R    (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR      s    t   NamespaceMetaclassc           B   s   e  Z d  „  Z RS(   c         C   s²   | d  d k r t  | ƒ ‚ n  |  t k r: t d ƒ ‚ n  |  j } | d  k	 rj | | k rj t  | ƒ ‚ n  i  } |  j r† | | d <n  t | |  j f | ƒ } t |  | | ƒ | S(   Ni   t   _s   Namespace class is abstractt   xmlname(	   t   AttributeErrort	   Namespacet
   ValueErrort   __tagspec__t   Nonet   __stickyname__t   typet   __tagclass__t   setattr(   t   selft   namet   tagspect	   classattrt   cls(    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyt   __getattr__   s    		(   t   __name__t
   __module__R   (    (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR      s   t   Tagc           B   sK   e  Z d  e f d „  ƒ  YZ d „  Z d „  Z e Z d d „ Z d „  Z RS(   t   Attrc           B   s   e  Z d  „  Z RS(   c         K   s   |  j  j | ƒ d  S(   N(   t   __dict__t   update(   R   t   kwargs(    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyt   __init__(   s    (   R   R   R!   (    (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR   '   s   c         O   s,   t  t |  ƒ j | ƒ |  j |   |  _ d  S(   N(   t   superR   R!   R   t   attr(   R   t   argsR    (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR!   +   s    c         C   s   |  j  d d ƒ S(   Nt   indenti    (   R   (   R   (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR   /   s    i   c         C   s2   g  } t  | j | ƒ j |  ƒ t d ƒ j | ƒ S(   Nt    (   t   SimpleUnicodeVisitort   appendt   visitR   t   join(   R   R%   t   l(    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR   3   s    c         C   s    |  j  j } d | t |  ƒ f S(   Ns   <%r tag object %d>(   t	   __class__R   t   id(   R   R   (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyt   __repr__8   s    (	   R   R   t   objectR   R!   R   t   __str__R   R.   (    (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR   &   s   		R   R   R   R   t   HtmlTagc           B   s   e  Z d  d „ Z RS(   i   c         C   s8   g  } t  | j | d t ƒj |  ƒ t d ƒ j | ƒ S(   Nt
   shortemptyR&   (   t   HtmlVisitorR(   t   FalseR)   R   R*   (   R   R%   R+   (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR   C   s    (   R   R   R   (    (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR1   B   s   t   htmlc           B   s^   e  Z e Z e Z e g  d  j d ƒ D] Z e r% e d f ^ q% ƒ Z	 d e
 f d „  ƒ  YZ RS(   sÉ  a,abbr,acronym,address,applet,area,article,aside,audio,b,base,basefont,bdi,bdo,big,blink,blockquote,body,br,button,canvas,caption,center,cite,code,col,colgroup,command,comment,datalist,dd,del,details,dfn,dir,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,font,form,frame,frameset,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,img,input,ins,isindex,kbd,keygen,label,legend,li,link,listing,map,mark,marquee,menu,meta,meter,multicol,nav,nobr,noembed,noframes,noscript,object,ol,optgroup,option,output,p,param,pre,progress,q,rp,rt,ruby,s,samp,script,section,select,small,source,span,strike,strong,style,sub,summary,sup,table,tbody,td,textarea,tfoot,th,thead,time,title,tr,track,tt,u,ul,xmp,var,video,wbrt   ,i   t   Stylec           B   s   e  Z d  „  Z RS(   c         K   sC   x< | j  ƒ  D]. \ } } | j d d ƒ } t |  | | ƒ q Wd  S(   NR	   t   -(   t   itemst   replaceR   (   R   t   kwR   t   y(    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR!   \   s    (   R   R   R!   (    (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR7   [   s   (   R   R   R1   R   t   TrueR   t   dictt   splitR   R   R/   R7   (    (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR5   I   s   (t   rawc           B   s   e  Z d  Z d „  Z RS(   s]   just a box that can contain a unicode string that will be
    included directly in the outputc         C   s   | |  _  d  S(   N(   t   uniobj(   R   RA   (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR!   e   s    (   R   R   t   __doc__R!   (    (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR@   b   s   R'   c           B   sz   e  Z d  Z d d e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z RS(   s%    recursive visitor to write unicode. i    c         C   sC   | |  _  i  |  _ i  |  _ | |  _ | |  _ g  |  _ | |  _ d  S(   N(   t   writet   cachet   visitedR%   t	   curindentt   parentsR2   (   R   RC   R%   RF   R2   (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR!   j   s    						c         C   s‹   | j  } y |  j | } Wn` t k
 r| x? | j D]+ } t |  | j d ƒ } | d k	 r4 Pq4 q4 W|  j } | |  j | <n X| | ƒ d S(   s(    dispatcher on node's class/bases name. N(   R,   RD   t   KeyErrort   __mro__t   getattrR   R   t   _SimpleUnicodeVisitor__object(   R   t   nodeR   t   visitmethodt   subclass(    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR)   s   s    		c         C   s   |  j  t t | ƒ ƒ ƒ d  S(   N(   RC   t   escapeR   (   R   t   obj(    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyt   __object„   s    c         C   s   |  j  | j ƒ d  S(   N(   RC   RA   (   R   RP   (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR@   ˆ   s    c         C   sP   t  | ƒ |  j k s t ‚ d |  j t  | ƒ <x | D] } |  j | ƒ q5 Wd  S(   Ni   (   R-   RE   t   AssertionErrorR)   (   R   RP   t   elem(    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyt   list‹   s    c         C   s¶  t  | ƒ |  j k s t ‚ y |  j d | _ Wn t k
 rK d  | _ n Xd |  j t  | ƒ <t | d | j j	 ƒ } |  j
 r± |  j | ƒ r± |  j d t d ƒ |  j
 ƒ n  | rV|  j
 |  j 7_
 |  j t d ƒ | |  j | ƒ f ƒ |  j j | ƒ x | D] } |  j | ƒ qW|  j j ƒ  |  j t d ƒ | ƒ |  j
 |  j 8_
 n\ | |  j | ƒ } |  j | ƒ r•|  j t d ƒ | f ƒ n |  j t d	 ƒ | | f ƒ d  S(
   Niÿÿÿÿi   R
   s   
t    s   <%s%s>s   </%s>s   <%s/>s	   <%s></%s>(   R-   RE   RR   RG   t   parentt
   IndexErrorR   RJ   R,   R   RF   t	   _isinlineRC   R   R%   t
   attributesR(   R)   t   popt   _issingleton(   R   t   tagt   tagnameR   t   nameattr(    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR   ‘   s,    !&c         C   sŠ   t  | j ƒ } | j ƒ  g  } x? | D]7 } |  j | j | ƒ } | d  k	 r& | j | ƒ q& q& W| j |  j | ƒ ƒ t d ƒ j	 | ƒ S(   NR&   (
   t   dirR#   t   sortt   repr_attributeR   R(   t   extendt   getstyleR   R*   (   R   R\   t   attrlistR+   R   t   res(    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyRY   «   s    
c         C   sz   | d  d k rv t  | | ƒ } | j d ƒ r; | d  } n  t | t ƒ rV | j } n t t | ƒ ƒ } d | | f Sd  S(   Ni   t   __R	   iÿÿÿÿs    %s="%s"(   RJ   t   endswitht
   isinstanceR@   RA   RO   R   (   R   t   attrsR   t   valuet   insert(    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyRa   ·   s    c         C   sv   y | j  j } Wn t k
 r$ g  SXg  | j ƒ  D] \ } } | d | ^ q2 } t d ƒ t d ƒ j | ƒ g Sd S(   s-    return attribute list suitable for styling. s   : s    style="%s"s   ; N(   t   styleR   R   R9   R   R*   (   R   R\   t	   styledictR   R<   t	   stylelist(    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyRc   Â   s    -c         C   s   |  j  S(   s*   can (and will) be overridden in subclasses(   R2   (   R   R]   (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR[   Ì   s    c         C   s   t  S(   s*   can (and will) be overridden in subclasses(   R4   (   R   R]   (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyRX   Ð   s    (   R   R   RB   R=   R!   R)   RK   R@   RT   R   RY   Ra   Rc   R[   RX   (    (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR'   h   s   									
	R3   c           B   s   e  Z e g  d  j d ƒ D] Z e d f ^ q ƒ Z e g  d j d ƒ D] Z e d f ^ qG ƒ Z d „  Z d „  Z d „  Z	 RS(   s3   br,img,area,param,col,hr,meta,link,base,input,frameR6   i   s“   a abbr acronym b basefont bdo big br cite code dfn em font i img input kbd label q s samp select small span strike strong sub sup textarea tt u varRU   c         C   sG   | d k r. t  | | ƒ } | d  k r. d  Sn  t t |  ƒ j | | ƒ S(   Nt   class_(   RJ   R   R"   R3   Ra   (   R   Ri   R   Rj   (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyRa   Þ   s
    c         C   s   | |  j  k S(   N(   t   single(   R   R]   (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR[   å   s    c         C   s   | |  j  k S(   N(   t   inline(   R   R]   (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyRX   è   s    (
   R   R   R>   R?   R   Rp   Rq   Ra   R[   RX   (    (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR3   Ô   s   ""		t   _escapec           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s–   i t  d ƒ t  d ƒ 6t  d ƒ t  d ƒ 6t  d ƒ t  d ƒ 6t  d ƒ t  d ƒ 6t  d	 ƒ t  d
 ƒ 6|  _ t j t  d ƒ j |  j j ƒ  ƒ ƒ |  _ d  S(   Ns   &quot;t   "s   &lt;t   <s   &gt;t   >s   &amp;t   &s   &apos;t   't   |(   R   RO   t   ret   compileR*   t   keyst
   charef_rex(   R   (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyR!   í   s    9,c         C   s   |  j  | j d ƒ S(   Ni    (   RO   t   group(   R   t   match(    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyt	   _replacerô   s    c         C   sO   y t  | ƒ } Wn& t k
 r8 t  | d d d ƒ} n X|  j j |  j | ƒ S(   s&    xml-escape the given unicode string. s   utf-8R   R:   (   R   t   UnicodeDecodeErrorR|   t   subR   (   R   t   ustring(    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyt   __call__÷   s
    (   R   R   R!   R   Rƒ   (    (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyRr   ì   s   		(   i   i    (    (   RB   t   sysRy   t   version_infoR   R   R   R   R   RT   R   R/   R4   R   R1   R5   R@   R'   R3   Rr   RO   (    (    (    s&   /tmp/pip-build-hU8Cw8/py/py/_xmlgen.pyt   <module>   s&   		l