
Sc           @   s  d  Z  d Z d d l m Z d d l Z d d l Z d d l Z d d l Td d l Z d d l	 Z	 d d l
 m Z d d l m Z d d l m Z m Z m Z d d	 l m Z d d
 l m Z d d l m Z m Z y d d l m Z Wn n Xd Z d d l m Z e   a d   Z d f  d     YZ d f  d     YZ d f  d     YZ d f  d     YZ d e j  f d     YZ! d e j  f d     YZ" d e e j# f d     YZ$ d e e j% f d     YZ& e' e d  rd e e j( f d      YZ) n  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.
#
################################################################################

s1   $Id: Server.py 1468 2008-05-24 01:55:33Z warnes $i(   t   __version__N(   t   *(   t   parseSOAPRPC(   t   Config(   t	   faultTypet   voidTypet   simplify(   t   NS(   t	   buildSOAP(   t   debugHeadert   debugFooter(   t   SSLc           C   s   t  t j   S(   N(   t	   _contextst   threadt	   get_ident(    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyt   GetSOAPContextK   s    t	   MethodSigc           B   s    e  Z d  d  d  Z d   Z RS(   i    c         C   s+   | |  _  | |  _ | |  _ | j |  _ d  S(   N(   t   funct   keywordst   contextt   __name__(   t   selfR   R   R   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyt   __init__W   s    			c         O   s   t  |  j | |  S(   N(   t   applyR   (   R   t   argst   kw(    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyt   __call__]   s    (   R   t
   __module__R   R   (    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyR   V   s   t   SOAPContextc           B   s   e  Z d    Z RS(   c         C   sC   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   t   headert   bodyt   attrst   xmldatat
   connectiont   httpheaderst
   soapaction(   R   R   R   R   R    R!   R"   R#   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyR   a   s    						(   R   R   R   (    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyR   `   s   t   HeaderHandlerc           B   s   e  Z d    Z RS(   c         C   s   x | j  j   D] } | d d k r, q n  t | |  } y' t | t |  t j d f  } Wn d } n X| r t d t j d d | f  q q Wd  S(   Ni    t   _t   mustUnderstands   %s:MustUnderstands   Required Header Misunderstoods   %s(	   t   __dict__t   keyst   getattrt   intt   idR   t   ENVR   t   ENV_T(   R   R   R   t   it   dt   fault(    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyR   o   s    '
(   R   R   R   (    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyR$   m   s   t   SOAPServerBasec           B   sb   e  Z d    Z d d d  Z d d d d  Z d d d  Z d d d d  Z d d d  Z RS(   c         C   sq   t  j j |   \ } } |  j rg t j |  j |  } | j |  | j   d k rg t j	 d  qg n  | | f S(   Ni   s   Couldn't accept SSL connection(
   t   SocketServert	   TCPServert   get_requestt   ssl_contextR   t
   Connectiont
   _setup_sslt
   accept_sslt   sockett   error(   R   t   sockt   addr(    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyR4      s    	t    c         C   s   | d k r$ | d k r$ |  j  } n  | d k rn | d k rn | j d d  } | d d k rn | d } qn n  | |  j | <d  S(   NR=   t   /t   :i    i   (   t	   namespacet   replacet   objmap(   R   t   objectR@   t   path(    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyt   registerObject   s      c         C   s   | s | j  } n  | d k r6 | d k r6 |  j } n  | d k r | d k r | j d d  } | d d k r | d } q n  |  j j |  r | |  j | | <n i | | 6|  j | <d  S(   NR=   R>   R?   i    i   (   R   R@   RA   t   funcmapt   has_key(   R   t   functionR@   t   funcNameRD   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyt   registerFunction   s       c         C   s   | d k r$ | d k r$ |  j  } n  | d k rn | d k rn | j d d  } | d d k rn | d } qn n  xX t | j  D]G } | d d k r~ t t | |   r~ |  j t | |  |  q~ q~ Wd  S(   NR=   R>   R?   i    i   R%   (   R@   RA   t   dirt	   __class__t   callableR)   t   registerKWFunction(   R   RC   R@   RD   R.   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyt   registerKWObject   s      %c         C   s   | d k r$ | d k r$ |  j  } n  | d k rn | d k rn | j d d  } | d d k rn | d } qn n  |  j t | d d | |  d  S(   NR=   R>   R?   i    i   R   (   R@   RA   RJ   R   (   R   RH   R@   RI   RD   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyRN      s      c         C   s|   | d k r$ | d k r$ |  j  } n  | d k rn | d k rn | j d d  } | d d k rn | d } qn n  |  j | =d  S(   NR=   R>   R?   i    i   (   R@   RA   RB   (   R   RC   R@   RD   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyt   unregisterObject   s      N(	   R   R   R4   RE   t   NoneRJ   RO   RN   RP   (    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyR1      s   	
t   SOAPRequestHandlerc           B   s2   e  Z e Z d    Z d   Z d   Z d   Z RS(   c         C   s%   d d t  d t j j   d d S(   Ns"   <a href="http://pywebsvcs.sf.net">s   SOAPpy s   </a> (Python i    t   )(   R    t   syst   versiont   split(   R   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyt   version_string   s    c         C   s   t  j j |   |  _ |  j S(   N(   t   BaseHTTPServert   BaseHTTPRequestHandlert   date_time_stringt*   _SOAPRequestHandler__last_date_time_string(   R   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyRZ      s    	c   "   
      s  d } yw|  j  j j rc d } t |  |  j j   GHd j t d   |  j j   GHt	 |  n  |  j
 j t |  j d   } |  j  j j r d } t |  | G| d d k r Hn  t	 |  n  t | d d	 d
 d	 d d	 d |  j \ } } } } | j } | j   }	 | j   }
 |  j  j j rDt |	  }	 t |
  }
 n  i    i  } |  j  j j rx |
 j   D]q \ } } | d d k ry t | d	  } |   | <Wqt k
 r| | t |  <qXql| | t |  <qlWn  | j } t |  j  d	 k r>| r>|  j j d d  } | d d k r>| d	 } q>n  d  }   j   } | j   t   f d   |  } |   d } | rd | | f } n | } y<|  j  j  j! |  rQ|  j  j  | j! |  rQ|  j  j  | | } |  j  j j" d  k r|  j  j j" } |  j  j  j! |  rN|  j  j  | j! |  rN|  j  j  | | } qNqn |  j  j# | } |  j  j j" d  k r|  j  j j" } t$ | |  rt% | |  } qn  | j& d  } x | D] } t% | |  } qWWnw t' j(   } zW t) t* d t+ j, d d | | d | d	 | d f  d |  j  j- d |  j  j } Wd  ~ Xd } n*Xy| rnt. | |  } n  d	 } d j/   |  j j   k s|  j d d k r| |  j d <n  t0 j1   } t2 | | | | |  j3 |  j |  j d  t4 | <| d  k r9t5 | d8 i t4 | d 6 s9t* d t+ j, d d  |   q9n  t6 | t7  r6d  } | j8 rdt4 | } n  |  j  j j r| r| | d <n  t5 |   |  } ql| j9 ri  } x* |
 j   D] \ } } | | t |  <qW| r| | d <n  t5 | d9 |  } ql| r!t5 | |	 i | d 6 } qlt5 | |	 i   } n6 |  j  j j rZt5 |   |  } n t5 | |	 i   } t: |  t: |   k rt6 | t;  rt) d! i | d" | 6d |  j  j- d |  j  j  } n9 t) d! i i | d# 6d" | 6d |  j  j- d |  j  j  } t4 j! |  rt4 | =n  WnXt< k
 ru} d d  l= } t' j(   } z |  j  j j> rd$ | } t |  | j? | d | d	 | d  t	 |  n  t6 | t*  r| } n t* d t+ j, d% d  |  } |  j  j j@ r| jA d j | jB | d | d	 | d    n1 t$ | d&  s@| jA d' | d | d	 f  n  Wd  ~ Xt) | d |  j  j- d |  j  j } d } n Xd( } WnUt* k
 r	} d d  l= } t' j(   } z |  j  j j> rd) } t |  | j? | d | d	 | d  t	 |  n  |  j  j j@ r8	| jA d j | jB | d | d	 | d    n1 t$ | d&  si	| jA d' | d | d	 f  n  Wd  ~ Xt) | d |  j  j- d |  j  j } d } nt< k
 r
} |  j  j j> r
d* | } d d  l= } t |  t' j(   } z# | j? | d | d	 | d  Wd  ~ Xt	 |  n  |  jC d  |  jD   |  j  j jE r|  jF d+ k rd, } t |  |  jG j! |  r
d- |  jG | d } n d } d. |  jH d | f GHd/ G|  jI   GHd0 G|  jJ GHt	 |  qnX|  jC |  d1 }  |  j  j- d  k r|  d2 |  j  j- 7}  n  |  jK d3 |   |  jK d t t |    |  jD   |  j  j jE r|  jF d+ k rd, } t |  |  jG j! |  rd- |  jG | d } n d } d. |  jH | | f GHd/ G|  jI   GHd0 G|  jJ GHd4 G|  GHd5 Gt |  GHt	 |  n  |  j  j jL r>d6 } t |  | G| d d k r1Hn  t	 |  n  |  jM jN |  |  jM jO   |  j  j jP rt6 |  j3 tQ jR  r|  j3 jS tQ jT tQ jU B n |  j3 jV d	  d7   }! d  S(:   Ni  s   Incoming HTTP headerss   
c         S   s
   |  j    S(   N(   t   strip(   t   x(    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyt   <lambda>   s    s   Content-lengths   Incoming SOAPiR   i   R   R   t
   ignore_exti    t   vR>   R?   c            s     |  S(   N(    (   R]   (   t   ordered_args(    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyR^     s    R=   s   %s:%st   .s	   %s:Clients   Method Not Founds   %s : %s %s %si   t   encodingt   configt
   SOAPActions   ""t   _SOAPContexts	   %s:Servers   Authorization failed.s   %sR   s
   %sResponset   Results   Method %s exceptions   Method Failedt   details   %s %si   s   Received fault exceptions   Internal exception %ss   HTTP/0.9s   Outgoing HTTP headerst    s   %s %d%ss   Server:s   Date:s   text/xmls   ; charset=%ss   Content-types   Content-type:s   Content-length:s   Outgoing SOAPc         S   sa  |  j  j   } | j d  r&d } d  } } |  j j j |  rs |  j j | j |  rs |  j j | | } nZ | |  j j j   k r |  j j | } | j	 d  } x  | D] } t
 | |  } q Wn  | r&|  j d  |  j d d  |  j   t | d  } |  j j t |   d  Sn  |  j d  |  j d d  |  j   |  j j d  d  S(	   Nt   wsdlRb   i   s   Content-types
   text/plains	   text/htmlsQ  <title>
<head>Error!</head>
</title>

<body>
<h1>Oops!</h1>

<p>
  This server supports HTTP GET requests only for the the purpose of
  obtaining Web Services Description Language (WSDL) for a specific
  service.

  Either you requested an URL that does not end in "wsdl" or this
  server does not implement a wsdl method.
</p>


</body>(    (   RD   t   lowert   endswithRQ   t   serverRF   RG   RB   R(   RV   R)   t   send_responset   send_headert   end_headersR   t   wfilet   writet   str(   R   RD   t   methodRH   R@   t   lR.   t   response(    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyt   do_GET/  s0    


	(    (    (W   Rm   Rd   t   dumpHeadersInR	   t   raw_requestlineR\   t   joint   mapt   headersR
   t   rfilet   readR*   t
   dumpSOAPInR   R_   t   _namet   _aslistt   _asdictt   simplify_objectsR   t   specialArgst   itemst
   ValueErrorRs   t   _nst   lenRD   RA   RQ   R(   t   sortRF   RG   t
   authMethodRB   t   hasattrR)   RV   RT   t   exc_infoR   R   R   R-   Rc   R$   Rk   R   R   R   R!   R   R   t
   isinstanceR   R   R   t   typeR   t	   Exceptiont	   tracebackt   dumpFaultInfot   print_exceptiont   returnFaultInfot
   _setDetailt   format_exceptionRn   Rp   t   dumpHeadersOutt   request_versiont	   responsest   protocol_versionRW   R[   Ro   t   dumpSOAPOutRq   Rr   t   flusht	   SSLserverR   R6   t   set_shutdownt   SSL_SENT_SHUTDOWNt   SSL_RECEIVED_SHUTDOWNt   shutdown("   R   t   statust   st   datat   rR   R   R   Rt   R   R   t
   named_argst   kR`   R.   t   nst   at   keylistt   tmpt   respt   nsmethodt   ft
   authmethodRu   t   infoR]   t   frt	   thread_idt   ct   strkwt   eR   t   tRw   (    (   Ra   s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyt   do_POST   s   

3		 

			

	"&


"&	

#



	
c         G   s)   |  j  j r% t j j |  | |  n  d  S(   N(   Rm   t   logRX   RY   t   log_message(   R   t   formatR   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyR   i  s    	(   R   R   t   TrueR_   RW   RZ   R   R   (    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyRR      s   			 t   SOAPInsecureRequestHandlerc           B   s   e  Z d  Z e Z RS(   s.   Request handler that does load POSTed doctypes(   R   R   t   __doc__t   FalseR_   (    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyR   o  s   t
   SOAPServerc           B   s&   e  Z d e d d e d d d  Z RS(   t	   localhosti@  i    s   UTF-8c         C   s   | d  k r d j |  n  | d  k r> | j r> t d  n  | |  _ i  |  _ i  |  _ | |  _ | |  _ | |  _	 | |  _
 d |  _ t j j |  | |  d  S(   NR=   s4   SSL server not supported by this Python installationi   (   RQ   t   encodeR   t   AttributeErrorR@   RB   RF   R5   Rc   Rd   R   t   allow_reuse_addressR2   R3   R   (   R   R<   t   RequestHandlerR   Rc   Rd   R@   R5   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyR   v  s    									(   R   i@  N(   R   R   RR   R   RQ   R   (    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyR   t  s   	t   ThreadingSOAPServerc           B   s&   e  Z d e d d e d d d  Z RS(   R   i@  i    s   UTF-8c         C   s   | d  k r d j |  n  | d  k r> | j r> t d  n  | |  _ i  |  _ i  |  _ | |  _ | |  _ | |  _	 | |  _
 d |  _ t j j |  | |  d  S(   NR=   s4   SSL server not supported by this Python installationi   (   RQ   R   R   R   R@   RB   RF   R5   Rc   Rd   R   R   R2   t   ThreadingTCPServerR   (   R   R<   R   R   Rc   Rd   R@   R5   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyR     s    									(   s	   localhosti@  N(   R   R   RR   R   RQ   R   (    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyR     s   	t   AF_UNIXt   SOAPUnixSocketServerc           B   s&   e  Z d  e d d e d d d  Z RS(   i@  i    s   UTF-8c         C   s   | d  k r d j |  n  | d  k r> | j r> t d  n  | |  _ i  |  _ i  |  _ | |  _ | |  _ | |  _	 | |  _
 d |  _ t j j |  t |  |  d  S(   NR=   s4   SSL server not supported by this Python installationi   (   RQ   R   R   R   R@   RB   RF   R5   Rc   Rd   R   R   R2   t   UnixStreamServerR   Rs   (   R   R<   R   R   Rc   Rd   R@   R5   (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyR     s    									N(   R   R   RR   R   RQ   R   (    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyR     s   	(*   R   t   identRU   R    R9   RT   R2   t   typesRX   R   t   ParserR   R   t   TypesR   R   R   R   t   SOAPBuilderR   t	   UtilitiesR	   R
   t   M2CryptoR   t   dictR   R   R   R   R$   R1   RY   RR   R   R3   R   R   R   R   R   R   (    (    (    s1   /usr/lib/python2.7/dist-packages/SOAPpy/Server.pyt   <module>*   sB   
  		
; 