
    \dn                     r    d Z ddlZddlmZ ddlmZmZmZ  G d dej                  Z	 G d d          Z
dS )	z
SOAP support for twisted.web.

Requires SOAPpy 0.10.1 or later.

Maintainer: Itamar Shtull-Trauring

Future plans:
SOAPContext support of some kind.
Pluggable method lookup policies.
    N)defer)clientresourceserverc                   @    e Zd ZdZdZdZd Zd Zd Zd Z	d Z
dd
ZdS )SOAPPublisherzPublish SOAP methods.

    By default, publish methods beginning with 'soap_'. If the method
    has an attribute 'useKeywords', it well get the arguments passed
    as keyword args.
       zUTF-8c                 *    t          | d|z  d          S )zLookup published SOAP function.

        Override in subclasses. Default behaviour - publish methods
        starting with soap_.

        @return: callable or None if not found.
        zsoap_%sN)getattr)selffunctionNames     0lib/python3.11/site-packages/twisted/web/soap.pylookupFunctionzSOAPPublisher.lookupFunction(   s     tY5t<<<    c                    |j                                         }t          j        |ddd          \  }}}}|j        |j        |j        }	}}t          |          r
 |            }t          |	          r
 |	            }	|                     |          }
|
s"| 	                    ||           t          j        S t          |
d          rAi }|	                                D ]\  }}||t          |          <   t          j        |
fi |}nt          j        |
g|R  }|                    | j        ||           |                    | j        ||           t          j        S )zHandle a SOAP command.r	   useKeywords)contentreadSOAPpyparseSOAPRPC_name_aslist_asdictcallabler   _methodNotFoundr   NOT_DONE_YEThasattritemsstrr   maybeDeferredaddCallback
_gotResult
addErrback	_gotError)r   requestdatapheaderbodyattrs
methodNameargskwargsfunctionkeywordskvds                  r   renderzSOAPPublisher.render2   sg   ##%%!'!4T1a!C!C64#$7AIqy&D
 D>> 	466DF 	VXXF&&z22 
	9  *555&&x// 9"LLNN ) )DAq'(HSVV$$'==H=='84888	dow
;;;	T^Wj999""r   c                     t          j        t          j        dt           j        j        z  d|z            | j                  }|                     ||d           d S )Nz	%s:ClientzMethod %s not foundencoding  status)r   	buildSOAP	faultTypeNSENV_Tr6   _sendResponse)r   r%   r+   responses       r   r   zSOAPPublisher._methodNotFoundR   sg    #fio-/Dz/Q  ]	
 
 
 	7HS99999r   c                     t          |t          j                  sd|i}t          j        d|z  |i| j                  }|                     ||           d S )NResultz
%sResponse)kwr6   )
isinstancer   voidTyper:   r6   r>   )r   resultr%   r+   r?   s        r   r"   zSOAPPublisher._gotResult[   sf    &&/22 	('F#z)62T]
 
 
 	7H-----r   c                    |j         }t          |t          j                  r|}n*t          j        dt          j        j        z  d|z            }t          j        || j                  }|                     ||d           d S )Nz	%s:ServerzMethod %s failed.r5   r7   r8   )	valuerC   r   r;   r<   r=   r:   r6   r>   )r   failurer%   r+   efaultr?   s          r   r$   zSOAPPublisher._gotErrorc   s    Ma)** 	EE$fio-/BZ/O E #EDMBBB7HS99999r      c                 6   |                     |           | j        d| j        z  }nd}|                    d|           |                    dt          t	          |                               |                    |           |                                 d S )Nztext/xml; charset="%s"text/xmlzContent-typezContent-length)setResponseCoder6   	setHeaderr   lenwritefinish)r   r%   r?   r9   mimeTypes        r   r>   zSOAPPublisher._sendResponsen   s    '''=$/$-?HH!H.(333*CH,>,>???hr   N)rK   )__name__
__module____qualname____doc__isLeafr6   r   r3   r   r"   r$   r>    r   r   r   r      s          F H= = =# # #@: : :. . .	: 	: 	:
 
 
 
 
 
r   r   c                   &    e Zd ZdZddZd Zd ZdS )Proxya  A Proxy for making remote SOAP calls.

    Pass the URL of the remote SOAP server to the constructor.

    Use proxy.callRemote('foobar', 1, 2) to call remote method
    'foobar' with args 1 and 2, proxy.callRemote('foobar', x=1)
    will call foobar with named argument 'x'.
    Nc                 0    || _         || _        || _        d S )N)url	namespacer(   )r   r]   r^   r(   s       r   __init__zProxy.__init__   s    "r   c                     t          j        |          }t          |d          r|j        S t	          |          dk    r|d         S |S )NrA   r	   r   )r   r   r   rA   rP   )r   rE   s     r   _cbGotResultzProxy._cbGotResult   sN    $V,,68$$ 
	= [[A !9Mr   c                     t          j        |||| j        | j                  }t	          j        | j        |dd|d                              | j                  S )N)r,   rB   methodr(   r^   POSTrM   )zcontent-type
SOAPAction)postdatarc   headers)	r   r:   r(   r^   r   getPager]   r!   ra   )r   rc   r,   r-   payloads        r   
callRemotezProxy.callRemote   so    ";n
 
 
 ~H%/vFF	
 
 

 +d'
(
(	)r   )NN)rT   rU   rV   rW   r_   ra   rj   rY   r   r   r[   r[   {   sP            
  ) ) ) ) )r   r[   )rW   r   twisted.internetr   twisted.webr   r   r   Resourcer   r[   rY   r   r   <module>rn      s   
 
  " " " " " " 1 0 0 0 0 0 0 0 0 0] ] ] ] ]H% ] ] ]@+) +) +) +) +) +) +) +) +) +)r   