
Sc           @   si  d  Z  d Z d d l m Z d d l Z d d l Td d l Z d d l Z d d l Z d d l	 Z	 d d l	 m
 Z
 m Z d d l Z d d l Td d l m Z d d l m Z d d	 l m Z d d l Td d
 l m Z m Z d   Z d d d     YZ d e j f d     YZ d e
 f d     YZ d e f d     YZ d d d     YZ d d d     YZ d S(   s  
################################################################################
#
# SOAPpy - Cayce Ullman       (cayce@actzero.com)
#          Brian Matthews     (blm@actzero.com)
#          Gregory Warnes     (Gregory.R.Warnes@Pfizer.com)
#          Christopher Blunck (blunck@gst.com)
#
################################################################################
# Copyright (c) 2003, Pfizer
# Copyright (c) 2001, Cayce Ullman.
# Copyright (c) 2001, Brian Matthews.
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# Neither the name of actzero, inc. nor the names of its contributors may
# be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
################################################################################

s5   $Id: Client.py 1496 2010-03-04 23:46:17Z pooryorick $i(   t   __version__N(   t   *(   t   HTTPConnectiont   HTTP(   t   Config(   t   parseSOAPRPC(   t	   buildSOAP(   t	   faultTypet   simplifyc           C   s   d t  d S(   Ns   SOAPpy s    (pywebsvcs.sf.net)(   R    (    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyt   SOAPUserAgentE   s    t   SOAPAddressc           B   s#   e  Z e d   Z d   Z e Z RS(   c         C   s1  t  j |  \ } } | d d !d k rX | d  k rE | d | } n  d | } d } n  t  j |  \ } } y t |  d | } Wn n X| s d } n  | d k r t d
  n  | d	 k r | j r t d  n  | d k r | j r t d  n  t  j	 |  \ |  _
 } | |  _ | |  _ | |  _ d  S(   Ni    i   s   //t   :t   https
   localhost:t   /t   httpst   httpgs   unsupported SOAP protocols4   GSI client not supported by this Python installations4   SSL client not supported by this Python installation(   R   R   R   (   t   urllibt	   splittypet   Nonet	   splithostt   intt   IOErrort	   GSIclientt   AttributeErrort	   SSLclientt	   splitusert   usert   protot   hostt   path(   t   selft   urlt   configR   t   uriR   R   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyt   __init__J   s4    
	
					c         C   s   d |  j  S(   Ns   %(proto)s://%(host)s%(path)s(   t   __dict__(   R   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyt   __str__n   s    (   t   __name__t
   __module__R   R"   R$   t   __repr__(    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyR
   I   s   $	t   SOAPTimeoutErrorc           B   s   e  Z d  Z RS(   sA   This exception is raised when a timeout occurs in SOAP operations(   R%   R&   t   __doc__(    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyR(   s   s   t   HTTPConnectionWithTimeoutc           B   s)   e  Z d  Z d d d d  Z d   Z RS(   s)   Extend HTTPConnection for timeout supportc         C   s#   t  j |  | | |  | |  _ d  S(   N(   R   R"   t   _timeout(   R   R   t   portt   strictt   timeout(    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyR"   z   s    c         C   s9   t  j |   |  j r5 |  j r5 |  j j |  j  n  d  S(   N(   R   t   connectt   sockR+   t
   settimeout(   R   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyR/   ~   s    N(   R%   R&   R)   R   R"   R/   (    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyR*   w   s   t   HTTPWithTimeoutc           B   s#   e  Z e Z d  d d d d  Z RS(   t    c         C   s8   | d k r d } n  |  j |  j | | | |   d S(   s6  Slight modification of superclass (httplib.HTTP) constructor.

        The only change is that arg ``timeout`` is also passed in the
        initialization of :attr:`_connection_class`.

        :param timeout: for the socket connection (seconds); None to disable
        :type timeout: float or None

        i    N(   R   t   _setupt   _connection_class(   R   R   R,   R-   R.   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyR"      s    
	N(   R%   R&   R*   R5   R   R"   (    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyR2      s   t   HTTPTransportc           B   s;   e  Z d    Z d   Z d   Z d d d e d d  Z RS(   c         C   s   t  j   |  _ d  S(   N(   t   Cookiet   SimpleCookiet   cookies(   R   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyR"      s    c         C   sT   t  |  t k rL d | d } t j | |  } | rE | j d  S| Sn | Sd S(   sQ   Extract the (possibly extended) namespace from the returned
        SOAP message.s   xmlns:\w+=['"](s   [^'"]*)['"]i   N(   t   typet
   StringTypet   ret   searcht   group(   R   t   original_namespacet   datat   patternt   match(    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyt   getNS   s    c         C   s   x |  j  j   D] \ } } g  } | j d d  } | d k r` | d k r` | j d |  n  | j d | | j f  | j d  } | r | j d |  n  | j d  } | r | j d	 |  n  | j d
 d j |   q Wd S(   s3   Add cookies from self.cookies to request r
        t   versionR3   t   0s   $Version=%ss   %s=%sR   s   $Path=%st   domains
   $Domain=%sR7   s   ; N(   R9   t   itemst   gett   appendt   coded_valuet	   putheadert   join(   R   t   rt   cnamet   morselt   attrst   value(    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyt   __addcookies   s    c	         C   s  t  | t  s! t | |  } n  | rK | }	 | j d | j | j }
 n | j }	 | j }
 | j d k r d d l m } | |	 d | j } nK | j d k r t j	 |	 d | j
 j d | j
 j } n t |	 d	 | } | j d
 |
  | j d | j  | j d t    d } | d  k r8| d | 7} n  | j d |  | j d t t |    |  j |  | j d  k rt j t j | j   } | j d d | j d d   n  | d  k st |  d k r| j d d  n | j d d |  | j rud } t |  d |
 | j f GHd G| j GHd t d GHd G| GHd Gt |  GHd | GHt |  n  | j    | j! rd  } t |  | G| d d k rHn  t |  n  | j" |  | j#   \ } } } t$ j%   |  _& | rB| j' d! d  } | j' d  } x6 | j( d"  D] } |  j& j) |  q%Wn d  } d  } | r| j* d#  } | d k r| |  } qn  y t+ |  } Wn d } n X| j,   } | d  k rt- | d$ | | f   n  | d k  r| j.   } t |  } n | j. |  } | j/ rBd% G| GHd& G| GHd' G| GHd( G| GHd) G| GHn  | j0 rd* } t |  | j1 rd+ | | f GHd j2 t3 d,   | j1   GHn d- | | f GHt |  n  d.   } | d/ k r| | d  o| d k rt- | |   n  | j4 rBd0 } t |  | Gt |  d k r5| d d k r5Hn  t |  n  | d2 k r`t- | |   n  | d  k rud  } n |  j5 | |  } | | f S(3   Ns   ://R   i(   t   GSIHTTPt   tcpAttrR   t   key_filet	   cert_fileR.   t   POSTt   Hosts
   User-agents   text/xmls   ; charset=%ss   Content-types   Content-lengtht   Authorizations   Basic s   
R3   i    t
   SOAPActions   "%s"s   Outgoing HTTP headerss
   POST %s %ss   Host:s   User-agent: SOAPpy s    (http://pywebsvcs.sf.net)s   Content-type:s   Content-length:s   SOAPAction: "%s"s   Outgoing SOAPs   content-types
   Set-Cookiet   ,s/   Empty response from server
Code: %s
Headers: %ss   code=s   msg=s   headers=s   content-type=s   data=s   Incoming HTTP headerss   HTTP/1.? %d %sc         S   s
   |  j    S(   N(   t   strip(   t   x(    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyt   <lambda>4  s    s   HTTP/0.9 %d %sc         S   s   |  d t  |  !| k S(   Ni    (   t   len(   t   stringt   val(    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyt
   startswith9  s    i  s   Incoming SOAPi   (   i   i  (6   t
   isinstanceR
   R   R   R   t   pyGlobus.ioRS   RT   t   httplibt   HTTPSt   SSLRU   RV   R2   t
   putrequestRK   R	   R   t   strR_   t   _HTTPTransport__addcookiesR   t   base64t   encodestringR   t   unquote_plust   replacet   dumpHeadersOutt   debugHeadert   _http_vsn_strR    t   debugFootert
   endheaderst   dumpSOAPOutt   sendt   getreplyR7   R8   R9   RH   t   getallmatchingheaderst   loadt   findR   t   getfilet	   HTTPErrort   readt   debugt   dumpHeadersInt   headersRL   t   mapt
   dumpSOAPInRC   (   R   t   addrR@   t	   namespacet
   soapactiont   encodingt
   http_proxyR    R.   t	   real_addrt	   real_pathRS   RM   t   tRa   t   st   codet   msgR   t   content_typet   content_lengtht   cookiet   commat   message_lent   fRb   t   new_ns(    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyt   call   s    		*#	
		
	

						
	 		
"	N(   R%   R&   R"   RC   Rj   R   R   R   (    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyR6      s
   			t	   SOAPProxyc           B   s{   e  Z d
 d
 d
 d
 e d  d d
 d
 e d d
 d
 d  Z d   Z d
 d
 d
 d
 d  Z d   Z d   Z	 d d d	     YZ
 RS(   s   UTF-8i   i    c         C   s  | d  k r d j |  n  |	 d  k r7 | j |  _ n	 |	 |  _ | d  k r[ | j |  _ n	 | |  _ t | |  |  _ | |  _ | |  _ | |  _ | |  _	 |   |  _
 | |  _ | |  _ |
 |  _ | |  _ | |  _ | |  _ t | d  rt | d  r| j |  _ | j |  _ n  d  S(   NR3   t   channel_modet   delegation_mode(   R   t   encodet   unwrap_resultst   simplify_objectsR
   t   proxyR   R   t   headert   methodattrst	   transportR   t   throw_faultsR   R    t   norootR.   t   hasattrR   R   (   R   R   R   R   R   R   R   R   R   R   R   R    R   R   R.   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyR"   Y  s0    												c         C   s   |  j  | | i   S(   N(   t   _SOAPProxy__call(   R   t   methodt   args(    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyt   invoke  s    c         C   s  | p |  j  } | p |  j } | rF t |  t k ra | d } qa n |  j r[ |  j } n | } | r t |  t k r | d } q n	 |  j } | p |  j } | r t |  t k r | d } q n	 |  j } | p |  j } t d | d | d | d | d | d | d |  j d	 |  j d
 |  j	  	} d }	 yO |  j
 j |  j | | | d |  j d |  j d	 |  j d |  j \ }
 |  _  Wn t j k
 rt  ng t k
 r } t |  j d  rt |  j j  r|  j j |  j |  }	 |	 s  qq  q  n X|	 rvyO |  j
 j |  j | | | d |  j d |  j d	 |  j d |  j \ }
 |  _  Wqvt j k
 rrt  qvXn  t |
 d d \ } } y |  j ot | t  } Wn d } n X| r|  j j r| GHn  |  n  |  j rXye d } xC | j j   D]2 } | d d k r| d 7} t | |  } qqW| d k rJ| } n  WqXqXXn  |  j rpt |  } n  |  j j  r| | f S| S(   Ni    R   t   kwR   R   R   R   R   R    R   R   R.   t   faultHandlerRP   i   t   _(!   R   R   R:   t	   TupleTypeR   R   R   R   R    R   R   R   R   R   R.   t   socketR(   t	   ExceptionR   t   callableR   R   R   Rc   R   R}   R   R#   t   keyst   getattrR   R   t   returnAllAttrs(   R   t   nameR   R   t   nst   sat   hdt   mat   mt
   call_retryRM   t   ext   pRP   t   throw_structt   countt   iR   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyt   __call  s    		 										
		
	
c         C   s   |  j  d  | i   S(   N(   R   R   (   R   t   body(    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyt   _callWithBody  s    c         C   s4   | d	 k r t  |  n  |  j |  j | d |  j S(
   Nt   __del__t   __getinitargs__t   __getnewargs__t   __getstate__t   __setstate__t
   __reduce__t   __reduce_ex__R    (   s   __del__R   s   __getnewargs__s   __getstate__s   __setstate__s
   __reduce__s   __reduce_ex__(   R   t   _SOAPProxy__MethodR   R    (   R   R   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyt   __getattr__   s    	t   __Methodc           B   sM   e  Z d d d d e d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   c         C   sC   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   t   _Method__callt   _Method__namet   _Method__nst   _Method__sat   _Method__hdt   _Method__mat   _Method__config(   R   R   R   R   R   R   R   R    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyR"     s    							c         O   sS   |  j  d d k r? |  j  d k r, |  j   S|  j | |   Sn |  j | |   Sd  S(   Ni    R   R'   R$   (   s   __repr__s   __str__(   R   R'   t   _Method__f_callt   _Method__r_call(   R   R   R   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyt   __call__  s
    
c         C   s   | d k r t  |  n  |  j d d k rV |  j |  j | |  j |  j |  j |  j  S|  j |  j d |  j | f |  j |  j |  j |  j  S(   NR   i    R   s   %s.%s(   R   R   t	   __class__R   R   R   R   R   (   R   R   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyR   #  s    c         O   sp   |  j  d k r | |  _ nQ |  j  d k r6 | |  _ n6 |  j  d k rQ | |  _ n |  j  d k rl | |  _ n  |  S(   Nt   _nst   _sat   _hdt   _ma(   R   R   R   R   R   (   R   R   R   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyt   __f_call.  s        c         O   s.   |  j  |  j | | |  j |  j |  j |  j  S(   N(   R   R   R   R   R   R   (   R   R   R   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyt   __r_call5  s    c         C   s   d |  j  t |   f S(   Ns
   <%s at %d>(   R   t   id(   R   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyR'   9  s    N(
   R%   R&   R   R   R"   R   R   R   R   R'   (    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyR     s   						N(    (   R%   R&   R   R6   R   R"   R   R   R   R   R   (    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyR   X  s   			&		v		(    (    (    (   R)   t   identRD   R    R   t   typesR<   Rk   R   Re   R   R   R7   t   ErrorsR   t   ParserR   t   SOAPBuilderR   t	   Utilitiest   TypesR   R   R	   R
   R.   R(   R*   R2   R6   R   (    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Client.pyt   <module>*   s,   


	*