%[Lc@s2dZddlZddljZddlmZddlTddlmZddlm Z m Z ddl m Z ddl mZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlm Z ddl!m"Z"ddl#m#Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)e)e*Z+de,fdYZ-dd*dYZdd+dYZ.dd,dYZ/d d-d!YZ0d"d.d#YZ1d$d/d%YZ2d&e2fd'YZ3d(d0d)YZ4dS(1sX The I{2nd generation} service proxy provides access to web services. See I{README.txt} iN(t CookieJar(t*(tDefinitionsReader(tTransportErrortRequest(tHttpAuthenticated(tServiceDefinition(t sudsobject(tFactory(tObject(t PathResolver(tBuilder(t Definitions(t ObjectCache(tDocument(tParser(tOptions(tUnskin(turlparse(tdeepcopy(tPluginContainer(t getLoggertClientcBseZdZedZedZedZdZdZdZ dZ dZ d Z d Z d ZRS( s A lightweight web services client. I{(2nd generation)} API. @ivar wsdl: The WSDL object. @type wsdl:L{Definitions} @ivar service: The service proxy used to invoke operations. @type service: L{Service} @ivar factory: The factory used to create objects. @type factory: L{Factory} @ivar sd: The service definition @type sd: L{ServiceDefinition} @ivar messages: The last sent/received messages. @type messages: str[2] cCs tj|S(s Extract the I{items} from a suds object much like the items() method works on I{dict}. @param sobject: A suds object @type sobject: L{Object} @return: A list of items contained in I{sobject}. @rtype: [(key, value),...] (Rtitems(tclstsobject((s//usr/lib/python2.7/site-packages/suds/client.pyR@s cCs tj|S(s Convert a sudsobject into a dictionary. @param sobject: A suds object @type sobject: L{Object} @return: A python dictionary containing the items contained in I{sobject}. @rtype: dict (Rtasdict(RR((s//usr/lib/python2.7/site-packages/suds/client.pytdictLs cCs|jS(s Extract the metadata from a suds object. @param sobject: A suds object @type sobject: L{Object} @return: The object's metadata @rtype: L{sudsobject.Metadata} (t __metadata__(RR((s//usr/lib/python2.7/site-packages/suds/client.pytmetadataXs cKs t}t|_||_tdd|_|j|t|t}|j ||_ t |j }|j jd|j t|j |_t||j j|_g|_x6|j jD](}t|j |}|jj|qWtdddd|_dS(s @param url: The URL for the WSDL. @type url: str @param kwargs: keyword arguments. @see: L{Options} tdaysitwsdlttxtrxN(RRt transporttoptionsR tcachet set_optionsRR topenRRtpluginstinitt initializedRtfactorytServiceSelectortservicestservicetsdRtappendRtNonetmessages(tselfturltkwargsR#treaderR'tsR.((s//usr/lib/python2.7/site-packages/suds/client.pyt__init__cs      cKs t|j}|j|dS(sa Set options. @param kwargs: keyword arguments. @see: L{Options} N(RR#tupdate(R2R4tp((s//usr/lib/python2.7/site-packages/suds/client.pyR%{scCsk|jj}|j|d}|dkr>|j||dS|d|krgtd||fndS(s Add I{static} mapping of an XML namespace prefix to a namespace. This is useful for cases when a wsdl and referenced schemas make heavy use of namespaces and those namespaces are subject to changed. @param prefix: An XML namespace prefix. @type prefix: str @param uri: An XML namespace URI. @type uri: str @raise Exception: when prefix is already mapped. Nis"%s" already mapped as "%s"(Rtroott resolvePrefixR0t addPrefixt Exception(R2tprefixturiR:tmapped((s//usr/lib/python2.7/site-packages/suds/client.pyt add_prefixs  cCs|jjdS(s| Get last sent I{soap} message. @return: The last sent I{soap} message. @rtype: L{Document} R (R1tget(R2((s//usr/lib/python2.7/site-packages/suds/client.pyt last_sentscCs|jjdS(s Get last received I{soap} message. @return: The last received I{soap} message. @rtype: L{Document} R!(R1RB(R2((s//usr/lib/python2.7/site-packages/suds/client.pyt last_receivedscCsdtfdY}|}t|_t|j}t|j}|jt||j|_|j|_t||jj |_ |j |_ t dddd|_|S(s Get a shallow clone of this object. The clone only shares the WSDL. All other attributes are unique to the cloned object including options. @return: A shallow clone. @rtype: L{Client} t UninitializedcBseZdZRS(cSsdS(N((R2((s//usr/lib/python2.7/site-packages/suds/client.pyR7s(t__name__t __module__R7(((s//usr/lib/python2.7/site-packages/suds/client.pyREsR R!N(RRR#RR8RRR*R+R,R-R.RR0R1(R2REtclonetcptmp((s//usr/lib/python2.7/site-packages/suds/client.pyRHs     cCs t|S(N(tunicode(R2((s//usr/lib/python2.7/site-packages/suds/client.pyt__str__scCsdg}tjj}|jd|jdtj|jd|d|dfx(|jD]}|jdt|qbWdj|S( Ns s'Suds ( https://fedorahosted.org/suds/ )s version: %ss %s build: %siis %st(tsudst __build__tsplitR/t __version__R.RKtjoin(R2R6tbuildR.((s//usr/lib/python2.7/site-packages/suds/client.pyt __unicode__s  (RFRGt__doc__t classmethodRRRR7R%RARCRDRHRLRT(((s//usr/lib/python2.7/site-packages/suds/client.pyR1s        RcBs)eZdZdZdZdZRS(s A factory for instantiating types defined in the wsdl @ivar resolver: A schema type resolver. @type resolver: L{PathResolver} @ivar builder: A schema object builder. @type builder: L{Builder} cCs.||_t||_t|j|_dS(sW @param wsdl: A schema object. @type wsdl: L{wsdl.Definitions} N(RR tresolverR tbuilder(R2R((s//usr/lib/python2.7/site-packages/suds/client.pyR7s cCs tj}|j|jj|}|dkrCt|n|jrtj |}x|j D]"\}}t ||j |j qkWnQy|j j|}Wn8tk r}tjd|dtt||nX|jtjjd|||S(s create a WSDL type by name @param name: The name of a type defined in the WSDL. @type name: str @return: The requested object. @rtype: L{Object} screate '%s' failedtexc_infos%s created: %sN(tmetricstTimertstartRWtfindR0t TypeNotFoundtenumt InstFactorytobjecttchildrentsetattrtnameRXRSR=tlogterrortTruet BuildErrortstoptdebug(R2Rdttimerttypetresultteta((s//usr/lib/python2.7/site-packages/suds/client.pytcreates"     cCst|j||_dS(sk Set the path separator. @param ps: The new path separator. @type ps: char N(R RRW(R2tps((s//usr/lib/python2.7/site-packages/suds/client.pyt separators(RFRGRUR7RpRr(((s//usr/lib/python2.7/site-packages/suds/client.pyRs R+cBs;eZdZdZdZdZdZdZRS(s The B{service} selector is used to select a web service. In most cases, the wsdl only defines (1) service in which access by subscript is passed through to a L{PortSelector}. This is also the behavior when a I{default} service has been specified. In cases where multiple services have been defined and no default has been specified, the service is found by name (or index) and a L{PortSelector} for the service is returned. In all cases, attribute access is forwarded to the L{PortSelector} for either the I{first} service or the I{default} service (when specified). @ivar __client: A suds client. @type __client: L{Client} @ivar __services: A list of I{wsdl} services. @type __services: list cCs||_||_dS(s @param client: A suds client. @type client: L{Client} @param services: A list of I{wsdl} services. @type services: list N(t_ServiceSelector__clientt_ServiceSelector__services(R2tclientR,((s//usr/lib/python2.7/site-packages/suds/client.pyR7s cCs=|j}|dkr*|jd}n|}t||S(s9 Request to access an attribute is forwarded to the L{PortSelector} for either the I{first} service or the I{default} service (when specified). @param name: The name of a method. @type name: str @return: A L{PortSelector}. @rtype: L{PortSelector}. iN(t_ServiceSelector__dsR0t_ServiceSelector__findtgetattr(R2Rdtdefaulttport((s//usr/lib/python2.7/site-packages/suds/client.pyt __getattr__s  cCs_t|jdkr,|jd}||S|j}|dk rR|}||S|j|S(s Provides selection of the I{service} by name (string) or index (integer). In cases where only (1) service is defined or a I{default} has been specified, the request is forwarded to the L{PortSelector}. @param name: The name (or index) of a service. @type name: (int|str) @return: A L{PortSelector} for the specified service. @rtype: L{PortSelector}. iiN(tlenRtRwRvR0(R2RdRzRy((s//usr/lib/python2.7/site-packages/suds/client.pyt __getitem__-s   cCsd}t|js!tdnt|trny|j|}|j}Wqtk rjtd|qXn-x*|jD]}||jkrx|}PqxqxW|dkrt|nt |j |j |S(s Find a I{service} by name (string) or index (integer). @param name: The name (or index) of a service. @type name: (int|str) @return: A L{PortSelector} for the found service. @rtype: L{PortSelector}. sNo services definedsat [%d]N( R0R|RtR=t isinstancetintRdt IndexErrortServiceNotFoundt PortSelectorRstports(R2RdR-R6((s//usr/lib/python2.7/site-packages/suds/client.pyt__findAs       cCs0|jjj}|dkrdS|j|SdS(s Get the I{default} service if defined in the I{options}. @return: A L{PortSelector} for the I{default} service. @rtype: L{PortSelector}. N(RsR#R-R0Rw(R2tds((s//usr/lib/python2.7/site-packages/suds/client.pyt__ds[s (RFRGRUR7R{R}RwRv(((s//usr/lib/python2.7/site-packages/suds/client.pyR+s    RcBs;eZdZdZdZdZdZdZRS(sv The B{port} selector is used to select a I{web service} B{port}. In cases where multiple ports have been defined and no default has been specified, the port is found by name (or index) and a L{MethodSelector} for the port is returned. In all cases, attribute access is forwarded to the L{MethodSelector} for either the I{first} port or the I{default} port (when specified). @ivar __client: A suds client. @type __client: L{Client} @ivar __ports: A list of I{service} ports. @type __ports: list @ivar __qn: The I{qualified} name of the port (used for logging). @type __qn: str cCs||_||_||_dS(s @param client: A suds client. @type client: L{Client} @param ports: A list of I{service} ports. @type ports: list @param qn: The name of the service. @type qn: str N(t_PortSelector__clientt_PortSelector__portst_PortSelector__qn(R2RuRtqn((s//usr/lib/python2.7/site-packages/suds/client.pyR7ws  cCs=|j}|dkr*|jd}n|}t||S(s9 Request to access an attribute is forwarded to the L{MethodSelector} for either the I{first} port or the I{default} port (when specified). @param name: The name of a method. @type name: str @return: A L{MethodSelector}. @rtype: L{MethodSelector}. iN(t_PortSelector__dpR0t_PortSelector__findRx(R2RdRytm((s//usr/lib/python2.7/site-packages/suds/client.pyR{s  cCs-|j}|dkr%|j|S|SdS(s Provides selection of the I{port} by name (string) or index (integer). In cases where only (1) port is defined or a I{default} has been specified, the request is forwarded to the L{MethodSelector}. @param name: The name (or index) of a port. @type name: (int|str) @return: A L{MethodSelector} for the specified port. @rtype: L{MethodSelector}. N(RR0R(R2RdRy((s//usr/lib/python2.7/site-packages/suds/client.pyR}s   cCs d}t|js(td|jnt|tr{d|j|f}y|j|}Wqtk rwt|qXnEdj |j|f}x*|jD]}||j kr|}PqqW|dkrt|ndj |j|j f}t |j |j |S(s Find a I{port} by name (string) or index (integer). @param name: The name (or index) of a port. @type name: (int|str) @return: A L{MethodSelector} for the found port. @rtype: L{MethodSelector}. sNo ports defined: %ss%s[%d]t.N(R0R|RR=RR~RRt PortNotFoundRRRdtMethodSelectorRtmethods(R2RdRzRR9((s//usr/lib/python2.7/site-packages/suds/client.pyRs$   cCs0|jjj}|dkrdS|j|SdS(s Get the I{default} port if defined in the I{options}. @return: A L{MethodSelector} for the I{default} port. @rtype: L{MethodSelector}. N(RR#RzR0R(R2tdp((s//usr/lib/python2.7/site-packages/suds/client.pyt__dps (RFRGRUR7R{R}RR(((s//usr/lib/python2.7/site-packages/suds/client.pyRhs    RcBs)eZdZdZdZdZRS(s, The B{method} selector is used to select a B{method} by name. @ivar __client: A suds client. @type __client: L{Client} @ivar __methods: A dictionary of methods. @type __methods: dict @ivar __qn: The I{qualified} name of the method (used for logging). @type __qn: str cCs||_||_||_dS(s @param client: A suds client. @type client: L{Client} @param methods: A dictionary of methods. @type methods: dict @param qn: The I{qualified} name of the port. @type qn: str N(t_MethodSelector__clientt_MethodSelector__methodst_MethodSelector__qn(R2RuRR((s//usr/lib/python2.7/site-packages/suds/client.pyR7s  cCs||S(s Get a method by name and return it in an I{execution wrapper}. @param name: The name of a method. @type name: str @return: An I{execution wrapper} for the specified method name. @rtype: L{Method} ((R2Rd((s//usr/lib/python2.7/site-packages/suds/client.pyR{scCsR|jj|}|dkrBdj|j|f}t|nt|j|S(s Get a method by name and return it in an I{execution wrapper}. @param name: The name of a method. @type name: str @return: An I{execution wrapper} for the specified method name. @rtype: L{Method} RN(RRBR0RRRtMethodNotFoundtMethodR(R2RdRR((s//usr/lib/python2.7/site-packages/suds/client.pyR}s   (RFRGRUR7R{R}(((s//usr/lib/python2.7/site-packages/suds/client.pyRs  RcBs2eZdZdZdZdZdZRS(s The I{method} (namespace) object. @ivar client: A client object. @type client: L{Client} @ivar method: A I{wsdl} method. @type I{wsdl} Method. cCs||_||_dS(s @param client: A client object. @type client: L{Client} @param method: A I{raw} method. @type I{raw} Method. N(Rutmethod(R2RuR((s//usr/lib/python2.7/site-packages/suds/client.pyR7s cOsx|j|}||j|j}|jsdy|j||SWqttk r`}d|fSXn|j||SdS(s$ Invoke the method. iN(t clientclassRuRtfaultstinvoketWebFault(R2targsR4RRuRn((s//usr/lib/python2.7/site-packages/suds/client.pyt__call__s cCs |jjjS(s get faults option (RuR#R(R2((s//usr/lib/python2.7/site-packages/suds/client.pyR scCstj|rtStSdS(s get soap client class N(t SimClientt simulationt SoapClient(R2R4((s//usr/lib/python2.7/site-packages/suds/client.pyR$s(RFRGRUR7RRR(((s//usr/lib/python2.7/site-packages/suds/client.pyRs   RcBseeZdZdZdZdZdZdZdZdZ d dZ d d Z RS( sb A lightweight soap based web client B{**not intended for external use} @ivar service: The target method. @type service: L{Service} @ivar method: A target method. @type method: L{Method} @ivar options: A dictonary of options. @type options: dict @ivar cookiejar: A cookie jar. @type cookiejar: libcookie.CookieJar cCs.||_||_|j|_t|_dS(s @param client: A suds client. @type client: L{Client} @param method: A target method. @type method: L{Method} N(RuRR#Rt cookiejar(R2RuR((s//usr/lib/python2.7/site-packages/suds/client.pyR79s   cCstj}|jd}|jjj}|j|j||}|jtj j d|jj ||j|j |}|jtj j d|jj ||S(sm Send the required soap message to invoke the specified method @param args: A list of args for the method invoked. @type args: list @param kwargs: Named (keyword) args for the method invoked. @type kwargs: dict @return: The result of the method invocation. @rtype: I{builtin}|I{subclass of} L{Object} smessage for '%s' created: %ssmethod '%s' invoked: %sN( RZR[R\R0Rtbindingtinputt get_messageRiReRjRdtsend(R2RR4RkRmRtsoapenv((s//usr/lib/python2.7/site-packages/suds/client.pyREs$         cCsd}|j}|jjj}|jj}|jj}|jj}|jj }t j d||y|j |t |jj} | jjd|j|r|j}n |j}|jd}| jjd|} | j}|rt|||St||} |j| _|j| } | jjd| j} | j| _|rf| j}n|j|| j}WnPtk r} | jdkrd}qt j |j |j!|| }nX|S( s Send soap message. @param soapenv: A soap envelope to send. @type soapenv: L{Document} @return: The reply to the sent message. @rtype: I{builtin} or I{subclass of} L{Object} ssending to (%s) message: %stenvelopesutf-8treplyiiN(ii("R0tlocationRRRR#R"tretxmltnosendt prettyxmlReRjRCRR'tmessaget marshalledR:tstrtplaintencodetsendingRtRequestContextRtheadersRtreceivedRt succeededRthttpcodeRftfailed(R2RRmRRR"RRRR'tctxtrequestRRn((s//usr/lib/python2.7/site-packages/suds/client.pyRbsD           cCsm|jjj}t|tr0|jd}nidd6|d6}t||jj}t j d||S(s Get http headers or the http/https request. @return: A dictionary of header/values. @rtype: dict sutf-8stext/xml; charset=utf-8s Content-Typet SOAPActions headers = %s( RtsoaptactionR~RKRRR#RReRj(R2RtstockRm((s//usr/lib/python2.7/site-packages/suds/client.pyRscCstjd|t|jj}t|dkr_|j|j|\}}|j|nd}|j j d|}|j }|jj r|Sd|fSdS(s_ Request succeeded, process the reply @param binding: The binding to be used to process the reply. @type binding: L{bindings.binding.Binding} @param reply: The raw reply text. @type reply: str @return: The method result. @rtype: I{builtin}, L{Object} @raise WebFault: On server. shttp succeeded: %siRiN(ReRjRR#R'R|t get_replyRRDR0Rt unmarshalledRR(R2RRR'RmR((s//usr/lib/python2.7/site-packages/suds/client.pyRs   cCs|jt|}}|jj}tjd||dkrt|dkr|j|\}}|j|||fS|dfSn|j j rt ||fn |dfSdS(s Request failed, process reply based on reason @param binding: The binding to be used to process the reply. @type binding: L{suds.bindings.binding.Binding} @param error: The http error message @type error: L{transport.TransportError} shttp failed: %siiN( RttostrtfptreadReRjR|t get_faultRDR0R#RR=(R2RRftstatustreasonRtrR9((s//usr/lib/python2.7/site-packages/suds/client.pyRs     cCs%t|j}|jd|jjS(NR(RR#RBRR(R2R9((s//usr/lib/python2.7/site-packages/suds/client.pyRscCs9d}|jj}|dkr+|j|S|||eZdZdZedZdZdZdZRS(s< Loopback client used for message/reply simulation. t__injectcCs|jtjS(s; get whether loopback has been specified in the I{kwargs}. (thas_keyRtinjkey(RR4((s//usr/lib/python2.7/site-packages/suds/client.pyRscCs||j}|jd}|jd}|jd}|dkr|dk re|j|||S|dk r~|j|Stdnt}|jd|}|j|S(sp Send the required soap message to invoke the specified method @param args: A list of args for the method invoked. @type args: list @param kwargs: Named (keyword) args for the method invoked. @type kwargs: dict @return: The result of the method invocation. @rtype: I{builtin} or I{subclass of} L{Object} tmsgRtfaults$(reply|fault) expected when msg=NonetstringN( RRBR0t_SimClient__replyt_SimClient__faultR=RtparseR(R2RR4RRRRtsax((s//usr/lib/python2.7/site-packages/suds/client.pyRs      cCsV|jjj}|j|j||}tjd||jjj}|j||S(s simulate the reply s#inject (simulated) send message: %s(RRRRReRjtoutputR(R2RRR4RR((s//usr/lib/python2.7/site-packages/suds/client.pyt__replys cCsO|jjj}|jjrG|j|\}}|j|d|fSdSdS(s simulate the (fault) reply iN(iN(RRRR#RRRDR0(R2RRRR9((s//usr/lib/python2.7/site-packages/suds/client.pyt__faults    ( RFRGRURRVRRRR(((s//usr/lib/python2.7/site-packages/suds/client.pyRs   RcBs)eZdZdZdZdZRS(s( A request context. Returned when the ''nosend'' options is specified. @ivar client: The suds client. @type client: L{Client} @ivar binding: The binding for this request. @type binding: I{Binding} @ivar envelope: The request soap envelope. @type envelope: str cCs||_||_||_dS(s @param client: The suds client. @type client: L{Client} @param binding: The binding for this request. @type binding: I{Binding} @param envelope: The request soap envelope. @type envelope: str N(RuRR(R2RuRR((s//usr/lib/python2.7/site-packages/suds/client.pyR7&s  cCsO|jj}t|j}|jjd|}|j}|jj|j|S(s Re-entry for processing a successful reply. @param reply: The reply soap envelope. @type reply: str @return: The returned value for the invoked method. @rtype: object R( RuR#RR'RRRRR(R2RR#R'R((s//usr/lib/python2.7/site-packages/suds/client.pyR3s   cCs|jj|j|S(s Re-entry for processing a failure reply. @param error: The error returned by the transport. @type error: A suds I{TransportError}. (RuRR(R2Rf((s//usr/lib/python2.7/site-packages/suds/client.pyRAs(RFRGRUR7RR(((s//usr/lib/python2.7/site-packages/suds/client.pyRs  ((((((((5RURNt suds.metricsRZt cookielibRt suds.readerRtsuds.transportRRtsuds.transport.httpsRtsuds.servicedefinitionRRRR`R t suds.resolverR t suds.builderR t suds.wsdlR t suds.cacheR tsuds.sax.documentRtsuds.sax.parserRt suds.optionsRtsuds.propertiesRRtcopyRt suds.pluginRtloggingRRFReRaRR+RRRRRR(((s//usr/lib/python2.7/site-packages/suds/client.pytsB   6fg0-7