
bc           @   s-  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z y e j	 e j
 g Z Wn e k
 r e j	 g Z n Xd   Z i  d  Z i  d  Z i  d  Z d   Z d e j f d	     YZ d
 e j f d     YZ d e j f d     YZ d d  Z d S(   sn   A library of useful helper classes to the SAX classes, for the
convenience of application and driver writers.
iNc         C   s3   x, | j    D] \ } } |  j | |  }  q W|  S(   s2   Replace substrings of a string using a dictionary.(   t   itemst   replace(   t   st   dt   keyt   value(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   __dict_replace   s    c         C   sR   |  j  d d  }  |  j  d d  }  |  j  d d  }  | rN t |  |  }  n  |  S(   s   Escape &, <, and > in a string of data.

    You can escape other strings of data by passing a dictionary as
    the optional entities parameter.  The keys and values must all be
    strings; each key will be replaced with its corresponding value.
    t   &s   &amp;t   >s   &gt;t   <s   &lt;(   R   R   (   t   datat   entities(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   escape   s    	c         C   sL   |  j  d d  }  |  j  d d  }  | r< t |  |  }  n  |  j  d d  S(   s
  Unescape &amp;, &lt;, and &gt; in a string of data.

    You can unescape other strings of data by passing a dictionary as
    the optional entities parameter.  The keys and values must all be
    strings; each key will be replaced with its corresponding value.
    s   &lt;R	   s   &gt;R   s   &amp;R   (   R   R   (   R
   R   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   unescape'   s
    c         C   s   | j    } | j i d d 6d d 6d d 6 t |  |  }  d |  k r{ d |  k rn d	 |  j d d
  }  q d |  }  n
 d	 |  }  |  S(   s  Escape and quote an attribute value.

    Escape &, <, and > in a string of data, then quote it for use as
    an attribute value.  The " character will be escaped as well, if
    necessary.

    You can escape other strings of data by passing a dictionary as
    the optional entities parameter.  The keys and values must all be
    strings; each key will be replaced with its corresponding value.
    s   &#10;s   
s   &#13;s   s   &#9;s   	t   "t   's   "%s"s   &quot;s   '%s'(   t   copyt   updateR   R   (   R
   R   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt	   quoteattr5   s    "
c         C   s   |  d  k r$ d d  l } | j }  n  t |  t j  rT t j |   } d   | _ nT t j   } d   | _ |  j	 | _	 y |  j
 | _
 |  j | _ Wn t k
 r n Xt | d | d d d d S(	   Nic           S   s   d  S(   N(   t   None(    (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   <lambda>V   t    c           S   s   t  S(   N(   t   True(    (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyR   [   R   t   encodingt   errorst   xmlcharrefreplacet   newlines   
(   R   t   syst   stdoutt
   isinstancet   iot	   RawIOBaset   BufferedIOBaset   closet   writablet   writet   seekablet   tellt   AttributeErrort   _UnbufferedTextIOWrapper(   t   outR   R   t   buffer(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   _gettextwriterM   s"    R'   c           B   s   e  Z d    Z RS(   c         C   s$   t  t |   j |  |  j   d  S(   N(   t   superR'   R#   t   flush(   t   selfR   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyR#   k   s    (   t   __name__t
   __module__R#   (    (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyR'   j   s   t   XMLGeneratorc           B   s   e  Z d d  d  Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z RS(   s
   iso-8859-1c         C   si   t  j j |   t | |  } | j |  _ | j |  _ i  g |  _ |  j d |  _	 g  |  _
 | |  _ d  S(   Ni(   t   handlert   ContentHandlert   __init__R*   R#   t   _writeR,   t   _flusht   _ns_contextst   _current_contextt   _undeclared_ns_mapst	   _encoding(   R-   R(   R   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyR3   r   s    	c         C   sX   | d rP d | d k r& d | d S|  j  | d } | rP | d | d Sn  | d S(   s7   Builds a qualified name from a (ns_url, localname) pairi    s$   http://www.w3.org/XML/1998/namespaces   xml:i   t   :(   R7   (   R-   t   namet   prefix(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   _qname|   s    
c         C   s   |  j  d |  j  d  S(   Nu$   <?xml version="1.0" encoding="%s"?>
(   R4   R9   (   R-   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   startDocument   s    	c         C   s   |  j    d  S(   N(   R5   (   R-   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   endDocument   s    c         C   s@   |  j  j |  j j    | |  j | <|  j j | | f  d  S(   N(   R6   t   appendR7   R   R8   (   R-   R<   t   uri(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   startPrefixMapping   s    c         C   s   |  j  d |  _ |  j  d =d  S(   Ni(   R6   R7   (   R-   R<   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   endPrefixMapping   s    c         C   s\   |  j  d |  x7 | j   D]) \ } } |  j  d | t |  f  q W|  j  d  d  S(   Nu   <u    %s=%su   >(   R4   R    R   (   R-   R;   t   attrsR   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   startElement   s    !c         C   s   |  j  d |  d  S(   Nu   </%s>(   R4   (   R-   R;   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt
   endElement   s    c         C   s   |  j  d |  j |   xH |  j D]= \ } } | rP |  j  d | | f  q$ |  j  d |  q$ Wg  |  _ x@ | j   D]2 \ } } |  j  d |  j |  t |  f  q{ W|  j  d  d  S(   Nu   <u    xmlns:%s="%s"u    xmlns="%s"u    %s=%su   >(   R4   R=   R8   R    R   (   R-   R;   t   qnameRD   R<   RA   R   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   startElementNS   s    	*c         C   s   |  j  d |  j |   d  S(   Nu   </%s>(   R4   R=   (   R-   R;   RG   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   endElementNS   s    c         C   s;   t  | t  s$ t | |  j  } n  |  j t |   d  S(   N(   R   t   unicodeR9   R4   R   (   R-   t   content(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt
   characters   s    c         C   s5   t  | t  s$ t | |  j  } n  |  j |  d  S(   N(   R   RJ   R9   R4   (   R-   RK   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   ignorableWhitespace   s    c         C   s   |  j  d | | f  d  S(   Nu	   <?%s %s?>(   R4   (   R-   t   targetR
   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   processingInstruction   s    N(   R.   R/   R   R3   R=   R>   R?   RB   RC   RE   RF   RH   RI   RL   RM   RO   (    (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyR0   p   s   
											t   XMLFilterBasec           B   s  e  Z d  Z d d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   sY  This class is designed to sit between an XMLReader and the
    client application's event handlers.  By default, it does nothing
    but pass requests up to the reader and events on to the handlers
    unmodified, but subclasses can override specific methods to modify
    the event stream or the configuration requests as they pass
    through.c         C   s   t  j j |   | |  _ d  S(   N(   t	   xmlreadert	   XMLReaderR3   t   _parent(   R-   t   parent(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyR3      s    c         C   s   |  j  j |  d  S(   N(   t   _err_handlert   error(   R-   t	   exception(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRV      s    c         C   s   |  j  j |  d  S(   N(   RU   t
   fatalError(   R-   RW   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRX      s    c         C   s   |  j  j |  d  S(   N(   RU   t   warning(   R-   RW   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRY      s    c         C   s   |  j  j |  d  S(   N(   t   _cont_handlert   setDocumentLocator(   R-   t   locator(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyR[      s    c         C   s   |  j  j   d  S(   N(   RZ   R>   (   R-   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyR>      s    c         C   s   |  j  j   d  S(   N(   RZ   R?   (   R-   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyR?      s    c         C   s   |  j  j | |  d  S(   N(   RZ   RB   (   R-   R<   RA   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRB      s    c         C   s   |  j  j |  d  S(   N(   RZ   RC   (   R-   R<   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRC      s    c         C   s   |  j  j | |  d  S(   N(   RZ   RE   (   R-   R;   RD   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRE      s    c         C   s   |  j  j |  d  S(   N(   RZ   RF   (   R-   R;   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRF      s    c         C   s   |  j  j | | |  d  S(   N(   RZ   RH   (   R-   R;   RG   RD   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRH      s    c         C   s   |  j  j | |  d  S(   N(   RZ   RI   (   R-   R;   RG   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRI      s    c         C   s   |  j  j |  d  S(   N(   RZ   RL   (   R-   RK   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRL      s    c         C   s   |  j  j |  d  S(   N(   RZ   RM   (   R-   t   chars(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRM      s    c         C   s   |  j  j | |  d  S(   N(   RZ   RO   (   R-   RN   R
   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRO     s    c         C   s   |  j  j |  d  S(   N(   RZ   t   skippedEntity(   R-   R;   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyR^     s    c         C   s   |  j  j | | |  d  S(   N(   t   _dtd_handlert   notationDecl(   R-   R;   t   publicIdt   systemId(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyR`   	  s    c         C   s   |  j  j | | | |  d  S(   N(   R_   t   unparsedEntityDecl(   R-   R;   Ra   Rb   t   ndata(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRc     s    c         C   s   |  j  j | |  S(   N(   t   _ent_handlert   resolveEntity(   R-   Ra   Rb   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRf     s    c         C   sT   |  j  j |   |  j  j |   |  j  j |   |  j  j |   |  j  j |  d  S(   N(   RS   t   setContentHandlert   setErrorHandlert   setEntityResolvert   setDTDHandlert   parse(   R-   t   source(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRk     s
    c         C   s   |  j  j |  d  S(   N(   RS   t	   setLocale(   R-   t   locale(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRm     s    c         C   s   |  j  j |  S(   N(   RS   t
   getFeature(   R-   R;   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRo      s    c         C   s   |  j  j | |  d  S(   N(   RS   t
   setFeature(   R-   R;   t   state(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRp   #  s    c         C   s   |  j  j |  S(   N(   RS   t   getProperty(   R-   R;   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRr   &  s    c         C   s   |  j  j | |  d  S(   N(   RS   t   setProperty(   R-   R;   R   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRs   )  s    c         C   s   |  j  S(   N(   RS   (   R-   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt	   getParent.  s    c         C   s   | |  _  d  S(   N(   RS   (   R-   RT   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt	   setParent1  s    N(    R.   R/   t   __doc__R   R3   RV   RX   RY   R[   R>   R?   RB   RC   RE   RF   RH   RI   RL   RM   RO   R^   R`   Rc   Rf   Rk   Rm   Ro   Rp   Rr   Rs   Rt   Ru   (    (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRP      s:   																										R   c         C   s  t  |   t k r$ t j |   }  nS t |  d  rw |  } t j   }  |  j |  t | d  rw |  j | j  qw n  |  j   d k ry|  j
   } t j j t j j |   } t j   } t | t  rt | t  sdy | j |  } Wqt k
 r| j |  } qXqdnH t | t  rdy | j |  } Wqdt k
 r`| j |  } qdXn  t j j | |  } t j j |  } Wn t k
 rt } n X| r|  j |  t | d  } n4 |  j t j | |  j
     t j |  j
    } |  j |  n  |  S(   s   This function takes an InputSource and an optional base URL and
    returns a fully resolved InputSource object ready for reading.t   readR;   t   rbN(   t   typet   _StringTypesRQ   t   InputSourcet   hasattrt   setByteStreamt   setSystemIdR;   t   getByteStreamR   t   getSystemIdt   ost   patht   dirnamet   normpathR   t   getfilesystemencodingR   RJ   t   decodet   UnicodeDecodeErrort   encodet   joint   isfilet   UnicodeErrort   Falset   opent   urlparset   urljoint   urllibt   urlopen(   Rl   t   baset   ft   sysidt   baseheadR   t   sysidfilenameR   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   prepare_input_source6  sF    
(   Rv   R   R   R   t   typesR   R   R1   RQ   t
   StringTypet   UnicodeTypeRz   R&   R   R   R   R   R*   t   TextIOWrapperR'   R2   R0   RR   RP   R   (    (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   <module>   s$   0		Wo