
sWc           @   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   s    c           S   s   t  S(   N(   t   True(    (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyR   [   s    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.pyR2   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   :(   R6   (   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"?>
(   R3   R8   (   R,   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   startDocument   s    	c         C   s   |  j    d  S(   N(   R4   (   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(   R5   t   appendR6   R   R7   (   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(   R5   R6   (   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   >(   R3   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>(   R3   (   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   >(   R3   R<   R7   R    R   (   R,   R:   t   qnameRC   R;   R@   R   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   startElementNS   s    	*c         C   s   |  j  d |  j |   d  S(   Nu   </%s>(   R3   R<   (   R,   R:   RF   (    (    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   unicodeR8   R3   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   RI   R8   R3   (   R,   RJ   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   ignorableWhitespace   s    c         C   s   |  j  d | | f  d  S(   Nu	   <?%s %s?>(   R3   (   R,   t   targetR
   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   processingInstruction   s    N(   R-   R.   R   R2   R<   R=   R>   RA   RB   RD   RE   RG   RH   RK   RL   RN   (    (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyR/   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	   XMLReaderR2   t   _parent(   R,   t   parent(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyR2      s    c         C   s   |  j  j |  d  S(   N(   t   _err_handlert   error(   R,   t	   exception(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRU      s    c         C   s   |  j  j |  d  S(   N(   RT   t
   fatalError(   R,   RV   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRW      s    c         C   s   |  j  j |  d  S(   N(   RT   t   warning(   R,   RV   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRX      s    c         C   s   |  j  j |  d  S(   N(   t   _cont_handlert   setDocumentLocator(   R,   t   locator(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRZ      s    c         C   s   |  j  j   d  S(   N(   RY   R=   (   R,   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyR=      s    c         C   s   |  j  j   d  S(   N(   RY   R>   (   R,   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyR>      s    c         C   s   |  j  j | |  d  S(   N(   RY   RA   (   R,   R;   R@   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRA      s    c         C   s   |  j  j |  d  S(   N(   RY   RB   (   R,   R;   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRB      s    c         C   s   |  j  j | |  d  S(   N(   RY   RD   (   R,   R:   RC   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRD      s    c         C   s   |  j  j |  d  S(   N(   RY   RE   (   R,   R:   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRE      s    c         C   s   |  j  j | | |  d  S(   N(   RY   RG   (   R,   R:   RF   RC   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRG      s    c         C   s   |  j  j | |  d  S(   N(   RY   RH   (   R,   R:   RF   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRH      s    c         C   s   |  j  j |  d  S(   N(   RY   RK   (   R,   RJ   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRK      s    c         C   s   |  j  j |  d  S(   N(   RY   RL   (   R,   t   chars(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRL      s    c         C   s   |  j  j | |  d  S(   N(   RY   RN   (   R,   RM   R
   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRN     s    c         C   s   |  j  j |  d  S(   N(   RY   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:   R`   Ra   t   ndata(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRb     s    c         C   s   |  j  j | |  S(   N(   t   _ent_handlert   resolveEntity(   R,   R`   Ra   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRe     s    c         C   sT   |  j  j |   |  j  j |   |  j  j |   |  j  j |   |  j  j |  d  S(   N(   RR   t   setContentHandlert   setErrorHandlert   setEntityResolvert   setDTDHandlert   parse(   R,   t   source(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRj     s
    c         C   s   |  j  j |  d  S(   N(   RR   t	   setLocale(   R,   t   locale(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRl     s    c         C   s   |  j  j |  S(   N(   RR   t
   getFeature(   R,   R:   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRn      s    c         C   s   |  j  j | |  d  S(   N(   RR   t
   setFeature(   R,   R:   t   state(    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRo   #  s    c         C   s   |  j  j |  S(   N(   RR   t   getProperty(   R,   R:   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRq   &  s    c         C   s   |  j  j | |  d  S(   N(   RR   t   setProperty(   R,   R:   R   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRr   )  s    c         C   s   |  j  S(   N(   RR   (   R,   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt	   getParent.  s    c         C   s   | |  _  d  S(   N(   RR   (   R,   RS   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt	   setParent1  s    N(    R-   R.   t   __doc__R   R2   RU   RW   RX   RZ   R=   R>   RA   RB   RD   RE   RG   RH   RK   RL   RN   R]   R_   Rb   Re   Rj   Rl   Rn   Ro   Rq   Rr   Rs   Rt   (    (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyRO      s:   																										t    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   _StringTypesRP   t   InputSourcet   hasattrt   setByteStreamt   setSystemIdR:   t   getByteStreamR   t   getSystemIdt   ost   patht   dirnamet   normpathR   t   getfilesystemencodingR   RI   t   decodet   UnicodeDecodeErrort   encodet   joint   isfilet   UnicodeErrort   Falset   opent   urlparset   urljoint   urllibt   urlopen(   Rk   t   baset   ft   sysidt   baseheadR   t   sysidfilenameR   (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   prepare_input_source6  sF    
(   Ru   R   R   R   t   typesR   R   R0   RP   t
   StringTypet   UnicodeTypeRz   R%   R   R   R   R   R)   t   TextIOWrapperR&   R1   R/   RQ   RO   R   (    (    (    s&   /usr/lib/python2.7/xml/sax/saxutils.pyt   <module>   s$   0		Wo