ó
OvWc           @  sļ   d  Z  d d l m Z d d l Z e j d k r@ e Z e Z n  d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l m Z m Z m Z m Z d d l m Z m Z m Z m Z m Z m Z m Z e j e  Z d e f d	     YZ d S(
   u   Simple XML manipulationi’’’’(   t   unicode_literalsNu   3i   (   t
   __author__t   __copyright__t   __license__t   __version__(   t   TYPE_MAPt   TYPE_MARSHAL_FNt   TYPE_UNMARSHAL_FNt   REVERSE_TYPE_MAPt   Structt   Datet   Decimalt   SimpleXMLElementc           B  sµ  e  Z d  Z d$ d$ d$ d$ d$ i  e d  Z d$ e d  Z d   Z d   Z	 d   Z
 d$ e d  Z e j d k r~ d   Z n	 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d$ d$ e e e d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e j d k rGe Z  n	 d   Z  d   Z! d   Z" e# d    Z$ e d  Z% d    Z& e e e e d!  Z' d"   Z( d$ e d#  Z) RS(%   u#   Simple XML manipulation (simil PHP)c   	      C  s¼   | |  _  d j | j    } t j d |  |  _ | |  _ | |  _ | |  _ | d k	 r¦ y t
 j j j |  |  _ Wn t j |    n X|  j j g |  _ n | |  _ | |  _ d S(   u   
        :param namespaces_map: How to map our namespace prefix to that given by the client;
          {prefix: received_prefix}
        u   |u	   ^(%s):.*$N(   t!   _SimpleXMLElement__namespaces_mapt   joint   keyst   ret   compilet   _SimpleXMLElement__ns_rxt   _SimpleXMLElement__nst   _SimpleXMLElement__prefixt   _SimpleXMLElement__jettyt   Nonet   xmlt   domt   minidomt   parseStringt   _SimpleXMLElement__documentt   logt   errort   documentElementt   _SimpleXMLElement__elements(	   t   selft   textt   elementst   documentt	   namespacet   prefixt   namespaces_mapt   jettyt   _rx(    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   __init__'   s    					c         C  s]  | s |  j  t k r+ |  j j |  } n t | t  rh |  j j |  } | r± | j d |  q± nI |  j r |  j j |  j  d |  j | f  } n |  j j |  j  |  } | d	 k	 rt | t
 j j j  rō | j |  j j | j   q| j |  j j |   n  |  j j |  t d | g d |  j d |  j  d |  j d |  j d |  j  S(
   u   Adding a child tag to a nodeu   xmlnsu   %s:%sR"   R#   R$   R%   R'   R&   N(   R   t   FalseR   t   createElementt
   isinstancet
   basestringt   setAttributeR   t   createElementNSR   R   R   R   t   CDATASectiont   appendChildt   createCDATASectiont   datat   createTextNodet   _elementR   R   R   (   R    t   nameR!   t   nst   element(    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt	   add_childA   s*    	(					c         C  s9   | j  d  r% t j |  | |  n |  j | |  d S(   u$   Add text child tag node (short form)u   _N(   t
   startswitht   objectt   __setattr__R9   (   R    t   tagR!   (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyR<   `   s    c         C  sV   g  |  j  j D] } | j | j k r | ^ q } x | D] } |  j  j |  q8 Wd S(   u#   Remove a child tag (non recursive!)N(   R5   t
   childNodest   nodeTypet   ELEMENT_NODEt   removeChild(   R    R=   t   _SimpleXMLElement__elementR"   R8   (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   __delattr__h   s    c         C  s&   |  j  j |  } |  j j |  d S(   u    Add an xml comment to this childN(   R   t   createCommentR5   R1   (   R    R3   t   comment(    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   add_commento   s    c         C  s-   | s |  j  j d  S|  j  j d d  Sd S(   u-   Return the XML representation of the documentu   UTF-8t   encodingN(   R   t   toxmlt   toprettyxml(   R    t   filenamet   pretty(    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   as_xmlt   s    u   3c         C  s   |  j  j   S(   u)   Return the XML representation of this tag(   R5   RH   (   R    (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   __repr__|   s    c         C  s   |  j  j d  S(   u)   Return the XML representation of this tagu   UTF-8(   R5   RH   (   R    (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyRM      s    c         C  s
   |  j  j S(   u    Return the tag name of this node(   R5   t   tagName(   R    (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   get_name   s    c         C  s
   |  j  j S(   u4   Return the tag local name (prefix:name) of this node(   R5   t	   localName(   R    (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   get_local_name   s    c         C  s
   |  j  j S(   u(   Return the namespace prefix of this node(   R5   R%   (   R    (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt
   get_prefix   s    c         C  sb   |  j  } xR | d k	 r] | j d k	 r] y | j d | j SWq t k
 rY | j } q Xq Wd S(   u%   Return the namespace uri for a prefixu   xmlns:%sN(   R5   R   t
   attributest   valuet   KeyErrort
   parentNode(   R    R7   R8   (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   get_namespace_uri   s    	c         C  s
   |  j  j S(   u(   Return a dict of attributes for this tag(   R5   RS   (   R    (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyRS      s    c         C  s¬   t  | t  r5 |  j j |  rØ |  j j | j Sns t  | t  r^ t |  j j j    | S|  j	 | } t
 d | g d |  j d |  j d |  j d |  j d |  j  Sd S(   u>   Return xml tag attribute value or a slice of attributes (iter)R"   R#   R$   R%   R'   R&   N(   R,   R-   R5   t   hasAttributeRS   RT   t   slicet   listt   itemsR   R   R   R   R   R   R   (   R    t   itemR8   (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   __getitem__   s    					c         C  s   |  j  j | |  d S(   u$   Set an attribute value from a stringN(   R5   R.   (   R    R6   RT   (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   add_attribute“   s    c         C  se   t  | t  r" |  j | |  n? t  | t  ra x- | j   D] \ } } |  j | |  q> Wn  d S(   u   Set an attribute valueN(   R,   R-   R^   RY   R[   (   R    R\   RT   t   kt   v(    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   __setitem__ø   s
    c         C  s   |  j  j |  d S(   u   Remove an attributeN(   R5   t   removeAttribute(   R    R\   (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   __delitem__Į   s    c   	      C  sĖ  y| rL t  d |  j j g d |  j d |  j d |  j d |  j d |  j  S| d k rb |  j   S| rr |  j	   Sd } t
 | t  r |  j | g } n  | rų | rų xN t
 | t t f  rÅ | pĖ | f D]% } |  j j | |  } | rĢ PqĢ qĢ Wn  |  j r#| r#|  j j |  j |  } n  | s>|  j j |  } n  | s`| rYt d   q`d Sn  t  d | d |  j d |  j d |  j d |  j d |  j  SWn) t k
 rĘ} t d	 | | f   n Xd S(
   u;   Search (even in child nodes) and return a child tag by nameR"   R#   R$   R%   R'   R&   u   No elements foundNu   Tag not found: %s (%s)(   R   R   R   R   R   R   R   R   t   __iter__t   childrenR,   t   intR   t   tupleRZ   R5   t   getElementsByTagNameNSt   getElementsByTagNamet   AttributeError(	   R    R=   R7   Re   t   rootR   R"   t   ns_urit   e(    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   __call__Å   sL    				


+				c         C  s   |  j  |  S(   u   Shortcut for __call__(   Rn   (   R    R=   (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   __getattr__ł   s    c         c  sg   yV xO |  j  D]D } t d | g d |  j d |  j d |  j d |  j d |  j  Vq WWn
   n Xd S(   u#   Iterate over xml tags at this levelR"   R#   R$   R%   R'   R&   N(   R   R   R   R   R   R   R   (   R    RB   (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyRd   ż   s    					c         C  s2   g  |  j  j D]! } | j | j k r | j ^ q S(   u   List xml children tags names(   R5   R>   R?   t	   TEXT_NODERN   (   R    t   node(    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   __dir__  s    c         C  su   g  |  j  j D] } | j | j k r | ^ q } | s; d St d | d |  j d |  j d |  j d |  j	 d |  j
  S(   u    Return xml children tags elementR"   R#   R$   R%   R'   R&   N(   R5   R>   R?   R@   R   R   R   R   R   R   R   (   R    RB   R"   (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyRe     s    				c         C  s   t  |  j  S(   u   Return element count(   t   lenR   (   R    (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   __len__!  s    c         C  s   |  j  j |  S(   u4   Search for a tag name in this element or child nodes(   R5   Ri   (   R    R\   (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   __contains__%  s    c         C  sU   d } xH |  j  j D]: } | j | j k s= | j | j k r | | j } q q W| S(   u5   Returns the unicode text nodes of the current elementu    (   R5   R>   R?   Rp   t   CDATA_SECTION_NODER3   (   R    t   rcRq   (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   __unicode__)  s
    $c         C  s   |  j    j d  S(   Nu   utf-8(   Rx   t   encode(   R    (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   __str__4  s    c         C  s   t  |  j    S(   u0   Returns the integer value of the current element(   Rf   Rz   (   R    (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   __int__7  s    c         C  s7   y t  |  j    SWn t |  j j     n Xd S(   u.   Returns the float value of the current elementN(   t   floatRz   t
   IndexErrorR5   RH   (   R    (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt	   __float__;  s    c         C  s   |  j  d S(   Ni    (   R   (   R    (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   <lambda>B  s    c         C  sĒ  i  } xŗ|    D]Æ} t  | j    } d } d | j   j   k rØ | d d } xQ |  d t  d  D]7 } | d | k rj | } | d j d  d } Pqj qj Wn  yt t | t  r| | }	 t	 g  | D] \ }
 } d |
 k rĻ |
 ^ qĻ  rt |	 t
  r|	 g }	 qn | }	 WnVt f k
 rt} | d	 pM| j | j    } d | j   j   k r%| d j d  d } y | d
 k rg  | D] \ }
 } d |
 k r|
 ^ qd } | | j d  d } d | k r÷| | j d   } n  t | g }	 n
 t | }	 Wqqd }	 qqXqu| d k r:d }	 qud | k rOd }	 qu| rkt d | f   qut  }	 n Xt |	 t
  r¶| j | g   } | j   } |	 r’t |	 d t  r’xō | pČg  D]/ } | j |	 d |  } | j | j    qÉWqµ|  j rt |	 d  d k rx | D]S } i  } x7 | j   pCg  D]# } | j | j |	 d |   qDW| j |  q%Wqµx3| pg  D]# } | j | j |	 d |   qWn’t |	 t  rĀg  } i  } | j   } t |	  d k o’t |	 d t  } x` | r|   pg  D]I } | rD| j | j |	 d |   q| j | j |	 d |   qW| r{| j |  n  | | k r³t
 | |  } | j |  t |  } qµt |  } nó t |	 t  rų| j   } | oņ| j |	 |  } n½ |	 d k r| } nØ t |  s7|	 t  k rÆt |  d k rÆyC t j |	 |	  }	 |	 t  k rgt |  } n |	 t |   } Wqµt t f k
 r«} t d | | f   qµXn d } | | | <q W| S(   u;   Convert to python values the current serialized xml elementu   hrefi   Rk   u   multiRefu   idu   xsi:typeu   :u	   arrayTypeu   xmlnsu   Arrayi    u   [u    http://www.w3.org/2001/XMLSchemau    Tag: %s invalid (type not found)u    u   Tag: %s: %sN(   t   strRQ   R   RS   R   t   Truet   splitR,   t   dictt   anyRZ   RU   RW   RR   t   indexR   t	   TypeErrort
   setdefaultRe   t
   unmarshallt   extendt   valuesR   Rs   t   updatet   appendRg   t   unicodeR   t   gett
   ValueError(   R    t   typest   strictt   dRq   R6   t   ref_name_typet   hreft   ref_nodet   fnR_   R`   Rm   t   xmlnst   xsd_typet
   array_typeRT   Re   t   childt   tmp_dictt   parentt   _dt   as_dictt   _tmp(    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyR   D  sŖ    	
B
0		
!$% !	*c         C  sq   |  j  j |  } | rm | j   d } y | j | |  j |  } Wqm t k
 ri t j d |  qm Xn  | S(   uB   Replace the defined namespace alias with tohse used by the client.i    u   Unknown namespace alias %s(   R   t   searcht   groupst   replaceR   RU   R   t   warning(   R    R6   t   pref(    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt
   _update_nsĘ  s    c      
   C  sz  |  j  |  } t | t  r“ | r9 |  j | d | p< |  } x4| j   D]a \ } }	 | sg t } n* t | d  r | j j |  } n d } | j
 | |	 d | d | qL WnĀt | t  r2| rŽ |  j | d | pį |  } | só t } n  x| D]1 \ } }	 t |  |  j
 | |	 d | d | qś WnDt | t  r®|  j | d | } | set } n  | r{| j d  n  xų | D]% }
 | j
 | |
 t d | d | qWnČ t | t j j j t f  rå|  j | | d | n | d k r|  j | d | no | t j   k rB|  j | d | } | j t |  n4 t j t |  t  } |  j | | |  d | d S(   uF   Analyze python value and add the serialized XML element using tag nameR7   u
   namespacest   add_commentsu   Repetitive array of:N(   R„   R,   R   R9   R[   R*   t   hasattrt
   namespacesR   R   t   marshallRg   t   getattrRZ   RF   R   R   R   R0   R-   R   R   R   t   typeR   (   R    R6   RT   R9   R¦   R7   t   add_children_nsR   R_   R`   t   tR   (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyR©   Ń  sB    !	#!	,	&c         C  s,   |  j  j | j t  } |  j j |  d  S(   N(   R   t
   importNodeR5   R   R1   (   R    t   othert   x(    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   import_node   s    c         C  s;   d d l  m } | j |  j | d | r. g  n d } | S(   u.   Generate the canonical version of the XML nodei   (   t   c14nt   unsuppressedPrefixesN(   t    R²   t   CanonicalizeR5   R   (   R    t   outputt	   exclusiveR²   R   (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt
   write_c14n  s    N(*   t   __name__t
   __module__t   __doc__R   R*   R)   R   R9   R<   RC   RF   RL   t   syst   versionRM   RO   RQ   RR   RW   RS   R]   R^   Ra   Rc   Rn   Ro   Rd   Rr   Re   Rt   Ru   Rx   Rz   R{   R~   t   propertyR5   R   R„   R©   R±   Rø   (    (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyR   $   sR   																3												.	(   R»   t
   __future__R    R¼   R½   R   R-   R   t   loggingR   t   timet   xml.dom.minidomR   R“   R   R   R   R   t   helpersR   R   R   R   R	   R
   R   t	   getLoggerR¹   R   R;   R   (    (    (    sU   /data/av2000/soap/soapenv/local/lib/python2.7/site-packages/pysimplesoap/simplexml.pyt   <module>   s   	"4